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

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

Issue 1719103002: CacheStorage: Expand cache.keys() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 4 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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 barrier_closure.Run(); 444 barrier_closure.Run();
445 } 445 }
446 446
447 void CacheStorageCache::BatchDidAllOperations( 447 void CacheStorageCache::BatchDidAllOperations(
448 std::unique_ptr<ErrorCallback> callback) { 448 std::unique_ptr<ErrorCallback> callback) {
449 if (callback->is_null()) 449 if (callback->is_null())
450 return; 450 return;
451 callback->Run(CACHE_STORAGE_OK); 451 callback->Run(CACHE_STORAGE_OK);
452 } 452 }
453 453
454 void CacheStorageCache::Keys(const RequestsCallback& callback) { 454 void CacheStorageCache::Keys(std::unique_ptr<ServiceWorkerFetchRequest> request,
455 const CacheStorageCacheQueryParams& options,
456 const RequestsCallback& callback) {
455 if (backend_state_ == BACKEND_CLOSED) { 457 if (backend_state_ == BACKEND_CLOSED) {
456 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Requests>()); 458 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Requests>());
457 return; 459 return;
458 } 460 }
459 461
460 scheduler_->ScheduleOperation( 462 scheduler_->ScheduleOperation(
461 base::Bind(&CacheStorageCache::KeysImpl, weak_ptr_factory_.GetWeakPtr(), 463 base::Bind(&CacheStorageCache::KeysImpl, weak_ptr_factory_.GetWeakPtr(),
464 base::Passed(std::move(request)), options,
462 scheduler_->WrapCallbackToRunNext(callback))); 465 scheduler_->WrapCallbackToRunNext(callback)));
463 } 466 }
464 467
465 void CacheStorageCache::Close(const base::Closure& callback) { 468 void CacheStorageCache::Close(const base::Closure& callback) {
466 DCHECK_NE(BACKEND_CLOSED, backend_state_) 469 DCHECK_NE(BACKEND_CLOSED, backend_state_)
467 << "Was CacheStorageCache::Close() called twice?"; 470 << "Was CacheStorageCache::Close() called twice?";
468 471
469 scheduler_->ScheduleOperation( 472 scheduler_->ScheduleOperation(
470 base::Bind(&CacheStorageCache::CloseImpl, weak_ptr_factory_.GetWeakPtr(), 473 base::Bind(&CacheStorageCache::CloseImpl, weak_ptr_factory_.GetWeakPtr(),
471 scheduler_->WrapCallbackToRunNext(callback))); 474 scheduler_->WrapCallbackToRunNext(callback)));
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 621
619 void CacheStorageCache::QueryCacheProcessNextEntry( 622 void CacheStorageCache::QueryCacheProcessNextEntry(
620 std::unique_ptr<QueryCacheResults> query_cache_results, 623 std::unique_ptr<QueryCacheResults> query_cache_results,
621 const Entries::iterator& iter) { 624 const Entries::iterator& iter) {
622 if (iter == query_cache_results->entries_context->entries.end()) { 625 if (iter == query_cache_results->entries_context->entries.end()) {
623 QueryCacheResultsCallback success_callback = query_cache_results->callback; 626 QueryCacheResultsCallback success_callback = query_cache_results->callback;
624 success_callback.Run(CACHE_STORAGE_OK, std::move(query_cache_results)); 627 success_callback.Run(CACHE_STORAGE_OK, std::move(query_cache_results));
625 return; 628 return;
626 } 629 }
627 630
628 if (query_cache_results->options.ignore_search) { 631 if (query_cache_results->request &&
629 DCHECK(query_cache_results->request); 632 !query_cache_results->request->url.is_empty()) {
630 disk_cache::Entry* entry(*iter); 633 disk_cache::Entry* entry(*iter);
631 if (RemoveQueryParam(query_cache_results->request->url) != 634 GURL requestURL = query_cache_results->request->url;
632 RemoveQueryParam(GURL(entry->GetKey()))) { 635 GURL cachedURL = GURL(entry->GetKey());
636
637 if (query_cache_results->options.ignore_search) {
638 requestURL = RemoveQueryParam(requestURL);
639 cachedURL = RemoveQueryParam(cachedURL);
640 }
641
642 if (cachedURL != requestURL) {
633 QueryCacheProcessNextEntry(std::move(query_cache_results), iter + 1); 643 QueryCacheProcessNextEntry(std::move(query_cache_results), iter + 1);
634 return; 644 return;
635 } 645 }
636 } 646 }
637 647
638 ReadMetadata(*iter, 648 ReadMetadata(*iter,
639 base::Bind(&CacheStorageCache::QueryCacheDidReadMetadata, 649 base::Bind(&CacheStorageCache::QueryCacheDidReadMetadata,
640 weak_ptr_factory_.GetWeakPtr(), 650 weak_ptr_factory_.GetWeakPtr(),
641 base::Passed(std::move(query_cache_results)), iter)); 651 base::Passed(std::move(query_cache_results)), iter));
642 } 652 }
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 DCHECK(entry_ptr); 1269 DCHECK(entry_ptr);
1260 disk_cache::ScopedEntryPtr entry(*entry_ptr); 1270 disk_cache::ScopedEntryPtr entry(*entry_ptr);
1261 1271
1262 entry->Doom(); 1272 entry->Doom();
1263 entry.reset(); 1273 entry.reset();
1264 1274
1265 UpdateCacheSize(); 1275 UpdateCacheSize();
1266 callback.Run(CACHE_STORAGE_OK); 1276 callback.Run(CACHE_STORAGE_OK);
1267 } 1277 }
1268 1278
1269 void CacheStorageCache::KeysImpl(const RequestsCallback& callback) { 1279 void CacheStorageCache::KeysImpl(
1280 std::unique_ptr<ServiceWorkerFetchRequest> request,
1281 const CacheStorageCacheQueryParams& options,
1282 const RequestsCallback& callback) {
1270 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 1283 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
1271 if (backend_state_ != BACKEND_OPEN) { 1284 if (backend_state_ != BACKEND_OPEN) {
1272 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Requests>()); 1285 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Requests>());
1273 return; 1286 return;
1274 } 1287 }
1275 1288
1276 std::unique_ptr<ServiceWorkerFetchRequest> request( 1289 QueryCache(std::move(request), options,
1277 new ServiceWorkerFetchRequest);
1278 QueryCache(std::move(request), CacheStorageCacheQueryParams(),
1279 base::Bind(&CacheStorageCache::KeysDidQueryCache, 1290 base::Bind(&CacheStorageCache::KeysDidQueryCache,
1280 weak_ptr_factory_.GetWeakPtr(), callback)); 1291 weak_ptr_factory_.GetWeakPtr(), callback));
1281 } 1292 }
1282 1293
1283 void CacheStorageCache::KeysDidQueryCache( 1294 void CacheStorageCache::KeysDidQueryCache(
1284 const RequestsCallback& callback, 1295 const RequestsCallback& callback,
1285 CacheStorageError error, 1296 CacheStorageError error,
1286 std::unique_ptr<QueryCacheResults> query_cache_results) { 1297 std::unique_ptr<QueryCacheResults> query_cache_results) {
1287 if (error != CACHE_STORAGE_OK) { 1298 if (error != CACHE_STORAGE_OK) {
1288 callback.Run(error, std::unique_ptr<Requests>()); 1299 callback.Run(error, std::unique_ptr<Requests>());
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); 1465 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA);
1455 return blob_storage_context_->AddFinishedBlob(&blob_data); 1466 return blob_storage_context_->AddFinishedBlob(&blob_data);
1456 } 1467 }
1457 1468
1458 std::unique_ptr<CacheStorageCacheHandle> 1469 std::unique_ptr<CacheStorageCacheHandle>
1459 CacheStorageCache::CreateCacheHandle() { 1470 CacheStorageCache::CreateCacheHandle() {
1460 return cache_storage_->CreateCacheHandle(this); 1471 return cache_storage_->CreateCacheHandle(this);
1461 } 1472 }
1462 1473
1463 } // namespace content 1474 } // 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