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

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

Issue 2598643002: [CacheStorage] Fix ownership of doomed cache as it's cleaned up (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « content/browser/cache_storage/cache_storage.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 cache_map_.erase(map_iter); 810 cache_map_.erase(map_iter);
811 811
812 cache_loader_->NotifyCacheDoomed(std::move(cache_handle)); 812 cache_loader_->NotifyCacheDoomed(std::move(cache_handle));
813 813
814 callback.Run(true, CACHE_STORAGE_OK); 814 callback.Run(true, CACHE_STORAGE_OK);
815 } 815 }
816 816
817 // Call this once the last handle to a doomed cache is gone. It's okay if this 817 // Call this once the last handle to a doomed cache is gone. It's okay if this
818 // doesn't get to complete before shutdown, the cache will be removed from disk 818 // doesn't get to complete before shutdown, the cache will be removed from disk
819 // on next startup in that case. 819 // on next startup in that case.
820 void CacheStorage::DeleteCacheFinalize( 820 void CacheStorage::DeleteCacheFinalize(CacheStorageCache* doomed_cache) {
821 std::unique_ptr<CacheStorageCache> doomed_cache) { 821 doomed_cache->Size(base::Bind(&CacheStorage::DeleteCacheDidGetSize,
822 CacheStorageCache* cache = doomed_cache.get(); 822 weak_factory_.GetWeakPtr(), doomed_cache));
823 cache->Size(base::Bind(&CacheStorage::DeleteCacheDidGetSize,
824 weak_factory_.GetWeakPtr(),
825 base::Passed(std::move(doomed_cache))));
826 } 823 }
827 824
828 void CacheStorage::DeleteCacheDidGetSize( 825 void CacheStorage::DeleteCacheDidGetSize(CacheStorageCache* doomed_cache,
829 std::unique_ptr<CacheStorageCache> cache, 826 int64_t cache_size) {
830 int64_t cache_size) {
831 quota_manager_proxy_->NotifyStorageModified( 827 quota_manager_proxy_->NotifyStorageModified(
832 storage::QuotaClient::kServiceWorkerCache, origin_, 828 storage::QuotaClient::kServiceWorkerCache, origin_,
833 storage::kStorageTypeTemporary, -1 * cache_size); 829 storage::kStorageTypeTemporary, -1 * cache_size);
834 830
835 cache_loader_->CleanUpDeletedCache(cache.get()); 831 cache_loader_->CleanUpDeletedCache(doomed_cache);
832 auto doomed_caches_iter = doomed_caches_.find(doomed_cache);
833 DCHECK(doomed_caches_iter != doomed_caches_.end());
834 doomed_caches_.erase(doomed_caches_iter);
836 } 835 }
837 836
838 void CacheStorage::EnumerateCachesImpl(const StringsCallback& callback) { 837 void CacheStorage::EnumerateCachesImpl(const StringsCallback& callback) {
839 callback.Run(ordered_cache_names_); 838 callback.Run(ordered_cache_names_);
840 } 839 }
841 840
842 void CacheStorage::MatchCacheImpl( 841 void CacheStorage::MatchCacheImpl(
843 const std::string& cache_name, 842 const std::string& cache_name,
844 std::unique_ptr<ServiceWorkerFetchRequest> request, 843 std::unique_ptr<ServiceWorkerFetchRequest> request,
845 const CacheStorageCacheQueryParams& match_params, 844 const CacheStorageCacheQueryParams& match_params,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 auto iter = cache_handle_counts_.find(cache); 945 auto iter = cache_handle_counts_.find(cache);
947 DCHECK(iter != cache_handle_counts_.end()); 946 DCHECK(iter != cache_handle_counts_.end());
948 DCHECK_GE(iter->second, 1U); 947 DCHECK_GE(iter->second, 1U);
949 948
950 iter->second -= 1; 949 iter->second -= 1;
951 if (iter->second == 0) { 950 if (iter->second == 0) {
952 cache_handle_counts_.erase(iter); 951 cache_handle_counts_.erase(iter);
953 auto doomed_caches_iter = doomed_caches_.find(cache); 952 auto doomed_caches_iter = doomed_caches_.find(cache);
954 if (doomed_caches_iter != doomed_caches_.end()) { 953 if (doomed_caches_iter != doomed_caches_.end()) {
955 // The last reference to a doomed cache is gone, perform clean up. 954 // The last reference to a doomed cache is gone, perform clean up.
956 DeleteCacheFinalize(std::move(doomed_caches_iter->second)); 955 DeleteCacheFinalize(cache);
957 doomed_caches_.erase(doomed_caches_iter);
958 return; 956 return;
959 } 957 }
960 958
961 auto cache_map_iter = cache_map_.find(cache->cache_name()); 959 auto cache_map_iter = cache_map_.find(cache->cache_name());
962 DCHECK(cache_map_iter != cache_map_.end()); 960 DCHECK(cache_map_iter != cache_map_.end());
963 961
964 cache_map_iter->second.reset(); 962 cache_map_iter->second.reset();
965 } 963 }
966 } 964 }
967 965
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 std::unique_ptr<CacheStorageCacheHandle> cache_handle = 1031 std::unique_ptr<CacheStorageCacheHandle> cache_handle =
1034 GetLoadedCache(cache_name); 1032 GetLoadedCache(cache_name);
1035 CacheStorageCache* cache = cache_handle->value(); 1033 CacheStorageCache* cache = cache_handle->value();
1036 cache->Size(base::Bind(&SizeRetrievedFromCache, 1034 cache->Size(base::Bind(&SizeRetrievedFromCache,
1037 base::Passed(std::move(cache_handle)), 1035 base::Passed(std::move(cache_handle)),
1038 barrier_closure, accumulator_ptr)); 1036 barrier_closure, accumulator_ptr));
1039 } 1037 }
1040 } 1038 }
1041 1039
1042 } // namespace content 1040 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698