Skip to content
Permalink
Browse files
Small refactor: Use HashCountedSet rather than HashMap<..., int> to s…
…tore client counts in WebPlaybackSessionManager{,Proxy}.

https://bugs.webkit.org/show_bug.cgi?id=165807

Reviewed by Eric Carlson.

* UIProcess/Cocoa/WebPlaybackSessionManagerProxy.h:
* UIProcess/Cocoa/WebPlaybackSessionManagerProxy.mm:
(WebKit::WebPlaybackSessionManagerProxy::addClientForContext):
(WebKit::WebPlaybackSessionManagerProxy::removeClientForContext):
* WebProcess/cocoa/WebPlaybackSessionManager.h:
* WebProcess/cocoa/WebPlaybackSessionManager.mm:
(WebKit::WebPlaybackSessionManager::addClientForContext):
(WebKit::WebPlaybackSessionManager::removeClientForContext):


Canonical link: https://commits.webkit.org/183568@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209937 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
jernoble committed Dec 16, 2016
1 parent 03a0268 commit ff5154652dae0a79793ec6d463282b113f410b52
@@ -1,3 +1,19 @@
2016-12-16 Jer Noble <jer.noble@apple.com>

Small refactor: Use HashCountedSet rather than HashMap<..., int> to store client counts in WebPlaybackSessionManager{,Proxy}.
https://bugs.webkit.org/show_bug.cgi?id=165807

Reviewed by Eric Carlson.

* UIProcess/Cocoa/WebPlaybackSessionManagerProxy.h:
* UIProcess/Cocoa/WebPlaybackSessionManagerProxy.mm:
(WebKit::WebPlaybackSessionManagerProxy::addClientForContext):
(WebKit::WebPlaybackSessionManagerProxy::removeClientForContext):
* WebProcess/cocoa/WebPlaybackSessionManager.h:
* WebProcess/cocoa/WebPlaybackSessionManager.mm:
(WebKit::WebPlaybackSessionManager::addClientForContext):
(WebKit::WebPlaybackSessionManager::removeClientForContext):

2016-12-16 Wenson Hsieh <wenson_hsieh@apple.com>

Visual viewports: carets and selection UI are incorrectly positioned when editing fixed elements
@@ -32,6 +32,7 @@
#include <WebCore/PlatformView.h>
#include <WebCore/TimeRanges.h>
#include <WebCore/WebPlaybackSessionModel.h>
#include <wtf/HashCountedSet.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/RefCounted.h>
@@ -203,7 +204,7 @@ class WebPlaybackSessionManagerProxy : public RefCounted<WebPlaybackSessionManag
WebPageProxy* m_page;
HashMap<uint64_t, ModelInterfaceTuple> m_contextMap;
uint64_t m_controlsManagerContextId { 0 };
HashMap<uint64_t, int> m_clientCounts;
HashCountedSet<uint64_t> m_clientCounts;
};

} // namespace WebKit
@@ -281,31 +281,16 @@

void WebPlaybackSessionManagerProxy::addClientForContext(uint64_t contextId)
{
auto addResult = m_clientCounts.add(contextId, 1);
if (!addResult.isNewEntry)
addResult.iterator->value++;
m_clientCounts.add(contextId);
}

void WebPlaybackSessionManagerProxy::removeClientForContext(uint64_t contextId)
{
ASSERT(m_clientCounts.contains(contextId));

int clientCount = m_clientCounts.get(contextId);
ASSERT(clientCount > 0);
clientCount--;

if (clientCount <= 0) {
m_clientCounts.remove(contextId);

RefPtr<WebPlaybackSessionModelContext> model;
RefPtr<PlatformWebPlaybackSessionInterface> interface;
std::tie(model, interface) = ensureModelAndInterface(contextId);
interface->invalidate();
m_contextMap.remove(contextId);
if (!m_clientCounts.remove(contextId))
return;
}

m_clientCounts.set(contextId, clientCount);
ensureInterface(contextId).invalidate();
m_contextMap.remove(contextId);
}

#pragma mark Messages from WebPlaybackSessionManager
@@ -34,6 +34,7 @@
#include <WebCore/PlatformCALayer.h>
#include <WebCore/WebPlaybackSessionInterface.h>
#include <WebCore/WebPlaybackSessionModelMediaElement.h>
#include <wtf/HashCountedSet.h>
#include <wtf/HashMap.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
@@ -151,7 +152,7 @@ class WebPlaybackSessionManager : public RefCounted<WebPlaybackSessionManager>,
HashMap<WebCore::HTMLMediaElement*, uint64_t> m_mediaElements;
HashMap<uint64_t, ModelInterfaceTuple> m_contextMap;
uint64_t m_controlsManagerContextId { 0 };
HashMap<uint64_t, int> m_clientCounts;
HashCountedSet<uint64_t> m_clientCounts;
};

} // namespace WebKit
@@ -213,26 +213,14 @@ static uint64_t nextContextId()

void WebPlaybackSessionManager::addClientForContext(uint64_t contextId)
{
auto addResult = m_clientCounts.add(contextId, 1);
if (!addResult.isNewEntry)
addResult.iterator->value++;
m_clientCounts.add(contextId);
}

void WebPlaybackSessionManager::removeClientForContext(uint64_t contextId)
{
ASSERT(m_clientCounts.contains(contextId));

int clientCount = m_clientCounts.get(contextId);
ASSERT(clientCount > 0);
clientCount--;

if (clientCount <= 0) {
m_clientCounts.remove(contextId);
if (m_clientCounts.remove(contextId))
removeContext(contextId);
return;
}

m_clientCounts.set(contextId, clientCount);
}

void WebPlaybackSessionManager::setUpPlaybackControlsManager(WebCore::HTMLMediaElement& mediaElement)

0 comments on commit ff51546

Please sign in to comment.