Title: [221624] trunk/Source
Revision
221624
Author
[email protected]
Date
2017-09-05 10:52:51 -0700 (Tue, 05 Sep 2017)

Log Message

Allow retrieving Cache Storage records for a given URL only
https://bugs.webkit.org/show_bug.cgi?id=176202

Patch by Youenn Fablet <[email protected]> on 2017-09-05
Reviewed by Alex Christensen.

Source/WebCore:

No observable change of behavior.

Adding a URL parameter to CacheStorageConnection::retrieveRecords.
If given URL is null, all records will be retrieved, which is useful for the keys method.
Other operations only need records that share the same URL (modulo query string and frag id).

* Modules/cache/Cache.cpp:
(WebCore::Cache::matchAll):
(WebCore::Cache::keys):
(WebCore::Cache::retrieveRecords):
(WebCore::Cache::queryCache):
* Modules/cache/Cache.h:
* Modules/cache/CacheStorageConnection.cpp:
(WebCore::CacheStorageConnection::retrieveRecords):
* Modules/cache/CacheStorageConnection.h:
(WebCore::CacheStorageConnection::doRetrieveRecords):
* Modules/cache/WorkerCacheStorageConnection.cpp:
(WebCore::WorkerCacheStorageConnection::doRetrieveRecords):
* Modules/cache/WorkerCacheStorageConnection.h:
* platform/URL.h:

Source/WebKit:

Update CacheStorageEngineCache to store records as a map URL -> Vector of Records.
This allows regular record retrieval to be faster.
Retrieval of all records is less efficient but this should happen less often.

* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::retrieveRecords):
* NetworkProcess/cache/CacheStorageEngine.h:
* NetworkProcess/cache/CacheStorageEngineCache.cpp:
(WebKit::CacheStorage::queryCache):
(WebKit::CacheStorage::Cache::retrieveRecords const):
(WebKit::CacheStorage::computeKeyURL):
(WebKit::CacheStorage::Cache::addNewURLRecord):
(WebKit::CacheStorage::Cache::recordsFromURL):
(WebKit::CacheStorage::Cache::recordsFromURL const):
(WebKit::CacheStorage::Cache::put):
(WebKit::CacheStorage::Cache::remove):
* NetworkProcess/cache/CacheStorageEngineCache.h:
* NetworkProcess/cache/CacheStorageEngineConnection.cpp:
(WebKit::CacheStorageEngineConnection::retrieveRecords):
* NetworkProcess/cache/CacheStorageEngineConnection.h:
* NetworkProcess/cache/CacheStorageEngineConnection.messages.in:
* WebProcess/Cache/WebCacheStorageConnection.cpp:
(WebKit::WebCacheStorageConnection::doRetrieveRecords):
* WebProcess/Cache/WebCacheStorageConnection.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (221623 => 221624)


--- trunk/Source/WebCore/ChangeLog	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebCore/ChangeLog	2017-09-05 17:52:51 UTC (rev 221624)
@@ -1,3 +1,31 @@
+2017-09-05  Youenn Fablet  <[email protected]>
+
+        Allow retrieving Cache Storage records for a given URL only
+        https://bugs.webkit.org/show_bug.cgi?id=176202
+
+        Reviewed by Alex Christensen.
+
+        No observable change of behavior.
+
+        Adding a URL parameter to CacheStorageConnection::retrieveRecords.
+        If given URL is null, all records will be retrieved, which is useful for the keys method.
+        Other operations only need records that share the same URL (modulo query string and frag id).
+
+        * Modules/cache/Cache.cpp:
+        (WebCore::Cache::matchAll):
+        (WebCore::Cache::keys):
+        (WebCore::Cache::retrieveRecords):
+        (WebCore::Cache::queryCache):
+        * Modules/cache/Cache.h:
+        * Modules/cache/CacheStorageConnection.cpp:
+        (WebCore::CacheStorageConnection::retrieveRecords):
+        * Modules/cache/CacheStorageConnection.h:
+        (WebCore::CacheStorageConnection::doRetrieveRecords):
+        * Modules/cache/WorkerCacheStorageConnection.cpp:
+        (WebCore::WorkerCacheStorageConnection::doRetrieveRecords):
+        * Modules/cache/WorkerCacheStorageConnection.h:
+        * platform/URL.h:
+
 2017-09-05  Tim Horton  <[email protected]>
 
         Remove some unused bits of code and resources

Modified: trunk/Source/WebCore/Modules/cache/CacheStorageConnection.cpp (221623 => 221624)


--- trunk/Source/WebCore/Modules/cache/CacheStorageConnection.cpp	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebCore/Modules/cache/CacheStorageConnection.cpp	2017-09-05 17:52:51 UTC (rev 221624)
@@ -55,12 +55,12 @@
     doRetrieveCaches(requestIdentifier, origin, updateCounter);
 }
 
-void CacheStorageConnection::retrieveRecords(uint64_t cacheIdentifier, RecordsCallback&& callback)
+void CacheStorageConnection::retrieveRecords(uint64_t cacheIdentifier, const URL& url, RecordsCallback&& callback)
 {
     uint64_t requestIdentifier = ++m_lastRequestIdentifier;
     m_retrieveRecordsPendingRequests.add(requestIdentifier, WTFMove(callback));
 
-    doRetrieveRecords(requestIdentifier, cacheIdentifier);
+    doRetrieveRecords(requestIdentifier, cacheIdentifier, url);
 }
 
 void CacheStorageConnection::batchDeleteOperation(uint64_t cacheIdentifier, const ResourceRequest& request, CacheQueryOptions&& options, RecordIdentifiersCallback&& callback)

Modified: trunk/Source/WebCore/Modules/cache/CacheStorageConnection.h (221623 => 221624)


--- trunk/Source/WebCore/Modules/cache/CacheStorageConnection.h	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebCore/Modules/cache/CacheStorageConnection.h	2017-09-05 17:52:51 UTC (rev 221624)
@@ -41,7 +41,7 @@
     void remove(uint64_t cacheIdentifier, DOMCacheEngine::CacheIdentifierCallback&&);
     void retrieveCaches(const String& origin, uint64_t updateCounter, DOMCacheEngine::CacheInfosCallback&&);
 
-    void retrieveRecords(uint64_t cacheIdentifier, DOMCacheEngine::RecordsCallback&&);
+    void retrieveRecords(uint64_t cacheIdentifier, const URL&, DOMCacheEngine::RecordsCallback&&);
     void batchDeleteOperation(uint64_t cacheIdentifier, const ResourceRequest&, CacheQueryOptions&&, DOMCacheEngine::RecordIdentifiersCallback&&);
     void batchPutOperation(uint64_t cacheIdentifier, Vector<DOMCacheEngine::Record>&&, DOMCacheEngine::RecordIdentifiersCallback&&);
 
@@ -64,7 +64,7 @@
     virtual void doRemove(uint64_t requestIdentifier, uint64_t /* cacheIdentifier */) { removeCompleted(requestIdentifier, makeUnexpected(DOMCacheEngine::Error::NotImplemented)); }
     virtual void doRetrieveCaches(uint64_t requestIdentifier, const String& /* origin */, uint64_t /* updateCounter */) { updateCaches(requestIdentifier, { }); }
 
-    virtual void doRetrieveRecords(uint64_t requestIdentifier, uint64_t /* cacheIdentifier */) { updateRecords(requestIdentifier, { }); }
+    virtual void doRetrieveRecords(uint64_t requestIdentifier, uint64_t /* cacheIdentifier */, const URL& /* url */) { updateRecords(requestIdentifier, { }); }
     virtual void doBatchDeleteOperation(uint64_t requestIdentifier, uint64_t /* cacheIdentifier */, const ResourceRequest&, CacheQueryOptions&&) { deleteRecordsCompleted(requestIdentifier, makeUnexpected(DOMCacheEngine::Error::NotImplemented)); }
     virtual void doBatchPutOperation(uint64_t requestIdentifier, uint64_t /* cacheIdentifier */, Vector<DOMCacheEngine::Record>&&) { putRecordsCompleted(requestIdentifier, makeUnexpected(DOMCacheEngine::Error::NotImplemented)); }
 

Modified: trunk/Source/WebCore/Modules/cache/DOMCache.cpp (221623 => 221624)


--- trunk/Source/WebCore/Modules/cache/DOMCache.cpp	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebCore/Modules/cache/DOMCache.cpp	2017-09-05 17:52:51 UTC (rev 221624)
@@ -109,7 +109,7 @@
     }
 
     if (!request) {
-        retrieveRecords([this, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
+        retrieveRecords(URL { }, [this, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
             if (exception) {
                 promise.reject(WTFMove(exception.value()));
                 return;
@@ -378,7 +378,7 @@
     }
 
     if (!request) {
-        retrieveRecords([this, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
+        retrieveRecords(URL { }, [this, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
             if (exception) {
                 promise.reject(WTFMove(exception.value()));
                 return;
@@ -407,10 +407,16 @@
     });
 }
 
-void DOMCache::retrieveRecords(WTF::Function<void(std::optional<Exception>&&)>&& callback)
+void DOMCache::retrieveRecords(const URL& url, WTF::Function<void(std::optional<Exception>&&)>&& callback)
 {
     setPendingActivity(this);
-    m_connection->retrieveRecords(m_identifier, [this, callback = WTFMove(callback)](RecordsOrError&& result) {
+
+    URL retrieveURL = url;
+    if (retrieveURL.hasQuery())
+        retrieveURL.setQuery({ });
+    retrieveURL.removeFragmentIdentifier();
+
+    m_connection->retrieveRecords(m_identifier, retrieveURL, [this, callback = WTFMove(callback)](RecordsOrError&& result) {
         if (!m_isStopped) {
             if (!result.hasValue()) {
                 callback(DOMCacheEngine::errorToException(result.error()));
@@ -427,7 +433,8 @@
 
 void DOMCache::queryCache(Ref<FetchRequest>&& request, CacheQueryOptions&& options, WTF::Function<void(ExceptionOr<Vector<CacheStorageRecord>>&&)>&& callback)
 {
-    retrieveRecords([this, request = WTFMove(request), options = WTFMove(options), callback = WTFMove(callback)](std::optional<Exception>&& exception) mutable {
+    auto url = ""
+    retrieveRecords(url, [this, request = WTFMove(request), options = WTFMove(options), callback = WTFMove(callback)](std::optional<Exception>&& exception) mutable {
         if (exception) {
             callback(WTFMove(exception.value()));
             return;

Modified: trunk/Source/WebCore/Modules/cache/DOMCache.h (221623 => 221624)


--- trunk/Source/WebCore/Modules/cache/DOMCache.h	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebCore/Modules/cache/DOMCache.h	2017-09-05 17:52:51 UTC (rev 221624)
@@ -69,7 +69,7 @@
     const char* activeDOMObjectName() const final;
     bool canSuspendForDocumentSuspension() const final;
 
-    void retrieveRecords(WTF::Function<void(std::optional<Exception>&&)>&&);
+    void retrieveRecords(const URL&, WTF::Function<void(std::optional<Exception>&&)>&&);
     Vector<CacheStorageRecord> queryCacheWithTargetStorage(const FetchRequest&, const CacheQueryOptions&, const Vector<CacheStorageRecord>&);
     void queryCache(Ref<FetchRequest>&&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<Vector<CacheStorageRecord>>&&)>&&);
     void batchDeleteOperation(const FetchRequest&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<bool>&&)>&&);

Modified: trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp (221623 => 221624)


--- trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp	2017-09-05 17:52:51 UTC (rev 221624)
@@ -196,13 +196,13 @@
     return recordsFromRecordsData(WTFMove(recordsData.value()));
 }
 
-void WorkerCacheStorageConnection::doRetrieveRecords(uint64_t requestIdentifier, uint64_t cacheIdentifier)
+void WorkerCacheStorageConnection::doRetrieveRecords(uint64_t requestIdentifier, uint64_t cacheIdentifier, const URL& url)
 {
-    m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier](ScriptExecutionContext&) mutable {
+    m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, url = "" mutable {
         ASSERT(isMainThread());
         ASSERT(m_mainThreadConnection);
 
-        m_mainThreadConnection->retrieveRecords(cacheIdentifier, [this, protectedThis = WTFMove(protectedThis), requestIdentifier](RecordsOrError&& result) mutable {
+        m_mainThreadConnection->retrieveRecords(cacheIdentifier, url, [this, protectedThis = WTFMove(protectedThis), requestIdentifier](RecordsOrError&& result) mutable {
             m_proxy.postTaskForModeToWorkerGlobalScope([this, protectedThis = WTFMove(protectedThis), result = recordsDataOrErrorFromRecords(result), requestIdentifier](ScriptExecutionContext& context) mutable {
                 ASSERT_UNUSED(context, context.isWorkerGlobalScope());
                 updateRecords(requestIdentifier, recordsOrErrorFromRecordsData(WTFMove(result)));

Modified: trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.h (221623 => 221624)


--- trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.h	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.h	2017-09-05 17:52:51 UTC (rev 221624)
@@ -46,7 +46,7 @@
     void doRemove(uint64_t requestIdentifier, uint64_t cacheIdentifier) final;
     void doRetrieveCaches(uint64_t requestIdentifier, const String& origin, uint64_t updateCounter) final;
 
-    void doRetrieveRecords(uint64_t requestIdentifier, uint64_t cacheIdentifier) final;
+    void doRetrieveRecords(uint64_t requestIdentifier, uint64_t cacheIdentifier, const URL&) final;
     void doBatchDeleteOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, const WebCore::ResourceRequest&, WebCore::CacheQueryOptions&&) final;
     void doBatchPutOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, Vector<DOMCacheEngine::Record>&&) final;
 

Modified: trunk/Source/WebCore/platform/URL.h (221623 => 221624)


--- trunk/Source/WebCore/platform/URL.h	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebCore/platform/URL.h	2017-09-05 17:52:51 UTC (rev 221624)
@@ -161,10 +161,10 @@
     // The query may begin with a question mark, or, if not, one will be added
     // for you. Setting the query to the empty string will leave a "?" in the
     // URL (with nothing after it). To clear the query, pass a null string.
-    void setQuery(const String&);
+    WEBCORE_EXPORT void setQuery(const String&);
 
     void setFragmentIdentifier(StringView);
-    void removeFragmentIdentifier();
+    WEBCORE_EXPORT void removeFragmentIdentifier();
 
     WEBCORE_EXPORT friend bool equalIgnoringFragmentIdentifier(const URL&, const URL&);
 

Modified: trunk/Source/WebKit/ChangeLog (221623 => 221624)


--- trunk/Source/WebKit/ChangeLog	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebKit/ChangeLog	2017-09-05 17:52:51 UTC (rev 221624)
@@ -1,5 +1,37 @@
 2017-09-05  Youenn Fablet  <[email protected]>
 
+        Allow retrieving Cache Storage records for a given URL only
+        https://bugs.webkit.org/show_bug.cgi?id=176202
+
+        Reviewed by Alex Christensen.
+
+        Update CacheStorageEngineCache to store records as a map URL -> Vector of Records.
+        This allows regular record retrieval to be faster.
+        Retrieval of all records is less efficient but this should happen less often.
+
+        * NetworkProcess/cache/CacheStorageEngine.cpp:
+        (WebKit::CacheStorage::Engine::retrieveRecords):
+        * NetworkProcess/cache/CacheStorageEngine.h:
+        * NetworkProcess/cache/CacheStorageEngineCache.cpp:
+        (WebKit::CacheStorage::queryCache):
+        (WebKit::CacheStorage::Cache::retrieveRecords const):
+        (WebKit::CacheStorage::computeKeyURL):
+        (WebKit::CacheStorage::Cache::addNewURLRecord):
+        (WebKit::CacheStorage::Cache::recordsFromURL):
+        (WebKit::CacheStorage::Cache::recordsFromURL const):
+        (WebKit::CacheStorage::Cache::put):
+        (WebKit::CacheStorage::Cache::remove):
+        * NetworkProcess/cache/CacheStorageEngineCache.h:
+        * NetworkProcess/cache/CacheStorageEngineConnection.cpp:
+        (WebKit::CacheStorageEngineConnection::retrieveRecords):
+        * NetworkProcess/cache/CacheStorageEngineConnection.h:
+        * NetworkProcess/cache/CacheStorageEngineConnection.messages.in:
+        * WebProcess/Cache/WebCacheStorageConnection.cpp:
+        (WebKit::WebCacheStorageConnection::doRetrieveRecords):
+        * WebProcess/Cache/WebCacheStorageConnection.h:
+
+2017-09-05  Youenn Fablet  <[email protected]>
+
         WebKitTestRunner should set the cache storage directory path
         https://bugs.webkit.org/show_bug.cgi?id=176373
 

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp (221623 => 221624)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2017-09-05 17:52:51 UTC (rev 221624)
@@ -124,15 +124,15 @@
     });
 }
 
-void Engine::retrieveRecords(uint64_t cacheIdentifier, RecordsCallback&& callback)
+void Engine::retrieveRecords(uint64_t cacheIdentifier, WebCore::URL&& url, RecordsCallback&& callback)
 {
-    readCache(cacheIdentifier, [callback = WTFMove(callback)](CacheOrError&& result) mutable {
+    readCache(cacheIdentifier, [url = "" callback = WTFMove(callback)](CacheOrError&& result) mutable {
         if (!result.hasValue()) {
             callback(makeUnexpected(result.error()));
             return;
         }
 
-        callback(result.value().get().records());
+        callback(result.value().get().retrieveRecords(url));
     });
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h (221623 => 221624)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h	2017-09-05 17:52:51 UTC (rev 221624)
@@ -57,7 +57,7 @@
     void remove(uint64_t cacheIdentifier, WebCore::DOMCacheEngine::CacheIdentifierCallback&&);
     void retrieveCaches(const String& origin, uint64_t updateCounter, WebCore::DOMCacheEngine::CacheInfosCallback&&);
 
-    void retrieveRecords(uint64_t cacheIdentifier, WebCore::DOMCacheEngine::RecordsCallback&&);
+    void retrieveRecords(uint64_t cacheIdentifier, WebCore::URL&&, WebCore::DOMCacheEngine::RecordsCallback&&);
     void putRecords(uint64_t cacheIdentifier, Vector<WebCore::DOMCacheEngine::Record>&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&);
     void deleteMatchingRecords(uint64_t cacheIdentifier, WebCore::ResourceRequest&&, WebCore::CacheQueryOptions&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&);
 

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp (221623 => 221624)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp	2017-09-05 17:52:51 UTC (rev 221624)
@@ -49,6 +49,22 @@
 
 namespace CacheStorage {
 
+static inline Vector<uint64_t> queryCache(const Vector<Record>* records, const ResourceRequest& request, const CacheQueryOptions& options)
+{
+    if (!records)
+        return { };
+
+    if (!options.ignoreMethod && request.httpMethod() != "GET")
+        return { };
+
+    Vector<uint64_t> results;
+    for (const auto& record : *records) {
+        if (WebCore::DOMCacheEngine::queryCacheMatch(request, record.request, record.response, options))
+            results.append(record.identifier);
+    }
+    return results;
+}
+
 Cache::Cache(uint64_t identifier, String&& name)
     : m_identifier(identifier)
     , m_name(WTFMove(name))
@@ -55,15 +71,67 @@
 {
 }
 
-Vector<Record> Cache::records() const
+Vector<Record> Cache::retrieveRecords(const URL& url) const
 {
-    Vector<Record> records;
-    records.reserveInitialCapacity(m_records.size());
-    for (auto& record : m_records)
-        records.uncheckedAppend(record.copy());
-    return records;
+    if (url.isNull()) {
+        Vector<Record> result;
+        for (auto& records : m_records.values()) {
+            for (auto& record : records)
+                result.append(record.copy());
+        }
+        std::sort(result.begin(), result.end(), [](const auto& a, const auto& b) {
+            return a.identifier < b.identifier;
+        });
+        return result;
+    }
+
+    const auto* records = recordsFromURL(url);
+    if (!records)
+        return { };
+
+    Vector<Record> result;
+    result.reserveInitialCapacity(records->size());
+    for (auto& record : *records)
+        result.uncheckedAppend(record.copy());
+    return result;
 }
 
+static inline String computeKeyURL(const URL& url)
+{
+    URL keyURL = url;
+    if (keyURL.hasQuery())
+        keyURL.setQuery({ });
+    keyURL.removeFragmentIdentifier();
+    return keyURL;
+}
+
+Record& Cache::addNewURLRecord(Record&& record)
+{
+    auto key = computeKeyURL(record.request.url());
+    ASSERT(!m_records.contains(key));
+
+    Vector<Record> newRecords;
+    newRecords.reserveInitialCapacity(1);
+    newRecords.uncheckedAppend(WTFMove(record));
+    return m_records.set(key, WTFMove(newRecords)).iterator->value.last();
+}
+
+Vector<Record>* Cache::recordsFromURL(const URL& url)
+{
+    auto iterator = m_records.find(computeKeyURL(url));
+    if (iterator == m_records.end())
+        return nullptr;
+    return &iterator->value;
+}
+
+const Vector<Record>* Cache::recordsFromURL(const URL& url) const
+{
+    auto iterator = m_records.find(computeKeyURL(url));
+    if (iterator == m_records.end())
+        return nullptr;
+    return &iterator->value;
+}
+
 void Cache::put(Vector<Record>&& records, RecordIdentifiersCallback&& callback)
 {
     bool shouldWriteRecordList { false };
@@ -71,20 +139,27 @@
     Vector<uint64_t> recordIdentifiers;
     recordIdentifiers.reserveInitialCapacity(records.size());
     for (auto& record : records) {
-        auto matchingRecords = queryCache(record.request, options);
+        auto* sameURLRecords = recordsFromURL(record.request.url());
+
+        auto matchingRecords = queryCache(sameURLRecords, record.request, options);
         if (matchingRecords.isEmpty()) {
             record.identifier = ++m_nextRecordIdentifier;
             recordIdentifiers.uncheckedAppend(record.identifier);
-            m_records.append(WTFMove(record));
 
             shouldWriteRecordList = true;
-            writeRecordToDisk(m_records.last());
+            if (!sameURLRecords) {
+                auto& recordToWrite = addNewURLRecord(WTFMove(record));
+                writeRecordToDisk(recordToWrite);
+            } else {
+                sameURLRecords->append(WTFMove(record));
+                writeRecordToDisk(sameURLRecords->last());
+            }
         } else {
             auto identifier = matchingRecords[0];
-            auto position = m_records.findMatching([&](const auto& item) { return item.identifier == identifier; });
+            auto position = sameURLRecords->findMatching([&](const auto& item) { return item.identifier == identifier; });
             ASSERT(position != notFound);
             if (position != notFound) {
-                auto& existingRecord = m_records[position];
+                auto& existingRecord = (*sameURLRecords)[position];
                 recordIdentifiers.uncheckedAppend(identifier);
                 existingRecord.responseHeadersGuard = record.responseHeadersGuard;
                 existingRecord.response = WTFMove(record.response);
@@ -111,20 +186,19 @@
 
 void Cache::remove(WebCore::ResourceRequest&& request, WebCore::CacheQueryOptions&& options, RecordIdentifiersCallback&& callback)
 {
-    auto recordIdentifiers = queryCache(request, options);
+    auto* records = recordsFromURL(request.url());
+    auto recordIdentifiers = queryCache(records, request, options);
     if (recordIdentifiers.isEmpty()) {
         callback({ });
         return;
     }
 
-    Vector<Record> recordsToKeep;
-    for (auto& record : m_records) {
-        if (recordIdentifiers.findMatching([&](auto item) { return item == record.identifier; }) == notFound)
-            recordsToKeep.append(WTFMove(record));
-        else
-            removeRecordFromDisk(record);
-    }
-    m_records = WTFMove(recordsToKeep);
+    records->removeAllMatching([this, &recordIdentifiers](auto& item) {
+        bool shouldRemove = recordIdentifiers.findMatching([&item](auto identifier) { return identifier == item.identifier; }) != notFound;
+        if (shouldRemove)
+            this->removeRecordFromDisk(item);
+        return shouldRemove;
+    });
 
     writeRecordsList([callback = WTFMove(callback), recordIdentifiers = WTFMove(recordIdentifiers)](std::optional<Error>&& error) mutable {
         if (error) {
@@ -135,19 +209,6 @@
     });
 }
 
-Vector<uint64_t> Cache::queryCache(const ResourceRequest& request, const CacheQueryOptions& options)
-{
-    if (!options.ignoreMethod && request.httpMethod() != "GET")
-        return { };
-
-    Vector<uint64_t> results;
-    for (const auto& record : m_records) {
-        if (WebCore::DOMCacheEngine::queryCacheMatch(request, record.request, record.response, options))
-            results.append(record.identifier);
-    }
-    return results;
-}
-
 void Cache::writeRecordsList(CompletionCallback&& callback)
 {
     // FIXME: Implement this.

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.h (221623 => 221624)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.h	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.h	2017-09-05 17:52:51 UTC (rev 221624)
@@ -40,7 +40,7 @@
     uint64_t identifier() const { return m_identifier; }
     const String& name() const { return m_name; }
 
-    Vector<WebCore::DOMCacheEngine::Record> records() const;
+    Vector<WebCore::DOMCacheEngine::Record> retrieveRecords(const WebCore::URL&) const;
     WebCore::DOMCacheEngine::CacheInfo info() const { return { m_identifier, m_name }; }
 
     void put(Vector<WebCore::DOMCacheEngine::Record>&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&);
@@ -47,7 +47,9 @@
     void remove(WebCore::ResourceRequest&&, WebCore::CacheQueryOptions&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&);
 
 private:
-    Vector<uint64_t> queryCache(const WebCore::ResourceRequest&, const WebCore::CacheQueryOptions&);
+    Vector<WebCore::DOMCacheEngine::Record>* recordsFromURL(const WebCore::URL&);
+    const Vector<WebCore::DOMCacheEngine::Record>* recordsFromURL(const WebCore::URL&) const;
+    WebCore::DOMCacheEngine::Record& addNewURLRecord(WebCore::DOMCacheEngine::Record&&);
 
     void writeRecordsList(WebCore::DOMCacheEngine::CompletionCallback&&);
     void writeRecordToDisk(WebCore::DOMCacheEngine::Record&);
@@ -55,7 +57,7 @@
 
     uint64_t m_identifier { 0 };
     String m_name;
-    Vector<WebCore::DOMCacheEngine::Record> m_records;
+    HashMap<String, Vector<WebCore::DOMCacheEngine::Record>> m_records;
     uint64_t m_nextRecordIdentifier { 0 };
 };
 

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.cpp (221623 => 221624)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.cpp	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.cpp	2017-09-05 17:52:51 UTC (rev 221624)
@@ -68,9 +68,9 @@
     Engine::from(sessionID).clearMemoryRepresentation(origin);
 }
 
-void CacheStorageEngineConnection::records(PAL::SessionID sessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier)
+void CacheStorageEngineConnection::retrieveRecords(PAL::SessionID sessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, WebCore::URL&& url)
 {
-    Engine::from(sessionID).retrieveRecords(cacheIdentifier, [protectedThis = makeRef(*this), this, sessionID, requestIdentifier](RecordsOrError&& result) {
+    Engine::from(sessionID).retrieveRecords(cacheIdentifier, WTFMove(url), [protectedThis = makeRef(*this), this, sessionID, requestIdentifier](RecordsOrError&& result) {
         m_connection.connection().send(Messages::WebCacheStorageConnection::UpdateRecords(requestIdentifier, result), sessionID.sessionID());
     });
 }

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.h (221623 => 221624)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.h	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.h	2017-09-05 17:52:51 UTC (rev 221624)
@@ -56,7 +56,7 @@
 
     void clearMemoryRepresentation(PAL::SessionID, const String& origin);
 
-    void records(PAL::SessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier);
+    void retrieveRecords(PAL::SessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, WebCore::URL&&);
     void deleteMatchingRecords(PAL::SessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, WebCore::ResourceRequest&&, WebCore::CacheQueryOptions&&);
     void putRecords(PAL::SessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, Vector<WebCore::DOMCacheEngine::Record>&&);
 

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


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.messages.in	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.messages.in	2017-09-05 17:52:51 UTC (rev 221624)
@@ -27,7 +27,7 @@
 
     ClearMemoryRepresentation(PAL::SessionID sessionID, String origin);
 
-    Records(PAL::SessionID sessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier);
+    RetrieveRecords(PAL::SessionID sessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, WebCore::URL url);
     DeleteMatchingRecords(PAL::SessionID sessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, WebCore::ResourceRequest request, struct WebCore::CacheQueryOptions options);
     PutRecords(PAL::SessionID sessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, Vector<WebCore::DOMCacheEngine::Record> record);
 }

Modified: trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.cpp (221623 => 221624)


--- trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.cpp	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.cpp	2017-09-05 17:52:51 UTC (rev 221624)
@@ -71,9 +71,9 @@
     connection().send(Messages::CacheStorageEngineConnection::Caches(m_sessionID, requestIdentifier, origin, updateCounter), 0);
 }
 
-void WebCacheStorageConnection::doRetrieveRecords(uint64_t requestIdentifier, uint64_t cacheIdentifier)
+void WebCacheStorageConnection::doRetrieveRecords(uint64_t requestIdentifier, uint64_t cacheIdentifier, const WebCore::URL& url)
 {
-    connection().send(Messages::CacheStorageEngineConnection::Records(m_sessionID, requestIdentifier, cacheIdentifier), 0);
+    connection().send(Messages::CacheStorageEngineConnection::RetrieveRecords(m_sessionID, requestIdentifier, cacheIdentifier, url), 0);
 }
 
 void WebCacheStorageConnection::doBatchDeleteOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, const WebCore::ResourceRequest& request, WebCore::CacheQueryOptions&& options)

Modified: trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.h (221623 => 221624)


--- trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.h	2017-09-05 17:48:42 UTC (rev 221623)
+++ trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.h	2017-09-05 17:52:51 UTC (rev 221624)
@@ -56,7 +56,7 @@
     void doRemove(uint64_t requestIdentifier, uint64_t cacheIdentifier) final;
     void doRetrieveCaches(uint64_t requestIdentifier, const String& origin, uint64_t updateCounter) final;
 
-    void doRetrieveRecords(uint64_t requestIdentifier, uint64_t cacheIdentifier) final;
+    void doRetrieveRecords(uint64_t requestIdentifier, uint64_t cacheIdentifier, const WebCore::URL&) final;
     void doBatchDeleteOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, const WebCore::ResourceRequest&, WebCore::CacheQueryOptions&&) final;
     void doBatchPutOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, Vector<WebCore::DOMCacheEngine::Record>&&) final;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to