Internals clearCacheStorageMemoryRepresentation should return a Promise
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Sep 2017 20:56:22 +0000 (20:56 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Sep 2017 20:56:22 +0000 (20:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176818

Patch by Youenn Fablet <youenn@apple.com> on 2017-09-13
Reviewed by Alex Christensen.

Source/WebCore:

No observable change of behavior.

* Modules/cache/DOMCacheEngine.h:
* testing/Internals.cpp:
(WebCore::Internals::clearCacheStorageMemoryRepresentation): Returning a promise when clearing is completed.
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

Adding a completion handler to clearMemoryRepresentation.

* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::clearMemoryRepresentation):
* NetworkProcess/cache/CacheStorageEngine.h:
* NetworkProcess/cache/CacheStorageEngineConnection.cpp:
(WebKit::CacheStorageEngineConnection::clearMemoryRepresentation):
* NetworkProcess/cache/CacheStorageEngineConnection.h:
* NetworkProcess/cache/CacheStorageEngineConnection.messages.in:
* WebProcess/Cache/WebCacheStorageConnection.cpp:
(WebKit::WebCacheStorageConnection::clearMemoryRepresentation):
(WebKit::WebCacheStorageConnection::clearMemoryRepresentationCompleted):
* WebProcess/Cache/WebCacheStorageConnection.h:
* WebProcess/Cache/WebCacheStorageConnection.messages.in:

LayoutTests:

Updating tests to interact with the caches after the clearCacheStorageMemoryRepresentation promise is completed.

* http/tests/cache-storage/cache-origins.https.html:
* http/tests/cache-storage/cache-persistency.https.html:

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

17 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/cache-storage/cache-origins.https.html
LayoutTests/http/tests/cache-storage/cache-persistency.https.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/cache/DOMCacheEngine.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.messages.in
Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.cpp
Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.h
Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.messages.in

index dbe7b35..02c4fa2 100644 (file)
@@ -1,3 +1,15 @@
+2017-09-13  Youenn Fablet  <youenn@apple.com>
+
+        Internals clearCacheStorageMemoryRepresentation should return a Promise
+        https://bugs.webkit.org/show_bug.cgi?id=176818
+
+        Reviewed by Alex Christensen.
+
+        Updating tests to interact with the caches after the clearCacheStorageMemoryRepresentation promise is completed.
+
+        * http/tests/cache-storage/cache-origins.https.html:
+        * http/tests/cache-storage/cache-persistency.https.html:
+
 2017-09-13  Matt Lewis  <jlewis3@apple.com>
 
         Fixed expectations of imported/w3c/web-platform-tests/html/webappapis/timers/type-long-setinterval.html.
index eb57ad7..f29b9b1 100644 (file)
             window.addEventListener("message", test.step_func((event) => {
                 if (++counter <= 1)
                     return;
-                internals.clearCacheStorageMemoryRepresentation();
-                checkCaches("Caches from different origins should not mix");
-                resolve();
+                internals.clearCacheStorageMemoryRepresentation().then(() => {
+                    checkCaches("Caches from different origins should not mix");
+                    resolve();
+                });
             }));
         })
     }, "Create a cache storage and look at the representation");
index 66ccee1..d1ead4d 100644 (file)
@@ -26,8 +26,9 @@
         return new Promise((resolve, reject) => {
             window.addEventListener("message", test.step_func((event) => {
                 if (event.data === "ready") {
-                    internals.clearCacheStorageMemoryRepresentation();
-                    check.innerHTML = "<iframe src='resources/cache-persistency-iframe.html#check'></iframe>";
+                    internals.clearCacheStorageMemoryRepresentation().then(() => {
+                       check.innerHTML = "<iframe src='resources/cache-persistency-iframe.html#check'></iframe>";
+                    });
                     return;
                 }
                 assert_true(event.data === false, "No cache object should be found");
     }, "Clear memory representation and disable disk persistency");
 
     promise_test(test => {
-        if (window.internals)
-            internals.clearCacheStorageMemoryRepresentation();
         if (window.testRunner)
             testRunner.setPrivateBrowsingEnabled(false);
+        var clearPromise;
+        if (window.internals)
+            clearPromise =internals.clearCacheStorageMemoryRepresentation();
 
-        return self.caches.keys().then(keys => {
+        return Promise.resolve(clearPromise).then(() => {
+            return self.caches.keys();
+        }).then(keys => {
             var pending = [];
             for (key of keys)
                 pending.push(self.caches.delete(keys[0]));
@@ -59,8 +63,9 @@
         return new Promise((resolve, reject) => {
             window.addEventListener("message", test.step_func((event) => {
                 if (event.data === "ready") {
-                    internals.clearCacheStorageMemoryRepresentation();
-                    check.innerHTML = "<iframe src='resources/cache-persistency-iframe.html#check'></iframe>";
+                    internals.clearCacheStorageMemoryRepresentation().then(() => {
+                        check.innerHTML = "<iframe src='resources/cache-persistency-iframe.html#check'></iframe>";
+                    });
                     return;
                 }
                 assert_true(event.data === true, "A cache object should be found");
         }).then(keys => {
             assert_array_equals(keys, ["test2", "test1"]);
         }).then(() => {
-            internals.clearCacheStorageMemoryRepresentation();
+            return internals.clearCacheStorageMemoryRepresentation();
+        }).then(() => {
             return self.caches.keys();
         }).then(keys => {
             assert_array_equals(keys, ["test2", "test1"]);
             return self.caches.delete("test2");
         }).then(() => {
-            internals.clearCacheStorageMemoryRepresentation();
+            return internals.clearCacheStorageMemoryRepresentation();
+        }).then(() => {
             return self.caches.keys();
         }).then(keys => {
             assert_array_equals(keys, ["test1"]);
         }).then(() => {
             return self.caches.open("test2");
         }).then(() => {
-            internals.clearCacheStorageMemoryRepresentation();
+            return internals.clearCacheStorageMemoryRepresentation();
+        }).then(() => {
             return self.caches.keys();
         }).then(keys => {
             assert_array_equals(keys, ["test1", "test2"]);
         }).then(() => {
             return Promise.all([self.caches.delete("test2"), self.caches.delete("test1")]);
         }).then(() => {
-            internals.clearCacheStorageMemoryRepresentation();
+            return internals.clearCacheStorageMemoryRepresentation();
+        }).then(() => {
             return self.caches.keys();
         }).then(keys => {
             assert_array_equals(keys, []);
index 4b4296a..35b71be 100644 (file)
@@ -1,3 +1,18 @@
+2017-09-13  Youenn Fablet  <youenn@apple.com>
+
+        Internals clearCacheStorageMemoryRepresentation should return a Promise
+        https://bugs.webkit.org/show_bug.cgi?id=176818
+
+        Reviewed by Alex Christensen.
+
+        No observable change of behavior.
+
+        * Modules/cache/DOMCacheEngine.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::clearCacheStorageMemoryRepresentation): Returning a promise when clearing is completed.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2017-09-13  Nikita Vasilyev  <nvasilyev@apple.com>
 
         Web Inspector: Frontend should be made to expect and handle disabled properties
index 4d451eb..ea66bbc 100644 (file)
@@ -45,7 +45,7 @@ enum class Error {
     Internal
 };
 
-Exception errorToException(Error);
+WEBCORE_EXPORT Exception errorToException(Error);
 
 WEBCORE_EXPORT bool queryCacheMatch(const ResourceRequest& request, const ResourceRequest& cachedRequest, const ResourceResponse&, const CacheQueryOptions&);
 WEBCORE_EXPORT bool queryCacheMatch(const ResourceRequest& request, const URL& url, bool hasVaryStar, const HashMap<String, String>& varyHeaders, const CacheQueryOptions&);
index 8a31be5..b9c0584 100644 (file)
@@ -4143,7 +4143,7 @@ String Internals::audioSessionCategory() const
     return emptyString();
 }
 
-void Internals::clearCacheStorageMemoryRepresentation()
+void Internals::clearCacheStorageMemoryRepresentation(DOMPromiseDeferred<void>&& promise)
 {
     auto* document = contextDocument();
     if (!document)
@@ -4155,7 +4155,10 @@ void Internals::clearCacheStorageMemoryRepresentation()
         if (!m_cacheStorageConnection)
             return;
     }
-    m_cacheStorageConnection->clearMemoryRepresentation(document->securityOrigin().toString(), [](std::optional<DOMCacheEngine::Error>&&) { });
+    m_cacheStorageConnection->clearMemoryRepresentation(document->securityOrigin().toString(), [promise = WTFMove(promise)](std::optional<DOMCacheEngine::Error>&& result) mutable {
+        ASSERT_UNUSED(result, !result);
+        promise.resolve();
+    });
 }
 
 void Internals::cacheStorageEngineRepresentation(DOMPromiseDeferred<IDLDOMString>&& promise)
index 9a5472c..eb23c13 100644 (file)
@@ -600,7 +600,7 @@ public:
 
     String audioSessionCategory() const;
 
-    void clearCacheStorageMemoryRepresentation();
+    void clearCacheStorageMemoryRepresentation(DOMPromiseDeferred<void>&&);
     void cacheStorageEngineRepresentation(DOMPromiseDeferred<IDLDOMString>&&);
 
 private:
index 22e3d5c..658b179 100644 (file)
@@ -545,7 +545,7 @@ enum EventThrottlingBehavior {
     [Conditional=MEDIA_STREAM] void removeMediaStreamTrack(MediaStream stream, MediaStreamTrack track);
     [Conditional=MEDIA_STREAM] void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack track);
 
-    void clearCacheStorageMemoryRepresentation();
+    Promise<void> clearCacheStorageMemoryRepresentation();
     Promise<DOMString> cacheStorageEngineRepresentation();
 
     DOMString audioSessionCategory();
index caff7b6..0b4c5cd 100644 (file)
@@ -1,3 +1,25 @@
+2017-09-13  Youenn Fablet  <youenn@apple.com>
+
+        Internals clearCacheStorageMemoryRepresentation should return a Promise
+        https://bugs.webkit.org/show_bug.cgi?id=176818
+
+        Reviewed by Alex Christensen.
+
+        Adding a completion handler to clearMemoryRepresentation.
+
+        * NetworkProcess/cache/CacheStorageEngine.cpp:
+        (WebKit::CacheStorage::Engine::clearMemoryRepresentation):
+        * NetworkProcess/cache/CacheStorageEngine.h:
+        * NetworkProcess/cache/CacheStorageEngineConnection.cpp:
+        (WebKit::CacheStorageEngineConnection::clearMemoryRepresentation):
+        * NetworkProcess/cache/CacheStorageEngineConnection.h:
+        * NetworkProcess/cache/CacheStorageEngineConnection.messages.in:
+        * WebProcess/Cache/WebCacheStorageConnection.cpp:
+        (WebKit::WebCacheStorageConnection::clearMemoryRepresentation):
+        (WebKit::WebCacheStorageConnection::clearMemoryRepresentationCompleted):
+        * WebProcess/Cache/WebCacheStorageConnection.h:
+        * WebProcess/Cache/WebCacheStorageConnection.messages.in:
+
 2017-09-13  Andy Estes  <aestes@apple.com>
 
         [CF] Upstream CFNetwork-related WebKitSystemInterface functions
index 3f039a3..5832c1a 100644 (file)
@@ -296,12 +296,15 @@ void Engine::removeCaches(const String& origin)
     m_caches.remove(origin);
 }
 
-void Engine::clearMemoryRepresentation(const String& origin)
+void Engine::clearMemoryRepresentation(const String& origin, WebCore::DOMCacheEngine::CompletionCallback&& callback)
 {
-    readCachesFromDisk(origin, [](CachesOrError&& result) {
-        if (!result.hasValue())
+    readCachesFromDisk(origin, [callback = WTFMove(callback)](CachesOrError&& result) {
+        if (!result.hasValue()) {
+            callback(result.error());
             return;
+        }
         result.value().get().clearMemoryRepresentation();
+        callback(std::nullopt);
     });
 }
 
index ea62016..996dc01 100644 (file)
@@ -77,7 +77,7 @@ public:
 
     void removeCaches(const String& origin);
 
-    void clearMemoryRepresentation(const String& origin);
+    void clearMemoryRepresentation(const String& origin, WebCore::DOMCacheEngine::CompletionCallback&&);
     String representation();
 
 private:
index 0fb0e29..9b7ea66 100644 (file)
@@ -127,9 +127,11 @@ void CacheStorageEngineConnection::dereference(PAL::SessionID sessionID, uint64_
     references.remove(referenceResult);
 }
 
-void CacheStorageEngineConnection::clearMemoryRepresentation(PAL::SessionID sessionID, const String& origin)
+void CacheStorageEngineConnection::clearMemoryRepresentation(PAL::SessionID sessionID, uint64_t requestIdentifier, const String& origin)
 {
-    Engine::from(sessionID).clearMemoryRepresentation(origin);
+    Engine::from(sessionID).clearMemoryRepresentation(origin, [protectedThis = makeRef(*this), this, sessionID, requestIdentifier] (std::optional<Error>&& error) {
+        m_connection.connection().send(Messages::WebCacheStorageConnection::ClearMemoryRepresentationCompleted(requestIdentifier, error), sessionID.sessionID());
+    });
 }
 
 void CacheStorageEngineConnection::engineRepresentation(PAL::SessionID sessionID, uint64_t requestIdentifier)
index 8f3572e..9afff68 100644 (file)
@@ -61,7 +61,7 @@ private:
     void reference(PAL::SessionID, uint64_t cacheIdentifier);
     void dereference(PAL::SessionID, uint64_t cacheIdentifier);
 
-    void clearMemoryRepresentation(PAL::SessionID, const String& origin);
+    void clearMemoryRepresentation(PAL::SessionID, uint64_t requestIdentifier, const String& origin);
     void engineRepresentation(PAL::SessionID, uint64_t requestIdentifier);
 
     NetworkConnectionToWebProcess& m_connection;
index 82536d7..d6e3ce5 100644 (file)
@@ -28,7 +28,7 @@ messages -> CacheStorageEngineConnection {
     Remove(PAL::SessionID sessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier);
     Caches(PAL::SessionID sessionID, uint64_t requestIdentifier, String origin, uint64_t updateCounter);
 
-    ClearMemoryRepresentation(PAL::SessionID sessionID, String origin);
+    ClearMemoryRepresentation(PAL::SessionID sessionID, uint64_t requestIdentifier, String origin);
     EngineRepresentation(PAL::SessionID sessionID, uint64_t requestIdentifier);
 
     RetrieveRecords(PAL::SessionID sessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, WebCore::URL url);
index b442328..4455107 100644 (file)
@@ -128,8 +128,15 @@ void WebCacheStorageConnection::putRecordsCompleted(uint64_t requestIdentifier,
 
 void WebCacheStorageConnection::clearMemoryRepresentation(const String& origin, CompletionCallback&& callback)
 {
-    connection().send(Messages::CacheStorageEngineConnection::ClearMemoryRepresentation(m_sessionID, origin), 0);
-    callback(std::nullopt);
+    uint64_t requestIdentifier = ++m_engineRepresentationNextIdentifier;
+    m_clearRepresentationCallbacks.set(requestIdentifier, WTFMove(callback));
+    connection().send(Messages::CacheStorageEngineConnection::ClearMemoryRepresentation(m_sessionID, requestIdentifier, origin), 0);
+}
+
+void WebCacheStorageConnection::clearMemoryRepresentationCompleted(uint64_t requestIdentifier, std::optional<Error>&& result)
+{
+    if (auto callback = m_clearRepresentationCallbacks.take(requestIdentifier))
+        callback(WTFMove(result));
 }
 
 void WebCacheStorageConnection::engineRepresentation(WTF::Function<void(const String&)>&& callback)
index 8b5ac85..0b24e2a 100644 (file)
@@ -75,11 +75,13 @@ private:
     void putRecordsCompleted(uint64_t requestIdentifier, WebCore::DOMCacheEngine::RecordIdentifiersOrError&&);
 
     void engineRepresentationCompleted(uint64_t requestIdentifier, const String& representation);
+    void clearMemoryRepresentationCompleted(uint64_t requestIdentifier, std::optional<WebCore::DOMCacheEngine::Error>&&);
 
     WebCacheStorageProvider& m_provider;
     PAL::SessionID m_sessionID;
     uint64_t m_engineRepresentationNextIdentifier { 0 };
     HashMap<uint64_t, WTF::Function<void(const String&)>> m_engineRepresentationCallbacks;
+    HashMap<uint64_t, WebCore::DOMCacheEngine::CompletionCallback> m_clearRepresentationCallbacks;
 };
 
 }
index 97329a6..5c0963c 100644 (file)
@@ -30,4 +30,5 @@ messages -> WebCacheStorageConnection {
     PutRecordsCompleted(uint64_t requestIdentifier, WebCore::DOMCacheEngine::RecordIdentifiersOrError result);
 
     EngineRepresentationCompleted(uint64_t requestIdentifier, String representation);
+    ClearMemoryRepresentationCompleted(uint64_t requestIdentifier, std::optional<WebCore::DOMCacheEngine::Error> error);
 }