Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2693)

Side by Side Diff: content/browser/cache_storage/cache_storage_cache.cc

Issue 1578363009: CacheStorage: Add ignoreSearch option to cache.matchAll(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/cache_storage/cache_storage_cache.h" 5 #include "content/browser/cache_storage/cache_storage_cache.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // If the header exists in one, it exists in both. Verify that the values 137 // If the header exists in one, it exists in both. Verify that the values
138 // are equal. 138 // are equal.
139 if (request_iter != request.end() && 139 if (request_iter != request.end() &&
140 request_iter->second != cached_request_iter->second) 140 request_iter->second != cached_request_iter->second)
141 return false; 141 return false;
142 } 142 }
143 143
144 return true; 144 return true;
145 } 145 }
146 146
147 GURL RemoveQueryParam(const GURL& url) {
148 url::Replacements<char> replacements;
149 replacements.ClearQuery();
150 return url.ReplaceComponents(replacements);
151 }
152
147 void ReadMetadata(disk_cache::Entry* entry, const MetadataCallback& callback) { 153 void ReadMetadata(disk_cache::Entry* entry, const MetadataCallback& callback) {
148 DCHECK(entry); 154 DCHECK(entry);
149 155
150 scoped_refptr<net::IOBufferWithSize> buffer( 156 scoped_refptr<net::IOBufferWithSize> buffer(
151 new net::IOBufferWithSize(entry->GetDataSize(INDEX_HEADERS))); 157 new net::IOBufferWithSize(entry->GetDataSize(INDEX_HEADERS)));
152 158
153 net::CompletionCallback read_header_callback = 159 net::CompletionCallback read_header_callback =
154 base::Bind(ReadMetadataDidReadMetadata, entry, callback, buffer); 160 base::Bind(ReadMetadataDidReadMetadata, entry, callback, buffer);
155 161
156 int read_rv = entry->ReadData(INDEX_HEADERS, 0, buffer.get(), buffer->size(), 162 int read_rv = entry->ReadData(INDEX_HEADERS, 0, buffer.get(), buffer->size(),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // Used for enumerating cache entries. 206 // Used for enumerating cache entries.
201 scoped_ptr<disk_cache::Backend::Iterator> backend_iterator; 207 scoped_ptr<disk_cache::Backend::Iterator> backend_iterator;
202 disk_cache::Entry* enumerated_entry; 208 disk_cache::Entry* enumerated_entry;
203 209
204 private: 210 private:
205 DISALLOW_COPY_AND_ASSIGN(OpenAllEntriesContext); 211 DISALLOW_COPY_AND_ASSIGN(OpenAllEntriesContext);
206 }; 212 };
207 213
208 // The state needed to pass between CacheStorageCache::MatchAll callbacks. 214 // The state needed to pass between CacheStorageCache::MatchAll callbacks.
209 struct CacheStorageCache::MatchAllContext { 215 struct CacheStorageCache::MatchAllContext {
210 explicit MatchAllContext(const CacheStorageCache::ResponsesCallback& callback) 216 MatchAllContext(scoped_ptr<ServiceWorkerFetchRequest> request,
211 : original_callback(callback), 217 const CacheStorageCacheQueryParams& match_params,
218 const ResponsesCallback& callback)
219 : request(std::move(request)),
220 options(match_params),
221 original_callback(callback),
212 out_responses(new Responses), 222 out_responses(new Responses),
213 out_blob_data_handles(new BlobDataHandles) {} 223 out_blob_data_handles(new BlobDataHandles) {}
214 ~MatchAllContext() {} 224 ~MatchAllContext() {}
215 225
226 scoped_ptr<ServiceWorkerFetchRequest> request;
227
228 CacheStorageCacheQueryParams options;
229
216 // The callback passed to the MatchAll() function. 230 // The callback passed to the MatchAll() function.
217 ResponsesCallback original_callback; 231 ResponsesCallback original_callback;
218 232
219 // The outputs of the MatchAll function. 233 // The outputs of the MatchAll function.
220 scoped_ptr<Responses> out_responses; 234 scoped_ptr<Responses> out_responses;
221 scoped_ptr<BlobDataHandles> out_blob_data_handles; 235 scoped_ptr<BlobDataHandles> out_blob_data_handles;
222 236
223 // The context holding open entries. 237 // The context holding open entries.
224 scoped_ptr<OpenAllEntriesContext> entries_context; 238 scoped_ptr<OpenAllEntriesContext> entries_context;
225 239
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 } 322 }
309 323
310 ResponseCallback pending_callback = 324 ResponseCallback pending_callback =
311 base::Bind(&CacheStorageCache::PendingResponseCallback, 325 base::Bind(&CacheStorageCache::PendingResponseCallback,
312 weak_ptr_factory_.GetWeakPtr(), callback); 326 weak_ptr_factory_.GetWeakPtr(), callback);
313 scheduler_->ScheduleOperation( 327 scheduler_->ScheduleOperation(
314 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), 328 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(),
315 base::Passed(std::move(request)), pending_callback)); 329 base::Passed(std::move(request)), pending_callback));
316 } 330 }
317 331
318 void CacheStorageCache::MatchAll(const ResponsesCallback& callback) { 332 void CacheStorageCache::MatchAll(
333 scoped_ptr<ServiceWorkerFetchRequest> request,
334 const CacheStorageCacheQueryParams& match_params,
335 const ResponsesCallback& callback) {
319 if (!LazyInitialize()) { 336 if (!LazyInitialize()) {
320 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(), 337 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(),
321 scoped_ptr<BlobDataHandles>()); 338 scoped_ptr<BlobDataHandles>());
322 return; 339 return;
323 } 340 }
324 341
325 ResponsesCallback pending_callback = 342 ResponsesCallback pending_callback =
326 base::Bind(&CacheStorageCache::PendingResponsesCallback, 343 base::Bind(&CacheStorageCache::PendingResponsesCallback,
327 weak_ptr_factory_.GetWeakPtr(), callback); 344 weak_ptr_factory_.GetWeakPtr(), callback);
345
346 scoped_ptr<MatchAllContext> context(
347 new MatchAllContext(std::move(request), match_params, pending_callback));
328 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::MatchAllImpl, 348 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::MatchAllImpl,
329 weak_ptr_factory_.GetWeakPtr(), 349 weak_ptr_factory_.GetWeakPtr(),
330 pending_callback)); 350 base::Passed(std::move(context))));
331 } 351 }
332 352
333 void CacheStorageCache::BatchOperation( 353 void CacheStorageCache::BatchOperation(
334 const std::vector<CacheStorageBatchOperation>& operations, 354 const std::vector<CacheStorageBatchOperation>& operations,
335 const ErrorCallback& callback) { 355 const ErrorCallback& callback) {
336 if (!LazyInitialize()) { 356 if (!LazyInitialize()) {
337 callback.Run(CACHE_STORAGE_ERROR_STORAGE); 357 callback.Run(CACHE_STORAGE_ERROR_STORAGE);
338 return; 358 return;
339 } 359 }
340 360
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 scoped_ptr<storage::BlobDataHandle>()); 634 scoped_ptr<storage::BlobDataHandle>());
615 return; 635 return;
616 } 636 }
617 637
618 scoped_ptr<storage::BlobDataHandle> blob_data_handle = 638 scoped_ptr<storage::BlobDataHandle> blob_data_handle =
619 PopulateResponseBody(std::move(entry), response.get()); 639 PopulateResponseBody(std::move(entry), response.get());
620 callback.Run(CACHE_STORAGE_OK, std::move(response), 640 callback.Run(CACHE_STORAGE_OK, std::move(response),
621 std::move(blob_data_handle)); 641 std::move(blob_data_handle));
622 } 642 }
623 643
624 void CacheStorageCache::MatchAllImpl(const ResponsesCallback& callback) { 644 void CacheStorageCache::MatchAllImpl(scoped_ptr<MatchAllContext> context) {
625 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 645 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
626 if (backend_state_ != BACKEND_OPEN) { 646 if (backend_state_ != BACKEND_OPEN) {
627 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(), 647 context->original_callback.Run(CACHE_STORAGE_ERROR_STORAGE,
628 scoped_ptr<BlobDataHandles>()); 648 scoped_ptr<Responses>(),
649 scoped_ptr<BlobDataHandles>());
629 return; 650 return;
630 } 651 }
631 652
632 OpenAllEntries(base::Bind(&CacheStorageCache::MatchAllDidOpenAllEntries, 653 OpenAllEntries(base::Bind(&CacheStorageCache::MatchAllDidOpenAllEntries,
633 weak_ptr_factory_.GetWeakPtr(), callback)); 654 weak_ptr_factory_.GetWeakPtr(),
655 base::Passed(std::move(context))));
634 } 656 }
635 657
636 void CacheStorageCache::MatchAllDidOpenAllEntries( 658 void CacheStorageCache::MatchAllDidOpenAllEntries(
637 const ResponsesCallback& callback, 659 scoped_ptr<MatchAllContext> context,
638 scoped_ptr<OpenAllEntriesContext> entries_context, 660 scoped_ptr<OpenAllEntriesContext> entries_context,
639 CacheStorageError error) { 661 CacheStorageError error) {
640 if (error != CACHE_STORAGE_OK) { 662 if (error != CACHE_STORAGE_OK) {
641 callback.Run(error, scoped_ptr<Responses>(), scoped_ptr<BlobDataHandles>()); 663 context->original_callback.Run(error, scoped_ptr<Responses>(),
664 scoped_ptr<BlobDataHandles>());
642 return; 665 return;
643 } 666 }
644 667
645 scoped_ptr<MatchAllContext> context(new MatchAllContext(callback));
646 context->entries_context.swap(entries_context); 668 context->entries_context.swap(entries_context);
647 Entries::iterator iter = context->entries_context->entries.begin(); 669 Entries::iterator iter = context->entries_context->entries.begin();
648 MatchAllProcessNextEntry(std::move(context), iter); 670 MatchAllProcessNextEntry(std::move(context), iter);
649 } 671 }
650 672
651 void CacheStorageCache::MatchAllProcessNextEntry( 673 void CacheStorageCache::MatchAllProcessNextEntry(
652 scoped_ptr<MatchAllContext> context, 674 scoped_ptr<MatchAllContext> context,
653 const Entries::iterator& iter) { 675 const Entries::iterator& iter) {
654 if (iter == context->entries_context->entries.end()) { 676 if (iter == context->entries_context->entries.end()) {
655 // All done. Return all of the responses. 677 // All done. Return all of the responses.
656 context->original_callback.Run(CACHE_STORAGE_OK, 678 context->original_callback.Run(CACHE_STORAGE_OK,
657 std::move(context->out_responses), 679 std::move(context->out_responses),
658 std::move(context->out_blob_data_handles)); 680 std::move(context->out_blob_data_handles));
659 return; 681 return;
660 } 682 }
661 683
684 if (context->options.ignore_search) {
685 DCHECK(context->request);
686 disk_cache::Entry* entry(*iter);
687 if (RemoveQueryParam(context->request->url) !=
688 RemoveQueryParam(GURL(entry->GetKey()))) {
689 // In this case, we don't need to read data.
690 MatchAllProcessNextEntry(std::move(context), iter + 1);
691 return;
692 }
693 }
694
662 ReadMetadata(*iter, base::Bind(&CacheStorageCache::MatchAllDidReadMetadata, 695 ReadMetadata(*iter, base::Bind(&CacheStorageCache::MatchAllDidReadMetadata,
663 weak_ptr_factory_.GetWeakPtr(), 696 weak_ptr_factory_.GetWeakPtr(),
664 base::Passed(std::move(context)), iter)); 697 base::Passed(std::move(context)), iter));
665 } 698 }
666 699
667 void CacheStorageCache::MatchAllDidReadMetadata( 700 void CacheStorageCache::MatchAllDidReadMetadata(
668 scoped_ptr<MatchAllContext> context, 701 scoped_ptr<MatchAllContext> context,
669 const Entries::iterator& iter, 702 const Entries::iterator& iter,
670 scoped_ptr<CacheMetadata> metadata) { 703 scoped_ptr<CacheMetadata> metadata) {
671 // Move ownership of the entry from the context. 704 // Move ownership of the entry from the context.
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 storage::BlobDataBuilder blob_data(response->blob_uuid); 1336 storage::BlobDataBuilder blob_data(response->blob_uuid);
1304 1337
1305 disk_cache::Entry* temp_entry = entry.get(); 1338 disk_cache::Entry* temp_entry = entry.get();
1306 blob_data.AppendDiskCacheEntry( 1339 blob_data.AppendDiskCacheEntry(
1307 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, 1340 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry,
1308 INDEX_RESPONSE_BODY); 1341 INDEX_RESPONSE_BODY);
1309 return blob_storage_context_->AddFinishedBlob(&blob_data); 1342 return blob_storage_context_->AddFinishedBlob(&blob_data);
1310 } 1343 }
1311 1344
1312 } // namespace content 1345 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.h ('k') | content/browser/cache_storage/cache_storage_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698