Changeset 228071 in webkit


Ignore:
Timestamp:
Feb 4, 2018 9:30:39 PM (6 years ago)
Author:
jmarcell@apple.com
Message:

Cherry-pick r228025. rdar://problem/37220140

Location:
branches/safari-605-branch
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-605-branch/Source/WebCore/ChangeLog

    r228069 r228071  
     12018-02-04  Jason Marcell  <jmarcell@apple.com>
     2
     3        Cherry-pick r228025. rdar://problem/37220140
     4
     5    2018-02-02  Youenn Fablet  <youenn@apple.com>
     6
     7            Clearing all service worker registrations should wait for importing service worker registration to finish
     8            https://bugs.webkit.org/show_bug.cgi?id=182407
     9
     10            Reviewed by Chris Dumez.
     11
     12            Covered by existing tests and the service worker API test being no longer flaky.
     13
     14            * workers/service/server/SWServer.cpp:
     15            (WebCore::SWServer::registrationStoreImportComplete):
     16            (WebCore::SWServer::clearAll):
     17            (WebCore::SWServer::clear):
     18            (WebCore::SWServer::getOriginsWithRegistrations):
     19            * workers/service/server/SWServer.h:
     20
    1212018-02-04  Jason Marcell  <jmarcell@apple.com>
    222
  • branches/safari-605-branch/Source/WebCore/workers/service/server/SWServer.cpp

    r228061 r228071  
    115115    m_importCompleted = true;
    116116    m_originStore->importComplete();
     117
     118    auto clearCallbacks = WTFMove(m_clearCompletionCallbacks);
     119    for (auto& callback : clearCallbacks)
     120        callback();
     121
    117122    performGetOriginsWithRegistrationsCallbacks();
    118123}
     
    183188}
    184189
    185 void SWServer::clearAll(WTF::CompletionHandler<void()>&& completionHandler)
    186 {
     190void SWServer::clearAll(CompletionHandler<void()>&& completionHandler)
     191{
     192    if (!m_importCompleted) {
     193        m_clearCompletionCallbacks.append([this, completionHandler = WTFMove(completionHandler)] () mutable {
     194            ASSERT(m_importCompleted);
     195            clearAll(WTFMove(completionHandler));
     196        });
     197        return;
     198    }
     199
    187200    m_jobQueues.clear();
    188201    while (!m_registrations.isEmpty())
     
    194207}
    195208
    196 void SWServer::clear(const SecurityOrigin& origin, WTF::CompletionHandler<void()>&& completionHandler)
    197 {
     209void SWServer::clear(const SecurityOrigin& origin, CompletionHandler<void()>&& completionHandler)
     210{
     211    if (!m_importCompleted) {
     212        m_clearCompletionCallbacks.append([this, origin = makeRef(origin), completionHandler = WTFMove(completionHandler)] () mutable {
     213            ASSERT(m_importCompleted);
     214            clear(origin, WTFMove(completionHandler));
     215        });
     216        return;
     217    }
     218
    198219    m_jobQueues.removeIf([&](auto& keyAndValue) {
    199220        return keyAndValue.key.relatesToOrigin(origin);
     
    209230        return contextData.registration.key.relatesToOrigin(origin);
    210231    });
     232
     233    if (registrationsToRemove.isEmpty())
     234        return;
    211235
    212236    // Calling SWServerRegistration::clear() takes care of updating m_registrations, m_originStore and m_registrationStore.
     
    770794}
    771795
    772 void SWServer::getOriginsWithRegistrations(WTF::Function<void(const HashSet<SecurityOriginData>&)> callback)
     796void SWServer::getOriginsWithRegistrations(Function<void(const HashSet<SecurityOriginData>&)>&& callback)
    773797{
    774798    m_getOriginsWithRegistrationsCallbacks.append(WTFMove(callback));
  • branches/safari-605-branch/Source/WebCore/workers/service/server/SWServer.h

    r228061 r228071  
    176176    void registrationStoreDatabaseFailedToOpen();
    177177
    178     WEBCORE_EXPORT void getOriginsWithRegistrations(WTF::Function<void(const HashSet<SecurityOriginData>&)>);
     178    WEBCORE_EXPORT void getOriginsWithRegistrations(Function<void(const HashSet<SecurityOriginData>&)>&&);
    179179
    180180private:
     
    227227    PAL::SessionID m_sessionID;
    228228    bool m_importCompleted { false };
    229     Vector<WTF::Function<void(const HashSet<SecurityOriginData>&)>> m_getOriginsWithRegistrationsCallbacks;
     229    Vector<CompletionHandler<void()>> m_clearCompletionCallbacks;
     230    Vector<Function<void(const HashSet<SecurityOriginData>&)>> m_getOriginsWithRegistrationsCallbacks;
    230231};
    231232
  • branches/safari-605-branch/Source/WebKit/ChangeLog

    r228070 r228071  
     12018-02-04  Jason Marcell  <jmarcell@apple.com>
     2
     3        Cherry-pick r228025. rdar://problem/37220140
     4
     5    2018-02-02  Youenn Fablet  <youenn@apple.com>
     6
     7            Clearing all service worker registrations should wait for importing service worker registration to finish
     8            https://bugs.webkit.org/show_bug.cgi?id=182407
     9
     10            Reviewed by Chris Dumez.
     11
     12            Updating API to take a completion handler.
     13
     14            * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
     15            (WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations):
     16            * UIProcess/API/C/WKWebsiteDataStoreRef.h:
     17
    1182018-02-04  Jason Marcell  <jmarcell@apple.com>
    219
  • branches/safari-605-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp

    r226349 r228071  
    385385}
    386386
    387 void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef)
     387void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveAllServiceWorkerRegistrationsCallback callback)
    388388{
    389389#if ENABLE(SERVICE_WORKER)
    390390    OptionSet<WebKit::WebsiteDataType> dataTypes = WebKit::WebsiteDataType::ServiceWorkerRegistrations;
    391     WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, -WallTime::infinity(), [] { });
     391    WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, -WallTime::infinity(), [context, callback] {
     392        callback(context);
     393    });
    392394#else
    393395    UNUSED_PARAM(dataStoreRef);
  • branches/safari-605-branch/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h

    r226346 r228071  
    8181WK_EXPORT void WKWebsiteDataStoreRemoveAllFetchCaches(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveFetchCacheRemovalFunction callback);
    8282
     83typedef void (*WKWebsiteDataStoreRemoveAllServiceWorkerRegistrationsCallback)(void* functionContext);
     84WK_EXPORT void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveAllServiceWorkerRegistrationsCallback callback);
     85
    8386WK_EXPORT void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef);
    84 WK_EXPORT void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef);
    8587
    8688typedef void (*WKWebsiteDataStoreGetFetchCacheOriginsFunction)(WKArrayRef, void*);
  • branches/safari-605-branch/Tools/ChangeLog

    r228070 r228071  
     12018-02-04  Jason Marcell  <jmarcell@apple.com>
     2
     3        Cherry-pick r228025. rdar://problem/37220140
     4
     5    2018-02-02  Youenn Fablet  <youenn@apple.com>
     6
     7            Clearing all service worker registrations should wait for importing service worker registration to finish
     8            https://bugs.webkit.org/show_bug.cgi?id=182407
     9
     10            Reviewed by Chris Dumez.
     11
     12            Make sure we finish clearing service worker registrations before running tests.
     13
     14            * WebKitTestRunner/TestController.cpp:
     15            (WTR::TestController::resetStateToConsistentValues):
     16            (WTR::ClearServiceWorkerRegistrationsCallbackContext::ClearServiceWorkerRegistrationsCallbackContext):
     17            (WTR::clearServiceWorkerRegistrationsCallback):
     18            (WTR::TestController::clearServiceWorkerRegistrations):
     19            * WebKitTestRunner/TestController.h:
     20
    1212018-02-04  Jason Marcell  <jmarcell@apple.com>
    222
  • branches/safari-605-branch/Tools/WebKitTestRunner/TestController.cpp

    r228070 r228071  
    783783    WKContextClearCachedCredentials(TestController::singleton().context());
    784784
    785     WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKContextGetWebsiteDataStore(platformContext()));
    786 
     785    clearServiceWorkerRegistrations();
    787786    clearDOMCaches();
    788787
     
    23302329
    23312330#if PLATFORM(COCOA) && WK_API_ENABLED
     2331struct ClearServiceWorkerRegistrationsCallbackContext {
     2332    explicit ClearServiceWorkerRegistrationsCallbackContext(TestController& controller)
     2333        : testController(controller)
     2334    {
     2335    }
     2336
     2337    TestController& testController;
     2338    bool done { false };
     2339};
     2340
     2341static void clearServiceWorkerRegistrationsCallback(void* userData)
     2342{
     2343    auto* context = static_cast<ClearServiceWorkerRegistrationsCallbackContext*>(userData);
     2344    context->done = true;
     2345    context->testController.notifyDone();
     2346}
     2347#endif
     2348
     2349void TestController::clearServiceWorkerRegistrations()
     2350{
     2351#if PLATFORM(COCOA) && WK_API_ENABLED
     2352    auto websiteDataStore = WKContextGetWebsiteDataStore(platformContext());
     2353    ClearServiceWorkerRegistrationsCallbackContext context(*this);
     2354
     2355    WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(websiteDataStore, &context, clearServiceWorkerRegistrationsCallback);
     2356
     2357    if (!context.done)
     2358        runUntil(context.done, m_currentInvocation->shortTimeout());
     2359#endif
     2360}
     2361
     2362#if PLATFORM(COCOA) && WK_API_ENABLED
    23322363struct ClearDOMCacheCallbackContext {
    23332364    explicit ClearDOMCacheCallbackContext(TestController& controller)
  • branches/safari-605-branch/Tools/WebKitTestRunner/TestController.h

    r225622 r228071  
    193193    void removeAllSessionCredentials();
    194194
     195    void clearServiceWorkerRegistrations();
     196
    195197    void clearDOMCache(WKStringRef origin);
    196198    void clearDOMCaches();
Note: See TracChangeset for help on using the changeset viewer.