Add "Identified" base class to replace a whole bunch of custom identifier generators.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2017 21:50:27 +0000 (21:50 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2017 21:50:27 +0000 (21:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176120

Reviewed by Alex Christensen.

Source/WebCore:

No new tests (No behavior change).

Instead of repeating the common pattern of a class with an integer identifier keeping its
own static counter of the next identifier and generating it for each instance, this
uses a common template in WTF that does that automatically.

* Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp:
(WebCore::IDBServer::UniqueIDBDatabaseConnection::UniqueIDBDatabaseConnection):
(WebCore::IDBServer::UniqueIDBDatabaseConnection::connectionPendingCloseFromClient):
(WebCore::IDBServer::UniqueIDBDatabaseConnection::connectionClosedFromClient):
(WebCore::IDBServer::UniqueIDBDatabaseConnection::confirmDidCloseFromServer):
(WebCore::IDBServer::UniqueIDBDatabaseConnection::didFireVersionChangeEvent):
(WebCore::IDBServer::UniqueIDBDatabaseConnection::didFinishHandlingVersionChange):
(WebCore::IDBServer::UniqueIDBDatabaseConnection::createVersionChangeTransaction):
(WebCore::IDBServer::UniqueIDBDatabaseConnection::establishTransaction):
(WebCore::IDBServer::UniqueIDBDatabaseConnection::didAbortTransaction):
(WebCore::IDBServer::UniqueIDBDatabaseConnection::didCommitTransaction):
(WebCore::IDBServer::nextDatabaseConnectionIdentifier): Deleted.
* Modules/indexeddb/server/UniqueIDBDatabaseConnection.h:
(WebCore::IDBServer::UniqueIDBDatabaseConnection::identifier const): Deleted.

* workers/service/ServiceWorkerJobData.cpp:
(WebCore::ServiceWorkerJobData::ServiceWorkerJobData):
(WebCore::ServiceWorkerJobData::isolatedCopy const):
* workers/service/ServiceWorkerJobData.h:
(WebCore::ServiceWorkerJobData::encode const):
(WebCore::ServiceWorkerJobData::decode):
(WebCore::ServiceWorkerJobData::identifier const): Deleted.

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::Connection::Connection):
* workers/service/server/SWServer.h:
(WebCore::SWServer::Connection::identifier const): Deleted.

* workers/service/server/SWServerRegistration.cpp:
(WebCore::SWServerRegistration::SWServerRegistration):
(WebCore::SWServerRegistration::data const):
* workers/service/server/SWServerRegistration.h:
(WebCore::SWServerRegistration::identifier const): Deleted.

Source/WebKit:

* UIProcess/API/APIUserScript.cpp:
(API::UserScript::UserScript):
(API::generateIdentifier): Deleted.
* UIProcess/API/APIUserScript.h:

* UIProcess/API/APIUserStyleSheet.cpp:
(API::UserStyleSheet::UserStyleSheet):
(API::generateIdentifier): Deleted.
* UIProcess/API/APIUserStyleSheet.h:

* UIProcess/UserContent/WebScriptMessageHandler.cpp:
(WebKit::WebScriptMessageHandler::WebScriptMessageHandler):
(WebKit::generateIdentifier): Deleted.
* UIProcess/UserContent/WebScriptMessageHandler.h:
(WebKit::WebScriptMessageHandler::identifier const): Deleted.

* UIProcess/UserContent/WebUserContentControllerProxy.cpp:
(WebKit::WebUserContentControllerProxy::WebUserContentControllerProxy):
(WebKit::WebUserContentControllerProxy::~WebUserContentControllerProxy):
(WebKit::WebUserContentControllerProxy::addProcess):
(WebKit::WebUserContentControllerProxy::removeProcess):
(WebKit::WebUserContentControllerProxy::addUserContentWorldUse):
(WebKit::WebUserContentControllerProxy::removeUserContentWorldUses):
(WebKit::WebUserContentControllerProxy::addUserScript):
(WebKit::WebUserContentControllerProxy::removeUserScript):
(WebKit::WebUserContentControllerProxy::removeAllUserScripts):
(WebKit::WebUserContentControllerProxy::addUserStyleSheet):
(WebKit::WebUserContentControllerProxy::removeUserStyleSheet):
(WebKit::WebUserContentControllerProxy::removeAllUserStyleSheets):
(WebKit::WebUserContentControllerProxy::addUserScriptMessageHandler):
(WebKit::WebUserContentControllerProxy::removeUserMessageHandlerForName):
(WebKit::WebUserContentControllerProxy::removeAllUserMessageHandlers):
(WebKit::WebUserContentControllerProxy::addContentRuleList):
(WebKit::WebUserContentControllerProxy::removeContentRuleList):
(WebKit::WebUserContentControllerProxy::removeAllContentRuleLists):
(WebKit::generateIdentifier): Deleted.
* UIProcess/UserContent/WebUserContentControllerProxy.h:
(WebKit::WebUserContentControllerProxy::identifier const): Deleted.

* UIProcess/VisitedLinkStore.cpp:
(WebKit::VisitedLinkStore::~VisitedLinkStore):
(WebKit::VisitedLinkStore::VisitedLinkStore):
(WebKit::VisitedLinkStore::addProcess):
(WebKit::VisitedLinkStore::removeProcess):
(WebKit::VisitedLinkStore::removeAll):
(WebKit::VisitedLinkStore::pendingVisitedLinksTimerFired):
(WebKit::VisitedLinkStore::sendTable):
(WebKit::generateIdentifier): Deleted.
* UIProcess/VisitedLinkStore.h:

* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::WebsiteDataStore):
(WebKit::generateIdentifier): Deleted.
* UIProcess/WebsiteData/WebsiteDataStore.h:
(WebKit::WebsiteDataStore::identifier const): Deleted.

* WebProcess/Network/WebSocketStream.cpp:
(WebKit::WebSocketStream::WebSocketStream):
(WebKit::WebSocketStream::~WebSocketStream):
(WebKit::WebSocketStream::messageSenderDestinationID):
* WebProcess/Network/WebSocketStream.h:

Source/WTF:

* WTF.xcodeproj/project.pbxproj:
* wtf/Identified.h: Added.
(WTF::IdentifiedBase::identifier const):
(WTF::IdentifiedBase::IdentifiedBase):
(WTF::Identified::Identified):
(WTF::ThreadSafeIdentified::ThreadSafeIdentified):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221399 268f45cc-cd09-0410-ab3c-d52691b4dbfc

27 files changed:
Source/WTF/ChangeLog
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/Identified.h [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseConnection.h
Source/WebCore/workers/service/ServiceWorkerJobData.cpp
Source/WebCore/workers/service/ServiceWorkerJobData.h
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebCore/workers/service/server/SWServer.h
Source/WebCore/workers/service/server/SWServerRegistration.cpp
Source/WebCore/workers/service/server/SWServerRegistration.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/APIUserScript.cpp
Source/WebKit/UIProcess/API/APIUserScript.h
Source/WebKit/UIProcess/API/APIUserStyleSheet.cpp
Source/WebKit/UIProcess/API/APIUserStyleSheet.h
Source/WebKit/UIProcess/UserContent/WebScriptMessageHandler.cpp
Source/WebKit/UIProcess/UserContent/WebScriptMessageHandler.h
Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp
Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.h
Source/WebKit/UIProcess/VisitedLinkStore.cpp
Source/WebKit/UIProcess/VisitedLinkStore.h
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
Source/WebKit/WebProcess/Network/WebSocketStream.cpp
Source/WebKit/WebProcess/Network/WebSocketStream.h

index 5ae9d4f..ec871f7 100644 (file)
@@ -1,3 +1,17 @@
+2017-08-30  Brady Eidson  <beidson@apple.com>
+
+        Add "Identified" base class to replace a whole bunch of custom identifier generators.
+        https://bugs.webkit.org/show_bug.cgi?id=176120
+
+        Reviewed by Alex Christensen.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/Identified.h: Added.
+        (WTF::IdentifiedBase::identifier const):
+        (WTF::IdentifiedBase::IdentifiedBase):
+        (WTF::Identified::Identified):
+        (WTF::ThreadSafeIdentified::ThreadSafeIdentified):
+
 2017-08-22  Filip Pizlo  <fpizlo@apple.com>
 
         Strings need to be in some kind of gigacage
index d4f48c1..b0a1908 100644 (file)
                515F794C1CFC9F4A00CCED93 /* CrossThreadCopier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossThreadCopier.h; sourceTree = "<group>"; };
                515F794D1CFC9F4A00CCED93 /* CrossThreadTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossThreadTask.h; sourceTree = "<group>"; };
                515F79551CFD3A6900CCED93 /* CrossThreadQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossThreadQueue.h; sourceTree = "<group>"; };
+               517A53571F5734B700DCDC0A /* Identified.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Identified.h; sourceTree = "<group>"; };
                5182C22C1F2BC7E60059BA7C /* InstanceCounted.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InstanceCounted.h; sourceTree = "<group>"; };
                51F175241F3D486000C74950 /* PersistentCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PersistentCoder.h; sourceTree = "<group>"; };
                51F175251F3D486000C74950 /* PersistentCoders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PersistentCoders.h; sourceTree = "<group>"; };
                                A8A472B9151A825A004123FF /* HashTable.h */,
                                A8A472BA151A825A004123FF /* HashTraits.h */,
                                A8A472BB151A825A004123FF /* HexNumber.h */,
+                               517A53571F5734B700DCDC0A /* Identified.h */,
                                FE8925AF1D00DAEC0046907E /* Indenter.h */,
                                9C67C542589348E285B49699 /* IndexedContainerIterator.h */,
                                0F2AC5621E8A01490001EE3F /* IndexKeyType.h */,
diff --git a/Source/WTF/wtf/Identified.h b/Source/WTF/wtf/Identified.h
new file mode 100644 (file)
index 0000000..3b6ac95
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+namespace WTF {
+
+template <typename IdentifierType, typename StaticType, typename ClassType>
+class IdentifiedBase {
+public:
+    IdentifierType identifier() const
+    {
+        return m_identifier;
+    }
+
+protected:
+    IdentifiedBase()
+        : m_identifier(++s_currentIdentifier)
+    {
+    }
+
+    IdentifiedBase(const IdentifiedBase& other)
+        : m_identifier(other.m_identifier)
+    {
+    }
+
+    explicit IdentifiedBase(IdentifierType identifier)
+        : m_identifier(identifier)
+    {
+    }
+
+private:
+    IdentifierType m_identifier;
+    static StaticType s_currentIdentifier;
+};
+
+template<typename IdentifierType, typename StaticType, typename ClassType> StaticType IdentifiedBase<IdentifierType, StaticType, ClassType>::s_currentIdentifier;
+
+template <typename T>
+class Identified : public IdentifiedBase<uint64_t, uint64_t, T> {
+protected:
+    Identified() = default;
+    Identified(const Identified&) = default;
+
+    explicit Identified(uint64_t identifier)
+        : IdentifiedBase<uint64_t, uint64_t, T>(identifier)
+    {
+    }
+};
+
+template <typename T>
+class ThreadSafeIdentified : public IdentifiedBase<uint64_t, std::atomic<uint64_t>, T> {
+protected:
+    ThreadSafeIdentified() = default;
+    ThreadSafeIdentified(const ThreadSafeIdentified&) = default;
+
+    explicit ThreadSafeIdentified(uint64_t identifier)
+        : IdentifiedBase<uint64_t, std::atomic<uint64_t>, T>(identifier)
+    {
+    }
+};
+
+} // namespace WTF
+
+using WTF::Identified;
+using WTF::ThreadSafeIdentified;
index 5d5153f..5267c7d 100644 (file)
@@ -1,3 +1,50 @@
+2017-08-30  Brady Eidson  <beidson@apple.com>
+
+        Add "Identified" base class to replace a whole bunch of custom identifier generators.
+        https://bugs.webkit.org/show_bug.cgi?id=176120
+
+        Reviewed by Alex Christensen.
+
+        No new tests (No behavior change).
+
+        Instead of repeating the common pattern of a class with an integer identifier keeping its
+        own static counter of the next identifier and generating it for each instance, this
+        uses a common template in WTF that does that automatically.
+
+        * Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::UniqueIDBDatabaseConnection):
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::connectionPendingCloseFromClient):
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::connectionClosedFromClient):
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::confirmDidCloseFromServer):
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::didFireVersionChangeEvent):
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::didFinishHandlingVersionChange):
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::createVersionChangeTransaction):
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::establishTransaction):
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::didAbortTransaction):
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::didCommitTransaction):
+        (WebCore::IDBServer::nextDatabaseConnectionIdentifier): Deleted.
+        * Modules/indexeddb/server/UniqueIDBDatabaseConnection.h:
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::identifier const): Deleted.
+
+        * workers/service/ServiceWorkerJobData.cpp:
+        (WebCore::ServiceWorkerJobData::ServiceWorkerJobData):
+        (WebCore::ServiceWorkerJobData::isolatedCopy const):
+        * workers/service/ServiceWorkerJobData.h:
+        (WebCore::ServiceWorkerJobData::encode const):
+        (WebCore::ServiceWorkerJobData::decode):
+        (WebCore::ServiceWorkerJobData::identifier const): Deleted.
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::Connection::Connection):
+        * workers/service/server/SWServer.h:
+        (WebCore::SWServer::Connection::identifier const): Deleted.
+
+        * workers/service/server/SWServerRegistration.cpp:
+        (WebCore::SWServerRegistration::SWServerRegistration):
+        (WebCore::SWServerRegistration::data const):
+        * workers/service/server/SWServerRegistration.h:
+        (WebCore::SWServerRegistration::identifier const): Deleted.
+
 2017-08-30  Youenn Fablet  <youenn@apple.com>
 
         Remove FetchRequest::InternalRequest
index 694b717..84015d8 100644 (file)
 namespace WebCore {
 namespace IDBServer {
 
-static uint64_t nextDatabaseConnectionIdentifier()
-{
-    static uint64_t nextIdentifier = 0;
-    return ++nextIdentifier;
-}
-
 Ref<UniqueIDBDatabaseConnection> UniqueIDBDatabaseConnection::create(UniqueIDBDatabase& database, ServerOpenDBRequest& request)
 {
     return adoptRef(*new UniqueIDBDatabaseConnection(database, request));
 }
 
 UniqueIDBDatabaseConnection::UniqueIDBDatabaseConnection(UniqueIDBDatabase& database, ServerOpenDBRequest& request)
-    : m_identifier(nextDatabaseConnectionIdentifier())
-    , m_database(database)
+    : m_database(database)
     , m_connectionToClient(request.connection())
     , m_openRequestIdentifier(request.requestData().requestIdentifier())
 {
@@ -85,35 +78,35 @@ void UniqueIDBDatabaseConnection::abortTransactionWithoutCallback(UniqueIDBDatab
 
 void UniqueIDBDatabaseConnection::connectionPendingCloseFromClient()
 {
-    LOG(IndexedDB, "UniqueIDBDatabaseConnection::connectionPendingCloseFromClient - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), m_identifier);
+    LOG(IndexedDB, "UniqueIDBDatabaseConnection::connectionPendingCloseFromClient - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), identifier());
 
     m_closePending = true;
 }
 
 void UniqueIDBDatabaseConnection::connectionClosedFromClient()
 {
-    LOG(IndexedDB, "UniqueIDBDatabaseConnection::connectionClosedFromClient - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), m_identifier);
+    LOG(IndexedDB, "UniqueIDBDatabaseConnection::connectionClosedFromClient - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), identifier());
 
     m_database.connectionClosedFromClient(*this);
 }
 
 void UniqueIDBDatabaseConnection::confirmDidCloseFromServer()
 {
-    LOG(IndexedDB, "UniqueIDBDatabaseConnection::confirmDidCloseFromServer - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), m_identifier);
+    LOG(IndexedDB, "UniqueIDBDatabaseConnection::confirmDidCloseFromServer - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), identifier());
 
     m_database.confirmDidCloseFromServer(*this);
 }
 
 void UniqueIDBDatabaseConnection::didFireVersionChangeEvent(const IDBResourceIdentifier& requestIdentifier)
 {
-    LOG(IndexedDB, "UniqueIDBDatabaseConnection::didFireVersionChangeEvent - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), m_identifier);
+    LOG(IndexedDB, "UniqueIDBDatabaseConnection::didFireVersionChangeEvent - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), identifier());
 
     m_database.didFireVersionChangeEvent(*this, requestIdentifier);
 }
 
 void UniqueIDBDatabaseConnection::didFinishHandlingVersionChange(const IDBResourceIdentifier& transactionIdentifier)
 {
-    LOG(IndexedDB, "UniqueIDBDatabaseConnection::didFinishHandlingVersionChange - %s - %" PRIu64, transactionIdentifier.loggingString().utf8().data(), m_identifier);
+    LOG(IndexedDB, "UniqueIDBDatabaseConnection::didFinishHandlingVersionChange - %s - %" PRIu64, transactionIdentifier.loggingString().utf8().data(), identifier());
 
     m_database.didFinishHandlingVersionChange(*this, transactionIdentifier);
 }
@@ -126,7 +119,7 @@ void UniqueIDBDatabaseConnection::fireVersionChangeEvent(const IDBResourceIdenti
 
 UniqueIDBDatabaseTransaction& UniqueIDBDatabaseConnection::createVersionChangeTransaction(uint64_t newVersion)
 {
-    LOG(IndexedDB, "UniqueIDBDatabaseConnection::createVersionChangeTransaction - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), m_identifier);
+    LOG(IndexedDB, "UniqueIDBDatabaseConnection::createVersionChangeTransaction - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), identifier());
     ASSERT(!m_closePending);
 
     IDBTransactionInfo info = IDBTransactionInfo::versionChange(m_connectionToClient, m_database.info(), newVersion);
@@ -139,7 +132,7 @@ UniqueIDBDatabaseTransaction& UniqueIDBDatabaseConnection::createVersionChangeTr
 
 void UniqueIDBDatabaseConnection::establishTransaction(const IDBTransactionInfo& info)
 {
-    LOG(IndexedDB, "UniqueIDBDatabaseConnection::establishTransaction - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), m_identifier);
+    LOG(IndexedDB, "UniqueIDBDatabaseConnection::establishTransaction - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), identifier());
 
     ASSERT(info.mode() != IDBTransactionMode::Versionchange);
 
@@ -154,7 +147,7 @@ void UniqueIDBDatabaseConnection::establishTransaction(const IDBTransactionInfo&
 
 void UniqueIDBDatabaseConnection::didAbortTransaction(UniqueIDBDatabaseTransaction& transaction, const IDBError& error)
 {
-    LOG(IndexedDB, "UniqueIDBDatabaseConnection::didAbortTransaction - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), m_identifier);
+    LOG(IndexedDB, "UniqueIDBDatabaseConnection::didAbortTransaction - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), identifier());
 
     auto transactionIdentifier = transaction.info().identifier();
     auto takenTransaction = m_transactionMap.take(transactionIdentifier);
@@ -166,7 +159,7 @@ void UniqueIDBDatabaseConnection::didAbortTransaction(UniqueIDBDatabaseTransacti
 
 void UniqueIDBDatabaseConnection::didCommitTransaction(UniqueIDBDatabaseTransaction& transaction, const IDBError& error)
 {
-    LOG(IndexedDB, "UniqueIDBDatabaseConnection::didCommitTransaction - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), m_identifier);
+    LOG(IndexedDB, "UniqueIDBDatabaseConnection::didCommitTransaction - %s - %" PRIu64, m_openRequestIdentifier.loggingString().utf8().data(), identifier());
 
     auto transactionIdentifier = transaction.info().identifier();
 
index 27d5884..2f1a29a 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "UniqueIDBDatabaseTransaction.h"
 #include <wtf/HashMap.h>
+#include <wtf/Identified.h>
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
 
@@ -44,13 +45,12 @@ class ServerOpenDBRequest;
 class UniqueIDBDatabase;
 class UniqueIDBDatabaseTransaction;
 
-class UniqueIDBDatabaseConnection : public RefCounted<UniqueIDBDatabaseConnection> {
+class UniqueIDBDatabaseConnection : public RefCounted<UniqueIDBDatabaseConnection>, public Identified<UniqueIDBDatabaseConnection> {
 public:
     static Ref<UniqueIDBDatabaseConnection> create(UniqueIDBDatabase&, ServerOpenDBRequest&);
 
     ~UniqueIDBDatabaseConnection();
 
-    uint64_t identifier() const { return m_identifier; }
     const IDBResourceIdentifier& openRequestIdentifier() { return m_openRequestIdentifier; }
     UniqueIDBDatabase& database() { return m_database; }
     IDBConnectionToClient& connectionToClient() { return m_connectionToClient; }
@@ -86,7 +86,6 @@ public:
 private:
     UniqueIDBDatabaseConnection(UniqueIDBDatabase&, ServerOpenDBRequest&);
 
-    uint64_t m_identifier { 0 };
     UniqueIDBDatabase& m_database;
     IDBConnectionToClient& m_connectionToClient;
     IDBResourceIdentifier m_openRequestIdentifier;
index 8fba67c..86a3bd7 100644 (file)
 
 namespace WebCore {
 
-static std::atomic<uint64_t> currentJobIdentifier;
-
-ServiceWorkerJobData::ServiceWorkerJobData(uint64_t connectionIdentifier)
-    : m_jobIdentifier(++currentJobIdentifier)
+ServiceWorkerJobData::ServiceWorkerJobData(uint64_t jobIdentifier, uint64_t connectionIdentifier)
+    : ThreadSafeIdentified(jobIdentifier)
     , m_connectionIdentifier(connectionIdentifier)
 {
 }
 
-ServiceWorkerJobData::ServiceWorkerJobData(const ServiceWorkerJobData& other)
+ServiceWorkerJobData::ServiceWorkerJobData(uint64_t connectionIdentifier)
+    : m_connectionIdentifier(connectionIdentifier)
 {
-    m_jobIdentifier = other.m_jobIdentifier;
-    m_connectionIdentifier = other.m_connectionIdentifier;
-    scriptURL = other.scriptURL;
-    clientCreationURL = other.clientCreationURL;
-    topOrigin = other.topOrigin;
-    scopeURL = other.scopeURL;
-    type = other.type;
-    registrationOptions = other.registrationOptions;
 }
 
 ServiceWorkerRegistrationKey ServiceWorkerJobData::registrationKey() const
@@ -57,9 +48,7 @@ ServiceWorkerRegistrationKey ServiceWorkerJobData::registrationKey() const
 
 ServiceWorkerJobData ServiceWorkerJobData::isolatedCopy() const
 {
-    ServiceWorkerJobData result;
-    result.m_jobIdentifier = m_jobIdentifier;
-    result.m_connectionIdentifier = m_connectionIdentifier;
+    ServiceWorkerJobData result { identifier(), m_connectionIdentifier };
     result.type = type;
 
     result.scriptURL = scriptURL.isolatedCopy();
index cf4eaa0..7065261 100644 (file)
 #include "ServiceWorkerRegistrationKey.h"
 #include "ServiceWorkerRegistrationOptions.h"
 #include "URL.h"
+#include <wtf/Identified.h>
 
 namespace WebCore {
 
-struct ServiceWorkerJobData {
+struct ServiceWorkerJobData : public ThreadSafeIdentified<ServiceWorkerJobData> {
 public:
     explicit ServiceWorkerJobData(uint64_t connectionIdentifier);
-    ServiceWorkerJobData(const ServiceWorkerJobData&);
+    ServiceWorkerJobData(const ServiceWorkerJobData&) = default;
     ServiceWorkerJobData() = default;
 
-    uint64_t identifier() const { return m_jobIdentifier; }
     uint64_t connectionIdentifier() const { return m_connectionIdentifier; }
 
     URL scriptURL;
@@ -56,17 +56,18 @@ public:
     ServiceWorkerJobData isolatedCopy() const;
 
     template<class Encoder> void encode(Encoder&) const;
-    template<class Decoder> static bool decode(Decoder&, ServiceWorkerJobData&);
+    template<class Decoder> static std::optional<ServiceWorkerJobData> decode(Decoder&);
 
 private:
-    uint64_t m_jobIdentifier { 0 };
+    WEBCORE_EXPORT ServiceWorkerJobData(uint64_t jobIdentifier, uint64_t connectionIdentifier);
+
     uint64_t m_connectionIdentifier { 0 };
 };
 
 template<class Encoder>
 void ServiceWorkerJobData::encode(Encoder& encoder) const
 {
-    encoder << m_jobIdentifier << m_connectionIdentifier << scriptURL << clientCreationURL << topOrigin << scopeURL;
+    encoder << identifier() << m_connectionIdentifier << scriptURL << clientCreationURL << topOrigin << scopeURL;
     encoder.encodeEnum(type);
     switch (type) {
     case ServiceWorkerJobType::Register:
@@ -76,31 +77,37 @@ void ServiceWorkerJobData::encode(Encoder& encoder) const
 }
 
 template<class Decoder>
-bool ServiceWorkerJobData::decode(Decoder& decoder, ServiceWorkerJobData& jobData)
+std::optional<ServiceWorkerJobData> ServiceWorkerJobData::decode(Decoder& decoder)
 {
-    if (!decoder.decode(jobData.m_jobIdentifier))
-        return false;
-    if (!decoder.decode(jobData.m_connectionIdentifier))
-        return false;
-    if (!decoder.decode(jobData.scriptURL))
-        return false;
-    if (!decoder.decode(jobData.clientCreationURL))
-        return false;
-    if (!decoder.decode(jobData.topOrigin))
-        return false;
-    if (!decoder.decode(jobData.scopeURL))
-        return false;
-    if (!decoder.decodeEnum(jobData.type))
-        return false;
-
-    switch (jobData.type) {
+    uint64_t jobIdentifier;
+    if (!decoder.decode(jobIdentifier))
+        return std::nullopt;
+
+    uint64_t connectionIdentifier;
+    if (!decoder.decode(connectionIdentifier))
+        return std::nullopt;
+
+    std::optional<ServiceWorkerJobData> jobData = { { jobIdentifier, connectionIdentifier } };
+
+    if (!decoder.decode(jobData->scriptURL))
+        return std::nullopt;
+    if (!decoder.decode(jobData->clientCreationURL))
+        return std::nullopt;
+    if (!decoder.decode(jobData->topOrigin))
+        return std::nullopt;
+    if (!decoder.decode(jobData->scopeURL))
+        return std::nullopt;
+    if (!decoder.decodeEnum(jobData->type))
+        return std::nullopt;
+
+    switch (jobData->type) {
     case ServiceWorkerJobType::Register:
-        if (!decoder.decode(jobData.registrationOptions))
-            return false;
+        if (!decoder.decode(jobData->registrationOptions))
+            return std::nullopt;
         break;
     }
 
-    return true;
+    return jobData;
 }
 
 } // namespace WebCore
index 5427a45..4019340 100644 (file)
@@ -38,8 +38,8 @@
 namespace WebCore {
 
 SWServer::Connection::Connection(SWServer& server, uint64_t identifier)
-    : m_server(server)
-    , m_identifier(identifier)
+    : Identified(identifier)
+    , m_server(server)
 {
     m_server.registerConnection(*this);
 }
index d3fc0c4..9bd40f7 100644 (file)
@@ -34,6 +34,7 @@
 #include <wtf/CrossThreadTask.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
+#include <wtf/Identified.h>
 #include <wtf/RunLoop.h>
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/Threading.h>
@@ -46,13 +47,11 @@ struct ServiceWorkerRegistrationData;
 
 class SWServer {
 public:
-    class Connection {
+    class Connection : public Identified<Connection> {
     friend class SWServer;
     public:
         WEBCORE_EXPORT virtual ~Connection();
 
-        uint64_t identifier() const { return m_identifier; };
-
     protected:
         WEBCORE_EXPORT Connection(SWServer&, uint64_t identifier);
         SWServer& server() { return m_server; }
@@ -64,7 +63,6 @@ public:
         virtual void resolveJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&) = 0;
 
         SWServer& m_server;
-        uint64_t m_identifier;
     };
 
     WEBCORE_EXPORT SWServer();
index ab79270..1052b9b 100644 (file)
 
 namespace WebCore {
 
-static std::atomic<uint64_t> currentIdentifier;
-
 SWServerRegistration::SWServerRegistration(SWServer& server, const ServiceWorkerRegistrationKey& key)
     : m_jobTimer(*this, &SWServerRegistration::startNextJob)
     , m_server(server)
-    , m_identifier(++currentIdentifier)
     , m_registrationKey(key)
 {
 }
@@ -203,7 +200,7 @@ void SWServerRegistration::finishCurrentJob()
 
 ServiceWorkerRegistrationData SWServerRegistration::data() const
 {
-    return { m_registrationKey, m_identifier };
+    return { m_registrationKey, identifier() };
 }
 
 
index c800068..9b6eabf 100644 (file)
@@ -31,6 +31,7 @@
 #include "ServiceWorkerRegistrationData.h"
 #include "Timer.h"
 #include <wtf/Deque.h>
+#include <wtf/Identified.h>
 
 namespace WebCore {
 
@@ -38,7 +39,7 @@ class SWServer;
 class SWServerWorker;
 struct ExceptionData;
 
-class SWServerRegistration {
+class SWServerRegistration : public ThreadSafeIdentified<SWServerRegistration> {
 public:
     explicit SWServerRegistration(SWServer&, const ServiceWorkerRegistrationKey&);
     SWServerRegistration(const SWServerRegistration&) = delete;
@@ -46,7 +47,6 @@ public:
 
     void enqueueJob(const ServiceWorkerJobData&);
 
-    uint64_t identifier() const { return m_identifier; }
     ServiceWorkerRegistrationData data() const;
 
 private:
@@ -76,7 +76,6 @@ private:
 
     Timer m_jobTimer;
     SWServer& m_server;
-    uint64_t m_identifier;
     ServiceWorkerRegistrationKey m_registrationKey;
 };
 
index 4d9dbd7..5879fe8 100644 (file)
@@ -1,5 +1,74 @@
 2017-08-30  Brady Eidson  <beidson@apple.com>
 
+        Add "Identified" base class to replace a whole bunch of custom identifier generators.
+        https://bugs.webkit.org/show_bug.cgi?id=176120
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/API/APIUserScript.cpp:
+        (API::UserScript::UserScript):
+        (API::generateIdentifier): Deleted.
+        * UIProcess/API/APIUserScript.h:
+
+        * UIProcess/API/APIUserStyleSheet.cpp:
+        (API::UserStyleSheet::UserStyleSheet):
+        (API::generateIdentifier): Deleted.
+        * UIProcess/API/APIUserStyleSheet.h:
+
+        * UIProcess/UserContent/WebScriptMessageHandler.cpp:
+        (WebKit::WebScriptMessageHandler::WebScriptMessageHandler):
+        (WebKit::generateIdentifier): Deleted.
+        * UIProcess/UserContent/WebScriptMessageHandler.h:
+        (WebKit::WebScriptMessageHandler::identifier const): Deleted.
+
+        * UIProcess/UserContent/WebUserContentControllerProxy.cpp:
+        (WebKit::WebUserContentControllerProxy::WebUserContentControllerProxy):
+        (WebKit::WebUserContentControllerProxy::~WebUserContentControllerProxy):
+        (WebKit::WebUserContentControllerProxy::addProcess):
+        (WebKit::WebUserContentControllerProxy::removeProcess):
+        (WebKit::WebUserContentControllerProxy::addUserContentWorldUse):
+        (WebKit::WebUserContentControllerProxy::removeUserContentWorldUses):
+        (WebKit::WebUserContentControllerProxy::addUserScript):
+        (WebKit::WebUserContentControllerProxy::removeUserScript):
+        (WebKit::WebUserContentControllerProxy::removeAllUserScripts):
+        (WebKit::WebUserContentControllerProxy::addUserStyleSheet):
+        (WebKit::WebUserContentControllerProxy::removeUserStyleSheet):
+        (WebKit::WebUserContentControllerProxy::removeAllUserStyleSheets):
+        (WebKit::WebUserContentControllerProxy::addUserScriptMessageHandler):
+        (WebKit::WebUserContentControllerProxy::removeUserMessageHandlerForName):
+        (WebKit::WebUserContentControllerProxy::removeAllUserMessageHandlers):
+        (WebKit::WebUserContentControllerProxy::addContentRuleList):
+        (WebKit::WebUserContentControllerProxy::removeContentRuleList):
+        (WebKit::WebUserContentControllerProxy::removeAllContentRuleLists):
+        (WebKit::generateIdentifier): Deleted.
+        * UIProcess/UserContent/WebUserContentControllerProxy.h:
+        (WebKit::WebUserContentControllerProxy::identifier const): Deleted.
+
+        * UIProcess/VisitedLinkStore.cpp:
+        (WebKit::VisitedLinkStore::~VisitedLinkStore):
+        (WebKit::VisitedLinkStore::VisitedLinkStore):
+        (WebKit::VisitedLinkStore::addProcess):
+        (WebKit::VisitedLinkStore::removeProcess):
+        (WebKit::VisitedLinkStore::removeAll):
+        (WebKit::VisitedLinkStore::pendingVisitedLinksTimerFired):
+        (WebKit::VisitedLinkStore::sendTable):
+        (WebKit::generateIdentifier): Deleted.
+        * UIProcess/VisitedLinkStore.h:
+
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::WebsiteDataStore):
+        (WebKit::generateIdentifier): Deleted.
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+        (WebKit::WebsiteDataStore::identifier const): Deleted.
+
+        * WebProcess/Network/WebSocketStream.cpp:
+        (WebKit::WebSocketStream::WebSocketStream):
+        (WebKit::WebSocketStream::~WebSocketStream):
+        (WebKit::WebSocketStream::messageSenderDestinationID):
+        * WebProcess/Network/WebSocketStream.h:
+
+2017-08-30  Brady Eidson  <beidson@apple.com>
+
         Implement all of "Register" right up until where the script is fetched.
         https://bugs.webkit.org/show_bug.cgi?id=176082
 
index 845ab57..7584e63 100644 (file)
 
 namespace API {
 
-static uint64_t generateIdentifier()
-{
-    static uint64_t identifier;
-
-    return ++identifier;
-}
-
 WebCore::URL UserScript::generateUniqueURL()
 {
     static uint64_t identifier;
@@ -48,8 +41,7 @@ WebCore::URL UserScript::generateUniqueURL()
 }
 
 UserScript::UserScript(WebCore::UserScript userScript, API::UserContentWorld& world)
-    : m_identifier(generateIdentifier())
-    , m_userScript(userScript)
+    : m_userScript(userScript)
     , m_world(world)
 {
 }
index 758350b..17a4090 100644 (file)
 #include "APIObject.h"
 #include "APIUserContentWorld.h"
 #include <WebCore/UserScript.h>
+#include <wtf/Identified.h>
 
 namespace API {
 
-class UserScript final : public ObjectImpl<Object::Type::UserScript> {
+class UserScript final : public ObjectImpl<Object::Type::UserScript>, public Identified<UserScript> {
 public:
     static WebCore::URL generateUniqueURL();
 
@@ -43,15 +44,12 @@ public:
 
     UserScript(WebCore::UserScript, API::UserContentWorld&);
 
-    uint64_t identifier() const { return m_identifier; }
-
     const WebCore::UserScript& userScript() const { return m_userScript; }
     
     UserContentWorld& userContentWorld() { return m_world; }
     const UserContentWorld& userContentWorld() const { return m_world; }
     
 private:
-    uint64_t m_identifier;
     WebCore::UserScript m_userScript;
     Ref<UserContentWorld> m_world;
 };
index 28e8009..1d595bb 100644 (file)
 
 namespace API {
 
-static uint64_t generateIdentifier()
-{
-    static uint64_t identifier;
-
-    return ++identifier;
-}
-
 WebCore::URL UserStyleSheet::generateUniqueURL()
 {
     static uint64_t identifier;
@@ -48,8 +41,7 @@ WebCore::URL UserStyleSheet::generateUniqueURL()
 }
 
 UserStyleSheet::UserStyleSheet(WebCore::UserStyleSheet userStyleSheet, API::UserContentWorld& world)
-    : m_identifier(generateIdentifier())
-    , m_userStyleSheet(userStyleSheet)
+    : m_userStyleSheet(userStyleSheet)
     , m_world(world)
 {
 }
index fe4f49b..d856f7a 100644 (file)
 #include "APIObject.h"
 #include "APIUserContentWorld.h"
 #include <WebCore/UserStyleSheet.h>
+#include <wtf/Identified.h>
 
 namespace API {
 
-class UserStyleSheet final : public ObjectImpl<Object::Type::UserStyleSheet> {
+class UserStyleSheet final : public ObjectImpl<Object::Type::UserStyleSheet>, public Identified<UserStyleSheet> {
 public:
     static WebCore::URL generateUniqueURL();
 
@@ -43,15 +44,12 @@ public:
 
     UserStyleSheet(WebCore::UserStyleSheet, API::UserContentWorld&);
 
-    uint64_t identifier() const { return m_identifier; }
-
     const WebCore::UserStyleSheet& userStyleSheet() const { return m_userStyleSheet; }
 
     UserContentWorld& userContentWorld() { return m_world; }
     const UserContentWorld& userContentWorld() const { return m_world; }
 
 private:
-    uint64_t m_identifier;
     WebCore::UserStyleSheet m_userStyleSheet;
     Ref<UserContentWorld> m_world;
 };
index 91e5cea..0515b0b 100644 (file)
 
 namespace WebKit {
 
-static uint64_t generateIdentifier()
-{
-    static uint64_t identifier;
-
-    return ++identifier;
-}
-
 Ref<WebScriptMessageHandler> WebScriptMessageHandler::create(std::unique_ptr<Client> client, const String& name, API::UserContentWorld& world)
 {
     return adoptRef(*new WebScriptMessageHandler(WTFMove(client), name, world));
 }
 
 WebScriptMessageHandler::WebScriptMessageHandler(std::unique_ptr<Client> client, const String& name, API::UserContentWorld& world)
-    : m_identifier(generateIdentifier())
-    , m_client(WTFMove(client))
+    : m_client(WTFMove(client))
     , m_name(name)
     , m_world(world)
 {
index 1c11a0a..9e012dc 100644 (file)
@@ -27,6 +27,7 @@
 #define WebScriptMessageHandler_h
 
 #include "WebUserContentControllerDataTypes.h"
+#include <wtf/Identified.h>
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
 #include <wtf/text/WTFString.h>
@@ -46,7 +47,7 @@ class WebPageProxy;
 class WebFrameProxy;
 struct FrameInfoData;
 
-class WebScriptMessageHandler : public RefCounted<WebScriptMessageHandler> {
+class WebScriptMessageHandler : public RefCounted<WebScriptMessageHandler>, public Identified<WebScriptMessageHandler>  {
 public:
     class Client {
     public:
@@ -57,7 +58,6 @@ public:
     static Ref<WebScriptMessageHandler> create(std::unique_ptr<Client>, const String& name, API::UserContentWorld&);
     virtual ~WebScriptMessageHandler();
 
-    uint64_t identifier() const { return m_identifier; }
     String name() const { return m_name; }
 
     const API::UserContentWorld& userContentWorld() const { return m_world; }
@@ -67,8 +67,6 @@ public:
 
 private:
     WebScriptMessageHandler(std::unique_ptr<Client>, const String&, API::UserContentWorld&);
-    
-    uint64_t m_identifier;
 
     std::unique_ptr<Client> m_client;
     String m_name;
index 98ce24e..4233c8e 100644 (file)
 
 namespace WebKit {
 
-static uint64_t generateIdentifier()
-{
-    static uint64_t identifier;
-
-    return ++identifier;
-}
-
 WebUserContentControllerProxy::WebUserContentControllerProxy()
-    : m_identifier(generateIdentifier())
-    , m_userScripts(API::Array::create())
+    : m_userScripts(API::Array::create())
     , m_userStyleSheets(API::Array::create())
 {
 }
@@ -63,7 +55,7 @@ WebUserContentControllerProxy::WebUserContentControllerProxy()
 WebUserContentControllerProxy::~WebUserContentControllerProxy()
 {
     for (WebProcessProxy* process : m_processes) {
-        process->removeMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), m_identifier);
+        process->removeMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), identifier());
         process->didDestroyWebUserContentControllerProxy(*this);
     }
 }
@@ -73,7 +65,7 @@ void WebUserContentControllerProxy::addProcess(WebProcessProxy& webProcessProxy,
     if (!m_processes.add(&webProcessProxy).isNewEntry)
         return;
 
-    webProcessProxy.addMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), m_identifier, *this);
+    webProcessProxy.addMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), identifier(), *this);
 
     ASSERT(parameters.userContentWorlds.isEmpty());
     for (const auto& world : m_userContentWorlds)
@@ -103,7 +95,7 @@ void WebUserContentControllerProxy::removeProcess(WebProcessProxy& webProcessPro
     ASSERT(m_processes.contains(&webProcessProxy));
 
     m_processes.remove(&webProcessProxy);
-    webProcessProxy.removeMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), m_identifier);
+    webProcessProxy.removeMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), identifier());
 }
 
 void WebUserContentControllerProxy::addUserContentWorldUse(API::UserContentWorld& world)
@@ -114,7 +106,7 @@ void WebUserContentControllerProxy::addUserContentWorldUse(API::UserContentWorld
     auto addResult = m_userContentWorlds.add(&world);
     if (addResult.isNewEntry) {
         for (WebProcessProxy* process : m_processes)
-            process->send(Messages::WebUserContentController::AddUserContentWorlds({ std::make_pair(world.identifier(), world.name()) }), m_identifier);
+            process->send(Messages::WebUserContentController::AddUserContentWorlds({ std::make_pair(world.identifier(), world.name()) }), identifier());
     }
 }
 
@@ -138,7 +130,7 @@ void WebUserContentControllerProxy::removeUserContentWorldUses(API::UserContentW
 {
     if (shouldSendRemoveUserContentWorldsMessage(world, numberOfUsesToRemove)) {
         for (WebProcessProxy* process : m_processes)
-            process->send(Messages::WebUserContentController::RemoveUserContentWorlds({ world.identifier() }), m_identifier);
+            process->send(Messages::WebUserContentController::RemoveUserContentWorlds({ world.identifier() }), identifier());
     }
 }
 
@@ -151,7 +143,7 @@ void WebUserContentControllerProxy::removeUserContentWorldUses(HashCountedSet<Re
     }
 
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::RemoveUserContentWorlds(worldsToRemove), m_identifier);
+        process->send(Messages::WebUserContentController::RemoveUserContentWorlds(worldsToRemove), identifier());
 }
 
 void WebUserContentControllerProxy::addUserScript(API::UserScript& userScript)
@@ -163,7 +155,7 @@ void WebUserContentControllerProxy::addUserScript(API::UserScript& userScript)
     m_userScripts->elements().append(&userScript);
 
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::AddUserScripts({ { userScript.identifier(), world->identifier(), userScript.userScript() } }), m_identifier);
+        process->send(Messages::WebUserContentController::AddUserScripts({ { userScript.identifier(), world->identifier(), userScript.userScript() } }), identifier());
 }
 
 void WebUserContentControllerProxy::removeUserScript(API::UserScript& userScript)
@@ -171,7 +163,7 @@ void WebUserContentControllerProxy::removeUserScript(API::UserScript& userScript
     Ref<API::UserContentWorld> world = userScript.userContentWorld();
 
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::RemoveUserScript(world->identifier(), userScript.identifier()), m_identifier);
+        process->send(Messages::WebUserContentController::RemoveUserScript(world->identifier(), userScript.identifier()), identifier());
 
     m_userScripts->elements().removeAll(&userScript);
 
@@ -181,7 +173,7 @@ void WebUserContentControllerProxy::removeUserScript(API::UserScript& userScript
 void WebUserContentControllerProxy::removeAllUserScripts(API::UserContentWorld& world)
 {
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::RemoveAllUserScripts({ world.identifier() }), m_identifier);
+        process->send(Messages::WebUserContentController::RemoveAllUserScripts({ world.identifier() }), identifier());
 
     unsigned userScriptsRemoved = m_userScripts->removeAllOfTypeMatching<API::UserScript>([&](const auto& userScript) {
         return &userScript->userContentWorld() == &world;
@@ -202,7 +194,7 @@ void WebUserContentControllerProxy::removeAllUserScripts()
         worldIdentifiers.uncheckedAppend(worldCountPair.key->identifier());
 
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::RemoveAllUserScripts(worldIdentifiers), m_identifier);
+        process->send(Messages::WebUserContentController::RemoveAllUserScripts(worldIdentifiers), identifier());
 
     m_userScripts->elements().clear();
 
@@ -218,7 +210,7 @@ void WebUserContentControllerProxy::addUserStyleSheet(API::UserStyleSheet& userS
     m_userStyleSheets->elements().append(&userStyleSheet);
 
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::AddUserStyleSheets({ { userStyleSheet.identifier(), world->identifier(), userStyleSheet.userStyleSheet() } }), m_identifier);
+        process->send(Messages::WebUserContentController::AddUserStyleSheets({ { userStyleSheet.identifier(), world->identifier(), userStyleSheet.userStyleSheet() } }), identifier());
 }
 
 void WebUserContentControllerProxy::removeUserStyleSheet(API::UserStyleSheet& userStyleSheet)
@@ -226,7 +218,7 @@ void WebUserContentControllerProxy::removeUserStyleSheet(API::UserStyleSheet& us
     Ref<API::UserContentWorld> world = userStyleSheet.userContentWorld();
 
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::RemoveUserStyleSheet(world->identifier(), userStyleSheet.identifier()), m_identifier);
+        process->send(Messages::WebUserContentController::RemoveUserStyleSheet(world->identifier(), userStyleSheet.identifier()), identifier());
 
     m_userStyleSheets->elements().removeAll(&userStyleSheet);
 
@@ -236,7 +228,7 @@ void WebUserContentControllerProxy::removeUserStyleSheet(API::UserStyleSheet& us
 void WebUserContentControllerProxy::removeAllUserStyleSheets(API::UserContentWorld& world)
 {
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::RemoveAllUserStyleSheets({ world.identifier() }), m_identifier);
+        process->send(Messages::WebUserContentController::RemoveAllUserStyleSheets({ world.identifier() }), identifier());
 
     unsigned userStyleSheetsRemoved = m_userStyleSheets->removeAllOfTypeMatching<API::UserStyleSheet>([&](const auto& userStyleSheet) {
         return &userStyleSheet->userContentWorld() == &world;
@@ -257,7 +249,7 @@ void WebUserContentControllerProxy::removeAllUserStyleSheets()
         worldIdentifiers.uncheckedAppend(worldCountPair.key->identifier());
 
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::RemoveAllUserStyleSheets(worldIdentifiers), m_identifier);
+        process->send(Messages::WebUserContentController::RemoveAllUserStyleSheets(worldIdentifiers), identifier());
 
     m_userStyleSheets->elements().clear();
 
@@ -278,7 +270,7 @@ bool WebUserContentControllerProxy::addUserScriptMessageHandler(WebScriptMessage
     m_scriptMessageHandlers.add(handler.identifier(), &handler);
 
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::AddUserScriptMessageHandlers({ { handler.identifier(), world->identifier(), handler.name() } }), m_identifier);
+        process->send(Messages::WebUserContentController::AddUserScriptMessageHandlers({ { handler.identifier(), world->identifier(), handler.name() } }), identifier());
     
     return true;
 }
@@ -288,7 +280,7 @@ void WebUserContentControllerProxy::removeUserMessageHandlerForName(const String
     for (auto it = m_scriptMessageHandlers.begin(), end = m_scriptMessageHandlers.end(); it != end; ++it) {
         if (it->value->name() == name && &it->value->userContentWorld() == &world) {
             for (WebProcessProxy* process : m_processes)
-                process->send(Messages::WebUserContentController::RemoveUserScriptMessageHandler(world.identifier(), it->value->identifier()), m_identifier);
+                process->send(Messages::WebUserContentController::RemoveUserScriptMessageHandler(world.identifier(), it->value->identifier()), identifier());
 
             m_scriptMessageHandlers.remove(it);
 
@@ -301,7 +293,7 @@ void WebUserContentControllerProxy::removeUserMessageHandlerForName(const String
 void WebUserContentControllerProxy::removeAllUserMessageHandlers(API::UserContentWorld& world)
 {
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::RemoveAllUserScriptMessageHandlers({ world.identifier() }), m_identifier);
+        process->send(Messages::WebUserContentController::RemoveAllUserScriptMessageHandlers({ world.identifier() }), identifier());
 
     unsigned numberRemoved = 0;
     m_scriptMessageHandlers.removeIf([&](auto& entry) {
@@ -339,7 +331,7 @@ void WebUserContentControllerProxy::addContentRuleList(API::ContentRuleList& con
     auto pair = std::make_pair(contentRuleList.name(), contentRuleList.compiledRuleList().data());
 
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::AddContentRuleLists({ pair }), m_identifier);
+        process->send(Messages::WebUserContentController::AddContentRuleLists({ pair }), identifier());
 }
 
 void WebUserContentControllerProxy::removeContentRuleList(const String& name)
@@ -347,7 +339,7 @@ void WebUserContentControllerProxy::removeContentRuleList(const String& name)
     m_contentRuleLists.remove(name);
 
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::RemoveContentRuleList(name), m_identifier);
+        process->send(Messages::WebUserContentController::RemoveContentRuleList(name), identifier());
 }
 
 void WebUserContentControllerProxy::removeAllContentRuleLists()
@@ -355,7 +347,7 @@ void WebUserContentControllerProxy::removeAllContentRuleLists()
     m_contentRuleLists.clear();
 
     for (WebProcessProxy* process : m_processes)
-        process->send(Messages::WebUserContentController::RemoveAllContentRuleLists(), m_identifier);
+        process->send(Messages::WebUserContentController::RemoveAllContentRuleLists(), identifier());
 }
 #endif
 
index 469306a..230f623 100644 (file)
@@ -31,6 +31,7 @@
 #include <wtf/HashCountedSet.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
+#include <wtf/Identified.h>
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
 #include <wtf/text/StringHash.h>
@@ -58,7 +59,7 @@ class WebScriptMessageHandler;
 struct FrameInfoData;
 struct WebPageCreationParameters;
 
-class WebUserContentControllerProxy : public API::ObjectImpl<API::Object::Type::UserContentController>, private IPC::MessageReceiver {
+class WebUserContentControllerProxy : public API::ObjectImpl<API::Object::Type::UserContentController>, private IPC::MessageReceiver, public Identified<WebUserContentControllerProxy> {
 public:
     static Ref<WebUserContentControllerProxy> create()
     { 
@@ -67,8 +68,6 @@ public:
     explicit WebUserContentControllerProxy();
     ~WebUserContentControllerProxy();
 
-    uint64_t identifier() const { return m_identifier; }
-
     void addProcess(WebProcessProxy&, WebPageCreationParameters&);
     void removeProcess(WebProcessProxy&);
 
@@ -108,7 +107,6 @@ private:
     void removeUserContentWorldUses(HashCountedSet<RefPtr<API::UserContentWorld>>&);
     bool shouldSendRemoveUserContentWorldsMessage(API::UserContentWorld&, unsigned numberOfUsesToRemove);
 
-    uint64_t m_identifier;
     HashSet<WebProcessProxy*> m_processes;    
     Ref<API::Array> m_userScripts;
     Ref<API::Array> m_userStyleSheets;
index 2959d59..bd002c0 100644 (file)
@@ -40,13 +40,6 @@ namespace WebKit {
 
 static const int visitedLinkTableMaxLoad = 2;
 
-static uint64_t generateIdentifier()
-{
-    static uint64_t identifier;
-
-    return ++identifier;
-}
-
 Ref<VisitedLinkStore> VisitedLinkStore::create()
 {
     return adoptRef(*new VisitedLinkStore);
@@ -55,14 +48,13 @@ Ref<VisitedLinkStore> VisitedLinkStore::create()
 VisitedLinkStore::~VisitedLinkStore()
 {
     for (WebProcessProxy* process : m_processes) {
-        process->removeMessageReceiver(Messages::VisitedLinkStore::messageReceiverName(), m_identifier);
+        process->removeMessageReceiver(Messages::VisitedLinkStore::messageReceiverName(), identifier());
         process->didDestroyVisitedLinkStore(*this);
     }
 }
 
 VisitedLinkStore::VisitedLinkStore()
-    : m_identifier(generateIdentifier())
-    , m_keyCount(0)
+    : m_keyCount(0)
     , m_tableSize(0)
     , m_pendingVisitedLinksTimer(RunLoop::main(), this, &VisitedLinkStore::pendingVisitedLinksTimerFired)
 {
@@ -75,7 +67,7 @@ void VisitedLinkStore::addProcess(WebProcessProxy& process)
     if (!m_processes.add(&process).isNewEntry)
         return;
 
-    process.addMessageReceiver(Messages::VisitedLinkStore::messageReceiverName(), m_identifier, *this);
+    process.addMessageReceiver(Messages::VisitedLinkStore::messageReceiverName(), identifier(), *this);
 
     if (!m_keyCount)
         return;
@@ -90,7 +82,7 @@ void VisitedLinkStore::removeProcess(WebProcessProxy& process)
     ASSERT(m_processes.contains(&process));
 
     m_processes.remove(&process);
-    process.removeMessageReceiver(Messages::VisitedLinkStore::messageReceiverName(), m_identifier);
+    process.removeMessageReceiver(Messages::VisitedLinkStore::messageReceiverName(), identifier());
 }
 
 void VisitedLinkStore::addVisitedLinkHash(LinkHash linkHash)
@@ -111,7 +103,7 @@ void VisitedLinkStore::removeAll()
 
     for (WebProcessProxy* process : m_processes) {
         ASSERT(process->processPool().processes().contains(process));
-        process->send(Messages::VisitedLinkTableController::RemoveAllVisitedLinks(), m_identifier);
+        process->send(Messages::VisitedLinkTableController::RemoveAllVisitedLinks(), identifier());
     }
 }
 
@@ -194,9 +186,9 @@ void VisitedLinkStore::pendingVisitedLinksTimerFired()
         ASSERT(process->processPool().processes().contains(process));
 
         if (addedVisitedLinks.size() > 20)
-            process->send(Messages::VisitedLinkTableController::AllVisitedLinkStateChanged(), m_identifier);
+            process->send(Messages::VisitedLinkTableController::AllVisitedLinkStateChanged(), identifier());
         else
-            process->send(Messages::VisitedLinkTableController::VisitedLinkStateChanged(addedVisitedLinks), m_identifier);
+            process->send(Messages::VisitedLinkTableController::VisitedLinkStateChanged(addedVisitedLinks), identifier());
     }
 }
 
@@ -253,7 +245,7 @@ void VisitedLinkStore::sendTable(WebProcessProxy& process)
     if (!m_table.sharedMemory()->createHandle(handle, SharedMemory::Protection::ReadOnly))
         return;
 
-    process.send(Messages::VisitedLinkTableController::SetVisitedLinkTable(handle), m_identifier);
+    process.send(Messages::VisitedLinkTableController::SetVisitedLinkTable(handle), identifier());
 }
 
 } // namespace WebKit
index 00032f3..5c6ad8d 100644 (file)
@@ -34,6 +34,7 @@
 #include <WebCore/LinkHash.h>
 #include <wtf/Forward.h>
 #include <wtf/HashSet.h>
+#include <wtf/Identified.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RunLoop.h>
 
@@ -42,15 +43,13 @@ namespace WebKit {
 class WebPageProxy;
 class WebProcessProxy;
     
-class VisitedLinkStore final : public API::ObjectImpl<API::Object::Type::VisitedLinkStore>, private IPC::MessageReceiver, public WebProcessLifetimeObserver {
+class VisitedLinkStore final : public API::ObjectImpl<API::Object::Type::VisitedLinkStore>, private IPC::MessageReceiver, public WebProcessLifetimeObserver, public Identified<VisitedLinkStore>  {
 public:
     static Ref<VisitedLinkStore> create();
 
     explicit VisitedLinkStore();
     virtual ~VisitedLinkStore();
 
-    uint64_t identifier() const { return m_identifier; }
-
     void addProcess(WebProcessProxy&);
     void removeProcess(WebProcessProxy&);
 
@@ -74,8 +73,6 @@ private:
 
     HashSet<WebProcessProxy*> m_processes;
 
-    uint64_t m_identifier;
-
     unsigned m_keyCount;
     unsigned m_tableSize;
     VisitedLinkTable m_table;
index db54c24..47b7511 100644 (file)
 
 namespace WebKit {
 
-static uint64_t generateIdentifier()
-{
-    static uint64_t identifier;
-
-    return ++identifier;
-}
-
 Ref<WebsiteDataStore> WebsiteDataStore::createNonPersistent()
 {
     return adoptRef(*new WebsiteDataStore(PAL::SessionID::generateEphemeralSessionID()));
@@ -72,8 +65,7 @@ Ref<WebsiteDataStore> WebsiteDataStore::create(Configuration configuration, PAL:
 }
 
 WebsiteDataStore::WebsiteDataStore(Configuration configuration, PAL::SessionID sessionID)
-    : m_identifier(generateIdentifier())
-    , m_sessionID(sessionID)
+    : m_sessionID(sessionID)
     , m_configuration(WTFMove(configuration))
     , m_storageManager(StorageManager::create(m_configuration.localStorageDirectory))
     , m_queue(WorkQueue::create("com.apple.WebKit.WebsiteDataStore"))
@@ -82,8 +74,7 @@ WebsiteDataStore::WebsiteDataStore(Configuration configuration, PAL::SessionID s
 }
 
 WebsiteDataStore::WebsiteDataStore(PAL::SessionID sessionID)
-    : m_identifier(generateIdentifier())
-    , m_sessionID(sessionID)
+    : m_sessionID(sessionID)
     , m_configuration()
     , m_queue(WorkQueue::create("com.apple.WebKit.WebsiteDataStore"))
 {
index e6429a7..3af1167 100644 (file)
@@ -32,6 +32,7 @@
 #include <pal/SessionID.h>
 #include <wtf/Function.h>
 #include <wtf/HashSet.h>
+#include <wtf/Identified.h>
 #include <wtf/OptionSet.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
@@ -64,7 +65,7 @@ struct PluginModuleInfo;
 
 enum class ShouldClearFirst { No, Yes };
 
-class WebsiteDataStore : public RefCounted<WebsiteDataStore>, public WebProcessLifetimeObserver {
+class WebsiteDataStore : public RefCounted<WebsiteDataStore>, public WebProcessLifetimeObserver, public Identified<WebsiteDataStore>  {
 public:
     struct Configuration {
         String cacheStorageDirectory;
@@ -85,8 +86,6 @@ public:
     static Ref<WebsiteDataStore> create(Configuration, PAL::SessionID);
     virtual ~WebsiteDataStore();
 
-    uint64_t identifier() const { return m_identifier; }
-
     bool isPersistent() const { return !m_sessionID.isEphemeral(); }
     PAL::SessionID sessionID() const { return m_sessionID; }
 
@@ -159,7 +158,6 @@ private:
     static void removeMediaKeys(const String& mediaKeysStorageDirectory, std::chrono::system_clock::time_point modifiedSince);
     static void removeMediaKeys(const String& mediaKeysStorageDirectory, const HashSet<WebCore::SecurityOriginData>&);
 
-    const uint64_t m_identifier;
     const PAL::SessionID m_sessionID;
 
     const Configuration m_configuration;
index a2857dc..bdc62ad 100644 (file)
@@ -41,8 +41,6 @@ using namespace WebCore;
 
 namespace WebKit {
 
-static uint64_t nextAvailableIdentifier = 1;
-
 static HashMap<uint64_t, WebSocketStream*>& globalWebSocketStreamMap()
 {
     static NeverDestroyed<HashMap<uint64_t, WebSocketStream*>> globalMap;
@@ -72,19 +70,18 @@ Ref<WebSocketStream> WebSocketStream::create(const URL& url, SocketStreamHandleC
 
 WebSocketStream::WebSocketStream(const WebCore::URL& url, WebCore::SocketStreamHandleClient& client, PAL::SessionID sessionID, const String& cachePartition)
     : SocketStreamHandle(url, client)
-    , m_identifier(nextAvailableIdentifier++)
     , m_client(client)
 {
-    WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::CreateSocketStream(url, sessionID, cachePartition, m_identifier), 0);
+    WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::CreateSocketStream(url, sessionID, cachePartition, identifier()), 0);
 
-    ASSERT(!globalWebSocketStreamMap().contains(m_identifier));
-    globalWebSocketStreamMap().set(m_identifier, this);
+    ASSERT(!globalWebSocketStreamMap().contains(identifier()));
+    globalWebSocketStreamMap().set(identifier(), this);
 }
 
 WebSocketStream::~WebSocketStream()
 {
-    ASSERT(globalWebSocketStreamMap().contains(m_identifier));
-    globalWebSocketStreamMap().remove(m_identifier);
+    ASSERT(globalWebSocketStreamMap().contains(identifier()));
+    globalWebSocketStreamMap().remove(identifier());
 }
 
 IPC::Connection* WebSocketStream::messageSenderConnection()
@@ -94,7 +91,7 @@ IPC::Connection* WebSocketStream::messageSenderConnection()
 
 uint64_t WebSocketStream::messageSenderDestinationID()
 {
-    return m_identifier;
+    return identifier();
 }
 
 void WebSocketStream::platformSend(const char* data, size_t length, Function<void(bool)>&& completionHandler)
index d50cad2..9e9b834 100644 (file)
@@ -29,6 +29,7 @@
 #include "MessageSender.h"
 #include <WebCore/SocketStreamHandle.h>
 #include <pal/SessionID.h>
+#include <wtf/Identified.h>
 
 namespace IPC {
 class Connection;
@@ -42,7 +43,7 @@ class SocketStreamError;
 
 namespace WebKit {
 
-class WebSocketStream : public IPC::MessageSender, public IPC::MessageReceiver, public WebCore::SocketStreamHandle {
+class WebSocketStream : public IPC::MessageSender, public IPC::MessageReceiver, public WebCore::SocketStreamHandle, public Identified<WebSocketStream> {
 public:
     static Ref<WebSocketStream> create(const WebCore::URL&, WebCore::SocketStreamHandleClient&, PAL::SessionID, const String& credentialPartition);
     static void networkProcessCrashed();
@@ -74,7 +75,6 @@ private:
     ~WebSocketStream();
 
     size_t m_bufferedAmount { 0 };
-    uint64_t m_identifier { 0 };
     WebCore::SocketStreamHandleClient& m_client;
     HashMap<uint64_t, Function<void(bool)>> m_sendDataCallbacks;
 };