Changeset 221942 in webkit
- Timestamp:
- Sep 12, 2017 4:13:17 PM (7 years ago)
- Location:
- trunk/Source
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r221941 r221942 1 2017-09-12 Youenn Fablet <youenn@apple.com> 2 3 Introduce a RecordData for Cache to efficiently check whether it matches a corresponding request or not 4 https://bugs.webkit.org/show_bug.cgi?id=176579 5 6 Reviewed by Alex Christensen. 7 8 No change of behavior. 9 10 Introducing another version of queryCacheMatch used for the NetworkProcess implementation of the Cache. 11 Exporting the copy of a response body to be used also there. 12 13 * Modules/cache/DOMCacheEngine.cpp: 14 (WebCore::DOMCacheEngine::matchURLs): 15 (WebCore::DOMCacheEngine::queryCacheMatch): 16 (WebCore::DOMCacheEngine::copyResponseBody): 17 * Modules/cache/DOMCacheEngine.h: 18 1 19 2017-09-12 Antti Koivisto <antti@apple.com> 2 20 -
trunk/Source/WebCore/Modules/cache/DOMCacheEngine.cpp
r221478 r221942 50 50 } 51 51 52 bool queryCacheMatch(const ResourceRequest& request, const ResourceRequest& cachedRequest, const ResourceResponse& cachedResponse, const CacheQueryOptions& options)52 static inline bool matchURLs(const ResourceRequest& request, const URL& cachedURL, const CacheQueryOptions& options) 53 53 { 54 54 ASSERT(options.ignoreMethod || request.httpMethod() == "GET"); 55 55 56 56 URL requestURL = request.url(); 57 URL cachedRequestURL = cached Request.url();57 URL cachedRequestURL = cachedURL; 58 58 59 59 if (options.ignoreSearch) { 60 requestURL.setQuery({ }); 61 cachedRequestURL.setQuery({ }); 60 if (requestURL.hasQuery()) 61 requestURL.setQuery({ }); 62 if (cachedRequestURL.hasQuery()) 63 cachedRequestURL.setQuery({ }); 62 64 } 63 if (!equalIgnoringFragmentIdentifier(requestURL, cachedRequestURL)) 65 return equalIgnoringFragmentIdentifier(requestURL, cachedRequestURL); 66 } 67 68 bool queryCacheMatch(const ResourceRequest& request, const ResourceRequest& cachedRequest, const ResourceResponse& cachedResponse, const CacheQueryOptions& options) 69 { 70 if (!matchURLs(request, cachedRequest.url(), options)) 64 71 return false; 65 72 … … 71 78 return true; 72 79 73 // FIXME: This is inefficient, we should be able to split and trim whitespaces at the same time. 74 Vector<String> varyHeaderNames; 75 varyValue.split(',', false, varyHeaderNames); 76 for (auto& name : varyHeaderNames) { 77 if (stripLeadingAndTrailingHTTPSpaces(name) == "*") 78 return false; 79 if (cachedRequest.httpHeaderField(name) != request.httpHeaderField(name)) 80 bool isVarying = false; 81 varyValue.split(',', false, [&](StringView view) { 82 if (isVarying) 83 return; 84 auto nameView = stripLeadingAndTrailingHTTPSpaces(view); 85 if (nameView == "*") { 86 isVarying = true; 87 return; 88 } 89 auto name = nameView.toString(); 90 isVarying = cachedRequest.httpHeaderField(name) != request.httpHeaderField(name); 91 }); 92 93 return !isVarying; 94 } 95 96 bool queryCacheMatch(const ResourceRequest& request, const URL& url, bool hasVaryStar, const HashMap<String, String>& varyHeaders, const CacheQueryOptions& options) 97 { 98 if (!matchURLs(request, url, options)) 99 return false; 100 101 if (options.ignoreVary) 102 return true; 103 104 if (hasVaryStar) 105 return false; 106 107 for (const auto& pair : varyHeaders) { 108 if (pair.value != request.httpHeaderField(pair.key)) 80 109 return false; 81 110 } … … 94 123 } 95 124 96 static inline ResponseBody copyResponseBody(const DOMCacheEngine::ResponseBody& body)125 ResponseBody copyResponseBody(const ResponseBody& body) 97 126 { 98 127 return WTF::switchOn(body, [](const Ref<FormData>& formData) { -
trunk/Source/WebCore/Modules/cache/DOMCacheEngine.h
r221506 r221942 49 49 50 50 WEBCORE_EXPORT bool queryCacheMatch(const ResourceRequest& request, const ResourceRequest& cachedRequest, const ResourceResponse&, const CacheQueryOptions&); 51 WEBCORE_EXPORT bool queryCacheMatch(const ResourceRequest& request, const URL& url, bool hasVaryStar, const HashMap<String, String>& varyHeaders, const CacheQueryOptions&); 51 52 52 53 using ResponseBody = Variant<std::nullptr_t, Ref<FormData>, Ref<SharedBuffer>>; 53 54 ResponseBody isolatedResponseBody(const ResponseBody&); 55 WEBCORE_EXPORT ResponseBody copyResponseBody(const ResponseBody&); 54 56 55 57 struct Record { -
trunk/Source/WebKit/ChangeLog
r221934 r221942 1 2017-09-12 Youenn Fablet <youenn@apple.com> 2 3 Introduce a RecordData for Cache to efficiently check whether it matches a corresponding request or not 4 https://bugs.webkit.org/show_bug.cgi?id=176579 5 6 Reviewed by Alex Christensen. 7 8 Introducing RecordData that splits its stored data in mandatory data, 9 used to check a record with a request and optional data that is 10 necessary to build a CacheStorageEngine::Record used by WebProcess. 11 12 The mandatory data contains the URL, Vary header information and identifiers. 13 Adding routines to go from a Record to RecordData and vice versa. 14 Storing in CacheStorage::Cache RecordData instead of Record. 15 16 * NetworkProcess/cache/CacheStorageEngineCache.cpp: 17 (WebKit::CacheStorage::queryCache): 18 (WebKit::CacheStorage::updateVaryInformation): 19 (WebKit::CacheStorage::toRecord): 20 (WebKit::CacheStorage::toRecordData): 21 (WebKit::CacheStorage::Cache::retrieveRecords const): 22 (WebKit::CacheStorage::Cache::addRecord): 23 (WebKit::CacheStorage::Cache::recordsFromURL): 24 (WebKit::CacheStorage::Cache::recordsFromURL const): 25 (WebKit::CacheStorage::Cache::put): 26 (WebKit::CacheStorage::Cache::writeRecordToDisk): 27 (WebKit::CacheStorage::Cache::removeRecordFromDisk): 28 * NetworkProcess/cache/CacheStorageEngineCache.h: 29 1 30 2017-09-12 Dan Bernstein <mitz@apple.com> 2 31 -
trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp
r221710 r221942 32 32 #include "NetworkProcess.h" 33 33 #include <WebCore/CacheQueryOptions.h> 34 #include <WebCore/HTTPParsers.h> 34 35 #include <pal/SessionID.h> 35 36 #include <wtf/CurrentTime.h> … … 51 52 namespace CacheStorage { 52 53 53 static inline Vector<uint64_t> queryCache(const Vector<Record >* records, const ResourceRequest& request, const CacheQueryOptions& options)54 static inline Vector<uint64_t> queryCache(const Vector<RecordData>* records, const ResourceRequest& request, const CacheQueryOptions& options) 54 55 { 55 56 if (!records) … … 61 62 Vector<uint64_t> results; 62 63 for (const auto& record : *records) { 63 if (WebCore::DOMCacheEngine::queryCacheMatch(request, record. request, record.response, options))64 if (WebCore::DOMCacheEngine::queryCacheMatch(request, record.url, record.hasVaryStar, record.varyHeaders, options)) 64 65 results.append(record.identifier); 65 66 } 66 67 return results; 68 } 69 70 static inline void updateVaryInformation(RecordData& recordData) 71 { 72 auto varyValue = recordData.data->response.httpHeaderField(WebCore::HTTPHeaderName::Vary); 73 if (varyValue.isNull()) { 74 recordData.hasVaryStar = false; 75 recordData.varyHeaders = { }; 76 return; 77 } 78 79 varyValue.split(',', false, [&](StringView view) { 80 if (!recordData.hasVaryStar && stripLeadingAndTrailingHTTPSpaces(view) == "*") 81 recordData.hasVaryStar = true; 82 String headerName = view.toString(); 83 recordData.varyHeaders.add(headerName, recordData.data->request.httpHeaderField(headerName)); 84 }); 85 86 if (recordData.hasVaryStar) 87 recordData.varyHeaders = { }; 88 } 89 90 static inline Record toRecord(const RecordData& record) 91 { 92 return { record.identifier, record.updateResponseCounter, record.data->requestHeadersGuard, record.data->request, record.data->options, record.data->referrer, record.data->responseHeadersGuard, record.data->response, copyResponseBody(record.data->responseBody) }; 93 } 94 95 static inline RecordData toRecordData(Record&& record) 96 { 97 auto url = record.request.url(); 98 RecordData::Data data = { record.requestHeadersGuard, WTFMove(record.request), WTFMove(record.options), WTFMove(record.referrer), WTFMove(record.responseHeadersGuard), WTFMove(record.response), WTFMove(record.responseBody) }; 99 RecordData recordData = { { }, monotonicallyIncreasingTimeMS(), record.identifier, 0, url, false, { }, WTFMove(data) }; 100 101 updateVaryInformation(recordData); 102 103 return recordData; 67 104 } 68 105 … … 132 169 for (auto& records : m_records.values()) { 133 170 for (auto& record : records) 134 result.append( record.copy());171 result.append(toRecord(record)); 135 172 } 136 173 std::sort(result.begin(), result.end(), [](const auto& a, const auto& b) { … … 147 184 result.reserveInitialCapacity(records->size()); 148 185 for (auto& record : *records) 149 result. uncheckedAppend(record.copy());186 result.append(toRecord(record)); 150 187 return result; 151 188 } … … 160 197 } 161 198 162 Record & Cache::addNewURLRecord(Record&& record)163 { 164 auto key = computeKeyURL(record.request.url());165 ASSERT(!m_records.contains(key));166 167 Vector<Record> newRecords;168 newRecords.reserveInitialCapacity(1);169 newRecords.uncheckedAppend(WTFMove(record));170 return m_records.set(key, WTFMove(newRecords)).iterator->value.last();171 } 172 173 Vector<Record >* Cache::recordsFromURL(const URL& url)199 RecordData& Cache::addRecord(Vector<RecordData>* records, Record&& record) 200 { 201 if (!records) { 202 auto key = computeKeyURL(record.request.url()); 203 ASSERT(!m_records.contains(key)); 204 records = &m_records.set(key, Vector<RecordData> { }).iterator->value; 205 } 206 records->append(toRecordData(WTFMove(record))); 207 return records->last(); 208 } 209 210 Vector<RecordData>* Cache::recordsFromURL(const URL& url) 174 211 { 175 212 auto iterator = m_records.find(computeKeyURL(url)); … … 179 216 } 180 217 181 const Vector<Record >* Cache::recordsFromURL(const URL& url) const218 const Vector<RecordData>* Cache::recordsFromURL(const URL& url) const 182 219 { 183 220 auto iterator = m_records.find(computeKeyURL(url)); … … 202 239 203 240 shouldWriteRecordList = true; 204 if (!sameURLRecords) { 205 auto& recordToWrite = addNewURLRecord(WTFMove(record)); 206 writeRecordToDisk(recordToWrite); 207 } else { 208 sameURLRecords->append(WTFMove(record)); 209 writeRecordToDisk(sameURLRecords->last()); 210 } 241 auto& recordToWrite = addRecord(sameURLRecords, WTFMove(record)); 242 writeRecordToDisk(recordToWrite); 211 243 } else { 212 244 auto identifier = matchingRecords[0]; … … 216 248 auto& existingRecord = (*sameURLRecords)[position]; 217 249 recordIdentifiers.uncheckedAppend(identifier); 218 existingRecord.responseHeadersGuard = record.responseHeadersGuard;219 existingRecord.response = WTFMove(record.response);220 existingRecord.responseBody = WTFMove(record.responseBody);221 250 ++existingRecord.updateResponseCounter; 222 251 252 // FIXME: Handle the case where data is null. 253 ASSERT(existingRecord.data); 254 existingRecord.data->responseHeadersGuard = record.responseHeadersGuard; 255 existingRecord.data->response = WTFMove(record.response); 256 existingRecord.data->responseBody = WTFMove(record.responseBody); 257 updateVaryInformation(existingRecord); 223 258 writeRecordToDisk(existingRecord); 224 259 } … … 276 311 } 277 312 278 void Cache::writeRecordToDisk(Record & record)313 void Cache::writeRecordToDisk(RecordData&) 279 314 { 280 315 // FIXME: Implement this. 281 316 } 282 317 283 void Cache::removeRecordFromDisk(Record & record)318 void Cache::removeRecordFromDisk(RecordData&) 284 319 { 285 320 // FIXME: Implement this. -
trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.h
r221710 r221942 26 26 #pragma once 27 27 28 #include "NetworkCacheKey.h" 28 29 #include <WebCore/DOMCacheEngine.h> 29 30 #include <wtf/Vector.h> … … 35 36 36 37 class Caches; 38 39 struct RecordData { 40 NetworkCache::Key key; 41 double insertionTime { 0 }; 42 43 uint64_t identifier { 0 }; 44 uint64_t updateResponseCounter { 0 }; 45 46 WebCore::URL url; 47 bool hasVaryStar { false }; 48 HashMap<String, String> varyHeaders; 49 50 struct Data { 51 WebCore::FetchHeaders::Guard requestHeadersGuard; 52 WebCore::ResourceRequest request; 53 WebCore::FetchOptions options; 54 String referrer; 55 56 WebCore::FetchHeaders::Guard responseHeadersGuard; 57 WebCore::ResourceResponse response; 58 WebCore::DOMCacheEngine::ResponseBody responseBody; 59 }; 60 61 std::optional<Data> data; 62 }; 37 63 38 64 class Cache { … … 57 83 58 84 private: 59 Vector< WebCore::DOMCacheEngine::Record>* recordsFromURL(const WebCore::URL&);60 const Vector< WebCore::DOMCacheEngine::Record>* recordsFromURL(const WebCore::URL&) const;61 WebCore::DOMCacheEngine::Record& addNewURLRecord(WebCore::DOMCacheEngine::Record&&);85 Vector<RecordData>* recordsFromURL(const WebCore::URL&); 86 const Vector<RecordData>* recordsFromURL(const WebCore::URL&) const; 87 RecordData& addRecord(Vector<RecordData>*, WebCore::DOMCacheEngine::Record&&); 62 88 63 89 void finishOpening(WebCore::DOMCacheEngine::CompletionCallback&&, std::optional<WebCore::DOMCacheEngine::Error>&&); … … 65 91 void readRecordsList(WebCore::DOMCacheEngine::CompletionCallback&&); 66 92 void writeRecordsList(WebCore::DOMCacheEngine::CompletionCallback&&); 67 void writeRecordToDisk( WebCore::DOMCacheEngine::Record&);68 void removeRecordFromDisk( WebCore::DOMCacheEngine::Record&);93 void writeRecordToDisk(RecordData&); 94 void removeRecordFromDisk(RecordData&); 69 95 70 96 Caches& m_caches; … … 72 98 uint64_t m_identifier { 0 }; 73 99 String m_name; 74 HashMap<String, Vector< WebCore::DOMCacheEngine::Record>> m_records;100 HashMap<String, Vector<RecordData>> m_records; 75 101 uint64_t m_nextRecordIdentifier { 0 }; 76 102 Vector<WebCore::DOMCacheEngine::CompletionCallback> m_pendingOpeningCallbacks;
Note: See TracChangeset
for help on using the changeset viewer.