+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()
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)
}
#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.");
+ }
});
}