Title: [219249] trunk/Source/WebKit2
Revision
219249
Author
an...@apple.com
Date
2017-07-07 00:22:12 -0700 (Fri, 07 Jul 2017)

Log Message

WKWebSiteDataStore.removeDataOfTypes should wait until disk cache files are actually removed before invoking completion handler
https://bugs.webkit.org/show_bug.cgi?id=174224
<rdar://problem/33067545>

Reviewed by Sam Weinig.

Currently we dispatch file deletion operations to a background queue and call the completion
handler without waiting for the I/O to complete.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::clearDiskCacheEntries):

    Call a new version of NetworkCache::remove() for bulk deletion.
    Note that it is fine to call this with an empty vector.

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::Cache::remove):

    Bulk deletion with a completion handler.

(WebKit::NetworkCache::Cache::deleteFiles): Added.

    Factor to a helper function.

* NetworkProcess/cache/NetworkCache.h:
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::Storage::remove):

    Remove files for all the provided keys in a queue and invoke the completion handler in the main thread when done.

* NetworkProcess/cache/NetworkCacheStorage.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (219248 => 219249)


--- trunk/Source/WebKit2/ChangeLog	2017-07-07 06:08:02 UTC (rev 219248)
+++ trunk/Source/WebKit2/ChangeLog	2017-07-07 07:22:12 UTC (rev 219249)
@@ -1,3 +1,37 @@
+2017-07-07  Antti Koivisto  <an...@apple.com>
+
+        WKWebSiteDataStore.removeDataOfTypes should wait until disk cache files are actually removed before invoking completion handler
+        https://bugs.webkit.org/show_bug.cgi?id=174224
+        <rdar://problem/33067545>
+
+        Reviewed by Sam Weinig.
+
+        Currently we dispatch file deletion operations to a background queue and call the completion
+        handler without waiting for the I/O to complete.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::clearDiskCacheEntries):
+
+            Call a new version of NetworkCache::remove() for bulk deletion.
+            Note that it is fine to call this with an empty vector.
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::Cache::remove):
+
+            Bulk deletion with a completion handler.
+
+        (WebKit::NetworkCache::Cache::deleteFiles): Added.
+
+            Factor to a helper function.
+
+        * NetworkProcess/cache/NetworkCache.h:
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::Storage::remove):
+
+            Remove files for all the provided keys in a queue and invoke the completion handler in the main thread when done.
+
+        * NetworkProcess/cache/NetworkCacheStorage.h:
+
 2017-07-06  Chris Dumez  <cdu...@apple.com>
 
         Fix bad usage of static variables in ResourceLoadStatisticsStore

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp (219248 => 219249)


--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp	2017-07-07 06:08:02 UTC (rev 219248)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp	2017-07-07 07:22:12 UTC (rev 219249)
@@ -449,10 +449,7 @@
                 return;
             }
 
-            for (auto& key : cacheKeysToDelete)
-                NetworkCache::singleton().remove(key);
-
-            RunLoop::main().dispatch(WTFMove(completionHandler));
+            NetworkCache::singleton().remove(cacheKeysToDelete, WTFMove(completionHandler));
             return;
         });
 

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (219248 => 219249)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp	2017-07-07 06:08:02 UTC (rev 219248)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp	2017-07-07 07:22:12 UTC (rev 219249)
@@ -505,6 +505,13 @@
     remove(makeCacheKey(request));
 }
 
+void Cache::remove(const Vector<Key>& keys, Function<void ()>&& completionHandler)
+{
+    ASSERT(isEnabled());
+
+    m_storage->remove(keys, WTFMove(completionHandler));
+}
+
 void Cache::traverse(Function<void (const TraversalEntry*)>&& traverseHandler)
 {
     ASSERT(isEnabled());

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h (219248 => 219249)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h	2017-07-07 06:08:02 UTC (rev 219248)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h	2017-07-07 07:22:12 UTC (rev 219249)
@@ -121,6 +121,7 @@
     void traverse(Function<void (const TraversalEntry*)>&&);
     void remove(const Key&);
     void remove(const WebCore::ResourceRequest&);
+    void remove(const Vector<Key>&, Function<void ()>&&);
 
     void clear();
     void clear(std::chrono::system_clock::time_point modifiedSince, Function<void ()>&& completionHandler);

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp (219248 => 219249)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp	2017-07-07 06:08:02 UTC (rev 219248)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp	2017-07-07 07:22:12 UTC (rev 219249)
@@ -555,11 +555,41 @@
     removeFromPendingWriteOperations(key);
 
     serialBackgroundIOQueue().dispatch([this, key] {
-        WebCore::deleteFile(recordPathForKey(key));
-        m_blobStorage.remove(blobPathForKey(key));
+        deleteFiles(key);
     });
 }
 
+void Storage::remove(const Vector<Key>& keys, Function<void ()>&& completionHandler)
+{
+    ASSERT(RunLoop::isMain());
+
+    Vector<Key> keysToRemove;
+    keysToRemove.reserveInitialCapacity(keys.size());
+
+    for (auto& key : keys) {
+        if (!mayContain(key))
+            continue;
+        removeFromPendingWriteOperations(key);
+        keysToRemove.uncheckedAppend(key);
+    }
+
+    serialBackgroundIOQueue().dispatch([this, keysToRemove = WTFMove(keysToRemove), completionHandler = WTFMove(completionHandler)] () mutable {
+        for (auto& key : keysToRemove)
+            deleteFiles(key);
+
+        if (completionHandler)
+            RunLoop::main().dispatch(WTFMove(completionHandler));
+    });
+}
+
+void Storage::deleteFiles(const Key& key)
+{
+    ASSERT(!RunLoop::isMain());
+
+    WebCore::deleteFile(recordPathForKey(key));
+    m_blobStorage.remove(blobPathForKey(key));
+}
+
 void Storage::updateFileModificationTime(const String& path)
 {
     serialBackgroundIOQueue().dispatch([path = path.isolatedCopy()] {

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h (219248 => 219249)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2017-07-07 06:08:02 UTC (rev 219248)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2017-07-07 07:22:12 UTC (rev 219249)
@@ -68,6 +68,7 @@
     void store(const Record&, MappedBodyHandler&&);
 
     void remove(const Key&);
+    void remove(const Vector<Key>&, Function<void ()>&&);
     void clear(const String& type, std::chrono::system_clock::time_point modifiedSinceTime, Function<void ()>&& completionHandler);
 
     struct RecordInfo {
@@ -143,6 +144,7 @@
     bool mayContainBlob(const Key&) const;
 
     void addToRecordFilter(const Key&);
+    void deleteFiles(const Key&);
 
     const String m_basePath;
     const String m_recordsPath;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to