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

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

Issue 2179353003: [CacheStorage] Check doomed caches first when dropping cache handles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the test to work around a different bug 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
« no previous file with comments | « no previous file | content/browser/cache_storage/cache_storage_manager_unittest.cc » ('j') | 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 quota_manager_proxy_, blob_context_); 175 quota_manager_proxy_, blob_context_);
176 } 176 }
177 177
178 void PrepareNewCacheDestination(const std::string& cache_name, 178 void PrepareNewCacheDestination(const std::string& cache_name,
179 const CacheCallback& callback) override { 179 const CacheCallback& callback) override {
180 std::unique_ptr<CacheStorageCache> cache = CreateCache(cache_name); 180 std::unique_ptr<CacheStorageCache> cache = CreateCache(cache_name);
181 callback.Run(std::move(cache)); 181 callback.Run(std::move(cache));
182 } 182 }
183 183
184 void CleanUpDeletedCache(const std::string& cache_name) override { 184 void CleanUpDeletedCache(const std::string& cache_name) override {
185 DCHECK(!ContainsKey(cache_handles_, cache_name));
186 } 185 }
187 186
188 void WriteIndex(const StringVector& cache_names, 187 void WriteIndex(const StringVector& cache_names,
189 const BoolCallback& callback) override { 188 const BoolCallback& callback) override {
190 callback.Run(true); 189 callback.Run(true);
191 } 190 }
192 191
193 void LoadIndex(std::unique_ptr<std::vector<std::string>> cache_names, 192 void LoadIndex(std::unique_ptr<std::vector<std::string>> cache_names,
194 const StringVectorCallback& callback) override { 193 const StringVectorCallback& callback) override {
195 callback.Run(std::move(cache_names)); 194 callback.Run(std::move(cache_names));
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 } 920 }
922 921
923 void CacheStorage::DropCacheHandleRef(CacheStorageCache* cache) { 922 void CacheStorage::DropCacheHandleRef(CacheStorageCache* cache) {
924 DCHECK_CURRENTLY_ON(BrowserThread::IO); 923 DCHECK_CURRENTLY_ON(BrowserThread::IO);
925 auto iter = cache_handle_counts_.find(cache); 924 auto iter = cache_handle_counts_.find(cache);
926 DCHECK(iter != cache_handle_counts_.end()); 925 DCHECK(iter != cache_handle_counts_.end());
927 DCHECK(iter->second >= 1); 926 DCHECK(iter->second >= 1);
928 927
929 iter->second -= 1; 928 iter->second -= 1;
930 if (iter->second == 0) { 929 if (iter->second == 0) {
931 // Delete the CacheStorageCache object. It's either in the main cache map or 930 auto doomed_caches_iter = doomed_caches_.find(cache);
932 // the CacheStorage::Delete operation has run on the cache, in which case 931 if (doomed_caches_iter != doomed_caches_.end()) {
933 // it's in the doomed caches map.
934 auto cache_map_iter = cache_map_.find(cache->cache_name());
935
936 if (cache_map_iter == cache_map_.end()) {
937 auto doomed_caches_iter = doomed_caches_.find(cache);
938 DCHECK(doomed_caches_iter != doomed_caches_.end());
939
940 // The last reference to a doomed cache is gone, perform clean up. 932 // The last reference to a doomed cache is gone, perform clean up.
941 DeleteCacheFinalize(std::move(doomed_caches_iter->second)); 933 DeleteCacheFinalize(std::move(doomed_caches_iter->second));
942 doomed_caches_.erase(doomed_caches_iter); 934 doomed_caches_.erase(doomed_caches_iter);
943 return; 935 return;
944 } 936 }
945 937
938 auto cache_map_iter = cache_map_.find(cache->cache_name());
939 DCHECK(cache_map_iter != cache_map_.end());
940
946 cache_map_iter->second.reset(); 941 cache_map_iter->second.reset();
947 cache_handle_counts_.erase(iter); 942 cache_handle_counts_.erase(iter);
948 } 943 }
949 } 944 }
950 945
951 std::unique_ptr<CacheStorageCacheHandle> CacheStorage::CreateCacheHandle( 946 std::unique_ptr<CacheStorageCacheHandle> CacheStorage::CreateCacheHandle(
952 CacheStorageCache* cache) { 947 CacheStorageCache* cache) {
953 DCHECK(cache); 948 DCHECK(cache);
954 return std::unique_ptr<CacheStorageCacheHandle>(new CacheStorageCacheHandle( 949 return std::unique_ptr<CacheStorageCacheHandle>(new CacheStorageCacheHandle(
955 cache->AsWeakPtr(), weak_factory_.GetWeakPtr())); 950 cache->AsWeakPtr(), weak_factory_.GetWeakPtr()));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 std::unique_ptr<CacheStorageCacheHandle> cache_handle = 1011 std::unique_ptr<CacheStorageCacheHandle> cache_handle =
1017 GetLoadedCache(cache_name); 1012 GetLoadedCache(cache_name);
1018 CacheStorageCache* cache = cache_handle->value(); 1013 CacheStorageCache* cache = cache_handle->value();
1019 cache->Size(base::Bind(&SizeRetrievedFromCache, 1014 cache->Size(base::Bind(&SizeRetrievedFromCache,
1020 base::Passed(std::move(cache_handle)), 1015 base::Passed(std::move(cache_handle)),
1021 barrier_closure, accumulator_ptr)); 1016 barrier_closure, accumulator_ptr));
1022 } 1017 }
1023 } 1018 }
1024 1019
1025 } // namespace content 1020 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/cache_storage/cache_storage_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698