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

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

Issue 2242883002: [CacheStorage] Use QueryCache everywhere (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from PS9 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.h" 5 #include "content/browser/cache_storage/cache_storage.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 storage::kStorageTypeTemporary); 581 storage::kStorageTypeTemporary);
582 582
583 scheduler_->ScheduleOperation( 583 scheduler_->ScheduleOperation(
584 base::Bind(&CacheStorage::EnumerateCachesImpl, weak_factory_.GetWeakPtr(), 584 base::Bind(&CacheStorage::EnumerateCachesImpl, weak_factory_.GetWeakPtr(),
585 scheduler_->WrapCallbackToRunNext(callback))); 585 scheduler_->WrapCallbackToRunNext(callback)));
586 } 586 }
587 587
588 void CacheStorage::MatchCache( 588 void CacheStorage::MatchCache(
589 const std::string& cache_name, 589 const std::string& cache_name,
590 std::unique_ptr<ServiceWorkerFetchRequest> request, 590 std::unique_ptr<ServiceWorkerFetchRequest> request,
591 const CacheStorageCacheQueryParams& match_params,
591 const CacheStorageCache::ResponseCallback& callback) { 592 const CacheStorageCache::ResponseCallback& callback) {
592 DCHECK_CURRENTLY_ON(BrowserThread::IO); 593 DCHECK_CURRENTLY_ON(BrowserThread::IO);
593 594
594 if (!initialized_) 595 if (!initialized_)
595 LazyInit(); 596 LazyInit();
596 597
597 quota_manager_proxy_->NotifyStorageAccessed( 598 quota_manager_proxy_->NotifyStorageAccessed(
598 storage::QuotaClient::kServiceWorkerCache, origin_, 599 storage::QuotaClient::kServiceWorkerCache, origin_,
599 storage::kStorageTypeTemporary); 600 storage::kStorageTypeTemporary);
600 601
601 scheduler_->ScheduleOperation( 602 scheduler_->ScheduleOperation(
602 base::Bind(&CacheStorage::MatchCacheImpl, weak_factory_.GetWeakPtr(), 603 base::Bind(&CacheStorage::MatchCacheImpl, weak_factory_.GetWeakPtr(),
603 cache_name, base::Passed(std::move(request)), 604 cache_name, base::Passed(std::move(request)), match_params,
604 scheduler_->WrapCallbackToRunNext(callback))); 605 scheduler_->WrapCallbackToRunNext(callback)));
605 } 606 }
606 607
607 void CacheStorage::MatchAllCaches( 608 void CacheStorage::MatchAllCaches(
608 std::unique_ptr<ServiceWorkerFetchRequest> request, 609 std::unique_ptr<ServiceWorkerFetchRequest> request,
610 const CacheStorageCacheQueryParams& match_params,
609 const CacheStorageCache::ResponseCallback& callback) { 611 const CacheStorageCache::ResponseCallback& callback) {
610 DCHECK_CURRENTLY_ON(BrowserThread::IO); 612 DCHECK_CURRENTLY_ON(BrowserThread::IO);
611 613
612 if (!initialized_) 614 if (!initialized_)
613 LazyInit(); 615 LazyInit();
614 616
615 quota_manager_proxy_->NotifyStorageAccessed( 617 quota_manager_proxy_->NotifyStorageAccessed(
616 storage::QuotaClient::kServiceWorkerCache, origin_, 618 storage::QuotaClient::kServiceWorkerCache, origin_,
617 storage::kStorageTypeTemporary); 619 storage::kStorageTypeTemporary);
618 620
619 scheduler_->ScheduleOperation( 621 scheduler_->ScheduleOperation(
620 base::Bind(&CacheStorage::MatchAllCachesImpl, weak_factory_.GetWeakPtr(), 622 base::Bind(&CacheStorage::MatchAllCachesImpl, weak_factory_.GetWeakPtr(),
621 base::Passed(std::move(request)), 623 base::Passed(std::move(request)), match_params,
622 scheduler_->WrapCallbackToRunNext(callback))); 624 scheduler_->WrapCallbackToRunNext(callback)));
623 } 625 }
624 626
625 void CacheStorage::GetSizeThenCloseAllCaches(const SizeCallback& callback) { 627 void CacheStorage::GetSizeThenCloseAllCaches(const SizeCallback& callback) {
626 DCHECK_CURRENTLY_ON(BrowserThread::IO); 628 DCHECK_CURRENTLY_ON(BrowserThread::IO);
627 629
628 if (!initialized_) 630 if (!initialized_)
629 LazyInit(); 631 LazyInit();
630 632
631 scheduler_->ScheduleOperation(base::Bind( 633 scheduler_->ScheduleOperation(base::Bind(
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 } 836 }
835 837
836 void CacheStorage::EnumerateCachesImpl( 838 void CacheStorage::EnumerateCachesImpl(
837 const StringsAndErrorCallback& callback) { 839 const StringsAndErrorCallback& callback) {
838 callback.Run(ordered_cache_names_, CACHE_STORAGE_OK); 840 callback.Run(ordered_cache_names_, CACHE_STORAGE_OK);
839 } 841 }
840 842
841 void CacheStorage::MatchCacheImpl( 843 void CacheStorage::MatchCacheImpl(
842 const std::string& cache_name, 844 const std::string& cache_name,
843 std::unique_ptr<ServiceWorkerFetchRequest> request, 845 std::unique_ptr<ServiceWorkerFetchRequest> request,
846 const CacheStorageCacheQueryParams& match_params,
844 const CacheStorageCache::ResponseCallback& callback) { 847 const CacheStorageCache::ResponseCallback& callback) {
845 std::unique_ptr<CacheStorageCacheHandle> cache_handle = 848 std::unique_ptr<CacheStorageCacheHandle> cache_handle =
846 GetLoadedCache(cache_name); 849 GetLoadedCache(cache_name);
847 850
848 if (!cache_handle) { 851 if (!cache_handle) {
849 callback.Run(CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND, 852 callback.Run(CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND,
850 std::unique_ptr<ServiceWorkerResponse>(), 853 std::unique_ptr<ServiceWorkerResponse>(),
851 std::unique_ptr<storage::BlobDataHandle>()); 854 std::unique_ptr<storage::BlobDataHandle>());
852 return; 855 return;
853 } 856 }
854 857
855 // Pass the cache handle along to the callback to keep the cache open until 858 // Pass the cache handle along to the callback to keep the cache open until
856 // match is done. 859 // match is done.
857 CacheStorageCache* cache_ptr = cache_handle->value(); 860 CacheStorageCache* cache_ptr = cache_handle->value();
858 cache_ptr->Match( 861 cache_ptr->Match(
859 std::move(request), 862 std::move(request), match_params,
860 base::Bind(&CacheStorage::MatchCacheDidMatch, weak_factory_.GetWeakPtr(), 863 base::Bind(&CacheStorage::MatchCacheDidMatch, weak_factory_.GetWeakPtr(),
861 base::Passed(std::move(cache_handle)), callback)); 864 base::Passed(std::move(cache_handle)), callback));
862 } 865 }
863 866
864 void CacheStorage::MatchCacheDidMatch( 867 void CacheStorage::MatchCacheDidMatch(
865 std::unique_ptr<CacheStorageCacheHandle> cache_handle, 868 std::unique_ptr<CacheStorageCacheHandle> cache_handle,
866 const CacheStorageCache::ResponseCallback& callback, 869 const CacheStorageCache::ResponseCallback& callback,
867 CacheStorageError error, 870 CacheStorageError error,
868 std::unique_ptr<ServiceWorkerResponse> response, 871 std::unique_ptr<ServiceWorkerResponse> response,
869 std::unique_ptr<storage::BlobDataHandle> handle) { 872 std::unique_ptr<storage::BlobDataHandle> handle) {
870 callback.Run(error, std::move(response), std::move(handle)); 873 callback.Run(error, std::move(response), std::move(handle));
871 } 874 }
872 875
873 void CacheStorage::MatchAllCachesImpl( 876 void CacheStorage::MatchAllCachesImpl(
874 std::unique_ptr<ServiceWorkerFetchRequest> request, 877 std::unique_ptr<ServiceWorkerFetchRequest> request,
878 const CacheStorageCacheQueryParams& match_params,
875 const CacheStorageCache::ResponseCallback& callback) { 879 const CacheStorageCache::ResponseCallback& callback) {
876 std::vector<CacheMatchResponse>* match_responses = 880 std::vector<CacheMatchResponse>* match_responses =
877 new std::vector<CacheMatchResponse>(ordered_cache_names_.size()); 881 new std::vector<CacheMatchResponse>(ordered_cache_names_.size());
878 882
879 base::Closure barrier_closure = base::BarrierClosure( 883 base::Closure barrier_closure = base::BarrierClosure(
880 ordered_cache_names_.size(), 884 ordered_cache_names_.size(),
881 base::Bind(&CacheStorage::MatchAllCachesDidMatchAll, 885 base::Bind(&CacheStorage::MatchAllCachesDidMatchAll,
882 weak_factory_.GetWeakPtr(), 886 weak_factory_.GetWeakPtr(),
883 base::Passed(base::WrapUnique(match_responses)), callback)); 887 base::Passed(base::WrapUnique(match_responses)), callback));
884 888
885 for (size_t i = 0, max = ordered_cache_names_.size(); i < max; ++i) { 889 for (size_t i = 0, max = ordered_cache_names_.size(); i < max; ++i) {
886 std::unique_ptr<CacheStorageCacheHandle> cache_handle = 890 std::unique_ptr<CacheStorageCacheHandle> cache_handle =
887 GetLoadedCache(ordered_cache_names_[i]); 891 GetLoadedCache(ordered_cache_names_[i]);
888 DCHECK(cache_handle); 892 DCHECK(cache_handle);
889 893
890 CacheStorageCache* cache_ptr = cache_handle->value(); 894 CacheStorageCache* cache_ptr = cache_handle->value();
891 cache_ptr->Match(base::WrapUnique(new ServiceWorkerFetchRequest(*request)), 895 cache_ptr->Match(base::WrapUnique(new ServiceWorkerFetchRequest(*request)),
896 match_params,
892 base::Bind(&CacheStorage::MatchAllCachesDidMatch, 897 base::Bind(&CacheStorage::MatchAllCachesDidMatch,
893 weak_factory_.GetWeakPtr(), 898 weak_factory_.GetWeakPtr(),
894 base::Passed(std::move(cache_handle)), 899 base::Passed(std::move(cache_handle)),
895 &match_responses->at(i), barrier_closure)); 900 &match_responses->at(i), barrier_closure));
896 } 901 }
897 } 902 }
898 903
899 void CacheStorage::MatchAllCachesDidMatch( 904 void CacheStorage::MatchAllCachesDidMatch(
900 std::unique_ptr<CacheStorageCacheHandle> cache_handle, 905 std::unique_ptr<CacheStorageCacheHandle> cache_handle,
901 CacheMatchResponse* out_match_response, 906 CacheMatchResponse* out_match_response,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 std::unique_ptr<CacheStorageCacheHandle> cache_handle = 1034 std::unique_ptr<CacheStorageCacheHandle> cache_handle =
1030 GetLoadedCache(cache_name); 1035 GetLoadedCache(cache_name);
1031 CacheStorageCache* cache = cache_handle->value(); 1036 CacheStorageCache* cache = cache_handle->value();
1032 cache->Size(base::Bind(&SizeRetrievedFromCache, 1037 cache->Size(base::Bind(&SizeRetrievedFromCache,
1033 base::Passed(std::move(cache_handle)), 1038 base::Passed(std::move(cache_handle)),
1034 barrier_closure, accumulator_ptr)); 1039 barrier_closure, accumulator_ptr));
1035 } 1040 }
1036 } 1041 }
1037 1042
1038 } // namespace content 1043 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage.h ('k') | content/browser/cache_storage/cache_storage_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698