Title: [221995] trunk
Revision
221995
Author
commit-qu...@webkit.org
Date
2017-09-13 13:56:22 -0700 (Wed, 13 Sep 2017)

Log Message

Internals clearCacheStorageMemoryRepresentation should return a Promise
https://bugs.webkit.org/show_bug.cgi?id=176818

Patch by Youenn Fablet <you...@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:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (221994 => 221995)


--- trunk/LayoutTests/ChangeLog	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/LayoutTests/ChangeLog	2017-09-13 20:56:22 UTC (rev 221995)
@@ -1,3 +1,15 @@
+2017-09-13  Youenn Fablet  <you...@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  <jlew...@apple.com>
 
         Fixed expectations of imported/w3c/web-platform-tests/html/webappapis/timers/type-long-setinterval.html.

Modified: trunk/LayoutTests/http/tests/cache-storage/cache-origins.https.html (221994 => 221995)


--- trunk/LayoutTests/http/tests/cache-storage/cache-origins.https.html	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/LayoutTests/http/tests/cache-storage/cache-origins.https.html	2017-09-13 20:56:22 UTC (rev 221995)
@@ -26,9 +26,10 @@
             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");

Modified: trunk/LayoutTests/http/tests/cache-storage/cache-persistency.https.html (221994 => 221995)


--- trunk/LayoutTests/http/tests/cache-storage/cache-persistency.https.html	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/LayoutTests/http/tests/cache-storage/cache-persistency.https.html	2017-09-13 20:56:22 UTC (rev 221995)
@@ -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=''></iframe>";
+                    internals.clearCacheStorageMemoryRepresentation().then(() => {
+                       check.innerHTML = "<iframe src=''></iframe>";
+                    });
                     return;
                 }
                 assert_true(event.data ="" false, "No cache object should be found");
@@ -39,12 +40,15 @@
     }, "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=''></iframe>";
+                    internals.clearCacheStorageMemoryRepresentation().then(() => {
+                        check.innerHTML = "<iframe src=''></iframe>";
+                    });
                     return;
                 }
                 assert_true(event.data ="" true, "A cache object should be found");
@@ -88,13 +93,15 @@
         }).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"]);
@@ -101,7 +108,8 @@
         }).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"]);
@@ -108,7 +116,8 @@
         }).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, []);

Modified: trunk/Source/WebCore/ChangeLog (221994 => 221995)


--- trunk/Source/WebCore/ChangeLog	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebCore/ChangeLog	2017-09-13 20:56:22 UTC (rev 221995)
@@ -1,3 +1,18 @@
+2017-09-13  Youenn Fablet  <you...@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  <nvasil...@apple.com>
 
         Web Inspector: Frontend should be made to expect and handle disabled properties

Modified: trunk/Source/WebCore/Modules/cache/DOMCacheEngine.h (221994 => 221995)


--- trunk/Source/WebCore/Modules/cache/DOMCacheEngine.h	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebCore/Modules/cache/DOMCacheEngine.h	2017-09-13 20:56:22 UTC (rev 221995)
@@ -45,7 +45,7 @@
     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&);

Modified: trunk/Source/WebCore/testing/Internals.cpp (221994 => 221995)


--- trunk/Source/WebCore/testing/Internals.cpp	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebCore/testing/Internals.cpp	2017-09-13 20:56:22 UTC (rev 221995)
@@ -4143,7 +4143,7 @@
     return emptyString();
 }
 
-void Internals::clearCacheStorageMemoryRepresentation()
+void Internals::clearCacheStorageMemoryRepresentation(DOMPromiseDeferred<void>&& promise)
 {
     auto* document = contextDocument();
     if (!document)
@@ -4155,7 +4155,10 @@
         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)

Modified: trunk/Source/WebCore/testing/Internals.h (221994 => 221995)


--- trunk/Source/WebCore/testing/Internals.h	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebCore/testing/Internals.h	2017-09-13 20:56:22 UTC (rev 221995)
@@ -600,7 +600,7 @@
 
     String audioSessionCategory() const;
 
-    void clearCacheStorageMemoryRepresentation();
+    void clearCacheStorageMemoryRepresentation(DOMPromiseDeferred<void>&&);
     void cacheStorageEngineRepresentation(DOMPromiseDeferred<IDLDOMString>&&);
 
 private:

Modified: trunk/Source/WebCore/testing/Internals.idl (221994 => 221995)


--- trunk/Source/WebCore/testing/Internals.idl	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebCore/testing/Internals.idl	2017-09-13 20:56:22 UTC (rev 221995)
@@ -545,7 +545,7 @@
     [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();

Modified: trunk/Source/WebKit/ChangeLog (221994 => 221995)


--- trunk/Source/WebKit/ChangeLog	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebKit/ChangeLog	2017-09-13 20:56:22 UTC (rev 221995)
@@ -1,3 +1,25 @@
+2017-09-13  Youenn Fablet  <you...@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  <aes...@apple.com>
 
         [CF] Upstream CFNetwork-related WebKitSystemInterface functions

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp (221994 => 221995)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2017-09-13 20:56:22 UTC (rev 221995)
@@ -296,12 +296,15 @@
     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);
     });
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h (221994 => 221995)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h	2017-09-13 20:56:22 UTC (rev 221995)
@@ -77,7 +77,7 @@
 
     void removeCaches(const String& origin);
 
-    void clearMemoryRepresentation(const String& origin);
+    void clearMemoryRepresentation(const String& origin, WebCore::DOMCacheEngine::CompletionCallback&&);
     String representation();
 
 private:

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.cpp (221994 => 221995)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.cpp	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.cpp	2017-09-13 20:56:22 UTC (rev 221995)
@@ -127,9 +127,11 @@
     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)

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.h (221994 => 221995)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.h	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.h	2017-09-13 20:56:22 UTC (rev 221995)
@@ -61,7 +61,7 @@
     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;

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.messages.in (221994 => 221995)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.messages.in	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.messages.in	2017-09-13 20:56:22 UTC (rev 221995)
@@ -28,7 +28,7 @@
     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);

Modified: trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.cpp (221994 => 221995)


--- trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.cpp	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.cpp	2017-09-13 20:56:22 UTC (rev 221995)
@@ -128,10 +128,17 @@
 
 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)
 {
     uint64_t requestIdentifier = ++m_engineRepresentationNextIdentifier;

Modified: trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.h (221994 => 221995)


--- trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.h	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.h	2017-09-13 20:56:22 UTC (rev 221995)
@@ -75,11 +75,13 @@
     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;
 };
 
 }

Modified: trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.messages.in (221994 => 221995)


--- trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.messages.in	2017-09-13 20:55:28 UTC (rev 221994)
+++ trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.messages.in	2017-09-13 20:56:22 UTC (rev 221995)
@@ -30,4 +30,5 @@
     PutRecordsCompleted(uint64_t requestIdentifier, WebCore::DOMCacheEngine::RecordIdentifiersOrError result);
 
     EngineRepresentationCompleted(uint64_t requestIdentifier, String representation);
+    ClearMemoryRepresentationCompleted(uint64_t requestIdentifier, std::optional<WebCore::DOMCacheEngine::Error> error);
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to