Changeset 258868 in webkit
- Timestamp:
- Mar 23, 2020 12:33:55 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r258866 r258868 1 2020-03-23 youenn fablet <youenn@apple.com> 2 3 Remove DOMCache::m_records 4 https://bugs.webkit.org/show_bug.cgi?id=209425 5 6 Reviewed by Alex Christensen. 7 8 We do not need to keep references of FetchRequest and FetchResponse since we clone them before exposing them. 9 For that reason, remove m_records and directly use records given from the CacheStorageConnection. 10 Minor refactoring to modernize/improve code readability. 11 12 This is a first step towards a future refactoring that will reduce the sending of records from network process to web process 13 based on the request parameters: record filtering will be done in network process instead of web process. 14 15 No change of behavior. 16 17 * Modules/cache/DOMCache.cpp: 18 (WebCore::createResponse): 19 (WebCore::DOMCache::doMatch): 20 (WebCore::DOMCache::cloneResponses): 21 (WebCore::DOMCache::matchAll): 22 (WebCore::createRequest): 23 (WebCore::DOMCache::keys): 24 (WebCore::DOMCache::retrieveRecords): 25 (WebCore::DOMCache::queryCache): 26 (WebCore::DOMCache::queryCacheWithTargetStorage): 27 (WebCore::DOMCache::batchDeleteOperation): 28 (WebCore::DOMCache::batchPutOperation): 29 (WebCore::copyRequestRef): Deleted. 30 (WebCore::queryCacheMatch): Deleted. 31 (WebCore::DOMCache::updateRecords): Deleted. 32 * Modules/cache/DOMCache.h: 33 1 34 2020-03-23 Rob Buis <rbuis@igalia.com> 2 35 -
trunk/Source/WebCore/Modules/cache/DOMCache.cpp
r254919 r258868 74 74 } 75 75 76 static Ref<FetchResponse> createResponse(ScriptExecutionContext& context, const DOMCacheEngine::Record& record) 77 { 78 auto resourceResponse = record.response; 79 resourceResponse.setSource(ResourceResponse::Source::DOMCache); 80 auto response = FetchResponse::create(context, WTF::nullopt, record.responseHeadersGuard, WTFMove(resourceResponse)); 81 response->setBodyData(copyResponseBody(record.responseBody), record.responseBodySize); 82 return response; 83 } 84 76 85 void DOMCache::doMatch(RequestInfo&& info, CacheQueryOptions&& options, MatchCallback&& callback) 77 86 { … … 86 95 auto request = requestOrException.releaseReturnValue(); 87 96 88 queryCache(request.get(), WTFMove(options), [this, callback = WTFMove(callback)]( ExceptionOr<Vector<CacheStorageRecord>>&& result) mutable {97 queryCache(request.get(), WTFMove(options), [this, callback = WTFMove(callback)](auto&& result) mutable { 89 98 if (result.hasException()) { 90 99 callback(result.releaseException()); 91 100 return; 92 101 } 93 if (result.returnValue().isEmpty()) { 94 callback(nullptr);95 return;96 }97 callback(RefPtr<FetchResponse>(result.returnValue()[0].response->clone(*scriptExecutionContext()).releaseReturnValue())); 98 });99 } 100 101 Vector<Ref<FetchResponse>> DOMCache::cloneResponses(const Vector<CacheStorageRecord>& records) 102 { 103 auto& context = *scriptExecutionContext(); 104 return WTF::map(records, [ &context] (const auto& record) {105 return record.response->clone(context).releaseReturnValue();102 103 RefPtr<FetchResponse> response; 104 if (!result.returnValue().isEmpty()) 105 response = createResponse(*scriptExecutionContext(), result.returnValue()[0]); 106 107 callback(WTFMove(response)); 108 }); 109 } 110 111 Vector<Ref<FetchResponse>> DOMCache::cloneResponses(const Vector<DOMCacheEngine::Record>& records) 112 { 113 return WTF::map(records, [this] (const auto& record) { 114 return createResponse(*scriptExecutionContext(), record); 106 115 }); 107 116 } … … 122 131 } 123 132 124 if (!request) { 125 retrieveRecords(URL { }, [this, promise = WTFMove(promise)](Optional<Exception>&& exception) mutable { 126 queueTaskKeepingObjectAlive(*this, TaskSource::DOMManipulation, [this, promise = WTFMove(promise), exception = WTFMove(exception)]() mutable { 127 if (exception) { 128 promise.reject(WTFMove(exception.value())); 129 return; 130 } 131 promise.resolve(cloneResponses(m_records)); 132 }); 133 }); 134 return; 135 } 136 queryCache(request.releaseNonNull(), WTFMove(options), [this, promise = WTFMove(promise)](ExceptionOr<Vector<CacheStorageRecord>>&& result) mutable { 133 RecordsCallback callback = [this, promise = WTFMove(promise)](auto&& result) mutable { 137 134 queueTaskKeepingObjectAlive(*this, TaskSource::DOMManipulation, [this, promise = WTFMove(promise), result = WTFMove(result)]() mutable { 138 135 if (result.hasException()) { … … 142 139 promise.resolve(cloneResponses(result.releaseReturnValue())); 143 140 }); 144 }); 141 }; 142 143 if (!request) 144 return retrieveRecords(URL { }, WTFMove(callback)); 145 queryCache(request.releaseNonNull(), WTFMove(options), WTFMove(callback)); 145 146 } 146 147 … … 414 415 } 415 416 416 static inline Ref<FetchRequest> copyRequestRef(const CacheStorageRecord& record) 417 { 418 return record.request.copyRef(); 417 static Ref<FetchRequest> createRequest(ScriptExecutionContext& context, const DOMCacheEngine::Record& record) 418 { 419 auto requestHeaders = FetchHeaders::create(record.requestHeadersGuard, HTTPHeaderMap { record.request.httpHeaderFields() }); 420 return FetchRequest::create(context, WTF::nullopt, WTFMove(requestHeaders), ResourceRequest { record.request }, FetchOptions { record.options }, String { record.referrer }); 419 421 } 420 422 … … 434 436 } 435 437 436 if (!request) { 437 retrieveRecords(URL { }, [this, promise = WTFMove(promise)](Optional<Exception>&& exception) mutable { 438 queueTaskKeepingObjectAlive(*this, TaskSource::DOMManipulation, [this, promise = WTFMove(promise), exception = WTFMove(exception)]() mutable { 439 if (exception) { 440 promise.reject(WTFMove(exception.value())); 441 return; 442 } 443 promise.resolve(WTF::map(m_records, copyRequestRef)); 444 }); 445 }); 446 return; 447 } 448 449 queryCache(request.releaseNonNull(), WTFMove(options), [this, protectedThis = makeRef(*this), promise = WTFMove(promise)](auto&& result) mutable { 450 queueTaskKeepingObjectAlive(*this, TaskSource::DOMManipulation, [promise = WTFMove(promise), result = WTFMove(result)]() mutable { 438 RecordsCallback callback = [this, promise = WTFMove(promise)](auto&& result) mutable { 439 queueTaskKeepingObjectAlive(*this, TaskSource::DOMManipulation, [this, promise = WTFMove(promise), result = WTFMove(result)]() mutable { 451 440 if (result.hasException()) { 452 441 promise.reject(result.releaseException()); … … 454 443 } 455 444 456 promise.resolve(WTF::map(result.releaseReturnValue(), copyRequestRef)); 457 }); 458 }); 459 } 460 461 void DOMCache::retrieveRecords(const URL& url, WTF::Function<void(Optional<Exception>&&)>&& callback) 445 auto records = result.releaseReturnValue(); 446 promise.resolve(WTF::map(records, [this](auto& record) { 447 return createRequest(*scriptExecutionContext(), record); 448 })); 449 }); 450 }; 451 452 if (!request) 453 return retrieveRecords(URL { }, WTFMove(callback)); 454 queryCache(request.releaseNonNull(), WTFMove(options), WTFMove(callback)); 455 } 456 457 void DOMCache::retrieveRecords(const URL& url, RecordsCallback&& callback) 462 458 { 463 459 URL retrieveURL = url; 464 460 retrieveURL.removeQueryAndFragmentIdentifier(); 465 461 466 m_connection->retrieveRecords(m_identifier, retrieveURL, [this, pendingActivity = makePendingActivity(*this), callback = WTFMove(callback)](RecordsOrError&& result) { 467 if (m_isStopped) 468 return; 462 m_connection->retrieveRecords(m_identifier, retrieveURL, [this, pendingActivity = makePendingActivity(*this), callback = WTFMove(callback)](auto&& result) mutable { 463 if (m_isStopped) { 464 callback(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), DOMCacheEngine::Error::Stopped)); 465 return; 466 } 469 467 470 468 if (!result.has_value()) { … … 473 471 } 474 472 475 updateRecords(WTFMove(result.value())); 476 callback(WTF::nullopt); 477 }); 478 } 479 480 void DOMCache::queryCache(Ref<FetchRequest>&& request, CacheQueryOptions&& options, WTF::Function<void(ExceptionOr<Vector<CacheStorageRecord>>&&)>&& callback) 473 callback(WTFMove(result.value())); 474 }); 475 } 476 477 void DOMCache::queryCache(Ref<FetchRequest>&& request, CacheQueryOptions&& options, RecordsCallback&& callback) 481 478 { 482 479 auto url = request->url(); 483 retrieveRecords(url, [this, request = WTFMove(request), options = WTFMove(options), callback = WTFMove(callback)](Optional<Exception>&& exception) mutable { 484 if (exception) { 485 callback(WTFMove(exception.value())); 486 return; 487 } 488 callback(queryCacheWithTargetStorage(request.get(), options, m_records)); 489 }); 490 } 491 492 static inline bool queryCacheMatch(const FetchRequest& request, const FetchRequest& cachedRequest, const ResourceResponse& cachedResponse, const CacheQueryOptions& options) 493 { 494 // We need to pass the resource request with all correct headers hence why we call resourceRequest(). 495 return DOMCacheEngine::queryCacheMatch(request.resourceRequest(), cachedRequest.resourceRequest(), cachedResponse, options); 496 } 497 498 Vector<CacheStorageRecord> DOMCache::queryCacheWithTargetStorage(const FetchRequest& request, const CacheQueryOptions& options, const Vector<CacheStorageRecord>& targetStorage) 480 retrieveRecords(url, [this, request = WTFMove(request), options = WTFMove(options), callback = WTFMove(callback)](auto&& result) mutable { 481 if (result.hasException()) { 482 callback(result.releaseException()); 483 return; 484 } 485 callback(queryCacheWithTargetStorage(request.get(), options, result.releaseReturnValue())); 486 }); 487 } 488 489 Vector<DOMCacheEngine::Record> DOMCache::queryCacheWithTargetStorage(const FetchRequest& request, const CacheQueryOptions& options, const Vector<DOMCacheEngine::Record>& targetStorage) 499 490 { 500 491 if (!options.ignoreMethod && request.method() != "GET") 501 492 return { }; 502 493 503 Vector< CacheStorageRecord> records;494 Vector<DOMCacheEngine::Record> records; 504 495 for (auto& record : targetStorage) { 505 if (queryCacheMatch(request, record.request.get(), record.response->resourceResponse(), options)) 506 records.append({ record.identifier, record.updateResponseCounter, record.request.copyRef(), record.response.copyRef() }); 496 // We need to pass the resource request with all correct headers hence why we call resourceRequest(). 497 if (DOMCacheEngine::queryCacheMatch(request.resourceRequest(), record.request, record.response, options)) 498 records.append(record.copy()); 507 499 } 508 500 return records; 509 501 } 510 502 511 void DOMCache::batchDeleteOperation(const FetchRequest& request, CacheQueryOptions&& options, WTF::Function<void(ExceptionOr<bool>&&)>&& callback) 512 { 513 m_connection->batchDeleteOperation(m_identifier, request.internalRequest(), WTFMove(options), [this, pendingActivity = makePendingActivity(*this), callback = WTFMove(callback)](RecordIdentifiersOrError&& result) { 514 if (m_isStopped) 515 return; 503 void DOMCache::batchDeleteOperation(const FetchRequest& request, CacheQueryOptions&& options, CompletionHandler<void(ExceptionOr<bool>&&)>&& callback) 504 { 505 m_connection->batchDeleteOperation(m_identifier, request.internalRequest(), WTFMove(options), [this, pendingActivity = makePendingActivity(*this), callback = WTFMove(callback)](RecordIdentifiersOrError&& result) mutable { 506 if (m_isStopped) { 507 callback(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), DOMCacheEngine::Error::Stopped)); 508 return; 509 } 516 510 517 511 if (!result.has_value()) { … … 544 538 } 545 539 546 void DOMCache::batchPutOperation(const FetchRequest& request, FetchResponse& response, DOMCacheEngine::ResponseBody&& responseBody, WTF::Function<void(ExceptionOr<void>&&)>&& callback)540 void DOMCache::batchPutOperation(const FetchRequest& request, FetchResponse& response, DOMCacheEngine::ResponseBody&& responseBody, CompletionHandler<void(ExceptionOr<void>&&)>&& callback) 547 541 { 548 542 Vector<Record> records; … … 552 546 } 553 547 554 void DOMCache::batchPutOperation(Vector<Record>&& records, WTF::Function<void(ExceptionOr<void>&&)>&& callback) 555 { 556 m_connection->batchPutOperation(m_identifier, WTFMove(records), [this, pendingActivity = makePendingActivity(*this), callback = WTFMove(callback)](RecordIdentifiersOrError&& result) { 557 if (m_isStopped) 558 return; 548 void DOMCache::batchPutOperation(Vector<Record>&& records, CompletionHandler<void(ExceptionOr<void>&&)>&& callback) 549 { 550 m_connection->batchPutOperation(m_identifier, WTFMove(records), [this, pendingActivity = makePendingActivity(*this), callback = WTFMove(callback)](auto&& result) mutable { 551 if (m_isStopped) { 552 callback(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), DOMCacheEngine::Error::Stopped)); 553 return; 554 } 555 559 556 if (!result.has_value()) { 560 557 callback(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), result.error())); … … 565 562 } 566 563 567 void DOMCache::updateRecords(Vector<Record>&& records)568 {569 ASSERT(scriptExecutionContext());570 Vector<CacheStorageRecord> newRecords;571 572 for (auto& record : records) {573 size_t index = m_records.findMatching([&](const auto& item) { return item.identifier == record.identifier; });574 if (index != notFound) {575 auto& current = m_records[index];576 if (current.updateResponseCounter != record.updateResponseCounter) {577 record.response.setSource(ResourceResponse::Source::DOMCache);578 auto response = FetchResponse::create(*scriptExecutionContext(), WTF::nullopt, record.responseHeadersGuard, WTFMove(record.response));579 response->setBodyData(WTFMove(record.responseBody), record.responseBodySize);580 581 current.response = WTFMove(response);582 current.updateResponseCounter = record.updateResponseCounter;583 }584 newRecords.append(WTFMove(current));585 } else {586 auto requestHeaders = FetchHeaders::create(record.requestHeadersGuard, HTTPHeaderMap { record.request.httpHeaderFields() });587 auto request = FetchRequest::create(*scriptExecutionContext(), WTF::nullopt, WTFMove(requestHeaders), WTFMove(record.request), WTFMove(record.options), WTFMove(record.referrer));588 589 record.response.setSource(ResourceResponse::Source::DOMCache);590 auto response = FetchResponse::create(*scriptExecutionContext(), WTF::nullopt, record.responseHeadersGuard, WTFMove(record.response));591 response->setBodyData(WTFMove(record.responseBody), record.responseBodySize);592 593 newRecords.append(CacheStorageRecord { record.identifier, record.updateResponseCounter, WTFMove(request), WTFMove(response) });594 }595 }596 m_records = WTFMove(newRecords);597 }598 599 564 void DOMCache::stop() 600 565 { -
trunk/Source/WebCore/Modules/cache/DOMCache.h
r252227 r258868 28 28 #include "ActiveDOMObject.h" 29 29 #include "CacheStorageConnection.h" 30 #include "CacheStorageRecord.h" 30 #include "FetchRequest.h" 31 #include "FetchResponse.h" 31 32 #include <wtf/UniqueRef.h> 32 33 … … 58 59 uint64_t identifier() const { return m_identifier; } 59 60 60 using MatchCallback = Function<void(ExceptionOr<RefPtr<FetchResponse>>)>;61 using MatchCallback = CompletionHandler<void(ExceptionOr<RefPtr<FetchResponse>>)>; 61 62 void doMatch(RequestInfo&&, CacheQueryOptions&&, MatchCallback&&); 62 63 … … 74 75 void putWithResponseData(DOMPromiseDeferred<void>&&, Ref<FetchRequest>&&, Ref<FetchResponse>&&, ExceptionOr<RefPtr<SharedBuffer>>&&); 75 76 76 void retrieveRecords(const URL&, WTF::Function<void(Optional<Exception>&&)>&&); 77 Vector<CacheStorageRecord> queryCacheWithTargetStorage(const FetchRequest&, const CacheQueryOptions&, const Vector<CacheStorageRecord>&); 78 void queryCache(Ref<FetchRequest>&&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<Vector<CacheStorageRecord>>&&)>&&); 79 void batchDeleteOperation(const FetchRequest&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<bool>&&)>&&); 80 void batchPutOperation(const FetchRequest&, FetchResponse&, DOMCacheEngine::ResponseBody&&, WTF::Function<void(ExceptionOr<void>&&)>&&); 81 void batchPutOperation(Vector<DOMCacheEngine::Record>&&, WTF::Function<void(ExceptionOr<void>&&)>&&); 77 using RecordsCallback = CompletionHandler<void(ExceptionOr<Vector<DOMCacheEngine::Record>>&&)>; 78 void retrieveRecords(const URL&, RecordsCallback&&); 79 Vector<DOMCacheEngine::Record> queryCacheWithTargetStorage(const FetchRequest&, const CacheQueryOptions&, const Vector<DOMCacheEngine::Record>&); 80 void queryCache(Ref<FetchRequest>&&, CacheQueryOptions&&, RecordsCallback&&); 81 void batchDeleteOperation(const FetchRequest&, CacheQueryOptions&&, CompletionHandler<void(ExceptionOr<bool>&&)>&&); 82 void batchPutOperation(const FetchRequest&, FetchResponse&, DOMCacheEngine::ResponseBody&&, CompletionHandler<void(ExceptionOr<void>&&)>&&); 83 void batchPutOperation(Vector<DOMCacheEngine::Record>&&, CompletionHandler<void(ExceptionOr<void>&&)>&&); 82 84 83 void updateRecords(Vector<DOMCacheEngine::Record>&&); 84 Vector<Ref<FetchResponse>> cloneResponses(const Vector<CacheStorageRecord>&); 85 Vector<Ref<FetchResponse>> cloneResponses(const Vector<DOMCacheEngine::Record>&); 85 86 DOMCacheEngine::Record toConnectionRecord(const FetchRequest&, FetchResponse&, DOMCacheEngine::ResponseBody&&); 86 87 … … 89 90 Ref<CacheStorageConnection> m_connection; 90 91 91 Vector<CacheStorageRecord> m_records;92 92 bool m_isStopped { false }; 93 93 }; -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r258843 r258868 1133 1133 41D129D01F3D0F0500D15E47 /* CacheQueryOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 41FB279B1F34CEF000795487 /* CacheQueryOptions.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1134 1134 41D129D11F3D0F0E00D15E47 /* DOMWindowCaches.h in Headers */ = {isa = PBXBuildFile; fileRef = 41FB278C1F34C28200795487 /* DOMWindowCaches.h */; }; 1135 41D129D21F3D0F1200D15E47 /* CacheStorageRecord.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D129CA1F3D0EE300D15E47 /* CacheStorageRecord.h */; };1136 1135 41D129D31F3D0F1600D15E47 /* CacheStorageConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D129CC1F3D0EE300D15E47 /* CacheStorageConnection.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1137 1136 41D129D51F3D0F6900D15E47 /* CacheStorageProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D129D41F3D0F6600D15E47 /* CacheStorageProvider.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 7559 7558 41D015C90F4B5C71004A662F /* ContentType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentType.cpp; sourceTree = "<group>"; }; 7560 7559 41D129C91F3D0EE300D15E47 /* CacheStorageConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CacheStorageConnection.cpp; sourceTree = "<group>"; }; 7561 41D129CA1F3D0EE300D15E47 /* CacheStorageRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheStorageRecord.h; sourceTree = "<group>"; };7562 7560 41D129CC1F3D0EE300D15E47 /* CacheStorageConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheStorageConnection.h; sourceTree = "<group>"; }; 7563 7561 41D129D41F3D0F6600D15E47 /* CacheStorageProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheStorageProvider.h; sourceTree = "<group>"; }; … … 18203 18201 41D129C91F3D0EE300D15E47 /* CacheStorageConnection.cpp */, 18204 18202 41D129CC1F3D0EE300D15E47 /* CacheStorageConnection.h */, 18205 41D129CA1F3D0EE300D15E47 /* CacheStorageRecord.h */,18206 18203 41380C201F34368A00155FDA /* DOMCache.cpp */, 18207 18204 41380C251F34369A00155FDA /* DOMCache.h */, … … 29582 29579 41D129D31F3D0F1600D15E47 /* CacheStorageConnection.h in Headers */, 29583 29580 41D129D51F3D0F6900D15E47 /* CacheStorageProvider.h in Headers */, 29584 41D129D21F3D0F1200D15E47 /* CacheStorageRecord.h in Headers */,29585 29581 E43AF8E71AC5B7EC00CA717E /* CacheValidation.h in Headers */, 29586 29582 49AE2D97134EE5F90072920A /* CalculationValue.h in Headers */,
Note: See TracChangeset
for help on using the changeset viewer.