Title: [228071] branches/safari-605-branch

Diff

Modified: branches/safari-605-branch/Source/WebCore/ChangeLog (228070 => 228071)


--- branches/safari-605-branch/Source/WebCore/ChangeLog	2018-02-05 05:30:35 UTC (rev 228070)
+++ branches/safari-605-branch/Source/WebCore/ChangeLog	2018-02-05 05:30:39 UTC (rev 228071)
@@ -1,5 +1,25 @@
 2018-02-04  Jason Marcell  <jmarc...@apple.com>
 
+        Cherry-pick r228025. rdar://problem/37220140
+
+    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-04  Jason Marcell  <jmarc...@apple.com>
+
         Cherry-pick r228015. rdar://problem/37220133
 
     2018-02-02  Chris Dumez  <cdu...@apple.com>

Modified: branches/safari-605-branch/Source/WebCore/workers/service/server/SWServer.cpp (228070 => 228071)


--- branches/safari-605-branch/Source/WebCore/workers/service/server/SWServer.cpp	2018-02-05 05:30:35 UTC (rev 228070)
+++ branches/safari-605-branch/Source/WebCore/workers/service/server/SWServer.cpp	2018-02-05 05:30:39 UTC (rev 228071)
@@ -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();
@@ -769,7 +793,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: branches/safari-605-branch/Source/WebCore/workers/service/server/SWServer.h (228070 => 228071)


--- branches/safari-605-branch/Source/WebCore/workers/service/server/SWServer.h	2018-02-05 05:30:35 UTC (rev 228070)
+++ branches/safari-605-branch/Source/WebCore/workers/service/server/SWServer.h	2018-02-05 05:30:39 UTC (rev 228071)
@@ -175,7 +175,7 @@
     void registrationStoreImportComplete();
     void registrationStoreDatabaseFailedToOpen();
 
-    WEBCORE_EXPORT void getOriginsWithRegistrations(WTF::Function<void(const HashSet<SecurityOriginData>&)>);
+    WEBCORE_EXPORT void getOriginsWithRegistrations(Function<void(const HashSet<SecurityOriginData>&)>&&);
 
 private:
     void registerConnection(Connection&);
@@ -226,7 +226,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: branches/safari-605-branch/Source/WebKit/ChangeLog (228070 => 228071)


--- branches/safari-605-branch/Source/WebKit/ChangeLog	2018-02-05 05:30:35 UTC (rev 228070)
+++ branches/safari-605-branch/Source/WebKit/ChangeLog	2018-02-05 05:30:39 UTC (rev 228071)
@@ -1,5 +1,22 @@
 2018-02-04  Jason Marcell  <jmarc...@apple.com>
 
+        Cherry-pick r228025. rdar://problem/37220140
+
+    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-04  Jason Marcell  <jmarc...@apple.com>
+
         Cherry-pick r228019. rdar://problem/37220144
 
     2018-02-02  Youenn Fablet  <you...@apple.com>

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp (228070 => 228071)


--- branches/safari-605-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp	2018-02-05 05:30:35 UTC (rev 228070)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp	2018-02-05 05:30:39 UTC (rev 228071)
@@ -384,11 +384,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: branches/safari-605-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h (228070 => 228071)


--- branches/safari-605-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h	2018-02-05 05:30:35 UTC (rev 228070)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h	2018-02-05 05:30:39 UTC (rev 228071)
@@ -80,8 +80,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: branches/safari-605-branch/Tools/ChangeLog (228070 => 228071)


--- branches/safari-605-branch/Tools/ChangeLog	2018-02-05 05:30:35 UTC (rev 228070)
+++ branches/safari-605-branch/Tools/ChangeLog	2018-02-05 05:30:39 UTC (rev 228071)
@@ -1,5 +1,25 @@
 2018-02-04  Jason Marcell  <jmarc...@apple.com>
 
+        Cherry-pick r228025. rdar://problem/37220140
+
+    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-04  Jason Marcell  <jmarc...@apple.com>
+
         Cherry-pick r228019. rdar://problem/37220144
 
     2018-02-02  Youenn Fablet  <you...@apple.com>

Modified: branches/safari-605-branch/Tools/WebKitTestRunner/TestController.cpp (228070 => 228071)


--- branches/safari-605-branch/Tools/WebKitTestRunner/TestController.cpp	2018-02-05 05:30:35 UTC (rev 228070)
+++ branches/safari-605-branch/Tools/WebKitTestRunner/TestController.cpp	2018-02-05 05:30:39 UTC (rev 228071)
@@ -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: branches/safari-605-branch/Tools/WebKitTestRunner/TestController.h (228070 => 228071)


--- branches/safari-605-branch/Tools/WebKitTestRunner/TestController.h	2018-02-05 05:30:35 UTC (rev 228070)
+++ branches/safari-605-branch/Tools/WebKitTestRunner/TestController.h	2018-02-05 05:30:39 UTC (rev 228071)
@@ -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