Clear Cache Storage structures before removing all related files
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Apr 2019 22:59:14 +0000 (22:59 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Apr 2019 22:59:14 +0000 (22:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196650

Reviewed by Alex Christensen.

Previously, we were clearing files in parallel to clearing the internal CacheStorage structures.
To make things more deterministic, clear files/folders directly
after CachesStorage structures have finished being cleared.

* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::clearAllCaches):
(WebKit::CacheStorage::Engine::clearCachesForOrigin):

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

Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp

index 2fc84fe..a960f18 100644 (file)
@@ -1,3 +1,18 @@
+2019-04-10  Youenn Fablet  <youenn@apple.com>
+
+        Clear Cache Storage structures before removing all related files
+        https://bugs.webkit.org/show_bug.cgi?id=196650
+
+        Reviewed by Alex Christensen.
+
+        Previously, we were clearing files in parallel to clearing the internal CacheStorage structures.
+        To make things more deterministic, clear files/folders directly
+        after CachesStorage structures have finished being cleared.
+
+        * NetworkProcess/cache/CacheStorageEngine.cpp:
+        (WebKit::CacheStorage::Engine::clearAllCaches):
+        (WebKit::CacheStorage::Engine::clearCachesForOrigin):
+
 2019-04-10  Alex Christensen  <achristensen@webkit.org>
 
         Add SPI WKNavigationResponse._downloadAttribute
index e6f9fc8..b3332f9 100644 (file)
@@ -523,15 +523,15 @@ void Engine::clearAllCaches(CompletionHandler<void()>&& completionHandler)
 {
     ASSERT(RunLoop::isMain());
 
-    auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
+    auto callbackAggregator = CallbackAggregator::create([this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)]() mutable {
+        if (!this->shouldPersist())
+            return;
+        
+        this->clearAllCachesFromDisk(WTFMove(completionHandler));
+    });
 
     for (auto& caches : m_caches.values())
         caches->clear([callbackAggregator = callbackAggregator.copyRef()] { });
-
-    if (!shouldPersist())
-        return;
-
-    clearAllCachesFromDisk([callbackAggregator = WTFMove(callbackAggregator)] { });
 }
 
 void Engine::clearAllCachesFromDisk(CompletionHandler<void()>&& completionHandler)
@@ -551,17 +551,19 @@ void Engine::clearCachesForOrigin(const WebCore::SecurityOriginData& origin, Com
 {
     ASSERT(RunLoop::isMain());
 
-    auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
+    auto callbackAggregator = CallbackAggregator::create([this, protectedThis = makeRef(*this), origin, completionHandler = WTFMove(completionHandler)]() mutable {
+        if (!this->shouldPersist())
+            return;
+
+        this->clearCachesForOriginFromDisk(origin, [completionHandler = WTFMove(completionHandler)]() mutable {
+            completionHandler();
+        });
+    });
 
     for (auto& keyValue : m_caches) {
         if (keyValue.key.topOrigin == origin || keyValue.key.clientOrigin == origin)
             keyValue.value->clear([callbackAggregator = callbackAggregator.copyRef()] { });
     }
-
-    if (!shouldPersist())
-        return;
-
-    clearCachesForOriginFromDisk(origin, [callbackAggregator = WTFMove(callbackAggregator)] { });
 }
 
 void Engine::clearCachesForOriginFromDisk(const WebCore::SecurityOriginData& origin, CompletionHandler<void()>&& completionHandler)