A service worker process should not be created when enqueuing a service worker job
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Oct 2019 06:59:13 +0000 (06:59 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Oct 2019 06:59:13 +0000 (06:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=202578
<rdar://problem/55979690>

Reviewed by Chris Dumez.

Source/WebCore:

Ask for a service worker context connection when planning to install or run a service worker.
This allows to not spin unnecessarily service worker processes for jobs that do not end up installing a service worker.

Covered by existing tests.

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::tryInstallContextData):
(WebCore::SWServer::runServiceWorkerIfNecessary):

Source/WebKit:

Remove the calls to create service worker context connection.
They are now done at SWServer level when trying to either run a service worker or install one.

* NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::startFetch):
(WebKit::WebSWServerConnection::postMessageToServiceWorker):
(WebKit::WebSWServerConnection::scheduleJobInServer):

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

Source/WebCore/ChangeLog
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp

index ae5cb6f..14339e7 100644 (file)
@@ -1,3 +1,20 @@
+2019-10-09  youenn fablet  <youenn@apple.com>
+
+        A service worker process should not be created when enqueuing a service worker job
+        https://bugs.webkit.org/show_bug.cgi?id=202578
+        <rdar://problem/55979690>
+
+        Reviewed by Chris Dumez.
+
+        Ask for a service worker context connection when planning to install or run a service worker.
+        This allows to not spin unnecessarily service worker processes for jobs that do not end up installing a service worker.
+
+        Covered by existing tests.
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::tryInstallContextData):
+        (WebCore::SWServer::runServiceWorkerIfNecessary):
+
 2019-10-09  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Unreviewed, fix the internal iOS build
index d3ba788..9bb66ab 100644 (file)
@@ -540,9 +540,11 @@ void SWServer::tryInstallContextData(ServiceWorkerContextData&& data)
     RegistrableDomain registrableDomain(data.scriptURL);
     auto* connection = contextConnectionForRegistrableDomain(registrableDomain);
     if (!connection) {
-        m_pendingContextDatas.ensure(WTFMove(registrableDomain), [] {
+        m_pendingContextDatas.ensure(registrableDomain, [] {
             return Vector<ServiceWorkerContextData> { };
         }).iterator->value.append(WTFMove(data));
+
+        createContextConnection(registrableDomain);
         return;
     }
     
@@ -619,6 +621,8 @@ void SWServer::runServiceWorkerIfNecessary(ServiceWorkerIdentifier identifier, R
         serviceWorkerRunRequestsForOrigin.ensure(identifier, [&] {
             return Vector<RunServiceWorkerCallback> { };
         }).iterator->value.append(WTFMove(callback));
+
+        createContextConnection(worker->registrableDomain());
         return;
     }
 
index 4d2c0d1..bfe3b17 100644 (file)
@@ -1,3 +1,19 @@
+2019-10-09  youenn fablet  <youenn@apple.com>
+
+        A service worker process should not be created when enqueuing a service worker job
+        https://bugs.webkit.org/show_bug.cgi?id=202578
+        <rdar://problem/55979690>
+
+        Reviewed by Chris Dumez.
+
+        Remove the calls to create service worker context connection.
+        They are now done at SWServer level when trying to either run a service worker or install one.
+
+        * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::startFetch):
+        (WebKit::WebSWServerConnection::postMessageToServiceWorker):
+        (WebKit::WebSWServerConnection::scheduleJobInServer):
+
 2019-10-09  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [Clipboard API] Refactor Pasteboard item reading functions to work on both iOS and macOS
index 012dac3..79e3265 100644 (file)
@@ -179,9 +179,6 @@ void WebSWServerConnection::startFetch(ServiceWorkerRegistrationIdentifier servi
             return;
         }
 
-        if (!worker->contextConnection())
-            server().createContextConnection(worker->registrableDomain());
-
         server().runServiceWorkerIfNecessary(serviceWorkerIdentifier, [weakThis = WTFMove(weakThis), this, fetchIdentifier, serviceWorkerIdentifier, request = WTFMove(request), options = WTFMove(options), formData = WTFMove(formData), referrer = WTFMove(referrer), shouldSkipFetchEvent = worker->shouldSkipFetchEvent()](auto* contextConnection) {
             if (!weakThis)
                 return;
@@ -230,9 +227,6 @@ void WebSWServerConnection::postMessageToServiceWorker(ServiceWorkerIdentifier d
     if (!sourceData)
         return;
 
-    if (!destinationWorker->contextConnection())
-        server().createContextConnection(destinationWorker->registrableDomain());
-
     // It's possible this specific worker cannot be re-run (e.g. its registration has been removed)
     server().runServiceWorkerIfNecessary(destinationIdentifier, [destinationIdentifier, message = WTFMove(message), sourceData = WTFMove(*sourceData)](auto* contextConnection) mutable {
         if (contextConnection)
@@ -242,10 +236,6 @@ void WebSWServerConnection::postMessageToServiceWorker(ServiceWorkerIdentifier d
 
 void WebSWServerConnection::scheduleJobInServer(ServiceWorkerJobData&& jobData)
 {
-    RegistrableDomain registrableDomain(jobData.scopeURL);
-    if (!server().contextConnectionForRegistrableDomain(registrableDomain))
-        server().createContextConnection(registrableDomain);
-
     SWSERVERCONNECTION_RELEASE_LOG_IF_ALLOWED("Scheduling ServiceWorker job %s in server", jobData.identifier().loggingString().utf8().data());
     ASSERT(identifier() == jobData.connectionIdentifier());