Title: [224792] trunk
Revision
224792
Author
[email protected]
Date
2017-11-13 16:20:25 -0800 (Mon, 13 Nov 2017)

Log Message

matchRegistration does not need to go to StorageProcess if no service worker is registered
https://bugs.webkit.org/show_bug.cgi?id=179480

Patch by Youenn Fablet <[email protected]> on 2017-11-13
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/activation.https-expected.txt:
* web-platform-tests/service-workers/service-worker/activation.https.html:
* web-platform-tests/service-workers/service-worker/registration-iframe.https.html:

Source/WebCore:

Covered by existing tests.

Moving the origin store in SWServer since they share the same session ID.
This allows updating the origin store based on each registration map update.
This also allows clearing the origin store when clearing the SWServer.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* workers/service/server/SWOriginStore.cpp: Added.
(WebCore::SWOriginStore::add):
(WebCore::SWOriginStore::remove):
(WebCore::SWOriginStore::clear):
(WebCore::SWOriginStore::clearAll):
* workers/service/server/SWOriginStore.h: Added.
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::addRegistration):
(WebCore::SWServer::removeRegistration):
(WebCore::SWServer::OriginStore::add):
(WebCore::SWServer::OriginStore::remove):
(WebCore::SWServer::OriginStore::clear):
(WebCore::SWServer::OriginStore::clearAll):
(WebCore::SWServer::clearAll):
(WebCore::SWServer::clear):
(WebCore::SWServer::SWServer):
* workers/service/server/SWServer.h:
(WebCore::SWServer::originStore):

Source/WebKit:

Removed origin store handling from StorageProcess since it is now handled within SWServer.
Updated clearing of web site data accordingly.
Optimized matchRegistration by looking at the origin store before doing any IPC.
Do IPC to the StorageProcess if the origin store is not yet initialized on the WebProcess.

* StorageProcess/ServiceWorker/WebSWOriginStore.h:
* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::resolveRegistrationJobInClient):
(WebKit::WebSWServerConnection::resolveUnregistrationJobInClient):
* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::deleteWebsiteData):
(WebKit::StorageProcess::deleteWebsiteDataForOrigins):
(WebKit::StorageProcess::swServerForSession):
(WebKit::StorageProcess::swOriginStoreForSession):
(WebKit::StorageProcess::registerSWServerConnection):
(WebKit::StorageProcess::unregisterSWServerConnection):
(WebKit::StorageProcess::ensureSWOriginStoreForSession): Deleted.
(WebKit::StorageProcess::swOriginStoreForSession const): Deleted.
* StorageProcess/StorageProcess.h:
* StorageProcess/ServiceWorker/WebSWOriginStore.cpp:
(WebKit::WebSWOriginStore::addToStore):
(WebKit::WebSWOriginStore::removeFromStore):
(WebKit::WebSWOriginStore::clearStore):
(WebKit::WebSWOriginStore::add): Deleted.
(WebKit::WebSWOriginStore::remove): Deleted.
(WebKit::WebSWOriginStore::clear): Deleted.
* StorageProcess/ServiceWorker/WebSWOriginStore.h:
* WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::matchRegistration):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (224791 => 224792)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-14 00:20:25 UTC (rev 224792)
@@ -1,3 +1,14 @@
+2017-11-13  Youenn Fablet  <[email protected]>
+
+        matchRegistration does not need to go to StorageProcess if no service worker is registered
+        https://bugs.webkit.org/show_bug.cgi?id=179480
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/service-workers/service-worker/activation.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/activation.https.html:
+        * web-platform-tests/service-workers/service-worker/registration-iframe.https.html:
+
 2017-11-12  Maciej Stachowiak  <[email protected]>
 
         Remove support for UTF-32 variant text encodings

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https-expected.txt (224791 => 224792)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https-expected.txt	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https-expected.txt	2017-11-14 00:20:25 UTC (rev 224792)
@@ -1,5 +1,5 @@
+  
 
-
 FAIL loss of controllees triggers activation assert_not_equals: got disallowed value null
 FAIL finishing a request triggers activation assert_not_equals: got disallowed value null
 FAIL skipWaiting bypasses no controllee requirement assert_not_equals: got disallowed value null

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https.html (224791 => 224792)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https.html	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https.html	2017-11-14 00:20:25 UTC (rev 224792)
@@ -1,6 +1,7 @@
 <!DOCTYPE html>
 <meta charset="utf-8">
 <title>service worker: activation</title>
+<body>
 <script src=""
 <script src=""
 <script src=""
@@ -177,3 +178,4 @@
         });
   }, 'finishing a request triggers unregister');
 </script>
+</body>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-iframe.https.html (224791 => 224792)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-iframe.https.html	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-iframe.https.html	2017-11-14 00:20:25 UTC (rev 224792)
@@ -1,6 +1,7 @@
 <!DOCTYPE html>
 <meta charset="utf-8">
 <title>Service Worker: Registration for iframe</title>
+<body>
 <script src=""
 <script src=""
 <script src=""
@@ -112,3 +113,4 @@
   }, 'A scope url should start with the given script url');
 
 </script>
+</body>

Modified: trunk/Source/WebCore/ChangeLog (224791 => 224792)


--- trunk/Source/WebCore/ChangeLog	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/Source/WebCore/ChangeLog	2017-11-14 00:20:25 UTC (rev 224792)
@@ -1,3 +1,37 @@
+2017-11-13  Youenn Fablet  <[email protected]>
+
+        matchRegistration does not need to go to StorageProcess if no service worker is registered
+        https://bugs.webkit.org/show_bug.cgi?id=179480
+
+        Reviewed by Chris Dumez.
+
+        Covered by existing tests.
+
+        Moving the origin store in SWServer since they share the same session ID.
+        This allows updating the origin store based on each registration map update.
+        This also allows clearing the origin store when clearing the SWServer.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * workers/service/server/SWOriginStore.cpp: Added.
+        (WebCore::SWOriginStore::add):
+        (WebCore::SWOriginStore::remove):
+        (WebCore::SWOriginStore::clear):
+        (WebCore::SWOriginStore::clearAll):
+        * workers/service/server/SWOriginStore.h: Added.
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::addRegistration):
+        (WebCore::SWServer::removeRegistration):
+        (WebCore::SWServer::OriginStore::add):
+        (WebCore::SWServer::OriginStore::remove):
+        (WebCore::SWServer::OriginStore::clear):
+        (WebCore::SWServer::OriginStore::clearAll):
+        (WebCore::SWServer::clearAll):
+        (WebCore::SWServer::clear):
+        (WebCore::SWServer::SWServer):
+        * workers/service/server/SWServer.h:
+        (WebCore::SWServer::originStore):
+
 2017-11-13  Alex Christensen  <[email protected]>
 
         Merge NetworkProcess::EnsurePrivateBrowsingSession and NetworkProcess::AddWebsiteDataStore into one message type

Modified: trunk/Source/WebCore/Sources.txt (224791 => 224792)


--- trunk/Source/WebCore/Sources.txt	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/Source/WebCore/Sources.txt	2017-11-14 00:20:25 UTC (rev 224792)
@@ -2190,6 +2190,7 @@
 workers/service/context/SWContextManager.cpp
 
 workers/service/server/SWClientConnection.cpp
+workers/service/server/SWOriginStore.cpp
 workers/service/server/SWServer.cpp
 workers/service/server/SWServerJobQueue.cpp
 workers/service/server/SWServerRegistration.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (224791 => 224792)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-11-14 00:20:25 UTC (rev 224792)
@@ -990,6 +990,7 @@
 		415080361E3F00AD0051D75D /* LibWebRTCAudioModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 415080341E3F00AA0051D75D /* LibWebRTCAudioModule.cpp */; };
 		415080371E3F00B00051D75D /* LibWebRTCAudioModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 415080351E3F00AA0051D75D /* LibWebRTCAudioModule.h */; };
 		4150F9F112B6E0E70008C860 /* SliderThumbElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4150F9EF12B6E0E70008C860 /* SliderThumbElement.h */; };
+		4151E5BB1FBA4C7A00E47E2D /* SWOriginStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 4151E5B71FBA4C7500E47E2D /* SWOriginStore.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		415747471E3869A400E914D8 /* LibWebRTCMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 415747431E38699E00E914D8 /* LibWebRTCMacros.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		415747481E3869A700E914D8 /* LibWebRTCProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 415747441E38699E00E914D8 /* LibWebRTCProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4157EBFA1E3AB67900AC9FE9 /* MockLibWebRTCPeerConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4157EBF91E3AB06800AC9FE9 /* MockLibWebRTCPeerConnection.cpp */; };
@@ -6941,6 +6942,8 @@
 		415080351E3F00AA0051D75D /* LibWebRTCAudioModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCAudioModule.h; path = libwebrtc/LibWebRTCAudioModule.h; sourceTree = "<group>"; };
 		4150F9EF12B6E0E70008C860 /* SliderThumbElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SliderThumbElement.h; sourceTree = "<group>"; };
 		4150F9F012B6E0E70008C860 /* SliderThumbElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SliderThumbElement.cpp; sourceTree = "<group>"; };
+		4151E5B71FBA4C7500E47E2D /* SWOriginStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWOriginStore.h; sourceTree = "<group>"; };
+		4151E5B91FBA4C7600E47E2D /* SWOriginStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWOriginStore.cpp; sourceTree = "<group>"; };
 		415747431E38699E00E914D8 /* LibWebRTCMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCMacros.h; path = libwebrtc/LibWebRTCMacros.h; sourceTree = "<group>"; };
 		415747441E38699E00E914D8 /* LibWebRTCProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCProvider.h; path = libwebrtc/LibWebRTCProvider.h; sourceTree = "<group>"; };
 		4157EBF81E3AB06800AC9FE9 /* MockLibWebRTCPeerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockLibWebRTCPeerConnection.h; sourceTree = "<group>"; };
@@ -17131,6 +17134,8 @@
 			children = (
 				517A52FE1F478CCE00DCDC0A /* SWClientConnection.cpp */,
 				517A52FF1F478CCE00DCDC0A /* SWClientConnection.h */,
+				4151E5B91FBA4C7600E47E2D /* SWOriginStore.cpp */,
+				4151E5B71FBA4C7500E47E2D /* SWOriginStore.h */,
 				517A52EF1F47535900DCDC0A /* SWServer.cpp */,
 				517A52EE1F47535900DCDC0A /* SWServer.h */,
 				8311C0001FAA2E8900E3C8E5 /* SWServerJobQueue.cpp */,
@@ -29409,6 +29414,7 @@
 				B2E4EC980D00C22B00432643 /* SVGZoomEvent.h in Headers */,
 				517A531D1F4B53B100DCDC0A /* SWClientConnection.h in Headers */,
 				46658DC91FA24B8700F7DD54 /* SWContextManager.h in Headers */,
+				4151E5BB1FBA4C7A00E47E2D /* SWOriginStore.h in Headers */,
 				517A52F01F47535B00DCDC0A /* SWServer.h in Headers */,
 				8311C0031FAA2E9500E3C8E5 /* SWServerJobQueue.h in Headers */,
 				51F645971F4A686F00B54DED /* SWServerRegistration.h in Headers */,

Copied: trunk/Source/WebCore/workers/service/server/SWOriginStore.cpp (from rev 224791, trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.h) (0 => 224792)


--- trunk/Source/WebCore/workers/service/server/SWOriginStore.cpp	                        (rev 0)
+++ trunk/Source/WebCore/workers/service/server/SWOriginStore.cpp	2017-11-14 00:20:25 UTC (rev 224792)
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "SWOriginStore.h"
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "SecurityOrigin.h"
+#include <wtf/text/StringHash.h>
+
+namespace WebCore {
+
+void SWOriginStore::add(const SecurityOrigin& origin)
+{
+    ++m_originCounts.ensure(origin.toString(), [&] {
+        addToStore(origin);
+        return 0;
+    }).iterator->value;
+}
+
+void SWOriginStore::remove(const SecurityOrigin& origin)
+{
+    auto iterator = m_originCounts.find(origin.toString());
+    ASSERT(iterator != m_originCounts.end());
+    if (iterator == m_originCounts.end())
+        return;
+
+    if (--iterator->value)
+        return;
+
+    m_originCounts.remove(iterator);
+    removeFromStore(origin);
+}
+
+void SWOriginStore::clear(const SecurityOrigin& origin)
+{
+    m_originCounts.remove(origin.toString());
+    removeFromStore(origin);
+}
+
+void SWOriginStore::clearAll()
+{
+    m_originCounts.clear();
+    clearStore();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)

Copied: trunk/Source/WebCore/workers/service/server/SWOriginStore.h (from rev 224791, trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.h) (0 => 224792)


--- trunk/Source/WebCore/workers/service/server/SWOriginStore.h	                        (rev 0)
+++ trunk/Source/WebCore/workers/service/server/SWOriginStore.h	2017-11-14 00:20:25 UTC (rev 224792)
@@ -0,0 +1,55 @@
+/*
+ * 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
+
+#if ENABLE(SERVICE_WORKER)
+
+#include <wtf/HashMap.h>
+
+namespace WebCore {
+
+class SecurityOrigin;
+
+class SWOriginStore {
+public:
+    virtual ~SWOriginStore() = default;
+
+    void add(const SecurityOrigin&);
+    void remove(const SecurityOrigin&);
+    void clear(const SecurityOrigin&);
+    void clearAll();
+
+private:
+    virtual void addToStore(const SecurityOrigin&) = 0;
+    virtual void removeFromStore(const SecurityOrigin&) = 0;
+    virtual void clearStore() = 0;
+
+    HashMap<String, uint64_t> m_originCounts;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (224791 => 224792)


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2017-11-14 00:20:25 UTC (rev 224792)
@@ -31,6 +31,7 @@
 #include "ExceptionCode.h"
 #include "ExceptionData.h"
 #include "Logging.h"
+#include "SWOriginStore.h"
 #include "SWServerJobQueue.h"
 #include "SWServerRegistration.h"
 #include "SWServerWorker.h"
@@ -84,21 +85,36 @@
 void SWServer::addRegistration(std::unique_ptr<SWServerRegistration>&& registration)
 {
     auto key = registration->key();
-    m_registrations.add(key, WTFMove(registration));
+    auto result = m_registrations.add(key, WTFMove(registration));
+    ASSERT_UNUSED(result, result.isNewEntry);
+
+    m_originStore->add(key.topOrigin().securityOrigin());
 }
 
-void SWServer::removeRegistration(const ServiceWorkerRegistrationKey& registrationKey)
+void SWServer::removeRegistration(const ServiceWorkerRegistrationKey& key)
 {
-    m_registrations.remove(registrationKey);
+    auto topOrigin = key.topOrigin().securityOrigin();
+    auto result = m_registrations.remove(key);
+    ASSERT_UNUSED(result, result);
+
+    m_originStore->remove(topOrigin);
 }
 
-void SWServer::clear()
+void SWServer::clearAll()
 {
     m_jobQueues.clear();
     m_registrations.clear();
+    m_originStore->clearAll();
     // FIXME: We should probably ask service workers to terminate.
 }
 
+void SWServer::clear(const SecurityOrigin& origin)
+{
+    m_originStore->clear(origin);
+
+    // FIXME: We should clear entries in m_registrations, m_jobQueues and m_workersByID.
+}
+
 void SWServer::Connection::scheduleJobInServer(const ServiceWorkerJobData& jobData)
 {
     LOG(ServiceWorker, "Scheduling ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.identifier());
@@ -152,7 +168,8 @@
     m_server.scriptContextStarted(*this, registrationKey, identifier);
 }
 
-SWServer::SWServer()
+SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore)
+    : m_originStore(WTFMove(originStore))
 {
     m_taskThread = Thread::create(ASCIILiteral("ServiceWorker Task Thread"), [this] {
         taskThreadEntryPoint();

Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (224791 => 224792)


--- trunk/Source/WebCore/workers/service/server/SWServer.h	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h	2017-11-14 00:20:25 UTC (rev 224792)
@@ -40,9 +40,11 @@
 #include <wtf/RunLoop.h>
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/Threading.h>
+#include <wtf/UniqueRef.h>
 
 namespace WebCore {
 
+class SWOriginStore;
 class SWServerJobQueue;
 class SWServerRegistration;
 enum class ServiceWorkerRegistrationState;
@@ -96,11 +98,13 @@
         SWServer& m_server;
     };
 
-    WEBCORE_EXPORT SWServer();
+    WEBCORE_EXPORT explicit SWServer(UniqueRef<SWOriginStore>&&);
     WEBCORE_EXPORT ~SWServer();
 
-    WEBCORE_EXPORT void clear();
+    WEBCORE_EXPORT void clearAll();
+    WEBCORE_EXPORT void clear(const SecurityOrigin&);
 
+
     SWServerRegistration* getRegistration(const ServiceWorkerRegistrationKey&);
     void addRegistration(std::unique_ptr<SWServerRegistration>&&);
     void removeRegistration(const ServiceWorkerRegistrationKey&);
@@ -120,6 +124,7 @@
     SWServerWorker* workerByID(ServiceWorkerIdentifier identifier) const { return m_workersByID.get(identifier); }
     
     Connection* getConnection(uint64_t identifier) { return m_connections.get(identifier); }
+    SWOriginStore& originStore() { return m_originStore; }
 
 private:
     void registerConnection(Connection&);
@@ -155,6 +160,7 @@
 
     Lock m_mainThreadReplyLock;
     bool m_mainThreadReplyScheduled { false };
+    UniqueRef<SWOriginStore> m_originStore;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebKit/ChangeLog (224791 => 224792)


--- trunk/Source/WebKit/ChangeLog	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/Source/WebKit/ChangeLog	2017-11-14 00:20:25 UTC (rev 224792)
@@ -1,3 +1,40 @@
+2017-11-13  Youenn Fablet  <[email protected]>
+
+        matchRegistration does not need to go to StorageProcess if no service worker is registered
+        https://bugs.webkit.org/show_bug.cgi?id=179480
+
+        Reviewed by Chris Dumez.
+
+        Removed origin store handling from StorageProcess since it is now handled within SWServer.
+        Updated clearing of web site data accordingly.
+        Optimized matchRegistration by looking at the origin store before doing any IPC.
+        Do IPC to the StorageProcess if the origin store is not yet initialized on the WebProcess.
+
+        * StorageProcess/ServiceWorker/WebSWOriginStore.h:
+        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::resolveRegistrationJobInClient):
+        (WebKit::WebSWServerConnection::resolveUnregistrationJobInClient):
+        * StorageProcess/StorageProcess.cpp:
+        (WebKit::StorageProcess::deleteWebsiteData):
+        (WebKit::StorageProcess::deleteWebsiteDataForOrigins):
+        (WebKit::StorageProcess::swServerForSession):
+        (WebKit::StorageProcess::swOriginStoreForSession):
+        (WebKit::StorageProcess::registerSWServerConnection):
+        (WebKit::StorageProcess::unregisterSWServerConnection):
+        (WebKit::StorageProcess::ensureSWOriginStoreForSession): Deleted.
+        (WebKit::StorageProcess::swOriginStoreForSession const): Deleted.
+        * StorageProcess/StorageProcess.h:
+        * StorageProcess/ServiceWorker/WebSWOriginStore.cpp:
+        (WebKit::WebSWOriginStore::addToStore):
+        (WebKit::WebSWOriginStore::removeFromStore):
+        (WebKit::WebSWOriginStore::clearStore):
+        (WebKit::WebSWOriginStore::add): Deleted.
+        (WebKit::WebSWOriginStore::remove): Deleted.
+        (WebKit::WebSWOriginStore::clear): Deleted.
+        * StorageProcess/ServiceWorker/WebSWOriginStore.h:
+        * WebProcess/Storage/WebSWClientConnection.cpp:
+        (WebKit::WebSWClientConnection::matchRegistration):
+
 2017-11-13  Alex Christensen  <[email protected]>
 
         Merge NetworkProcess::EnsurePrivateBrowsingSession and NetworkProcess::AddWebsiteDataStore into one message type

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp (224791 => 224792)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp	2017-11-14 00:20:25 UTC (rev 224792)
@@ -41,26 +41,19 @@
 {
 }
 
-void WebSWOriginStore::add(const SecurityOrigin& origin)
+void WebSWOriginStore::addToStore(const SecurityOrigin& origin)
 {
     m_store.scheduleAddition(computeSharedStringHash(origin.toString()));
     m_store.flushPendingChanges();
 }
 
-void WebSWOriginStore::addAll(const Vector<SecurityOrigin>& origins)
+void WebSWOriginStore::removeFromStore(const SecurityOrigin& origin)
 {
-    for (auto& origin : origins)
-        m_store.scheduleAddition(computeSharedStringHash(origin.toString()));
-    m_store.flushPendingChanges();
-}
-
-void WebSWOriginStore::remove(const SecurityOrigin& origin)
-{
     m_store.scheduleRemoval(computeSharedStringHash(origin.toString()));
     m_store.flushPendingChanges();
 }
 
-void WebSWOriginStore::clear()
+void WebSWOriginStore::clearStore()
 {
     m_store.clear();
 }

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.h (224791 => 224792)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.h	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.h	2017-11-14 00:20:25 UTC (rev 224792)
@@ -28,6 +28,7 @@
 #if ENABLE(SERVICE_WORKER)
 
 #include "SharedStringHashStore.h"
+#include <WebCore/SWOriginStore.h>
 #include <wtf/HashSet.h>
 
 namespace WebCore {
@@ -38,15 +39,10 @@
 
 class WebSWServerConnection;
 
-class WebSWOriginStore final : private SharedStringHashStore::Client {
+class WebSWOriginStore final : public WebCore::SWOriginStore, private SharedStringHashStore::Client {
 public:
     WebSWOriginStore();
 
-    void add(const WebCore::SecurityOrigin&);
-    void addAll(const Vector<WebCore::SecurityOrigin>&);
-    void remove(const WebCore::SecurityOrigin&);
-    void clear();
-
     void registerSWServerConnection(WebSWServerConnection&);
     void unregisterSWServerConnection(WebSWServerConnection&);
 
@@ -53,6 +49,10 @@
 private:
     void sendStoreHandle(WebSWServerConnection&);
 
+    void addToStore(const WebCore::SecurityOrigin&) final;
+    void removeFromStore(const WebCore::SecurityOrigin&) final;
+    void clearStore() final;
+
     // SharedStringHashStore::Client.
     void didInvalidateSharedMemory() final;
 

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp (224791 => 224792)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp	2017-11-14 00:20:25 UTC (rev 224792)
@@ -31,7 +31,6 @@
 #include "DataReference.h"
 #include "Logging.h"
 #include "ServiceWorkerClientFetchMessages.h"
-#include "StorageProcess.h"
 #include "StorageToWebProcessConnectionMessages.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebProcess.h"
@@ -38,7 +37,6 @@
 #include "WebProcessMessages.h"
 #include "WebSWClientConnectionMessages.h"
 #include "WebSWContextManagerConnectionMessages.h"
-#include "WebSWOriginStore.h"
 #include "WebSWServerConnectionMessages.h"
 #include "WebToStorageProcessConnection.h"
 #include <WebCore/ExceptionData.h>
@@ -78,16 +76,11 @@
 
 void WebSWServerConnection::resolveRegistrationJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData& registrationData, ShouldNotifyWhenResolved shouldNotifyWhenResolved)
 {
-    auto origin = registrationData.key.topOrigin().securityOrigin();
-    StorageProcess::singleton().ensureSWOriginStoreForSession(m_sessionID).add(origin);
     send(Messages::WebSWClientConnection::RegistrationJobResolvedInServer(jobIdentifier, registrationData, shouldNotifyWhenResolved));
 }
 
 void WebSWServerConnection::resolveUnregistrationJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationKey& registrationKey, bool unregistrationResult)
 {
-    auto origin = registrationKey.topOrigin().securityOrigin();
-    if (auto* store = StorageProcess::singleton().swOriginStoreForSession(m_sessionID))
-        store->remove(origin);
     send(Messages::WebSWClientConnection::UnregistrationJobResolvedInServer(jobIdentifier, unregistrationResult));
 }
 

Modified: trunk/Source/WebKit/StorageProcess/StorageProcess.cpp (224791 => 224792)


--- trunk/Source/WebKit/StorageProcess/StorageProcess.cpp	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/Source/WebKit/StorageProcess/StorageProcess.cpp	2017-11-14 00:20:25 UTC (rev 224792)
@@ -232,10 +232,8 @@
 
 #if ENABLE(SERVICE_WORKER)
     if (websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations)) {
-        if (auto* store = swOriginStoreForSession(sessionID))
-            store->clear();
         if (auto* server = m_swServers.get(sessionID))
-            server->clear();
+            server->clearAll();
     }
 #endif
 
@@ -257,11 +255,10 @@
 
 #if ENABLE(SERVICE_WORKER)
     if (websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations)) {
-        if (auto* store = swOriginStoreForSession(sessionID)) {
+        if (auto* server = m_swServers.get(sessionID)) {
             for (auto& originData : securityOriginDatas)
-                store->remove(originData.securityOrigin());
+                server->clear(originData.securityOrigin());
         }
-        // FIXME: Clear service workers and registrations related to the origin.
     }
 #endif
 
@@ -345,12 +342,17 @@
 {
     auto result = m_swServers.add(sessionID, nullptr);
     if (result.isNewEntry)
-        result.iterator->value = std::make_unique<SWServer>();
+        result.iterator->value = std::make_unique<SWServer>(makeUniqueRef<WebSWOriginStore>());
 
     ASSERT(result.iterator->value);
     return *result.iterator->value;
 }
 
+WebSWOriginStore& StorageProcess::swOriginStoreForSession(PAL::SessionID sessionID)
+{
+    return static_cast<WebSWOriginStore&>(swServerForSession(sessionID).originStore());
+}
+
 IPC::Connection* StorageProcess::workerContextProcessConnection()
 {
     return m_workerContextProcessConnection.get();
@@ -365,21 +367,6 @@
     parentProcessConnection()->send(Messages::StorageProcessProxy::GetWorkerContextProcessConnection(), 0);
 }
 
-WebSWOriginStore& StorageProcess::ensureSWOriginStoreForSession(PAL::SessionID sessionID)
-{
-    return *m_swOriginStores.ensure(sessionID, [] {
-        return std::make_unique<WebSWOriginStore>();
-    }).iterator->value;
-}
-
-WebSWOriginStore* StorageProcess::swOriginStoreForSession(PAL::SessionID sessionID) const
-{
-    auto it = m_swOriginStores.find(sessionID);
-    if (it == m_swOriginStores.end())
-        return nullptr;
-    return it->value.get();
-}
-
 void StorageProcess::didGetWorkerContextProcessConnection(IPC::Attachment&& encodedConnectionIdentifier)
 {
     ASSERT(m_waitingForWorkerContextProcessConnection);
@@ -476,7 +463,7 @@
 {
     ASSERT(!m_swServerConnections.contains(connection.identifier()));
     m_swServerConnections.add(connection.identifier(), &connection);
-    ensureSWOriginStoreForSession(connection.sessionID()).registerSWServerConnection(connection);
+    swOriginStoreForSession(connection.sessionID()).registerSWServerConnection(connection);
 }
 
 void StorageProcess::unregisterSWServerConnection(WebSWServerConnection& connection)
@@ -483,8 +470,7 @@
 {
     ASSERT(m_swServerConnections.get(connection.identifier()) == &connection);
     m_swServerConnections.remove(connection.identifier());
-    if (auto* originStore = swOriginStoreForSession(connection.sessionID()))
-        originStore->unregisterSWServerConnection(connection);
+    swOriginStoreForSession(connection.sessionID()).unregisterSWServerConnection(connection);
 }
 #endif
 

Modified: trunk/Source/WebKit/StorageProcess/StorageProcess.h (224791 => 224792)


--- trunk/Source/WebKit/StorageProcess/StorageProcess.h	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/Source/WebKit/StorageProcess/StorageProcess.h	2017-11-14 00:20:25 UTC (rev 224792)
@@ -83,9 +83,6 @@
     IPC::Connection* workerContextProcessConnection();
     void createWorkerContextProcessConnection();
 
-    WebSWOriginStore& ensureSWOriginStoreForSession(PAL::SessionID);
-    WebSWOriginStore* swOriginStoreForSession(PAL::SessionID) const;
-
     WebCore::SWServer& swServerForSession(PAL::SessionID);
     void registerSWServerConnection(WebSWServerConnection&);
     void unregisterSWServerConnection(WebSWServerConnection&);
@@ -132,6 +129,7 @@
     void didFinishServiceWorkerActivation(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerRegistrationKey&, WebCore::ServiceWorkerIdentifier);
     void setServiceWorkerHasPendingEvents(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier, bool hasPendingEvents);
     void postMessageToServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin);
+    WebSWOriginStore& swOriginStoreForSession(PAL::SessionID);
 #endif
 #if ENABLE(INDEXED_DATABASE)
     Vector<WebCore::SecurityOriginData> indexedDatabaseOrigins(const String& path);
@@ -162,7 +160,6 @@
     bool m_waitingForWorkerContextProcessConnection { false };
     HashMap<PAL::SessionID, std::unique_ptr<WebCore::SWServer>> m_swServers;
     HashMap<uint64_t, WebSWServerConnection*> m_swServerConnections;
-    HashMap<PAL::SessionID, std::unique_ptr<WebSWOriginStore>> m_swOriginStores;
 #endif
 };
 

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (224791 => 224792)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2017-11-13 23:50:47 UTC (rev 224791)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2017-11-14 00:20:25 UTC (rev 224792)
@@ -112,6 +112,11 @@
 
 void WebSWClientConnection::matchRegistration(const SecurityOrigin& topOrigin, const URL& clientURL, RegistrationCallback&& callback)
 {
+    if (!hasServiceWorkerRegisteredForOrigin(topOrigin)) {
+        callback(std::nullopt);
+        return;
+    }
+
     uint64_t requestIdentifier = ++m_previousMatchRegistrationTaskIdentifier;
     m_ongoingMatchRegistrationTasks.add(requestIdentifier, WTFMove(callback));
     send(Messages::WebSWServerConnection::MatchRegistration(requestIdentifier, SecurityOriginData::fromSecurityOrigin(topOrigin), clientURL));
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to