OLD | NEW |
---|---|
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 Loading... | |
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, | |
611 | |
nhiroki
2016/08/18 00:05:42
blank line
jkarlin
2016/08/18 14:08:23
Done.
| |
609 const CacheStorageCache::ResponseCallback& callback) { | 612 const CacheStorageCache::ResponseCallback& callback) { |
610 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 613 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
611 | 614 |
612 if (!initialized_) | 615 if (!initialized_) |
613 LazyInit(); | 616 LazyInit(); |
614 | 617 |
615 quota_manager_proxy_->NotifyStorageAccessed( | 618 quota_manager_proxy_->NotifyStorageAccessed( |
616 storage::QuotaClient::kServiceWorkerCache, origin_, | 619 storage::QuotaClient::kServiceWorkerCache, origin_, |
617 storage::kStorageTypeTemporary); | 620 storage::kStorageTypeTemporary); |
618 | 621 |
619 scheduler_->ScheduleOperation( | 622 scheduler_->ScheduleOperation( |
620 base::Bind(&CacheStorage::MatchAllCachesImpl, weak_factory_.GetWeakPtr(), | 623 base::Bind(&CacheStorage::MatchAllCachesImpl, weak_factory_.GetWeakPtr(), |
621 base::Passed(std::move(request)), | 624 base::Passed(std::move(request)), match_params, |
622 scheduler_->WrapCallbackToRunNext(callback))); | 625 scheduler_->WrapCallbackToRunNext(callback))); |
623 } | 626 } |
624 | 627 |
625 void CacheStorage::GetSizeThenCloseAllCaches(const SizeCallback& callback) { | 628 void CacheStorage::GetSizeThenCloseAllCaches(const SizeCallback& callback) { |
626 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 629 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
627 | 630 |
628 if (!initialized_) | 631 if (!initialized_) |
629 LazyInit(); | 632 LazyInit(); |
630 | 633 |
631 scheduler_->ScheduleOperation(base::Bind( | 634 scheduler_->ScheduleOperation(base::Bind( |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
834 } | 837 } |
835 | 838 |
836 void CacheStorage::EnumerateCachesImpl( | 839 void CacheStorage::EnumerateCachesImpl( |
837 const StringsAndErrorCallback& callback) { | 840 const StringsAndErrorCallback& callback) { |
838 callback.Run(ordered_cache_names_, CACHE_STORAGE_OK); | 841 callback.Run(ordered_cache_names_, CACHE_STORAGE_OK); |
839 } | 842 } |
840 | 843 |
841 void CacheStorage::MatchCacheImpl( | 844 void CacheStorage::MatchCacheImpl( |
842 const std::string& cache_name, | 845 const std::string& cache_name, |
843 std::unique_ptr<ServiceWorkerFetchRequest> request, | 846 std::unique_ptr<ServiceWorkerFetchRequest> request, |
847 const CacheStorageCacheQueryParams& match_params, | |
844 const CacheStorageCache::ResponseCallback& callback) { | 848 const CacheStorageCache::ResponseCallback& callback) { |
845 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 849 std::unique_ptr<CacheStorageCacheHandle> cache_handle = |
846 GetLoadedCache(cache_name); | 850 GetLoadedCache(cache_name); |
847 | 851 |
848 if (!cache_handle) { | 852 if (!cache_handle) { |
849 callback.Run(CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND, | 853 callback.Run(CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND, |
850 std::unique_ptr<ServiceWorkerResponse>(), | 854 std::unique_ptr<ServiceWorkerResponse>(), |
851 std::unique_ptr<storage::BlobDataHandle>()); | 855 std::unique_ptr<storage::BlobDataHandle>()); |
852 return; | 856 return; |
853 } | 857 } |
854 | 858 |
855 // Pass the cache handle along to the callback to keep the cache open until | 859 // Pass the cache handle along to the callback to keep the cache open until |
856 // match is done. | 860 // match is done. |
857 CacheStorageCache* cache_ptr = cache_handle->value(); | 861 CacheStorageCache* cache_ptr = cache_handle->value(); |
858 cache_ptr->Match( | 862 cache_ptr->Match( |
859 std::move(request), | 863 std::move(request), match_params, |
860 base::Bind(&CacheStorage::MatchCacheDidMatch, weak_factory_.GetWeakPtr(), | 864 base::Bind(&CacheStorage::MatchCacheDidMatch, weak_factory_.GetWeakPtr(), |
861 base::Passed(std::move(cache_handle)), callback)); | 865 base::Passed(std::move(cache_handle)), callback)); |
862 } | 866 } |
863 | 867 |
864 void CacheStorage::MatchCacheDidMatch( | 868 void CacheStorage::MatchCacheDidMatch( |
865 std::unique_ptr<CacheStorageCacheHandle> cache_handle, | 869 std::unique_ptr<CacheStorageCacheHandle> cache_handle, |
866 const CacheStorageCache::ResponseCallback& callback, | 870 const CacheStorageCache::ResponseCallback& callback, |
867 CacheStorageError error, | 871 CacheStorageError error, |
868 std::unique_ptr<ServiceWorkerResponse> response, | 872 std::unique_ptr<ServiceWorkerResponse> response, |
869 std::unique_ptr<storage::BlobDataHandle> handle) { | 873 std::unique_ptr<storage::BlobDataHandle> handle) { |
870 callback.Run(error, std::move(response), std::move(handle)); | 874 callback.Run(error, std::move(response), std::move(handle)); |
871 } | 875 } |
872 | 876 |
873 void CacheStorage::MatchAllCachesImpl( | 877 void CacheStorage::MatchAllCachesImpl( |
874 std::unique_ptr<ServiceWorkerFetchRequest> request, | 878 std::unique_ptr<ServiceWorkerFetchRequest> request, |
879 const CacheStorageCacheQueryParams& match_params, | |
875 const CacheStorageCache::ResponseCallback& callback) { | 880 const CacheStorageCache::ResponseCallback& callback) { |
876 std::vector<CacheMatchResponse>* match_responses = | 881 std::vector<CacheMatchResponse>* match_responses = |
877 new std::vector<CacheMatchResponse>(ordered_cache_names_.size()); | 882 new std::vector<CacheMatchResponse>(ordered_cache_names_.size()); |
878 | 883 |
879 base::Closure barrier_closure = base::BarrierClosure( | 884 base::Closure barrier_closure = base::BarrierClosure( |
880 ordered_cache_names_.size(), | 885 ordered_cache_names_.size(), |
881 base::Bind(&CacheStorage::MatchAllCachesDidMatchAll, | 886 base::Bind(&CacheStorage::MatchAllCachesDidMatchAll, |
882 weak_factory_.GetWeakPtr(), | 887 weak_factory_.GetWeakPtr(), |
883 base::Passed(base::WrapUnique(match_responses)), callback)); | 888 base::Passed(base::WrapUnique(match_responses)), callback)); |
884 | 889 |
885 for (size_t i = 0, max = ordered_cache_names_.size(); i < max; ++i) { | 890 for (size_t i = 0, max = ordered_cache_names_.size(); i < max; ++i) { |
886 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 891 std::unique_ptr<CacheStorageCacheHandle> cache_handle = |
887 GetLoadedCache(ordered_cache_names_[i]); | 892 GetLoadedCache(ordered_cache_names_[i]); |
888 DCHECK(cache_handle); | 893 DCHECK(cache_handle); |
889 | 894 |
890 CacheStorageCache* cache_ptr = cache_handle->value(); | 895 CacheStorageCache* cache_ptr = cache_handle->value(); |
891 cache_ptr->Match(base::WrapUnique(new ServiceWorkerFetchRequest(*request)), | 896 cache_ptr->Match(base::WrapUnique(new ServiceWorkerFetchRequest(*request)), |
897 match_params, | |
892 base::Bind(&CacheStorage::MatchAllCachesDidMatch, | 898 base::Bind(&CacheStorage::MatchAllCachesDidMatch, |
893 weak_factory_.GetWeakPtr(), | 899 weak_factory_.GetWeakPtr(), |
894 base::Passed(std::move(cache_handle)), | 900 base::Passed(std::move(cache_handle)), |
895 &match_responses->at(i), barrier_closure)); | 901 &match_responses->at(i), barrier_closure)); |
896 } | 902 } |
897 } | 903 } |
898 | 904 |
899 void CacheStorage::MatchAllCachesDidMatch( | 905 void CacheStorage::MatchAllCachesDidMatch( |
900 std::unique_ptr<CacheStorageCacheHandle> cache_handle, | 906 std::unique_ptr<CacheStorageCacheHandle> cache_handle, |
901 CacheMatchResponse* out_match_response, | 907 CacheMatchResponse* out_match_response, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1029 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 1035 std::unique_ptr<CacheStorageCacheHandle> cache_handle = |
1030 GetLoadedCache(cache_name); | 1036 GetLoadedCache(cache_name); |
1031 CacheStorageCache* cache = cache_handle->value(); | 1037 CacheStorageCache* cache = cache_handle->value(); |
1032 cache->Size(base::Bind(&SizeRetrievedFromCache, | 1038 cache->Size(base::Bind(&SizeRetrievedFromCache, |
1033 base::Passed(std::move(cache_handle)), | 1039 base::Passed(std::move(cache_handle)), |
1034 barrier_closure, accumulator_ptr)); | 1040 barrier_closure, accumulator_ptr)); |
1035 } | 1041 } |
1036 } | 1042 } |
1037 | 1043 |
1038 } // namespace content | 1044 } // namespace content |
OLD | NEW |