NetworkProcessConnection does not need HashMaps of sessionIDs for Service Workers...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Sep 2019 21:52:05 +0000 (21:52 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Sep 2019 21:52:05 +0000 (21:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=201830

Reviewed by Geoffrey Garen.

NetworkProcessConnection does not need HashMaps of sessionIDs for Service Workers and IDB, since
we now have one sessionID per WebContent process.

* NetworkProcess/IndexedDB/WebIDBConnectionToClient.h:
* NetworkProcess/ServiceWorker/WebSWServerConnection.h:
* WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp:
(WebKit::WebIDBConnectionToServer::create):
(WebKit::WebIDBConnectionToServer::WebIDBConnectionToServer):
* WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.h:
* WebProcess/Databases/WebDatabaseProvider.cpp:
(WebKit::WebDatabaseProvider::idbConnectionToServerForSession):
* WebProcess/Network/NetworkProcessConnection.cpp:
(WebKit::NetworkProcessConnection::didReceiveMessage):
(WebKit::NetworkProcessConnection::didClose):
(WebKit::NetworkProcessConnection::idbConnectionToServerForSession):
(WebKit::NetworkProcessConnection::serviceWorkerConnectionForSession):
* WebProcess/Network/NetworkProcessConnection.h:
(WebKit::NetworkProcessConnection::existingIDBConnectionToServer const):
(WebKit::NetworkProcessConnection::existingServiceWorkerConnectionForSession):
* WebProcess/Storage/WebServiceWorkerProvider.cpp:
(WebKit::WebServiceWorkerProvider::serviceWorkerConnectionForSession):
(WebKit::WebServiceWorkerProvider::existingServiceWorkerConnectionForSession):
(WebKit::WebServiceWorkerProvider::handleFetch):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::networkProcessConnectionClosed):

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

Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/IndexedDB/WebIDBConnectionToClient.h
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h
Source/WebKit/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp
Source/WebKit/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.h
Source/WebKit/WebProcess/Databases/WebDatabaseProvider.cpp
Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp
Source/WebKit/WebProcess/Network/NetworkProcessConnection.h
Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp
Source/WebKit/WebProcess/WebProcess.cpp

index 126f0ce..e974b57 100644 (file)
@@ -1,3 +1,36 @@
+2019-09-16  Chris Dumez  <cdumez@apple.com>
+
+        NetworkProcessConnection does not need HashMaps of sessionIDs for Service Workers and IDB
+        https://bugs.webkit.org/show_bug.cgi?id=201830
+
+        Reviewed by Geoffrey Garen.
+
+        NetworkProcessConnection does not need HashMaps of sessionIDs for Service Workers and IDB, since
+        we now have one sessionID per WebContent process.
+
+        * NetworkProcess/IndexedDB/WebIDBConnectionToClient.h:
+        * NetworkProcess/ServiceWorker/WebSWServerConnection.h:
+        * WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp:
+        (WebKit::WebIDBConnectionToServer::create):
+        (WebKit::WebIDBConnectionToServer::WebIDBConnectionToServer):
+        * WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.h:
+        * WebProcess/Databases/WebDatabaseProvider.cpp:
+        (WebKit::WebDatabaseProvider::idbConnectionToServerForSession):
+        * WebProcess/Network/NetworkProcessConnection.cpp:
+        (WebKit::NetworkProcessConnection::didReceiveMessage):
+        (WebKit::NetworkProcessConnection::didClose):
+        (WebKit::NetworkProcessConnection::idbConnectionToServerForSession):
+        (WebKit::NetworkProcessConnection::serviceWorkerConnectionForSession):
+        * WebProcess/Network/NetworkProcessConnection.h:
+        (WebKit::NetworkProcessConnection::existingIDBConnectionToServer const):
+        (WebKit::NetworkProcessConnection::existingServiceWorkerConnectionForSession):
+        * WebProcess/Storage/WebServiceWorkerProvider.cpp:
+        (WebKit::WebServiceWorkerProvider::serviceWorkerConnectionForSession):
+        (WebKit::WebServiceWorkerProvider::existingServiceWorkerConnectionForSession):
+        (WebKit::WebServiceWorkerProvider::handleFetch):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::networkProcessConnectionClosed):
+
 2019-09-16  Brent Fulgham  <bfulgham@apple.com>
 
         [FTW] Correct lifespan of other SharedBitmaps
index 222c93f..dc732d8 100644 (file)
@@ -73,7 +73,7 @@ private:
     WebIDBConnectionToClient(NetworkProcess&, IPC::Connection&, WebCore::ProcessIdentifier, PAL::SessionID);
 
     IPC::Connection* messageSenderConnection() const final;
-    uint64_t messageSenderDestinationID() const final { return m_sessionID.toUInt64(); }
+    uint64_t messageSenderDestinationID() const final { return 0; }
 
     // Messages received from WebProcess
     void deleteDatabase(const WebCore::IDBRequestData&);
index f2e9c6c..10e442e 100644 (file)
@@ -105,7 +105,7 @@ private:
     void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source);
 
     IPC::Connection* messageSenderConnection() const final { return m_contentConnection.ptr(); }
-    uint64_t messageSenderDestinationID() const final { return m_sessionID.toUInt64(); }
+    uint64_t messageSenderDestinationID() const final { return 0; }
     
     template<typename U> static void sendToContextProcess(WebCore::SWServerToContextConnection&, U&& message);
 
index 9733a63..33eea24 100644 (file)
 namespace WebKit {
 using namespace WebCore;
 
-Ref<WebIDBConnectionToServer> WebIDBConnectionToServer::create(PAL::SessionID sessionID)
+Ref<WebIDBConnectionToServer> WebIDBConnectionToServer::create()
 {
-    return adoptRef(*new WebIDBConnectionToServer(sessionID));
+    return adoptRef(*new WebIDBConnectionToServer());
 }
 
-WebIDBConnectionToServer::WebIDBConnectionToServer(PAL::SessionID sessionID)
-    : m_sessionID(sessionID)
-    , m_connectionToServer(IDBClient::IDBConnectionToServer::create(*this))
+WebIDBConnectionToServer::WebIDBConnectionToServer()
+    : m_connectionToServer(IDBClient::IDBConnectionToServer::create(*this))
 {
     send(Messages::NetworkConnectionToWebProcess::EstablishIDBConnectionToServer(), 0);
 }
index cd9a987..b25259f 100644 (file)
@@ -31,7 +31,6 @@
 #include "SandboxExtension.h"
 #include <WebCore/IDBConnectionToServer.h>
 #include <WebCore/ProcessIdentifier.h>
-#include <pal/SessionID.h>
 
 namespace WebKit {
 
@@ -39,7 +38,7 @@ class WebIDBResult;
 
 class WebIDBConnectionToServer final : private WebCore::IDBClient::IDBConnectionToServerDelegate, private IPC::MessageSender, public RefCounted<WebIDBConnectionToServer> {
 public:
-    static Ref<WebIDBConnectionToServer> create(PAL::SessionID);
+    static Ref<WebIDBConnectionToServer> create();
     virtual ~WebIDBConnectionToServer();
 
     WebCore::IDBClient::IDBConnectionToServer& coreConnectionToServer();
@@ -52,10 +51,10 @@ public:
     void deref() final { RefCounted<WebIDBConnectionToServer>::deref(); }
 
 private:
-    explicit WebIDBConnectionToServer(PAL::SessionID);
+    WebIDBConnectionToServer();
 
     IPC::Connection* messageSenderConnection() const final;
-    uint64_t messageSenderDestinationID() const final { return m_sessionID.toUInt64(); }
+    uint64_t messageSenderDestinationID() const final { return 0; }
 
     // IDBConnectionToServerDelegate
     void deleteDatabase(const WebCore::IDBRequestData&) final;
@@ -112,7 +111,6 @@ private:
     void notifyOpenDBRequestBlocked(const WebCore::IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion);
     void didGetAllDatabaseNames(uint64_t callbackID, const Vector<String>& databaseNames);
 
-    PAL::SessionID m_sessionID;
     Ref<WebCore::IDBClient::IDBConnectionToServer> m_connectionToServer;
 };
 
index 1728dcd..044d772 100644 (file)
@@ -67,9 +67,9 @@ WebDatabaseProvider::~WebDatabaseProvider()
 }
 
 #if ENABLE(INDEXED_DATABASE)
-WebCore::IDBClient::IDBConnectionToServer& WebDatabaseProvider::idbConnectionToServerForSession(const PAL::SessionID& sessionID)
+WebCore::IDBClient::IDBConnectionToServer& WebDatabaseProvider::idbConnectionToServerForSession(const PAL::SessionID&)
 {
-    return WebProcess::singleton().ensureNetworkProcessConnection().idbConnectionToServerForSession(sessionID).coreConnectionToServer();
+    return WebProcess::singleton().ensureNetworkProcessConnection().idbConnectionToServerForSession().coreConnectionToServer();
 }
 #endif
 
index 53e7e13..6a75791 100644 (file)
@@ -130,17 +130,16 @@ void NetworkProcessConnection::didReceiveMessage(IPC::Connection& connection, IP
 
 #if ENABLE(INDEXED_DATABASE)
     if (decoder.messageReceiverName() == Messages::WebIDBConnectionToServer::messageReceiverName()) {
-        if (auto* idbConnection = m_webIDBConnectionsBySession.get(decoder.destinationID()))
-            idbConnection->didReceiveMessage(connection, decoder);
+        if (m_webIDBConnection)
+            m_webIDBConnection->didReceiveMessage(connection, decoder);
         return;
     }
 #endif
 
 #if ENABLE(SERVICE_WORKER)
     if (decoder.messageReceiverName() == Messages::WebSWClientConnection::messageReceiverName()) {
-        auto serviceWorkerConnection = m_swConnectionsBySession.get(PAL::SessionID { decoder.destinationID() });
-        if (serviceWorkerConnection)
-            serviceWorkerConnection->didReceiveMessage(connection, decoder);
+        if (m_swConnection)
+            m_swConnection->didReceiveMessage(connection, decoder);
         return;
     }
     if (decoder.messageReceiverName() == Messages::ServiceWorkerClientFetch::messageReceiverName()) {
@@ -195,15 +194,13 @@ void NetworkProcessConnection::didClose(IPC::Connection&)
     WebProcess::singleton().networkProcessConnectionClosed(this);
 
 #if ENABLE(INDEXED_DATABASE)
-    auto idbConnections = std::exchange(m_webIDBConnectionsBySession, { });
-    for (auto& connection : idbConnections.values())
-        connection->connectionToServerLost();
+    if (auto idbConnection = std::exchange(m_webIDBConnection, nullptr))
+        idbConnection->connectionToServerLost();
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    auto swConnections = std::exchange(m_swConnectionsBySession, { });
-    for (auto& connection : swConnections.values())
-        connection->connectionToServerLost();
+    if (auto swConnection = std::exchange(m_swConnection, nullptr))
+        swConnection->connectionToServerLost();
 #endif
 }
 
@@ -249,21 +246,20 @@ void NetworkProcessConnection::didCacheResource(const ResourceRequest& request,
 #endif
 
 #if ENABLE(INDEXED_DATABASE)
-WebIDBConnectionToServer& NetworkProcessConnection::idbConnectionToServerForSession(PAL::SessionID sessionID)
+WebIDBConnectionToServer& NetworkProcessConnection::idbConnectionToServerForSession()
 {
-    return *m_webIDBConnectionsBySession.ensure(sessionID.toUInt64(), [&] {
-        return WebIDBConnectionToServer::create(sessionID);
-    }).iterator->value;
+    if (!m_webIDBConnection)
+        m_webIDBConnection = WebIDBConnectionToServer::create();
+    return *m_webIDBConnection;
 }
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-WebSWClientConnection& NetworkProcessConnection::serviceWorkerConnectionForSession(PAL::SessionID sessionID)
+WebSWClientConnection& NetworkProcessConnection::serviceWorkerConnection()
 {
-    ASSERT(sessionID.isValid());
-    return *m_swConnectionsBySession.ensure(sessionID, [] {
-        return WebSWClientConnection::create();
-    }).iterator->value;
+    if (!m_swConnection)
+        m_swConnection = WebSWClientConnection::create();
+    return *m_swConnection;
 }
 #endif
 
index 62cf8f9..494ea7e 100644 (file)
@@ -71,13 +71,13 @@ public:
     void writeBlobsToTemporaryFiles(PAL::SessionID, const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&&);
 
 #if ENABLE(INDEXED_DATABASE)
-    WebIDBConnectionToServer* existingIDBConnectionToServer(PAL::SessionID sessionID) const { return m_webIDBConnectionsBySession.get(sessionID.toUInt64()); };
-    WebIDBConnectionToServer& idbConnectionToServerForSession(PAL::SessionID);
+    WebIDBConnectionToServer* existingIDBConnectionToServer() const { return m_webIDBConnection.get(); };
+    WebIDBConnectionToServer& idbConnectionToServerForSession();
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    WebSWClientConnection* existingServiceWorkerConnectionForSession(PAL::SessionID sessionID) { return m_swConnectionsBySession.get(sessionID); }
-    WebSWClientConnection& serviceWorkerConnectionForSession(PAL::SessionID);
+    WebSWClientConnection* existingServiceWorkerConnection() { return m_swConnection.get(); }
+    WebSWClientConnection& serviceWorkerConnection();
 #endif
 
     WTF::ProcessID networkProcessPID() const { return m_networkProcessPID; }
@@ -108,12 +108,11 @@ private:
     WTF::ProcessID m_networkProcessPID { 0 };
 
 #if ENABLE(INDEXED_DATABASE)
-    HashMap<uint64_t, RefPtr<WebIDBConnectionToServer>> m_webIDBConnectionsBySession;
+    RefPtr<WebIDBConnectionToServer> m_webIDBConnection;
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    // FIXME: This should be a single connection.
-    HashMap<PAL::SessionID, RefPtr<WebSWClientConnection>> m_swConnectionsBySession;
+    RefPtr<WebSWClientConnection> m_swConnection;
 #endif
 };
 
index 1637779..ab4d82e 100644 (file)
@@ -56,16 +56,17 @@ WebServiceWorkerProvider::WebServiceWorkerProvider()
 
 WebCore::SWClientConnection& WebServiceWorkerProvider::serviceWorkerConnectionForSession(SessionID sessionID)
 {
-    ASSERT(sessionID.isValid());
-    return WebProcess::singleton().ensureNetworkProcessConnection().serviceWorkerConnectionForSession(sessionID);
+    ASSERT_UNUSED(sessionID, sessionID == WebProcess::singleton().sessionID());
+    return WebProcess::singleton().ensureNetworkProcessConnection().serviceWorkerConnection();
 }
 
 WebCore::SWClientConnection* WebServiceWorkerProvider::existingServiceWorkerConnectionForSession(SessionID sessionID)
 {
+    ASSERT_UNUSED(sessionID, sessionID == WebProcess::singleton().sessionID());
     auto* networkProcessConnection = WebProcess::singleton().existingNetworkProcessConnection();
     if (!networkProcessConnection)
         return nullptr;
-    return networkProcessConnection->existingServiceWorkerConnectionForSession(sessionID);
+    return networkProcessConnection->existingServiceWorkerConnection();
 }
 
 static inline bool shouldHandleFetch(const ResourceLoaderOptions& options)
@@ -81,12 +82,14 @@ static inline bool shouldHandleFetch(const ResourceLoaderOptions& options)
 
 void WebServiceWorkerProvider::handleFetch(ResourceLoader& loader, PAL::SessionID sessionID, bool shouldClearReferrerOnHTTPSToHTTPRedirect, ServiceWorkerClientFetch::Callback&& callback)
 {
+    ASSERT_UNUSED(sessionID, sessionID == WebProcess::singleton().sessionID());
+
     if (!SchemeRegistry::canServiceWorkersHandleURLScheme(loader.request().url().protocol().toStringWithoutCopying()) || !shouldHandleFetch(loader.options())) {
         callback(ServiceWorkerClientFetch::Result::Unhandled);
         return;
     }
 
-    auto& connection = WebProcess::singleton().ensureNetworkProcessConnection().serviceWorkerConnectionForSession(sessionID);
+    auto& connection = WebProcess::singleton().ensureNetworkProcessConnection().serviceWorkerConnection();
     auto fetchIdentifier = makeObjectIdentifier<FetchIdentifierType>(loader.identifier());
     m_ongoingFetchTasks.add(fetchIdentifier, ServiceWorkerClientFetch::create(*this, loader, fetchIdentifier, connection, shouldClearReferrerOnHTTPSToHTTPRedirect, WTFMove(callback)));
 }
index 169acca..ff884fb 100644 (file)
@@ -1255,8 +1255,8 @@ void WebProcess::networkProcessConnectionClosed(NetworkProcessConnection* connec
         if (!idbConnection)
             continue;
         
-        if (connection->existingIDBConnectionToServer(page->corePage()->sessionID())) {
-            ASSERT(idbConnection == &connection->existingIDBConnectionToServer(page->corePage()->sessionID())->coreConnectionToServer());
+        if (auto* existingIDBConnectionToServer = connection->existingIDBConnectionToServer()) {
+            ASSERT(idbConnection == &existingIDBConnectionToServer->coreConnectionToServer());
             page->corePage()->clearIDBConnection();
         }
     }