Title: [228025] trunk
Revision
228025
Author
commit-qu...@webkit.org
Date
2018-02-02 13:08:58 -0800 (Fri, 02 Feb 2018)

Log Message

Clearing all service worker registrations should wait for importing service worker registration to finish
https://bugs.webkit.org/show_bug.cgi?id=182407

Patch by Youenn Fablet <you...@apple.com> on 2018-02-02
Reviewed by Chris Dumez.

Source/WebCore:

Covered by existing tests and the service worker API test being no longer flaky.

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::registrationStoreImportComplete):
(WebCore::SWServer::clearAll):
(WebCore::SWServer::clear):
(WebCore::SWServer::getOriginsWithRegistrations):
* workers/service/server/SWServer.h:

Source/WebKit:

Updating API to take a completion handler.

* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
(WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations):
* UIProcess/API/C/WKWebsiteDataStoreRef.h:

Tools:

Make sure we finish clearing service worker registrations before running tests.

* WebKitTestRunner/TestController.cpp:
(WTR::TestController::resetStateToConsistentValues):
(WTR::ClearServiceWorkerRegistrationsCallbackContext::ClearServiceWorkerRegistrationsCallbackContext):
(WTR::clearServiceWorkerRegistrationsCallback):
(WTR::TestController::clearServiceWorkerRegistrations):
* WebKitTestRunner/TestController.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (228024 => 228025)


--- trunk/Source/WebCore/ChangeLog	2018-02-02 21:04:52 UTC (rev 228024)
+++ trunk/Source/WebCore/ChangeLog	2018-02-02 21:08:58 UTC (rev 228025)
@@ -1,3 +1,19 @@
+2018-02-02  Youenn Fablet  <you...@apple.com>
+
+        Clearing all service worker registrations should wait for importing service worker registration to finish
+        https://bugs.webkit.org/show_bug.cgi?id=182407
+
+        Reviewed by Chris Dumez.
+
+        Covered by existing tests and the service worker API test being no longer flaky.
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::registrationStoreImportComplete):
+        (WebCore::SWServer::clearAll):
+        (WebCore::SWServer::clear):
+        (WebCore::SWServer::getOriginsWithRegistrations):
+        * workers/service/server/SWServer.h:
+
 2018-02-02  Chris Dumez  <cdu...@apple.com>
 
         Clearing a registration should null out its workers before setting their state to "redundant"

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


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2018-02-02 21:04:52 UTC (rev 228024)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2018-02-02 21:08:58 UTC (rev 228025)
@@ -114,6 +114,11 @@
     ASSERT(!m_importCompleted);
     m_importCompleted = true;
     m_originStore->importComplete();
+
+    auto clearCallbacks = WTFMove(m_clearCompletionCallbacks);
+    for (auto& callback : clearCallbacks)
+        callback();
+
     performGetOriginsWithRegistrationsCallbacks();
 }
 
@@ -182,8 +187,16 @@
     return matchingRegistrationDatas;
 }
 
-void SWServer::clearAll(WTF::CompletionHandler<void()>&& completionHandler)
+void SWServer::clearAll(CompletionHandler<void()>&& completionHandler)
 {
+    if (!m_importCompleted) {
+        m_clearCompletionCallbacks.append([this, completionHandler = WTFMove(completionHandler)] () mutable {
+            ASSERT(m_importCompleted);
+            clearAll(WTFMove(completionHandler));
+        });
+        return;
+    }
+
     m_jobQueues.clear();
     while (!m_registrations.isEmpty())
         m_registrations.begin()->value->clear();
@@ -193,8 +206,16 @@
     m_registrationStore.clearAll(WTFMove(completionHandler));
 }
 
-void SWServer::clear(const SecurityOrigin& origin, WTF::CompletionHandler<void()>&& completionHandler)
+void SWServer::clear(const SecurityOrigin& origin, CompletionHandler<void()>&& completionHandler)
 {
+    if (!m_importCompleted) {
+        m_clearCompletionCallbacks.append([this, origin = makeRef(origin), completionHandler = WTFMove(completionHandler)] () mutable {
+            ASSERT(m_importCompleted);
+            clear(origin, WTFMove(completionHandler));
+        });
+        return;
+    }
+
     m_jobQueues.removeIf([&](auto& keyAndValue) {
         return keyAndValue.key.relatesToOrigin(origin);
     });
@@ -209,6 +230,9 @@
         return contextData.registration.key.relatesToOrigin(origin);
     });
 
+    if (registrationsToRemove.isEmpty())
+        return;
+
     // Calling SWServerRegistration::clear() takes care of updating m_registrations, m_originStore and m_registrationStore.
     for (auto* registration : registrationsToRemove)
         registration->clear();
@@ -771,7 +795,7 @@
     });
 }
 
-void SWServer::getOriginsWithRegistrations(WTF::Function<void(const HashSet<SecurityOriginData>&)> callback)
+void SWServer::getOriginsWithRegistrations(Function<void(const HashSet<SecurityOriginData>&)>&& callback)
 {
     m_getOriginsWithRegistrationsCallbacks.append(WTFMove(callback));
 

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


--- trunk/Source/WebCore/workers/service/server/SWServer.h	2018-02-02 21:04:52 UTC (rev 228024)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h	2018-02-02 21:08:58 UTC (rev 228025)
@@ -174,7 +174,7 @@
     void registrationStoreImportComplete();
     void registrationStoreDatabaseFailedToOpen();
 
-    WEBCORE_EXPORT void getOriginsWithRegistrations(WTF::Function<void(const HashSet<SecurityOriginData>&)>);
+    WEBCORE_EXPORT void getOriginsWithRegistrations(Function<void(const HashSet<SecurityOriginData>&)>&&);
 
     PAL::SessionID sessionID() const { return m_sessionID; }
 
@@ -227,7 +227,8 @@
     HashMap<ServiceWorkerIdentifier, Vector<RunServiceWorkerCallback>> m_serviceWorkerRunRequests;
     PAL::SessionID m_sessionID;
     bool m_importCompleted { false };
-    Vector<WTF::Function<void(const HashSet<SecurityOriginData>&)>> m_getOriginsWithRegistrationsCallbacks;
+    Vector<CompletionHandler<void()>> m_clearCompletionCallbacks;
+    Vector<Function<void(const HashSet<SecurityOriginData>&)>> m_getOriginsWithRegistrationsCallbacks;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebKit/ChangeLog (228024 => 228025)


--- trunk/Source/WebKit/ChangeLog	2018-02-02 21:04:52 UTC (rev 228024)
+++ trunk/Source/WebKit/ChangeLog	2018-02-02 21:08:58 UTC (rev 228025)
@@ -1,3 +1,16 @@
+2018-02-02  Youenn Fablet  <you...@apple.com>
+
+        Clearing all service worker registrations should wait for importing service worker registration to finish
+        https://bugs.webkit.org/show_bug.cgi?id=182407
+
+        Reviewed by Chris Dumez.
+
+        Updating API to take a completion handler.
+
+        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
+        (WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations):
+        * UIProcess/API/C/WKWebsiteDataStoreRef.h:
+
 2018-02-02  Fujii Hironori  <hironori.fu...@sony.com>
 
         [Win] MSVC doesn't seem to like "friend class NeverDestroyed<Foo>"

Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp (228024 => 228025)


--- trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp	2018-02-02 21:04:52 UTC (rev 228024)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp	2018-02-02 21:08:58 UTC (rev 228025)
@@ -393,11 +393,13 @@
     WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, -WallTime::infinity(), [] { });
 }
 
-void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef)
+void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveAllServiceWorkerRegistrationsCallback callback)
 {
 #if ENABLE(SERVICE_WORKER)
     OptionSet<WebKit::WebsiteDataType> dataTypes = WebKit::WebsiteDataType::ServiceWorkerRegistrations;
-    WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, -WallTime::infinity(), [] { });
+    WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, -WallTime::infinity(), [context, callback] {
+        callback(context);
+    });
 #else
     UNUSED_PARAM(dataStoreRef);
 #endif

Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h (228024 => 228025)


--- trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h	2018-02-02 21:04:52 UTC (rev 228024)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h	2018-02-02 21:08:58 UTC (rev 228025)
@@ -83,8 +83,10 @@
 WK_EXPORT void WKWebsiteDataStoreRemoveFetchCacheForOrigin(WKWebsiteDataStoreRef dataStoreRef, WKSecurityOriginRef origin, void* context, WKWebsiteDataStoreRemoveFetchCacheRemovalFunction callback);
 WK_EXPORT void WKWebsiteDataStoreRemoveAllFetchCaches(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveFetchCacheRemovalFunction callback);
 
+typedef void (*WKWebsiteDataStoreRemoveAllServiceWorkerRegistrationsCallback)(void* functionContext);
+WK_EXPORT void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveAllServiceWorkerRegistrationsCallback callback);
+
 WK_EXPORT void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef);
-WK_EXPORT void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef);
 
 typedef void (*WKWebsiteDataStoreGetFetchCacheOriginsFunction)(WKArrayRef, void*);
 WK_EXPORT void WKWebsiteDataStoreGetFetchCacheOrigins(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreGetFetchCacheOriginsFunction function);

Modified: trunk/Tools/ChangeLog (228024 => 228025)


--- trunk/Tools/ChangeLog	2018-02-02 21:04:52 UTC (rev 228024)
+++ trunk/Tools/ChangeLog	2018-02-02 21:08:58 UTC (rev 228025)
@@ -1,5 +1,21 @@
 2018-02-02  Youenn Fablet  <you...@apple.com>
 
+        Clearing all service worker registrations should wait for importing service worker registration to finish
+        https://bugs.webkit.org/show_bug.cgi?id=182407
+
+        Reviewed by Chris Dumez.
+
+        Make sure we finish clearing service worker registrations before running tests.
+
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::resetStateToConsistentValues):
+        (WTR::ClearServiceWorkerRegistrationsCallbackContext::ClearServiceWorkerRegistrationsCallbackContext):
+        (WTR::clearServiceWorkerRegistrationsCallback):
+        (WTR::TestController::clearServiceWorkerRegistrations):
+        * WebKitTestRunner/TestController.h:
+
+2018-02-02  Youenn Fablet  <you...@apple.com>
+
         Configure serviceWorkerRegistrationDirectory on the web site data store and move it to a Caches subfolder as a default
         https://bugs.webkit.org/show_bug.cgi?id=182403
 

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (228024 => 228025)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2018-02-02 21:04:52 UTC (rev 228024)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2018-02-02 21:08:58 UTC (rev 228025)
@@ -782,8 +782,7 @@
 
     WKContextClearCachedCredentials(TestController::singleton().context());
 
-    WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKContextGetWebsiteDataStore(platformContext()));
-
+    clearServiceWorkerRegistrations();
     clearDOMCaches();
 
     WKContextSetAllowsAnySSLCertificateForServiceWorkerTesting(platformContext(), true);
@@ -2329,6 +2328,38 @@
 #endif
 
 #if PLATFORM(COCOA) && WK_API_ENABLED
+struct ClearServiceWorkerRegistrationsCallbackContext {
+    explicit ClearServiceWorkerRegistrationsCallbackContext(TestController& controller)
+        : testController(controller)
+    {
+    }
+
+    TestController& testController;
+    bool done { false };
+};
+
+static void clearServiceWorkerRegistrationsCallback(void* userData)
+{
+    auto* context = static_cast<ClearServiceWorkerRegistrationsCallbackContext*>(userData);
+    context->done = true;
+    context->testController.notifyDone();
+}
+#endif
+
+void TestController::clearServiceWorkerRegistrations()
+{
+#if PLATFORM(COCOA) && WK_API_ENABLED
+    auto websiteDataStore = WKContextGetWebsiteDataStore(platformContext());
+    ClearServiceWorkerRegistrationsCallbackContext context(*this);
+
+    WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(websiteDataStore, &context, clearServiceWorkerRegistrationsCallback);
+
+    if (!context.done)
+        runUntil(context.done, m_currentInvocation->shortTimeout());
+#endif
+}
+
+#if PLATFORM(COCOA) && WK_API_ENABLED
 struct ClearDOMCacheCallbackContext {
     explicit ClearDOMCacheCallbackContext(TestController& controller)
         : testController(controller)

Modified: trunk/Tools/WebKitTestRunner/TestController.h (228024 => 228025)


--- trunk/Tools/WebKitTestRunner/TestController.h	2018-02-02 21:04:52 UTC (rev 228024)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2018-02-02 21:08:58 UTC (rev 228025)
@@ -192,6 +192,8 @@
 
     void removeAllSessionCredentials();
 
+    void clearServiceWorkerRegistrations();
+
     void clearDOMCache(WKStringRef origin);
     void clearDOMCaches();
     bool hasDOMCache(WKStringRef origin);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to