Clear persistent storage between tests for resourceLoadStatistics
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Sep 2018 22:57:23 +0000 (22:57 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Sep 2018 22:57:23 +0000 (22:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189684
<rdar://problem/44540099>

Patch by Woodrow Wang <woodrow_wang@apple.com> on 2018-09-19
Reviewed by Chris Dumez.

* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
(WKWebsiteDataStoreStatisticsResetToConsistentState):
* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::scheduleClearInMemoryAndPersistent):

Remove function only called in testing for resetting statistics to consistent
state.

(WebKit::WebResourceLoadStatisticsStore::scheduleClearInMemory): Deleted.

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp
Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp

index ad6821f..e282389 100644 (file)
@@ -1,3 +1,21 @@
+2018-09-19  Woodrow Wang  <woodrow_wang@apple.com>
+
+        Clear persistent storage between tests for resourceLoadStatistics
+        https://bugs.webkit.org/show_bug.cgi?id=189684
+        <rdar://problem/44540099>
+
+        Reviewed by Chris Dumez.
+
+        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
+        (WKWebsiteDataStoreStatisticsResetToConsistentState):
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::scheduleClearInMemoryAndPersistent):
+
+        Remove function only called in testing for resetting statistics to consistent
+        state. 
+        
+        (WebKit::WebResourceLoadStatisticsStore::scheduleClearInMemory): Deleted.
+
 2018-09-19  Chris Dumez  <cdumez@apple.com>
 
         Crash under WebPageProxy::decidePolicyForNavigationAction()
index 2464b0b..0ef2944 100644 (file)
@@ -484,7 +484,7 @@ void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef da
         return;
 
     statisticsStore->resetParametersToDefaultValues([callbackAggregator = callbackAggregator.copyRef()] { });
-    statisticsStore->scheduleClearInMemory([callbackAggregator = callbackAggregator.copyRef()] { });
+    statisticsStore->scheduleClearInMemoryAndPersistent(WebKit::WebResourceLoadStatisticsStore::ShouldGrandfather::No, [callbackAggregator = callbackAggregator.copyRef()] { });
 }
 
 void WKWebsiteDataStoreRemoveAllFetchCaches(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveFetchCacheRemovalFunction callback)
index 11be045..fa5ef21 100644 (file)
@@ -759,41 +759,30 @@ void WebResourceLoadStatisticsStore::scheduleCookieBlockingStateReset()
 }
 #endif
 
-void WebResourceLoadStatisticsStore::scheduleClearInMemory(CompletionHandler<void()>&& completionHandler)
-{
-    ASSERT(RunLoop::isMain());
-    postTask([this, completionHandler = WTFMove(completionHandler)]() mutable {
-
-        CompletionHandler<void()> callCompletionHandlerOnMainThread = [completionHandler = WTFMove(completionHandler)]() mutable {
-            postTaskReply(WTFMove(completionHandler));
-        };
-
-        if (!m_memoryStore) {
-            callCompletionHandlerOnMainThread();
-            return;
-        }
-
-        m_memoryStore->clear(WTFMove(callCompletionHandlerOnMainThread));
-    });
-}
-
 void WebResourceLoadStatisticsStore::scheduleClearInMemoryAndPersistent(ShouldGrandfather shouldGrandfather, CompletionHandler<void()>&& completionHandler)
 {
     ASSERT(RunLoop::isMain());
-    postTask([this, shouldGrandfather, completionHandler = WTFMove(completionHandler)] () mutable {
-        if (m_memoryStore)
-            m_memoryStore->clear([] { });
+    postTask([this, protectedThis = makeRef(*this), shouldGrandfather, completionHandler = WTFMove(completionHandler)] () mutable {
         if (m_persistentStorage)
             m_persistentStorage->clear();
-        
-        CompletionHandler<void()> callCompletionHandlerOnMainThread = [completionHandler = WTFMove(completionHandler)]() mutable {
+
+        CompletionHandlerCallingScope completionHandlerCaller([completionHandler = WTFMove(completionHandler)]() mutable {
             postTaskReply(WTFMove(completionHandler));
-        };
+        });
 
-        if (shouldGrandfather == ShouldGrandfather::Yes && m_memoryStore)
-            m_memoryStore->grandfatherExistingWebsiteData(WTFMove(callCompletionHandlerOnMainThread));
-        else
-            callCompletionHandlerOnMainThread();
+        if (m_memoryStore) {
+            m_memoryStore->clear([this, protectedThis = protectedThis.copyRef(), shouldGrandfather, completionHandlerCaller = WTFMove(completionHandlerCaller)] () mutable {
+                if (shouldGrandfather == ShouldGrandfather::Yes) {
+                    if (m_memoryStore)
+                        m_memoryStore->grandfatherExistingWebsiteData(completionHandlerCaller.release());
+                    else
+                        RELEASE_LOG(ResourceLoadStatistics, "WebResourceLoadStatisticsStore::scheduleClearInMemoryAndPersistent After being cleared, m_memoryStore is null when trying to grandfather data.");
+                }
+            });
+        } else {
+            if (shouldGrandfather == ShouldGrandfather::Yes)
+                RELEASE_LOG(ResourceLoadStatistics, "WebResourceLoadStatisticsStore::scheduleClearInMemoryAndPersistent Before being cleared, m_memoryStore is null when trying to grandfather data.");
+        }
     });
 }