| 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 const int kCachePreservationInSecs = 30; | 42 const int kCachePreservationInSecs = 30; |
| 43 | 43 |
| 44 std::string HexedHash(const std::string& value) { | 44 std::string HexedHash(const std::string& value) { |
| 45 std::string value_hash = base::SHA1HashString(value); | 45 std::string value_hash = base::SHA1HashString(value); |
| 46 std::string valued_hexed_hash = base::ToLowerASCII( | 46 std::string valued_hexed_hash = base::ToLowerASCII( |
| 47 base::HexEncode(value_hash.c_str(), value_hash.length())); | 47 base::HexEncode(value_hash.c_str(), value_hash.length())); |
| 48 return valued_hexed_hash; | 48 return valued_hexed_hash; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void SizeRetrievedFromCache(const base::Closure& closure, | 51 void SizeRetrievedFromCache(const scoped_refptr<CacheStorageCache>& cache, |
| 52 const base::Closure& closure, |
| 52 int64_t* accumulator, | 53 int64_t* accumulator, |
| 53 int64_t size) { | 54 int64_t size) { |
| 54 *accumulator += size; | 55 *accumulator += size; |
| 55 closure.Run(); | 56 closure.Run(); |
| 56 } | 57 } |
| 57 | 58 |
| 59 void SizeRetrievedFromAllCaches(std::unique_ptr<int64_t> accumulator, |
| 60 const CacheStorage::SizeCallback& callback) { |
| 61 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 62 FROM_HERE, base::Bind(callback, *accumulator)); |
| 63 } |
| 58 | 64 |
| 59 } // namespace | 65 } // namespace |
| 60 | 66 |
| 61 const char CacheStorage::kIndexFileName[] = "index.txt"; | 67 const char CacheStorage::kIndexFileName[] = "index.txt"; |
| 62 | 68 |
| 63 struct CacheStorage::CacheMatchResponse { | 69 struct CacheStorage::CacheMatchResponse { |
| 64 CacheMatchResponse() = default; | 70 CacheMatchResponse() = default; |
| 65 ~CacheMatchResponse() = default; | 71 ~CacheMatchResponse() = default; |
| 66 | 72 |
| 67 CacheStorageError error; | 73 CacheStorageError error; |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 cache_loader_->PrepareNewCacheDestination( | 697 cache_loader_->PrepareNewCacheDestination( |
| 692 cache_name, base::Bind(&CacheStorage::CreateCacheDidCreateCache, | 698 cache_name, base::Bind(&CacheStorage::CreateCacheDidCreateCache, |
| 693 weak_factory_.GetWeakPtr(), cache_name, callback)); | 699 weak_factory_.GetWeakPtr(), cache_name, callback)); |
| 694 } | 700 } |
| 695 | 701 |
| 696 void CacheStorage::CreateCacheDidCreateCache( | 702 void CacheStorage::CreateCacheDidCreateCache( |
| 697 const std::string& cache_name, | 703 const std::string& cache_name, |
| 698 const CacheAndErrorCallback& callback, | 704 const CacheAndErrorCallback& callback, |
| 699 scoped_refptr<CacheStorageCache> cache) { | 705 scoped_refptr<CacheStorageCache> cache) { |
| 700 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 706 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 701 DCHECK(!callback_cache_.get()); | 707 |
| 702 UMA_HISTOGRAM_BOOLEAN("ServiceWorkerCache.CreateCacheStorageResult", | 708 UMA_HISTOGRAM_BOOLEAN("ServiceWorkerCache.CreateCacheStorageResult", |
| 703 static_cast<bool>(cache)); | 709 static_cast<bool>(cache)); |
| 704 | 710 |
| 705 if (!cache.get()) { | 711 if (!cache.get()) { |
| 706 callback.Run(scoped_refptr<CacheStorageCache>(), | 712 callback.Run(scoped_refptr<CacheStorageCache>(), |
| 707 CACHE_STORAGE_ERROR_STORAGE); | 713 CACHE_STORAGE_ERROR_STORAGE); |
| 708 return; | 714 return; |
| 709 } | 715 } |
| 710 | 716 |
| 711 cache_map_.insert(std::make_pair(cache_name, cache->AsWeakPtr())); | 717 cache_map_.insert(std::make_pair(cache_name, cache->AsWeakPtr())); |
| 712 ordered_cache_names_.push_back(cache_name); | 718 ordered_cache_names_.push_back(cache_name); |
| 713 | 719 |
| 714 TemporarilyPreserveCache(cache); | 720 TemporarilyPreserveCache(cache); |
| 715 callback_cache_ = std::move(cache); | |
| 716 | 721 |
| 717 cache_loader_->WriteIndex(ordered_cache_names_, | 722 cache_loader_->WriteIndex( |
| 718 base::Bind(&CacheStorage::CreateCacheDidWriteIndex, | 723 ordered_cache_names_, |
| 719 weak_factory_.GetWeakPtr(), callback)); | 724 base::Bind(&CacheStorage::CreateCacheDidWriteIndex, |
| 725 weak_factory_.GetWeakPtr(), callback, std::move(cache))); |
| 720 } | 726 } |
| 721 | 727 |
| 722 void CacheStorage::CreateCacheDidWriteIndex( | 728 void CacheStorage::CreateCacheDidWriteIndex( |
| 723 const CacheAndErrorCallback& callback, | 729 const CacheAndErrorCallback& callback, |
| 730 scoped_refptr<CacheStorageCache> cache, |
| 724 bool success) { | 731 bool success) { |
| 725 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 732 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 726 DCHECK(callback_cache_.get()); | 733 DCHECK(cache.get()); |
| 727 | 734 |
| 728 // TODO(jkarlin): Handle !success. | 735 // TODO(jkarlin): Handle !success. |
| 729 callback.Run(std::move(callback_cache_), CACHE_STORAGE_OK); | 736 |
| 737 callback.Run(std::move(cache), CACHE_STORAGE_OK); |
| 730 } | 738 } |
| 731 | 739 |
| 732 void CacheStorage::HasCacheImpl(const std::string& cache_name, | 740 void CacheStorage::HasCacheImpl(const std::string& cache_name, |
| 733 const BoolAndErrorCallback& callback) { | 741 const BoolAndErrorCallback& callback) { |
| 734 bool has_cache = ContainsKey(cache_map_, cache_name); | 742 bool has_cache = ContainsKey(cache_map_, cache_name); |
| 735 callback.Run(has_cache, CACHE_STORAGE_OK); | 743 callback.Run(has_cache, CACHE_STORAGE_OK); |
| 736 } | 744 } |
| 737 | 745 |
| 738 void CacheStorage::DeleteCacheImpl(const std::string& cache_name, | 746 void CacheStorage::DeleteCacheImpl(const std::string& cache_name, |
| 739 const BoolAndErrorCallback& callback) { | 747 const BoolAndErrorCallback& callback) { |
| 740 DCHECK(!callback_cache_.get()); | |
| 741 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); | 748 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); |
| 742 if (!cache.get()) { | 749 if (!cache.get()) { |
| 743 base::ThreadTaskRunnerHandle::Get()->PostTask( | 750 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 744 FROM_HERE, base::Bind(callback, false, CACHE_STORAGE_ERROR_NOT_FOUND)); | 751 FROM_HERE, base::Bind(callback, false, CACHE_STORAGE_ERROR_NOT_FOUND)); |
| 745 return; | 752 return; |
| 746 } | 753 } |
| 747 | 754 |
| 748 CacheMap::iterator map_iter = cache_map_.find(cache_name); | 755 CacheMap::iterator map_iter = cache_map_.find(cache_name); |
| 749 cache_map_.erase(map_iter); | 756 cache_map_.erase(map_iter); |
| 750 | 757 |
| 751 // Delete the name from ordered_cache_names_. | 758 // Delete the name from ordered_cache_names_. |
| 752 StringVector::iterator iter = std::find( | 759 StringVector::iterator iter = std::find( |
| 753 ordered_cache_names_.begin(), ordered_cache_names_.end(), cache_name); | 760 ordered_cache_names_.begin(), ordered_cache_names_.end(), cache_name); |
| 754 DCHECK(iter != ordered_cache_names_.end()); | 761 DCHECK(iter != ordered_cache_names_.end()); |
| 755 ordered_cache_names_.erase(iter); | 762 ordered_cache_names_.erase(iter); |
| 756 | 763 |
| 757 cache->GetSizeThenClose(base::Bind(&CacheStorage::DeleteCacheDidClose, | 764 cache->GetSizeThenClose(base::Bind(&CacheStorage::DeleteCacheDidClose, |
| 758 weak_factory_.GetWeakPtr(), cache_name, | 765 weak_factory_.GetWeakPtr(), cache_name, |
| 759 callback, ordered_cache_names_)); | 766 callback, ordered_cache_names_, cache)); |
| 760 callback_cache_ = std::move(cache); | |
| 761 } | 767 } |
| 762 | 768 |
| 763 void CacheStorage::DeleteCacheDidClose(const std::string& cache_name, | 769 void CacheStorage::DeleteCacheDidClose(const std::string& cache_name, |
| 764 const BoolAndErrorCallback& callback, | 770 const BoolAndErrorCallback& callback, |
| 765 const StringVector& ordered_cache_names, | 771 const StringVector& ordered_cache_names, |
| 772 scoped_refptr<CacheStorageCache> cache, |
| 766 int64_t cache_size) { | 773 int64_t cache_size) { |
| 767 callback_cache_ = nullptr; | |
| 768 cache_loader_->WriteIndex( | 774 cache_loader_->WriteIndex( |
| 769 ordered_cache_names, | 775 ordered_cache_names, |
| 770 base::Bind(&CacheStorage::DeleteCacheDidWriteIndex, | 776 base::Bind(&CacheStorage::DeleteCacheDidWriteIndex, |
| 771 weak_factory_.GetWeakPtr(), cache_name, callback, cache_size)); | 777 weak_factory_.GetWeakPtr(), cache_name, callback, cache_size)); |
| 772 } | 778 } |
| 773 | 779 |
| 774 void CacheStorage::DeleteCacheDidWriteIndex( | 780 void CacheStorage::DeleteCacheDidWriteIndex( |
| 775 const std::string& cache_name, | 781 const std::string& cache_name, |
| 776 const BoolAndErrorCallback& callback, | 782 const BoolAndErrorCallback& callback, |
| 777 int cache_size, | 783 int cache_size, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 796 | 802 |
| 797 void CacheStorage::EnumerateCachesImpl( | 803 void CacheStorage::EnumerateCachesImpl( |
| 798 const StringsAndErrorCallback& callback) { | 804 const StringsAndErrorCallback& callback) { |
| 799 callback.Run(ordered_cache_names_, CACHE_STORAGE_OK); | 805 callback.Run(ordered_cache_names_, CACHE_STORAGE_OK); |
| 800 } | 806 } |
| 801 | 807 |
| 802 void CacheStorage::MatchCacheImpl( | 808 void CacheStorage::MatchCacheImpl( |
| 803 const std::string& cache_name, | 809 const std::string& cache_name, |
| 804 std::unique_ptr<ServiceWorkerFetchRequest> request, | 810 std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 805 const CacheStorageCache::ResponseCallback& callback) { | 811 const CacheStorageCache::ResponseCallback& callback) { |
| 806 DCHECK(!callback_cache_.get()); | |
| 807 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); | 812 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); |
| 808 | 813 |
| 809 if (!cache.get()) { | 814 if (!cache.get()) { |
| 810 callback.Run(CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND, | 815 callback.Run(CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND, |
| 811 std::unique_ptr<ServiceWorkerResponse>(), | 816 std::unique_ptr<ServiceWorkerResponse>(), |
| 812 std::unique_ptr<storage::BlobDataHandle>()); | 817 std::unique_ptr<storage::BlobDataHandle>()); |
| 813 return; | 818 return; |
| 814 } | 819 } |
| 815 | 820 |
| 821 // Pass the cache along to the callback to keep the cache open until match is |
| 822 // done. |
| 816 cache->Match(std::move(request), | 823 cache->Match(std::move(request), |
| 817 base::Bind(&CacheStorage::MatchCacheDidMatch, | 824 base::Bind(&CacheStorage::MatchCacheDidMatch, |
| 818 weak_factory_.GetWeakPtr(), callback)); | 825 weak_factory_.GetWeakPtr(), cache, callback)); |
| 819 callback_cache_ = std::move(cache); | |
| 820 } | 826 } |
| 821 | 827 |
| 822 void CacheStorage::MatchCacheDidMatch( | 828 void CacheStorage::MatchCacheDidMatch( |
| 829 scoped_refptr<CacheStorageCache> cache, |
| 823 const CacheStorageCache::ResponseCallback& callback, | 830 const CacheStorageCache::ResponseCallback& callback, |
| 824 CacheStorageError error, | 831 CacheStorageError error, |
| 825 std::unique_ptr<ServiceWorkerResponse> response, | 832 std::unique_ptr<ServiceWorkerResponse> response, |
| 826 std::unique_ptr<storage::BlobDataHandle> handle) { | 833 std::unique_ptr<storage::BlobDataHandle> handle) { |
| 827 callback_cache_ = nullptr; | |
| 828 callback.Run(error, std::move(response), std::move(handle)); | 834 callback.Run(error, std::move(response), std::move(handle)); |
| 829 } | 835 } |
| 830 | 836 |
| 831 void CacheStorage::MatchAllCachesImpl( | 837 void CacheStorage::MatchAllCachesImpl( |
| 832 std::unique_ptr<ServiceWorkerFetchRequest> request, | 838 std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 833 const CacheStorageCache::ResponseCallback& callback) { | 839 const CacheStorageCache::ResponseCallback& callback) { |
| 834 DCHECK(callback_caches_.empty()); | |
| 835 std::vector<CacheMatchResponse>* match_responses = | 840 std::vector<CacheMatchResponse>* match_responses = |
| 836 new std::vector<CacheMatchResponse>(ordered_cache_names_.size()); | 841 new std::vector<CacheMatchResponse>(ordered_cache_names_.size()); |
| 837 | 842 |
| 838 base::Closure barrier_closure = base::BarrierClosure( | 843 base::Closure barrier_closure = base::BarrierClosure( |
| 839 ordered_cache_names_.size(), | 844 ordered_cache_names_.size(), |
| 840 base::Bind(&CacheStorage::MatchAllCachesDidMatchAll, | 845 base::Bind(&CacheStorage::MatchAllCachesDidMatchAll, |
| 841 weak_factory_.GetWeakPtr(), | 846 weak_factory_.GetWeakPtr(), |
| 842 base::Passed(base::WrapUnique(match_responses)), callback)); | 847 base::Passed(base::WrapUnique(match_responses)), callback)); |
| 843 | 848 |
| 844 callback_caches_.resize(ordered_cache_names_.size()); | |
| 845 for (size_t i = 0, max = ordered_cache_names_.size(); i < max; ++i) { | 849 for (size_t i = 0, max = ordered_cache_names_.size(); i < max; ++i) { |
| 846 scoped_refptr<CacheStorageCache> cache = | 850 scoped_refptr<CacheStorageCache> cache = |
| 847 GetLoadedCache(ordered_cache_names_[i]); | 851 GetLoadedCache(ordered_cache_names_[i]); |
| 848 DCHECK(cache.get()); | 852 DCHECK(cache.get()); |
| 849 | 853 |
| 850 cache->Match(base::WrapUnique(new ServiceWorkerFetchRequest(*request)), | 854 cache->Match(base::WrapUnique(new ServiceWorkerFetchRequest(*request)), |
| 851 base::Bind(&CacheStorage::MatchAllCachesDidMatch, | 855 base::Bind(&CacheStorage::MatchAllCachesDidMatch, |
| 852 weak_factory_.GetWeakPtr(), &match_responses->at(i), | 856 weak_factory_.GetWeakPtr(), cache, |
| 853 barrier_closure)); | 857 &match_responses->at(i), barrier_closure)); |
| 854 callback_caches_.push_back(std::move(cache)); | |
| 855 } | 858 } |
| 856 } | 859 } |
| 857 | 860 |
| 858 void CacheStorage::MatchAllCachesDidMatch( | 861 void CacheStorage::MatchAllCachesDidMatch( |
| 862 scoped_refptr<CacheStorageCache> cache, |
| 859 CacheMatchResponse* out_match_response, | 863 CacheMatchResponse* out_match_response, |
| 860 const base::Closure& barrier_closure, | 864 const base::Closure& barrier_closure, |
| 861 CacheStorageError error, | 865 CacheStorageError error, |
| 862 std::unique_ptr<ServiceWorkerResponse> service_worker_response, | 866 std::unique_ptr<ServiceWorkerResponse> service_worker_response, |
| 863 std::unique_ptr<storage::BlobDataHandle> handle) { | 867 std::unique_ptr<storage::BlobDataHandle> handle) { |
| 864 out_match_response->error = error; | 868 out_match_response->error = error; |
| 865 out_match_response->service_worker_response = | 869 out_match_response->service_worker_response = |
| 866 std::move(service_worker_response); | 870 std::move(service_worker_response); |
| 867 out_match_response->blob_data_handle = std::move(handle); | 871 out_match_response->blob_data_handle = std::move(handle); |
| 868 barrier_closure.Run(); | 872 barrier_closure.Run(); |
| 869 } | 873 } |
| 870 | 874 |
| 871 void CacheStorage::MatchAllCachesDidMatchAll( | 875 void CacheStorage::MatchAllCachesDidMatchAll( |
| 872 std::unique_ptr<std::vector<CacheMatchResponse>> match_responses, | 876 std::unique_ptr<std::vector<CacheMatchResponse>> match_responses, |
| 873 const CacheStorageCache::ResponseCallback& callback) { | 877 const CacheStorageCache::ResponseCallback& callback) { |
| 874 callback_caches_.clear(); | |
| 875 for (CacheMatchResponse& match_response : *match_responses) { | 878 for (CacheMatchResponse& match_response : *match_responses) { |
| 876 if (match_response.error == CACHE_STORAGE_ERROR_NOT_FOUND) | 879 if (match_response.error == CACHE_STORAGE_ERROR_NOT_FOUND) |
| 877 continue; | 880 continue; |
| 878 callback.Run(match_response.error, | 881 callback.Run(match_response.error, |
| 879 std::move(match_response.service_worker_response), | 882 std::move(match_response.service_worker_response), |
| 880 std::move(match_response.blob_data_handle)); | 883 std::move(match_response.blob_data_handle)); |
| 881 return; | 884 return; |
| 882 } | 885 } |
| 883 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND, | 886 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND, |
| 884 std::unique_ptr<ServiceWorkerResponse>(), | 887 std::unique_ptr<ServiceWorkerResponse>(), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 void CacheStorage::RemovePreservedCache(const CacheStorageCache* cache) { | 934 void CacheStorage::RemovePreservedCache(const CacheStorageCache* cache) { |
| 932 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 935 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 933 DCHECK(ContainsKey(preserved_caches_, cache)); | 936 DCHECK(ContainsKey(preserved_caches_, cache)); |
| 934 | 937 |
| 935 preserved_caches_.erase(cache); | 938 preserved_caches_.erase(cache); |
| 936 } | 939 } |
| 937 | 940 |
| 938 void CacheStorage::GetSizeThenCloseAllCachesImpl(const SizeCallback& callback) { | 941 void CacheStorage::GetSizeThenCloseAllCachesImpl(const SizeCallback& callback) { |
| 939 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 942 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 940 DCHECK(initialized_); | 943 DCHECK(initialized_); |
| 941 DCHECK(callback_caches_.empty()); | |
| 942 | 944 |
| 943 std::unique_ptr<int64_t> accumulator(new int64_t(0)); | 945 std::unique_ptr<int64_t> accumulator(new int64_t(0)); |
| 944 int64_t* accumulator_ptr = accumulator.get(); | 946 int64_t* accumulator_ptr = accumulator.get(); |
| 945 | 947 |
| 946 base::Closure barrier_closure = base::BarrierClosure( | 948 base::Closure barrier_closure = base::BarrierClosure( |
| 947 ordered_cache_names_.size(), | 949 ordered_cache_names_.size(), |
| 948 base::Bind(&CacheStorage::SizeRetrievedFromAllCaches, | 950 base::Bind(&SizeRetrievedFromAllCaches, |
| 949 weak_factory_.GetWeakPtr(), | |
| 950 base::Passed(std::move(accumulator)), callback)); | 951 base::Passed(std::move(accumulator)), callback)); |
| 951 | 952 |
| 952 callback_caches_.resize(ordered_cache_names_.size()); | |
| 953 for (const std::string& cache_name : ordered_cache_names_) { | 953 for (const std::string& cache_name : ordered_cache_names_) { |
| 954 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); | 954 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); |
| 955 cache->GetSizeThenClose( | 955 cache->GetSizeThenClose(base::Bind(&SizeRetrievedFromCache, cache, |
| 956 base::Bind(&SizeRetrievedFromCache, barrier_closure, accumulator_ptr)); | 956 barrier_closure, accumulator_ptr)); |
| 957 callback_caches_.push_back(std::move(cache)); | |
| 958 } | 957 } |
| 959 } | 958 } |
| 960 | 959 |
| 961 void CacheStorage::SizeImpl(const SizeCallback& callback) { | 960 void CacheStorage::SizeImpl(const SizeCallback& callback) { |
| 962 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 961 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 963 DCHECK(initialized_); | 962 DCHECK(initialized_); |
| 964 DCHECK(callback_caches_.empty()); | |
| 965 | 963 |
| 966 std::unique_ptr<int64_t> accumulator(new int64_t(0)); | 964 std::unique_ptr<int64_t> accumulator(new int64_t(0)); |
| 967 int64_t* accumulator_ptr = accumulator.get(); | 965 int64_t* accumulator_ptr = accumulator.get(); |
| 968 | 966 |
| 969 base::Closure barrier_closure = base::BarrierClosure( | 967 base::Closure barrier_closure = base::BarrierClosure( |
| 970 ordered_cache_names_.size(), | 968 ordered_cache_names_.size(), |
| 971 base::Bind(&CacheStorage::SizeRetrievedFromAllCaches, | 969 base::Bind(&SizeRetrievedFromAllCaches, |
| 972 weak_factory_.GetWeakPtr(), | |
| 973 base::Passed(std::move(accumulator)), callback)); | 970 base::Passed(std::move(accumulator)), callback)); |
| 974 | 971 |
| 975 callback_caches_.resize(ordered_cache_names_.size()); | |
| 976 for (const std::string& cache_name : ordered_cache_names_) { | 972 for (const std::string& cache_name : ordered_cache_names_) { |
| 977 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); | 973 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); |
| 978 cache->Size( | 974 cache->Size(base::Bind(&SizeRetrievedFromCache, cache, barrier_closure, |
| 979 base::Bind(&SizeRetrievedFromCache, barrier_closure, accumulator_ptr)); | 975 accumulator_ptr)); |
| 980 callback_caches_.push_back(std::move(cache)); | |
| 981 } | 976 } |
| 982 } | 977 } |
| 983 | 978 |
| 984 void CacheStorage::SizeRetrievedFromAllCaches( | |
| 985 std::unique_ptr<int64_t> accumulator, | |
| 986 const CacheStorage::SizeCallback& callback) { | |
| 987 callback_caches_.clear(); | |
| 988 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 989 FROM_HERE, base::Bind(callback, *accumulator)); | |
| 990 } | |
| 991 | |
| 992 void CacheStorage::PendingClosure(const base::Closure& callback) { | 979 void CacheStorage::PendingClosure(const base::Closure& callback) { |
| 993 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); | 980 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); |
| 994 | 981 |
| 995 callback.Run(); | 982 callback.Run(); |
| 996 if (cache_storage) | 983 if (cache_storage) |
| 997 scheduler_->CompleteOperationAndRunNext(); | 984 scheduler_->CompleteOperationAndRunNext(); |
| 998 } | 985 } |
| 999 | 986 |
| 1000 void CacheStorage::PendingBoolAndErrorCallback( | 987 void CacheStorage::PendingBoolAndErrorCallback( |
| 1001 const BoolAndErrorCallback& callback, | 988 const BoolAndErrorCallback& callback, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 void CacheStorage::PendingSizeCallback(const SizeCallback& callback, | 1032 void CacheStorage::PendingSizeCallback(const SizeCallback& callback, |
| 1046 int64_t size) { | 1033 int64_t size) { |
| 1047 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); | 1034 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); |
| 1048 | 1035 |
| 1049 callback.Run(size); | 1036 callback.Run(size); |
| 1050 if (cache_storage) | 1037 if (cache_storage) |
| 1051 scheduler_->CompleteOperationAndRunNext(); | 1038 scheduler_->CompleteOperationAndRunNext(); |
| 1052 } | 1039 } |
| 1053 | 1040 |
| 1054 } // namespace content | 1041 } // namespace content |
| OLD | NEW |