Chromium Code Reviews| 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> |
| 11 #include <unordered_map> | |
|
jkarlin
2016/11/23 16:02:17
Unused
cmumford
2016/11/29 18:10:20
Done.
| |
| 11 #include <utility> | 12 #include <utility> |
| 12 | 13 |
| 13 #include "base/barrier_closure.h" | 14 #include "base/barrier_closure.h" |
| 14 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 15 #include "base/files/memory_mapped_file.h" | 16 #include "base/files/memory_mapped_file.h" |
| 16 #include "base/guid.h" | 17 #include "base/guid.h" |
| 17 #include "base/location.h" | 18 #include "base/location.h" |
| 18 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| 19 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 20 #include "base/metrics/histogram_macros.h" | 21 #include "base/metrics/histogram_macros.h" |
| 21 #include "base/numerics/safe_conversions.h" | 22 #include "base/numerics/safe_conversions.h" |
| 22 #include "base/sha1.h" | 23 #include "base/sha1.h" |
| 23 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
| 24 #include "base/stl_util.h" | 25 #include "base/stl_util.h" |
| 25 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
| 26 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 28 #include "content/browser/cache_storage/cache_storage.pb.h" | 29 #include "content/browser/cache_storage/cache_storage.pb.h" |
| 29 #include "content/browser/cache_storage/cache_storage_cache.h" | 30 #include "content/browser/cache_storage/cache_storage_cache.h" |
| 30 #include "content/browser/cache_storage/cache_storage_cache_handle.h" | 31 #include "content/browser/cache_storage/cache_storage_cache_handle.h" |
| 32 #include "content/browser/cache_storage/cache_storage_index.h" | |
| 31 #include "content/browser/cache_storage/cache_storage_scheduler.h" | 33 #include "content/browser/cache_storage/cache_storage_scheduler.h" |
| 32 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 33 #include "net/base/directory_lister.h" | 35 #include "net/base/directory_lister.h" |
| 34 #include "net/base/net_errors.h" | 36 #include "net/base/net_errors.h" |
| 35 #include "net/url_request/url_request_context_getter.h" | 37 #include "net/url_request/url_request_context_getter.h" |
| 36 #include "storage/browser/blob/blob_storage_context.h" | 38 #include "storage/browser/blob/blob_storage_context.h" |
| 37 #include "storage/browser/quota/quota_manager_proxy.h" | 39 #include "storage/browser/quota/quota_manager_proxy.h" |
| 38 | 40 |
| 39 namespace content { | 41 namespace content { |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 std::string HexedHash(const std::string& value) { | 45 std::string HexedHash(const std::string& value) { |
| 44 std::string value_hash = base::SHA1HashString(value); | 46 std::string value_hash = base::SHA1HashString(value); |
| 45 std::string valued_hexed_hash = base::ToLowerASCII( | 47 std::string valued_hexed_hash = base::ToLowerASCII( |
| 46 base::HexEncode(value_hash.c_str(), value_hash.length())); | 48 base::HexEncode(value_hash.c_str(), value_hash.length())); |
| 47 return valued_hexed_hash; | 49 return valued_hexed_hash; |
| 48 } | 50 } |
| 49 | 51 |
| 50 void SizeRetrievedFromCache( | |
| 51 std::unique_ptr<CacheStorageCacheHandle> cache_handle, | |
| 52 const base::Closure& closure, | |
| 53 int64_t* accumulator, | |
| 54 int64_t size) { | |
| 55 *accumulator += size; | |
| 56 closure.Run(); | |
| 57 } | |
| 58 | |
| 59 void SizeRetrievedFromAllCaches(std::unique_ptr<int64_t> accumulator, | 52 void SizeRetrievedFromAllCaches(std::unique_ptr<int64_t> accumulator, |
| 60 const CacheStorage::SizeCallback& callback) { | 53 const CacheStorage::SizeCallback& callback) { |
| 61 base::ThreadTaskRunnerHandle::Get()->PostTask( | 54 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 62 FROM_HERE, base::Bind(callback, *accumulator)); | 55 FROM_HERE, base::Bind(callback, *accumulator)); |
| 63 } | 56 } |
| 64 | 57 |
| 58 void DoNothingWithBool(bool success) {} | |
| 59 | |
| 65 } // namespace | 60 } // namespace |
| 66 | 61 |
| 67 const char CacheStorage::kIndexFileName[] = "index.txt"; | 62 const char CacheStorage::kIndexFileName[] = "index.txt"; |
| 63 const int64_t CacheStorage::kSizeUnknown; | |
| 68 | 64 |
| 69 struct CacheStorage::CacheMatchResponse { | 65 struct CacheStorage::CacheMatchResponse { |
| 70 CacheMatchResponse() = default; | 66 CacheMatchResponse() = default; |
| 71 ~CacheMatchResponse() = default; | 67 ~CacheMatchResponse() = default; |
| 72 | 68 |
| 73 CacheStorageError error; | 69 CacheStorageError error; |
| 74 std::unique_ptr<ServiceWorkerResponse> service_worker_response; | 70 std::unique_ptr<ServiceWorkerResponse> service_worker_response; |
| 75 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; | 71 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; |
| 76 }; | 72 }; |
| 77 | 73 |
| 78 // Handles the loading and clean up of CacheStorageCache objects. | 74 // Handles the loading and clean up of CacheStorageCache objects. |
| 79 class CacheStorage::CacheLoader { | 75 class CacheStorage::CacheLoader { |
| 80 public: | 76 public: |
| 81 typedef base::Callback<void(std::unique_ptr<CacheStorageCache>)> | 77 typedef base::Callback<void(std::unique_ptr<CacheStorageCache>)> |
| 82 CacheCallback; | 78 CacheCallback; |
| 83 typedef base::Callback<void(bool)> BoolCallback; | 79 typedef base::Callback<void(bool)> BoolCallback; |
| 84 typedef base::Callback<void(std::unique_ptr<std::vector<std::string>>)> | 80 using CacheStorageIndexCallback = |
| 85 StringVectorCallback; | 81 base::Callback<void(std::unique_ptr<CacheStorageIndex>)>; |
| 86 | 82 |
| 87 CacheLoader( | 83 CacheLoader( |
| 88 base::SequencedTaskRunner* cache_task_runner, | 84 base::SequencedTaskRunner* cache_task_runner, |
| 89 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 85 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 90 storage::QuotaManagerProxy* quota_manager_proxy, | 86 storage::QuotaManagerProxy* quota_manager_proxy, |
| 91 base::WeakPtr<storage::BlobStorageContext> blob_context, | 87 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 92 CacheStorage* cache_storage, | 88 CacheStorage* cache_storage, |
| 93 const GURL& origin) | 89 const GURL& origin) |
| 94 : cache_task_runner_(cache_task_runner), | 90 : cache_task_runner_(cache_task_runner), |
| 95 request_context_getter_(request_context_getter), | 91 request_context_getter_(request_context_getter), |
| 96 quota_manager_proxy_(quota_manager_proxy), | 92 quota_manager_proxy_(quota_manager_proxy), |
| 97 blob_context_(blob_context), | 93 blob_context_(blob_context), |
| 98 cache_storage_(cache_storage), | 94 cache_storage_(cache_storage), |
| 99 origin_(origin) { | 95 origin_(origin) { |
| 100 DCHECK(!origin_.is_empty()); | 96 DCHECK(!origin_.is_empty()); |
| 101 } | 97 } |
| 102 | 98 |
| 103 virtual ~CacheLoader() {} | 99 virtual ~CacheLoader() {} |
| 104 | 100 |
| 105 // Creates a CacheStorageCache with the given name. It does not attempt to | 101 // Creates a CacheStorageCache with the given name. It does not attempt to |
| 106 // load the backend, that happens lazily when the cache is used. | 102 // load the backend, that happens lazily when the cache is used. |
| 107 virtual std::unique_ptr<CacheStorageCache> CreateCache( | 103 virtual std::unique_ptr<CacheStorageCache> CreateCache( |
| 108 const std::string& cache_name) = 0; | 104 const std::string& cache_name, |
| 105 int64_t cache_size) = 0; | |
| 109 | 106 |
| 110 // Deletes any pre-existing cache of the same name and then loads it. | 107 // Deletes any pre-existing cache of the same name and then loads it. |
| 111 virtual void PrepareNewCacheDestination(const std::string& cache_name, | 108 virtual void PrepareNewCacheDestination(const std::string& cache_name, |
| 112 const CacheCallback& callback) = 0; | 109 const CacheCallback& callback) = 0; |
| 113 | 110 |
| 114 // After the backend has been deleted, do any extra house keeping such as | 111 // After the backend has been deleted, do any extra house keeping such as |
| 115 // removing the cache's directory. | 112 // removing the cache's directory. |
| 116 virtual void CleanUpDeletedCache(CacheStorageCache* cache) = 0; | 113 virtual void CleanUpDeletedCache(CacheStorageCache* cache) = 0; |
| 117 | 114 |
| 118 // Writes the cache names (and sizes) to disk if applicable. | 115 // Writes the cache index to disk if applicable. |
| 119 virtual void WriteIndex(const StringVector& cache_names, | 116 virtual void WriteIndex(const CacheStorageIndex& index, |
| 120 const BoolCallback& callback) = 0; | 117 const BoolCallback& callback) = 0; |
| 121 | 118 |
| 122 // Loads the cache names from disk if applicable. | 119 // Loads the cache index from disk if applicable. |
| 123 virtual void LoadIndex(std::unique_ptr<std::vector<std::string>> cache_names, | 120 virtual void LoadIndex(const CacheStorageIndexCallback& callback) = 0; |
| 124 const StringVectorCallback& callback) = 0; | |
| 125 | 121 |
| 126 // Called when CacheStorage has created a cache. Used to hold onto a handle to | 122 // Called when CacheStorage has created a cache. Used to hold onto a handle to |
| 127 // the cache if necessary. | 123 // the cache if necessary. |
| 128 virtual void NotifyCacheCreated( | 124 virtual void NotifyCacheCreated( |
| 129 const std::string& cache_name, | 125 const std::string& cache_name, |
| 130 std::unique_ptr<CacheStorageCacheHandle> cache_handle) {} | 126 std::unique_ptr<CacheStorageCacheHandle> cache_handle) {} |
| 131 | 127 |
| 132 // Notification that the cache for |cache_handle| has been doomed. If the | 128 // Notification that the cache for |cache_handle| has been doomed. If the |
| 133 // loader is holding a handle to the cache, it should drop it now. | 129 // loader is holding a handle to the cache, it should drop it now. |
| 134 virtual void NotifyCacheDoomed( | 130 virtual void NotifyCacheDoomed( |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 161 base::WeakPtr<storage::BlobStorageContext> blob_context, | 157 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 162 CacheStorage* cache_storage, | 158 CacheStorage* cache_storage, |
| 163 const GURL& origin) | 159 const GURL& origin) |
| 164 : CacheLoader(cache_task_runner, | 160 : CacheLoader(cache_task_runner, |
| 165 request_context, | 161 request_context, |
| 166 quota_manager_proxy, | 162 quota_manager_proxy, |
| 167 blob_context, | 163 blob_context, |
| 168 cache_storage, | 164 cache_storage, |
| 169 origin) {} | 165 origin) {} |
| 170 | 166 |
| 171 std::unique_ptr<CacheStorageCache> CreateCache( | 167 std::unique_ptr<CacheStorageCache> CreateCache(const std::string& cache_name, |
| 172 const std::string& cache_name) override { | 168 int64_t cache_size) override { |
| 173 return CacheStorageCache::CreateMemoryCache( | 169 return CacheStorageCache::CreateMemoryCache( |
| 174 origin_, cache_name, cache_storage_, request_context_getter_, | 170 origin_, cache_name, cache_storage_, request_context_getter_, |
| 175 quota_manager_proxy_, blob_context_); | 171 quota_manager_proxy_, blob_context_); |
| 176 } | 172 } |
| 177 | 173 |
| 178 void PrepareNewCacheDestination(const std::string& cache_name, | 174 void PrepareNewCacheDestination(const std::string& cache_name, |
| 179 const CacheCallback& callback) override { | 175 const CacheCallback& callback) override { |
| 180 std::unique_ptr<CacheStorageCache> cache = CreateCache(cache_name); | 176 std::unique_ptr<CacheStorageCache> cache = |
| 177 CreateCache(cache_name, 0 /*cache_size*/); | |
| 181 callback.Run(std::move(cache)); | 178 callback.Run(std::move(cache)); |
| 182 } | 179 } |
| 183 | 180 |
| 184 void CleanUpDeletedCache(CacheStorageCache* cache) override {} | 181 void CleanUpDeletedCache(CacheStorageCache* cache) override {} |
| 185 | 182 |
| 186 void WriteIndex(const StringVector& cache_names, | 183 void WriteIndex(const CacheStorageIndex& index, |
| 187 const BoolCallback& callback) override { | 184 const BoolCallback& callback) override { |
| 188 callback.Run(true); | 185 callback.Run(true); |
| 189 } | 186 } |
| 190 | 187 |
| 191 void LoadIndex(std::unique_ptr<std::vector<std::string>> cache_names, | 188 void LoadIndex(const CacheStorageIndexCallback& callback) override { |
| 192 const StringVectorCallback& callback) override { | 189 callback.Run(base::MakeUnique<CacheStorageIndex>()); |
| 193 callback.Run(std::move(cache_names)); | |
| 194 } | 190 } |
| 195 | 191 |
| 196 void NotifyCacheCreated( | 192 void NotifyCacheCreated( |
| 197 const std::string& cache_name, | 193 const std::string& cache_name, |
| 198 std::unique_ptr<CacheStorageCacheHandle> cache_handle) override { | 194 std::unique_ptr<CacheStorageCacheHandle> cache_handle) override { |
| 199 DCHECK(!base::ContainsKey(cache_handles_, cache_name)); | 195 DCHECK(!base::ContainsKey(cache_handles_, cache_name)); |
| 200 cache_handles_.insert(std::make_pair(cache_name, std::move(cache_handle))); | 196 cache_handles_.insert(std::make_pair(cache_name, std::move(cache_handle))); |
| 201 }; | 197 }; |
| 202 | 198 |
| 203 void NotifyCacheDoomed( | 199 void NotifyCacheDoomed( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 229 const GURL& origin) | 225 const GURL& origin) |
| 230 : CacheLoader(cache_task_runner, | 226 : CacheLoader(cache_task_runner, |
| 231 request_context, | 227 request_context, |
| 232 quota_manager_proxy, | 228 quota_manager_proxy, |
| 233 blob_context, | 229 blob_context, |
| 234 cache_storage, | 230 cache_storage, |
| 235 origin), | 231 origin), |
| 236 origin_path_(origin_path), | 232 origin_path_(origin_path), |
| 237 weak_ptr_factory_(this) {} | 233 weak_ptr_factory_(this) {} |
| 238 | 234 |
| 239 std::unique_ptr<CacheStorageCache> CreateCache( | 235 std::unique_ptr<CacheStorageCache> CreateCache(const std::string& cache_name, |
| 240 const std::string& cache_name) override { | 236 int64_t cache_size) override { |
| 241 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 237 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 242 DCHECK(base::ContainsKey(cache_name_to_cache_dir_, cache_name)); | 238 DCHECK(base::ContainsKey(cache_name_to_cache_dir_, cache_name)); |
| 243 | 239 |
| 244 std::string cache_dir = cache_name_to_cache_dir_[cache_name]; | 240 std::string cache_dir = cache_name_to_cache_dir_[cache_name]; |
| 245 base::FilePath cache_path = origin_path_.AppendASCII(cache_dir); | 241 base::FilePath cache_path = origin_path_.AppendASCII(cache_dir); |
| 246 return CacheStorageCache::CreatePersistentCache( | 242 return CacheStorageCache::CreatePersistentCache( |
| 247 origin_, cache_name, cache_storage_, cache_path, | 243 origin_, cache_name, cache_storage_, cache_path, |
| 248 request_context_getter_, quota_manager_proxy_, blob_context_); | 244 request_context_getter_, quota_manager_proxy_, blob_context_, |
| 245 cache_size); | |
| 249 } | 246 } |
| 250 | 247 |
| 251 void PrepareNewCacheDestination(const std::string& cache_name, | 248 void PrepareNewCacheDestination(const std::string& cache_name, |
| 252 const CacheCallback& callback) override { | 249 const CacheCallback& callback) override { |
| 253 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 250 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 254 | 251 |
| 255 PostTaskAndReplyWithResult( | 252 PostTaskAndReplyWithResult( |
| 256 cache_task_runner_.get(), FROM_HERE, | 253 cache_task_runner_.get(), FROM_HERE, |
| 257 base::Bind(&SimpleCacheLoader::PrepareNewCacheDirectoryInPool, | 254 base::Bind(&SimpleCacheLoader::PrepareNewCacheDirectoryInPool, |
| 258 origin_path_), | 255 origin_path_), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 275 | 272 |
| 276 void PrepareNewCacheCreateCache(const std::string& cache_name, | 273 void PrepareNewCacheCreateCache(const std::string& cache_name, |
| 277 const CacheCallback& callback, | 274 const CacheCallback& callback, |
| 278 const std::string& cache_dir) { | 275 const std::string& cache_dir) { |
| 279 if (cache_dir.empty()) { | 276 if (cache_dir.empty()) { |
| 280 callback.Run(std::unique_ptr<CacheStorageCache>()); | 277 callback.Run(std::unique_ptr<CacheStorageCache>()); |
| 281 return; | 278 return; |
| 282 } | 279 } |
| 283 | 280 |
| 284 cache_name_to_cache_dir_[cache_name] = cache_dir; | 281 cache_name_to_cache_dir_[cache_name] = cache_dir; |
| 285 callback.Run(CreateCache(cache_name)); | 282 callback.Run(CreateCache(cache_name, CacheStorage::kSizeUnknown)); |
| 286 } | 283 } |
| 287 | 284 |
| 288 void CleanUpDeletedCache(CacheStorageCache* cache) override { | 285 void CleanUpDeletedCache(CacheStorageCache* cache) override { |
| 289 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 286 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 290 DCHECK(base::ContainsKey(doomed_cache_to_path_, cache)); | 287 DCHECK(base::ContainsKey(doomed_cache_to_path_, cache)); |
| 291 | 288 |
| 292 base::FilePath cache_path = | 289 base::FilePath cache_path = |
| 293 origin_path_.AppendASCII(doomed_cache_to_path_[cache]); | 290 origin_path_.AppendASCII(doomed_cache_to_path_[cache]); |
| 294 doomed_cache_to_path_.erase(cache); | 291 doomed_cache_to_path_.erase(cache); |
| 295 | 292 |
| 296 cache_task_runner_->PostTask( | 293 cache_task_runner_->PostTask( |
| 297 FROM_HERE, base::Bind(&SimpleCacheLoader::CleanUpDeleteCacheDirInPool, | 294 FROM_HERE, base::Bind(&SimpleCacheLoader::CleanUpDeleteCacheDirInPool, |
| 298 cache_path)); | 295 cache_path)); |
| 299 } | 296 } |
| 300 | 297 |
| 301 static void CleanUpDeleteCacheDirInPool(const base::FilePath& cache_path) { | 298 static void CleanUpDeleteCacheDirInPool(const base::FilePath& cache_path) { |
| 302 base::DeleteFile(cache_path, true /* recursive */); | 299 base::DeleteFile(cache_path, true /* recursive */); |
| 303 } | 300 } |
| 304 | 301 |
| 305 void WriteIndex(const StringVector& cache_names, | 302 void WriteIndex(const CacheStorageIndex& index, |
| 306 const BoolCallback& callback) override { | 303 const BoolCallback& callback) override { |
| 307 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 304 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 308 | 305 |
| 309 // 1. Create the index file as a string. (WriteIndex) | 306 // 1. Create the index file as a string. (WriteIndex) |
| 310 // 2. Write the file to disk. (WriteIndexWriteToFileInPool) | 307 // 2. Write the file to disk. (WriteIndexWriteToFileInPool) |
| 311 | 308 |
| 312 proto::CacheStorageIndex index; | 309 proto::CacheStorageIndex protobuf_index; |
| 313 index.set_origin(origin_.spec()); | 310 protobuf_index.set_origin(origin_.spec()); |
| 314 | 311 |
| 315 for (size_t i = 0u, max = cache_names.size(); i < max; ++i) { | 312 for (const auto& cache_metadata : index.ordered_cache_metadata()) { |
| 316 DCHECK(base::ContainsKey(cache_name_to_cache_dir_, cache_names[i])); | 313 DCHECK(base::ContainsKey(cache_name_to_cache_dir_, cache_metadata.name)); |
| 317 | 314 |
| 318 proto::CacheStorageIndex::Cache* index_cache = index.add_cache(); | 315 proto::CacheStorageIndex::Cache* index_cache = protobuf_index.add_cache(); |
| 319 index_cache->set_name(cache_names[i]); | 316 index_cache->set_name(cache_metadata.name); |
| 320 index_cache->set_cache_dir(cache_name_to_cache_dir_[cache_names[i]]); | 317 index_cache->set_cache_dir(cache_name_to_cache_dir_[cache_metadata.name]); |
| 318 if (cache_metadata.size == CacheStorage::kSizeUnknown) | |
| 319 index_cache->clear_size(); | |
| 320 else | |
| 321 index_cache->set_size(cache_metadata.size); | |
| 321 } | 322 } |
| 322 | 323 |
| 323 std::string serialized; | 324 std::string serialized; |
| 324 bool success = index.SerializeToString(&serialized); | 325 bool success = protobuf_index.SerializeToString(&serialized); |
| 325 DCHECK(success); | 326 DCHECK(success); |
| 326 | 327 |
| 327 base::FilePath tmp_path = origin_path_.AppendASCII("index.txt.tmp"); | 328 base::FilePath tmp_path = origin_path_.AppendASCII("index.txt.tmp"); |
| 328 base::FilePath index_path = | 329 base::FilePath index_path = |
| 329 origin_path_.AppendASCII(CacheStorage::kIndexFileName); | 330 origin_path_.AppendASCII(CacheStorage::kIndexFileName); |
| 330 | 331 |
| 331 PostTaskAndReplyWithResult( | 332 PostTaskAndReplyWithResult( |
| 332 cache_task_runner_.get(), FROM_HERE, | 333 cache_task_runner_.get(), FROM_HERE, |
| 333 base::Bind(&SimpleCacheLoader::WriteIndexWriteToFileInPool, tmp_path, | 334 base::Bind(&SimpleCacheLoader::WriteIndexWriteToFileInPool, tmp_path, |
| 334 index_path, serialized), | 335 index_path, serialized), |
| 335 callback); | 336 callback); |
| 336 } | 337 } |
| 337 | 338 |
| 338 static bool WriteIndexWriteToFileInPool(const base::FilePath& tmp_path, | 339 static bool WriteIndexWriteToFileInPool(const base::FilePath& tmp_path, |
| 339 const base::FilePath& index_path, | 340 const base::FilePath& index_path, |
| 340 const std::string& data) { | 341 const std::string& data) { |
| 341 int bytes_written = base::WriteFile(tmp_path, data.c_str(), data.size()); | 342 int bytes_written = base::WriteFile(tmp_path, data.c_str(), data.size()); |
| 342 if (bytes_written != base::checked_cast<int>(data.size())) { | 343 if (bytes_written != base::checked_cast<int>(data.size())) { |
| 343 base::DeleteFile(tmp_path, /* recursive */ false); | 344 base::DeleteFile(tmp_path, /* recursive */ false); |
| 344 return false; | 345 return false; |
| 345 } | 346 } |
| 346 | 347 |
| 347 // Atomically rename the temporary index file to become the real one. | 348 // Atomically rename the temporary index file to become the real one. |
| 348 return base::ReplaceFile(tmp_path, index_path, NULL); | 349 return base::ReplaceFile(tmp_path, index_path, NULL); |
| 349 } | 350 } |
| 350 | 351 |
| 351 void LoadIndex(std::unique_ptr<std::vector<std::string>> names, | 352 void LoadIndex(const CacheStorageIndexCallback& callback) override { |
| 352 const StringVectorCallback& callback) override { | |
| 353 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 353 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 354 | 354 |
| 355 // 1. Read the file from disk. (LoadIndexReadFileInPool) | |
| 356 // 2. Parse file and return the names of the caches (LoadIndexDidReadFile) | |
| 357 | |
| 358 base::FilePath index_path = | |
| 359 origin_path_.AppendASCII(CacheStorage::kIndexFileName); | |
| 360 | |
| 361 PostTaskAndReplyWithResult( | 355 PostTaskAndReplyWithResult( |
| 362 cache_task_runner_.get(), FROM_HERE, | 356 cache_task_runner_.get(), FROM_HERE, |
| 363 base::Bind(&SimpleCacheLoader::ReadAndMigrateIndexInPool, index_path), | 357 base::Bind(&SimpleCacheLoader::ReadAndMigrateIndexInPool, origin_path_), |
| 364 base::Bind(&SimpleCacheLoader::LoadIndexDidReadFile, | 358 base::Bind(&SimpleCacheLoader::LoadIndexDidReadIndex, |
| 365 weak_ptr_factory_.GetWeakPtr(), base::Passed(&names), | 359 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 366 callback)); | |
| 367 } | 360 } |
| 368 | 361 |
| 369 void LoadIndexDidReadFile(std::unique_ptr<std::vector<std::string>> names, | 362 void LoadIndexDidReadIndex(const CacheStorageIndexCallback& callback, |
| 370 const StringVectorCallback& callback, | 363 proto::CacheStorageIndex protobuf_index) { |
| 371 const std::string& serialized) { | |
| 372 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 364 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 373 | 365 |
| 374 std::unique_ptr<std::set<std::string>> cache_dirs( | 366 std::unique_ptr<std::set<std::string>> cache_dirs( |
| 375 new std::set<std::string>); | 367 new std::set<std::string>); |
| 376 | 368 |
| 377 proto::CacheStorageIndex index; | 369 auto index = base::MakeUnique<CacheStorageIndex>(); |
| 378 if (index.ParseFromString(serialized)) { | 370 for (int i = 0, max = protobuf_index.cache_size(); i < max; ++i) { |
| 379 for (int i = 0, max = index.cache_size(); i < max; ++i) { | 371 const proto::CacheStorageIndex::Cache& cache = protobuf_index.cache(i); |
| 380 const proto::CacheStorageIndex::Cache& cache = index.cache(i); | 372 DCHECK(cache.has_cache_dir()); |
| 381 DCHECK(cache.has_cache_dir()); | 373 int64_t cache_size = |
| 382 names->push_back(cache.name()); | 374 cache.has_size() ? cache.size() : CacheStorage::kSizeUnknown; |
| 383 cache_name_to_cache_dir_[cache.name()] = cache.cache_dir(); | 375 index->Insert(CacheStorageIndex::CacheMetadata(cache.name(), cache_size)); |
| 384 cache_dirs->insert(cache.cache_dir()); | 376 cache_name_to_cache_dir_[cache.name()] = cache.cache_dir(); |
| 385 } | 377 cache_dirs->insert(cache.cache_dir()); |
| 386 } | 378 } |
| 387 | 379 |
| 388 cache_task_runner_->PostTask( | 380 cache_task_runner_->PostTask( |
| 389 FROM_HERE, base::Bind(&DeleteUnreferencedCachesInPool, origin_path_, | 381 FROM_HERE, base::Bind(&DeleteUnreferencedCachesInPool, origin_path_, |
| 390 base::Passed(&cache_dirs))); | 382 base::Passed(&cache_dirs))); |
| 391 callback.Run(std::move(names)); | 383 callback.Run(std::move(index)); |
| 392 } | 384 } |
| 393 | 385 |
| 394 void NotifyCacheDoomed( | 386 void NotifyCacheDoomed( |
| 395 std::unique_ptr<CacheStorageCacheHandle> cache_handle) override { | 387 std::unique_ptr<CacheStorageCacheHandle> cache_handle) override { |
| 396 DCHECK(base::ContainsKey(cache_name_to_cache_dir_, | 388 DCHECK(base::ContainsKey(cache_name_to_cache_dir_, |
| 397 cache_handle->value()->cache_name())); | 389 cache_handle->value()->cache_name())); |
| 398 auto iter = | 390 auto iter = |
| 399 cache_name_to_cache_dir_.find(cache_handle->value()->cache_name()); | 391 cache_name_to_cache_dir_.find(cache_handle->value()->cache_name()); |
| 400 doomed_cache_to_path_[cache_handle->value()] = iter->second; | 392 doomed_cache_to_path_[cache_handle->value()] = iter->second; |
| 401 cache_name_to_cache_dir_.erase(iter); | 393 cache_name_to_cache_dir_.erase(iter); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 417 while (!(cache_path = file_enum.Next()).empty()) { | 409 while (!(cache_path = file_enum.Next()).empty()) { |
| 418 if (!base::ContainsKey(*cache_dirs, cache_path.BaseName().AsUTF8Unsafe())) | 410 if (!base::ContainsKey(*cache_dirs, cache_path.BaseName().AsUTF8Unsafe())) |
| 419 dirs_to_delete.push_back(cache_path); | 411 dirs_to_delete.push_back(cache_path); |
| 420 } | 412 } |
| 421 | 413 |
| 422 for (const base::FilePath& cache_path : dirs_to_delete) | 414 for (const base::FilePath& cache_path : dirs_to_delete) |
| 423 base::DeleteFile(cache_path, true /* recursive */); | 415 base::DeleteFile(cache_path, true /* recursive */); |
| 424 } | 416 } |
| 425 | 417 |
| 426 // Runs on cache_task_runner_ | 418 // Runs on cache_task_runner_ |
| 427 static std::string MigrateCachesIfNecessaryInPool( | 419 static proto::CacheStorageIndex ReadAndMigrateIndexInPool( |
| 428 const std::string& body, | 420 const base::FilePath& origin_path) { |
| 429 const base::FilePath& index_path) { | 421 const base::FilePath index_path = |
| 422 origin_path.AppendASCII(CacheStorage::kIndexFileName); | |
| 423 | |
| 430 proto::CacheStorageIndex index; | 424 proto::CacheStorageIndex index; |
| 431 if (!index.ParseFromString(body)) | 425 std::string body; |
| 432 return body; | 426 if (!base::ReadFileToString(index_path, &body) || |
| 427 !index.ParseFromString(body)) | |
| 428 return proto::CacheStorageIndex(); | |
| 429 body.clear(); | |
| 433 | 430 |
| 434 base::FilePath origin_path = index_path.DirName(); | 431 base::File::Info file_info; |
| 435 bool index_is_dirty = false; | 432 base::Time index_last_modified; |
| 436 const std::string kBadIndexState(""); | 433 if (GetFileInfo(index_path, &file_info)) |
| 434 index_last_modified = file_info.last_modified; | |
| 435 bool index_modified = false; | |
| 437 | 436 |
| 438 // Look for caches that have no cache_dir. Give any such caches a directory | 437 // Look for caches that have no cache_dir. Give any such caches a directory |
| 439 // with a random name and move them there. Then, rewrite the index file. | 438 // with a random name and move them there. Then, rewrite the index file. |
| 439 // Additionally invalidate any index entries where the cache was modified | |
| 440 // after the index (making it out-of-date) | |
| 440 for (int i = 0, max = index.cache_size(); i < max; ++i) { | 441 for (int i = 0, max = index.cache_size(); i < max; ++i) { |
| 441 const proto::CacheStorageIndex::Cache& cache = index.cache(i); | 442 const proto::CacheStorageIndex::Cache& cache = index.cache(i); |
| 442 if (!cache.has_cache_dir()) { | 443 if (cache.has_cache_dir()) { |
| 444 if (cache.has_size()) { | |
| 445 base::FilePath cache_dir = origin_path.AppendASCII(cache.cache_dir()); | |
| 446 if (!GetFileInfo(cache_dir, &file_info) || | |
| 447 index_last_modified <= file_info.last_modified) { | |
| 448 // Index is older than this cache, so invalidate index entries that | |
| 449 // may change as a result of cache operations. | |
| 450 index.mutable_cache(i)->clear_size(); | |
| 451 } | |
| 452 } | |
| 453 } else { | |
| 443 // Find a new home for the cache. | 454 // Find a new home for the cache. |
| 444 base::FilePath legacy_cache_path = | 455 base::FilePath legacy_cache_path = |
| 445 origin_path.AppendASCII(HexedHash(cache.name())); | 456 origin_path.AppendASCII(HexedHash(cache.name())); |
| 446 std::string cache_dir; | 457 std::string cache_dir; |
| 447 base::FilePath cache_path; | 458 base::FilePath cache_path; |
| 448 do { | 459 do { |
| 449 cache_dir = base::GenerateGUID(); | 460 cache_dir = base::GenerateGUID(); |
| 450 cache_path = origin_path.AppendASCII(cache_dir); | 461 cache_path = origin_path.AppendASCII(cache_dir); |
| 451 } while (base::PathExists(cache_path)); | 462 } while (base::PathExists(cache_path)); |
| 452 | 463 |
| 453 if (!base::Move(legacy_cache_path, cache_path)) { | 464 if (!base::Move(legacy_cache_path, cache_path)) { |
| 454 // If the move fails then the cache is in a bad state. Return an empty | 465 // If the move fails then the cache is in a bad state. Return an empty |
| 455 // index so that the CacheStorage can start fresh. The unreferenced | 466 // index so that the CacheStorage can start fresh. The unreferenced |
| 456 // caches will be discarded later in initialization. | 467 // caches will be discarded later in initialization. |
| 457 return kBadIndexState; | 468 return proto::CacheStorageIndex(); |
| 458 } | 469 } |
| 459 | 470 |
| 460 index.mutable_cache(i)->set_cache_dir(cache_dir); | 471 index.mutable_cache(i)->set_cache_dir(cache_dir); |
| 461 index_is_dirty = true; | 472 index.mutable_cache(i)->clear_size(); |
| 473 index_modified = true; | |
| 462 } | 474 } |
| 463 } | 475 } |
| 464 | 476 |
| 465 if (index_is_dirty) { | 477 if (index_modified) { |
|
jkarlin
2016/11/23 16:02:18
Since only one place marks index_modified as true,
cmumford
2016/11/29 18:10:20
index_modified_ is being set when looping all cach
jkarlin
2016/12/01 17:43:30
Quite right. Never mind me :)
| |
| 466 std::string new_body; | 478 if (!index.SerializeToString(&body)) |
| 467 if (!index.SerializeToString(&new_body)) | 479 return proto::CacheStorageIndex(); |
| 468 return kBadIndexState; | 480 if (base::WriteFile(index_path, body.c_str(), body.size()) != |
| 469 if (base::WriteFile(index_path, new_body.c_str(), new_body.size()) != | 481 base::checked_cast<int>(body.size())) |
| 470 base::checked_cast<int>(new_body.size())) | 482 return proto::CacheStorageIndex(); |
| 471 return kBadIndexState; | |
| 472 return new_body; | |
| 473 } | 483 } |
| 474 | 484 |
| 475 return body; | 485 return index; |
| 476 } | |
| 477 | |
| 478 // Runs on cache_task_runner_ | |
| 479 static std::string ReadAndMigrateIndexInPool( | |
| 480 const base::FilePath& index_path) { | |
| 481 std::string body; | |
| 482 base::ReadFileToString(index_path, &body); | |
| 483 | |
| 484 return MigrateCachesIfNecessaryInPool(body, index_path); | |
| 485 } | 486 } |
| 486 | 487 |
| 487 const base::FilePath origin_path_; | 488 const base::FilePath origin_path_; |
| 488 std::map<std::string, std::string> cache_name_to_cache_dir_; | 489 std::map<std::string, std::string> cache_name_to_cache_dir_; |
| 489 std::map<CacheStorageCache*, std::string> doomed_cache_to_path_; | 490 std::map<CacheStorageCache*, std::string> doomed_cache_to_path_; |
| 490 | 491 |
| 491 base::WeakPtrFactory<SimpleCacheLoader> weak_ptr_factory_; | 492 base::WeakPtrFactory<SimpleCacheLoader> weak_ptr_factory_; |
| 492 }; | 493 }; |
| 493 | 494 |
| 494 CacheStorage::CacheStorage( | 495 CacheStorage::CacheStorage( |
| 495 const base::FilePath& path, | 496 const base::FilePath& path, |
| 496 bool memory_only, | 497 bool memory_only, |
| 497 base::SequencedTaskRunner* cache_task_runner, | 498 base::SequencedTaskRunner* cache_task_runner, |
| 498 scoped_refptr<net::URLRequestContextGetter> request_context, | 499 scoped_refptr<net::URLRequestContextGetter> request_context, |
| 499 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 500 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| 500 base::WeakPtr<storage::BlobStorageContext> blob_context, | 501 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 501 const GURL& origin) | 502 const GURL& origin) |
| 502 : initialized_(false), | 503 : initialized_(false), |
| 503 initializing_(false), | 504 initializing_(false), |
| 504 memory_only_(memory_only), | 505 memory_only_(memory_only), |
| 505 scheduler_(new CacheStorageScheduler( | 506 scheduler_(new CacheStorageScheduler( |
| 506 CacheStorageSchedulerClient::CLIENT_STORAGE)), | 507 CacheStorageSchedulerClient::CLIENT_STORAGE)), |
| 508 index_(base::MakeUnique<CacheStorageIndex>()), | |
| 507 origin_path_(path), | 509 origin_path_(path), |
| 508 cache_task_runner_(cache_task_runner), | 510 cache_task_runner_(cache_task_runner), |
| 509 quota_manager_proxy_(quota_manager_proxy), | 511 quota_manager_proxy_(quota_manager_proxy), |
| 510 origin_(origin), | 512 origin_(origin), |
| 511 weak_factory_(this) { | 513 weak_factory_(this) { |
| 512 if (memory_only) | 514 if (memory_only) |
| 513 cache_loader_.reset(new MemoryLoader( | 515 cache_loader_.reset(new MemoryLoader( |
| 514 cache_task_runner_.get(), std::move(request_context), | 516 cache_task_runner_.get(), std::move(request_context), |
| 515 quota_manager_proxy.get(), blob_context, this, origin)); | 517 quota_manager_proxy.get(), blob_context, this, origin)); |
| 516 else | 518 else |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 | 565 |
| 564 quota_manager_proxy_->NotifyStorageAccessed( | 566 quota_manager_proxy_->NotifyStorageAccessed( |
| 565 storage::QuotaClient::kServiceWorkerCache, origin_, | 567 storage::QuotaClient::kServiceWorkerCache, origin_, |
| 566 storage::kStorageTypeTemporary); | 568 storage::kStorageTypeTemporary); |
| 567 | 569 |
| 568 scheduler_->ScheduleOperation( | 570 scheduler_->ScheduleOperation( |
| 569 base::Bind(&CacheStorage::DeleteCacheImpl, weak_factory_.GetWeakPtr(), | 571 base::Bind(&CacheStorage::DeleteCacheImpl, weak_factory_.GetWeakPtr(), |
| 570 cache_name, scheduler_->WrapCallbackToRunNext(callback))); | 572 cache_name, scheduler_->WrapCallbackToRunNext(callback))); |
| 571 } | 573 } |
| 572 | 574 |
| 573 void CacheStorage::EnumerateCaches(const StringsCallback& callback) { | 575 void CacheStorage::EnumerateCaches(const CacheMetadataCallback& callback) { |
| 574 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 576 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 575 | 577 |
| 576 if (!initialized_) | 578 if (!initialized_) |
| 577 LazyInit(); | 579 LazyInit(); |
| 578 | 580 |
| 579 quota_manager_proxy_->NotifyStorageAccessed( | 581 quota_manager_proxy_->NotifyStorageAccessed( |
| 580 storage::QuotaClient::kServiceWorkerCache, origin_, | 582 storage::QuotaClient::kServiceWorkerCache, origin_, |
| 581 storage::kStorageTypeTemporary); | 583 storage::kStorageTypeTemporary); |
| 582 | 584 |
| 583 scheduler_->ScheduleOperation( | 585 scheduler_->ScheduleOperation( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 641 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 640 | 642 |
| 641 if (!initialized_) | 643 if (!initialized_) |
| 642 LazyInit(); | 644 LazyInit(); |
| 643 | 645 |
| 644 scheduler_->ScheduleOperation( | 646 scheduler_->ScheduleOperation( |
| 645 base::Bind(&CacheStorage::SizeImpl, weak_factory_.GetWeakPtr(), | 647 base::Bind(&CacheStorage::SizeImpl, weak_factory_.GetWeakPtr(), |
| 646 scheduler_->WrapCallbackToRunNext(callback))); | 648 scheduler_->WrapCallbackToRunNext(callback))); |
| 647 } | 649 } |
| 648 | 650 |
| 651 void CacheStorage::ScheduleWriteIndex() { | |
| 652 // TODO(cmumford): Write in a lazy fashion to minimize writes. | |
| 653 // TODO(cmumford): Write the index before/after other cache writes because | |
| 654 // modification-times are used for out-of-date checks. | |
|
jkarlin
2016/11/23 16:02:17
I'd say post a cancelable (with 5 second delay) ta
cmumford
2016/11/29 18:10:20
Done.
| |
| 655 cache_loader_->WriteIndex(*index_, base::Bind(&DoNothingWithBool)); | |
| 656 } | |
| 657 | |
| 658 void CacheStorage::CacheSizeSet(const CacheStorageCache* cache, | |
| 659 Whence whence, | |
| 660 int64_t size) { | |
| 661 switch (whence) { | |
|
jkarlin
2016/11/23 16:02:18
This complexity (deltas vs total size) seems unnec
cmumford
2016/11/29 18:10:20
You're totally right - fixed.
| |
| 662 case Whence::SET: | |
| 663 index_->SetCacheSize(cache->cache_name(), size); | |
| 664 break; | |
| 665 case Whence::DELTA: | |
| 666 if (!size) | |
| 667 return; | |
| 668 index_->SetCacheSizeModified(cache->cache_name(), size); | |
| 669 break; | |
| 670 } | |
| 671 ScheduleWriteIndex(); | |
| 672 } | |
| 673 | |
| 649 void CacheStorage::StartAsyncOperationForTesting() { | 674 void CacheStorage::StartAsyncOperationForTesting() { |
| 650 scheduler_->ScheduleOperation(base::Bind(&base::DoNothing)); | 675 scheduler_->ScheduleOperation(base::Bind(&base::DoNothing)); |
| 651 } | 676 } |
| 652 | 677 |
| 653 void CacheStorage::CompleteAsyncOperationForTesting() { | 678 void CacheStorage::CompleteAsyncOperationForTesting() { |
| 654 scheduler_->CompleteOperationAndRunNext(); | 679 scheduler_->CompleteOperationAndRunNext(); |
| 655 } | 680 } |
| 656 | 681 |
| 657 // Init is run lazily so that it is called on the proper MessageLoop. | 682 // Init is run lazily so that it is called on the proper MessageLoop. |
| 658 void CacheStorage::LazyInit() { | 683 void CacheStorage::LazyInit() { |
| 659 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 684 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 660 DCHECK(!initialized_); | 685 DCHECK(!initialized_); |
| 661 | 686 |
| 662 if (initializing_) | 687 if (initializing_) |
| 663 return; | 688 return; |
| 664 | 689 |
| 665 DCHECK(!scheduler_->ScheduledOperations()); | 690 DCHECK(!scheduler_->ScheduledOperations()); |
| 666 | 691 |
| 667 initializing_ = true; | 692 initializing_ = true; |
| 668 scheduler_->ScheduleOperation( | 693 scheduler_->ScheduleOperation( |
| 669 base::Bind(&CacheStorage::LazyInitImpl, weak_factory_.GetWeakPtr())); | 694 base::Bind(&CacheStorage::LazyInitImpl, weak_factory_.GetWeakPtr())); |
| 670 } | 695 } |
| 671 | 696 |
| 672 void CacheStorage::LazyInitImpl() { | 697 void CacheStorage::LazyInitImpl() { |
| 673 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 698 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 674 DCHECK(!initialized_); | 699 DCHECK(!initialized_); |
| 675 DCHECK(initializing_); | 700 DCHECK(initializing_); |
| 676 | 701 |
| 677 // 1. Get the list of cache names (async call) | 702 // 1. Get the cache index (async call) |
| 678 // 2. For each cache name, load the cache (async call) | 703 // 2. For each cache name, load the cache (async call) |
| 679 // 3. Once each load is complete, update the map variables. | 704 // 3. Once each load is complete, update the map variables. |
| 680 // 4. Call the list of waiting callbacks. | 705 // 4. Call the list of waiting callbacks. |
| 681 | 706 |
| 682 std::unique_ptr<std::vector<std::string>> indexed_cache_names( | 707 cache_loader_->LoadIndex(base::Bind(&CacheStorage::LazyInitDidLoadIndex, |
| 683 new std::vector<std::string>()); | |
| 684 | |
| 685 cache_loader_->LoadIndex(std::move(indexed_cache_names), | |
| 686 base::Bind(&CacheStorage::LazyInitDidLoadIndex, | |
| 687 weak_factory_.GetWeakPtr())); | 708 weak_factory_.GetWeakPtr())); |
| 688 } | 709 } |
| 689 | 710 |
| 690 void CacheStorage::LazyInitDidLoadIndex( | 711 void CacheStorage::LazyInitDidLoadIndex( |
| 691 std::unique_ptr<std::vector<std::string>> indexed_cache_names) { | 712 std::unique_ptr<CacheStorageIndex> index) { |
| 692 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 713 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 714 DCHECK(cache_map_.empty()); | |
| 693 | 715 |
| 694 for (size_t i = 0u, max = indexed_cache_names->size(); i < max; ++i) { | 716 for (const auto& cache_metadata : index->ordered_cache_metadata()) { |
| 695 cache_map_.insert(std::make_pair(indexed_cache_names->at(i), | 717 cache_map_.insert(std::make_pair(cache_metadata.name, |
| 696 std::unique_ptr<CacheStorageCache>())); | 718 std::unique_ptr<CacheStorageCache>())); |
| 697 ordered_cache_names_.push_back(indexed_cache_names->at(i)); | |
| 698 } | 719 } |
| 699 | 720 |
| 721 index_.swap(index); | |
|
jkarlin
2016/11/23 16:02:17
index_ = std::move(index);
cmumford
2016/11/29 18:10:20
Done.
| |
| 722 | |
| 700 initializing_ = false; | 723 initializing_ = false; |
| 701 initialized_ = true; | 724 initialized_ = true; |
| 702 | 725 |
| 703 scheduler_->CompleteOperationAndRunNext(); | 726 scheduler_->CompleteOperationAndRunNext(); |
| 704 } | 727 } |
| 705 | 728 |
| 706 void CacheStorage::OpenCacheImpl(const std::string& cache_name, | 729 void CacheStorage::OpenCacheImpl(const std::string& cache_name, |
| 707 const CacheAndErrorCallback& callback) { | 730 const CacheAndErrorCallback& callback) { |
| 708 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 731 std::unique_ptr<CacheStorageCacheHandle> cache_handle = |
| 709 GetLoadedCache(cache_name); | 732 GetLoadedCache(cache_name); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 728 | 751 |
| 729 if (!cache) { | 752 if (!cache) { |
| 730 callback.Run(std::unique_ptr<CacheStorageCacheHandle>(), | 753 callback.Run(std::unique_ptr<CacheStorageCacheHandle>(), |
| 731 CACHE_STORAGE_ERROR_STORAGE); | 754 CACHE_STORAGE_ERROR_STORAGE); |
| 732 return; | 755 return; |
| 733 } | 756 } |
| 734 | 757 |
| 735 CacheStorageCache* cache_ptr = cache.get(); | 758 CacheStorageCache* cache_ptr = cache.get(); |
| 736 | 759 |
| 737 cache_map_.insert(std::make_pair(cache_name, std::move(cache))); | 760 cache_map_.insert(std::make_pair(cache_name, std::move(cache))); |
| 738 ordered_cache_names_.push_back(cache_name); | 761 index_->Insert( |
| 762 CacheStorageIndex::CacheMetadata(cache_name, cache_ptr->cache_size())); | |
| 739 | 763 |
| 740 cache_loader_->WriteIndex( | 764 cache_loader_->WriteIndex( |
| 741 ordered_cache_names_, | 765 *index_, base::Bind(&CacheStorage::CreateCacheDidWriteIndex, |
| 742 base::Bind(&CacheStorage::CreateCacheDidWriteIndex, | 766 weak_factory_.GetWeakPtr(), callback, |
| 743 weak_factory_.GetWeakPtr(), callback, | 767 base::Passed(CreateCacheHandle(cache_ptr)))); |
| 744 base::Passed(CreateCacheHandle(cache_ptr)))); | |
| 745 | 768 |
| 746 cache_loader_->NotifyCacheCreated(cache_name, CreateCacheHandle(cache_ptr)); | 769 cache_loader_->NotifyCacheCreated(cache_name, CreateCacheHandle(cache_ptr)); |
| 747 } | 770 } |
| 748 | 771 |
| 749 void CacheStorage::CreateCacheDidWriteIndex( | 772 void CacheStorage::CreateCacheDidWriteIndex( |
| 750 const CacheAndErrorCallback& callback, | 773 const CacheAndErrorCallback& callback, |
| 751 std::unique_ptr<CacheStorageCacheHandle> cache_handle, | 774 std::unique_ptr<CacheStorageCacheHandle> cache_handle, |
| 752 bool success) { | 775 bool success) { |
| 753 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 776 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 754 DCHECK(cache_handle); | 777 DCHECK(cache_handle); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 765 } | 788 } |
| 766 | 789 |
| 767 void CacheStorage::DeleteCacheImpl(const std::string& cache_name, | 790 void CacheStorage::DeleteCacheImpl(const std::string& cache_name, |
| 768 const BoolAndErrorCallback& callback) { | 791 const BoolAndErrorCallback& callback) { |
| 769 if (!GetLoadedCache(cache_name)) { | 792 if (!GetLoadedCache(cache_name)) { |
| 770 base::ThreadTaskRunnerHandle::Get()->PostTask( | 793 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 771 FROM_HERE, base::Bind(callback, false, CACHE_STORAGE_ERROR_NOT_FOUND)); | 794 FROM_HERE, base::Bind(callback, false, CACHE_STORAGE_ERROR_NOT_FOUND)); |
| 772 return; | 795 return; |
| 773 } | 796 } |
| 774 | 797 |
| 775 // Delete the name from ordered_cache_names_. | 798 // Save the current index so that it can be restored if the write fails. |
| 776 StringVector original_ordered_cache_names = ordered_cache_names_; | 799 // TODO(cmumford): Avoid creating a copy, and make CacheStorageCacheIndex |
| 777 StringVector::iterator iter = std::find( | 800 // DISALLOW_COPY_AND_ASSIGN. |
| 778 ordered_cache_names_.begin(), ordered_cache_names_.end(), cache_name); | 801 auto prior_index = base::MakeUnique<CacheStorageIndex>(*index_); |
| 779 DCHECK(iter != ordered_cache_names_.end()); | 802 index_->Delete(cache_name); |
| 780 ordered_cache_names_.erase(iter); | |
| 781 | 803 |
| 782 cache_loader_->WriteIndex(ordered_cache_names_, | 804 cache_loader_->WriteIndex( |
| 783 base::Bind(&CacheStorage::DeleteCacheDidWriteIndex, | 805 *index_, base::Bind(&CacheStorage::DeleteCacheDidWriteIndex, |
| 784 weak_factory_.GetWeakPtr(), cache_name, | 806 weak_factory_.GetWeakPtr(), cache_name, |
| 785 original_ordered_cache_names, callback)); | 807 base::Passed(std::move(prior_index)), callback)); |
| 786 } | 808 } |
| 787 | 809 |
| 788 void CacheStorage::DeleteCacheDidWriteIndex( | 810 void CacheStorage::DeleteCacheDidWriteIndex( |
| 789 const std::string& cache_name, | 811 const std::string& cache_name, |
| 790 const StringVector& original_ordered_cache_names, | 812 std::unique_ptr<CacheStorageIndex> index_before_delete, |
| 791 const BoolAndErrorCallback& callback, | 813 const BoolAndErrorCallback& callback, |
| 792 bool success) { | 814 bool success) { |
| 793 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 815 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 794 | 816 |
| 795 if (!success) { | 817 if (!success) { |
| 796 // Undo any changes if the change couldn't be written to disk. | 818 // Undo any changes if the change couldn't be written to disk. |
| 797 ordered_cache_names_ = original_ordered_cache_names; | 819 index_.swap(index_before_delete); |
|
jkarlin
2016/11/23 16:02:18
index_ = std::move(index_before_delete);
cmumford
2016/11/29 18:10:20
Done.
| |
| 798 callback.Run(false, CACHE_STORAGE_ERROR_STORAGE); | 820 callback.Run(false, CACHE_STORAGE_ERROR_STORAGE); |
| 799 return; | 821 return; |
| 800 } | 822 } |
| 801 | 823 |
| 802 // Make sure that a cache handle exists for the doomed cache to ensure that | 824 // Make sure that a cache handle exists for the doomed cache to ensure that |
| 803 // DeleteCacheFinalize is called. | 825 // DeleteCacheFinalize is called. |
| 804 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 826 std::unique_ptr<CacheStorageCacheHandle> cache_handle = |
| 805 GetLoadedCache(cache_name); | 827 GetLoadedCache(cache_name); |
| 806 | 828 |
| 807 CacheMap::iterator map_iter = cache_map_.find(cache_name); | 829 CacheMap::iterator map_iter = cache_map_.find(cache_name); |
| 808 doomed_caches_.insert( | 830 doomed_caches_.insert( |
| 809 std::make_pair(map_iter->second.get(), std::move(map_iter->second))); | 831 std::make_pair(map_iter->second.get(), std::move(map_iter->second))); |
| 810 cache_map_.erase(map_iter); | 832 cache_map_.erase(map_iter); |
| 811 | 833 |
| 812 cache_loader_->NotifyCacheDoomed(std::move(cache_handle)); | 834 cache_loader_->NotifyCacheDoomed(std::move(cache_handle)); |
| 813 | 835 |
| 814 callback.Run(true, CACHE_STORAGE_OK); | 836 callback.Run(true, CACHE_STORAGE_OK); |
| 815 } | 837 } |
| 816 | 838 |
| 817 // Call this once the last handle to a doomed cache is gone. It's okay if this | 839 // 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 | 840 // doesn't get to complete before shutdown, the cache will be removed from disk |
| 819 // on next startup in that case. | 841 // on next startup in that case. |
| 820 void CacheStorage::DeleteCacheFinalize( | 842 void CacheStorage::DeleteCacheFinalize( |
| 821 std::unique_ptr<CacheStorageCache> doomed_cache) { | 843 std::unique_ptr<CacheStorageCache> doomed_cache) { |
| 822 CacheStorageCache* cache = doomed_cache.get(); | 844 CacheStorageCache* cache = doomed_cache.get(); |
| 845 cache->SetObserver(nullptr); | |
| 823 cache->Size(base::Bind(&CacheStorage::DeleteCacheDidGetSize, | 846 cache->Size(base::Bind(&CacheStorage::DeleteCacheDidGetSize, |
| 824 weak_factory_.GetWeakPtr(), | 847 weak_factory_.GetWeakPtr(), |
| 825 base::Passed(std::move(doomed_cache)))); | 848 base::Passed(std::move(doomed_cache)))); |
| 826 } | 849 } |
| 827 | 850 |
| 828 void CacheStorage::DeleteCacheDidGetSize( | 851 void CacheStorage::DeleteCacheDidGetSize( |
| 829 std::unique_ptr<CacheStorageCache> cache, | 852 std::unique_ptr<CacheStorageCache> cache, |
| 830 int64_t cache_size) { | 853 int64_t cache_size) { |
| 831 quota_manager_proxy_->NotifyStorageModified( | 854 quota_manager_proxy_->NotifyStorageModified( |
| 832 storage::QuotaClient::kServiceWorkerCache, origin_, | 855 storage::QuotaClient::kServiceWorkerCache, origin_, |
| 833 storage::kStorageTypeTemporary, -1 * cache_size); | 856 storage::kStorageTypeTemporary, -1 * cache_size); |
| 834 | 857 |
| 835 cache_loader_->CleanUpDeletedCache(cache.get()); | 858 cache_loader_->CleanUpDeletedCache(cache.get()); |
| 836 } | 859 } |
| 837 | 860 |
| 838 void CacheStorage::EnumerateCachesImpl(const StringsCallback& callback) { | 861 void CacheStorage::EnumerateCachesImpl(const CacheMetadataCallback& callback) { |
| 839 callback.Run(ordered_cache_names_); | 862 callback.Run(*index_); |
| 840 } | 863 } |
| 841 | 864 |
| 842 void CacheStorage::MatchCacheImpl( | 865 void CacheStorage::MatchCacheImpl( |
| 843 const std::string& cache_name, | 866 const std::string& cache_name, |
| 844 std::unique_ptr<ServiceWorkerFetchRequest> request, | 867 std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 845 const CacheStorageCacheQueryParams& match_params, | 868 const CacheStorageCacheQueryParams& match_params, |
| 846 const CacheStorageCache::ResponseCallback& callback) { | 869 const CacheStorageCache::ResponseCallback& callback) { |
| 847 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 870 std::unique_ptr<CacheStorageCacheHandle> cache_handle = |
| 848 GetLoadedCache(cache_name); | 871 GetLoadedCache(cache_name); |
| 849 | 872 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 870 std::unique_ptr<ServiceWorkerResponse> response, | 893 std::unique_ptr<ServiceWorkerResponse> response, |
| 871 std::unique_ptr<storage::BlobDataHandle> handle) { | 894 std::unique_ptr<storage::BlobDataHandle> handle) { |
| 872 callback.Run(error, std::move(response), std::move(handle)); | 895 callback.Run(error, std::move(response), std::move(handle)); |
| 873 } | 896 } |
| 874 | 897 |
| 875 void CacheStorage::MatchAllCachesImpl( | 898 void CacheStorage::MatchAllCachesImpl( |
| 876 std::unique_ptr<ServiceWorkerFetchRequest> request, | 899 std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 877 const CacheStorageCacheQueryParams& match_params, | 900 const CacheStorageCacheQueryParams& match_params, |
| 878 const CacheStorageCache::ResponseCallback& callback) { | 901 const CacheStorageCache::ResponseCallback& callback) { |
| 879 std::vector<CacheMatchResponse>* match_responses = | 902 std::vector<CacheMatchResponse>* match_responses = |
| 880 new std::vector<CacheMatchResponse>(ordered_cache_names_.size()); | 903 new std::vector<CacheMatchResponse>(index_->num_entries()); |
| 881 | 904 |
| 882 base::Closure barrier_closure = base::BarrierClosure( | 905 base::Closure barrier_closure = base::BarrierClosure( |
| 883 ordered_cache_names_.size(), | 906 index_->num_entries(), |
| 884 base::Bind(&CacheStorage::MatchAllCachesDidMatchAll, | 907 base::Bind(&CacheStorage::MatchAllCachesDidMatchAll, |
| 885 weak_factory_.GetWeakPtr(), | 908 weak_factory_.GetWeakPtr(), |
| 886 base::Passed(base::WrapUnique(match_responses)), callback)); | 909 base::Passed(base::WrapUnique(match_responses)), callback)); |
| 887 | 910 |
| 888 for (size_t i = 0, max = ordered_cache_names_.size(); i < max; ++i) { | 911 size_t idx = 0; |
| 912 for (const auto& cache_metadata : index_->ordered_cache_metadata()) { | |
| 889 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 913 std::unique_ptr<CacheStorageCacheHandle> cache_handle = |
| 890 GetLoadedCache(ordered_cache_names_[i]); | 914 GetLoadedCache(cache_metadata.name); |
| 891 DCHECK(cache_handle); | 915 DCHECK(cache_handle); |
| 892 | 916 |
| 893 CacheStorageCache* cache_ptr = cache_handle->value(); | 917 CacheStorageCache* cache_ptr = cache_handle->value(); |
| 894 cache_ptr->Match(base::MakeUnique<ServiceWorkerFetchRequest>(*request), | 918 cache_ptr->Match(base::MakeUnique<ServiceWorkerFetchRequest>(*request), |
| 895 match_params, | 919 match_params, |
| 896 base::Bind(&CacheStorage::MatchAllCachesDidMatch, | 920 base::Bind(&CacheStorage::MatchAllCachesDidMatch, |
| 897 weak_factory_.GetWeakPtr(), | 921 weak_factory_.GetWeakPtr(), |
| 898 base::Passed(std::move(cache_handle)), | 922 base::Passed(std::move(cache_handle)), |
| 899 &match_responses->at(i), barrier_closure)); | 923 &match_responses->at(idx), barrier_closure)); |
| 924 idx++; | |
| 900 } | 925 } |
| 901 } | 926 } |
| 902 | 927 |
| 903 void CacheStorage::MatchAllCachesDidMatch( | 928 void CacheStorage::MatchAllCachesDidMatch( |
| 904 std::unique_ptr<CacheStorageCacheHandle> cache_handle, | 929 std::unique_ptr<CacheStorageCacheHandle> cache_handle, |
| 905 CacheMatchResponse* out_match_response, | 930 CacheMatchResponse* out_match_response, |
| 906 const base::Closure& barrier_closure, | 931 const base::Closure& barrier_closure, |
| 907 CacheStorageError error, | 932 CacheStorageError error, |
| 908 std::unique_ptr<ServiceWorkerResponse> service_worker_response, | 933 std::unique_ptr<ServiceWorkerResponse> service_worker_response, |
| 909 std::unique_ptr<storage::BlobDataHandle> handle) { | 934 std::unique_ptr<storage::BlobDataHandle> handle) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 977 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1002 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 978 DCHECK(initialized_); | 1003 DCHECK(initialized_); |
| 979 | 1004 |
| 980 CacheMap::iterator map_iter = cache_map_.find(cache_name); | 1005 CacheMap::iterator map_iter = cache_map_.find(cache_name); |
| 981 if (map_iter == cache_map_.end()) | 1006 if (map_iter == cache_map_.end()) |
| 982 return std::unique_ptr<CacheStorageCacheHandle>(); | 1007 return std::unique_ptr<CacheStorageCacheHandle>(); |
| 983 | 1008 |
| 984 CacheStorageCache* cache = map_iter->second.get(); | 1009 CacheStorageCache* cache = map_iter->second.get(); |
| 985 | 1010 |
| 986 if (!cache) { | 1011 if (!cache) { |
| 987 std::unique_ptr<CacheStorageCache> new_cache = | 1012 std::unique_ptr<CacheStorageCache> new_cache = cache_loader_->CreateCache( |
| 988 cache_loader_->CreateCache(cache_name); | 1013 cache_name, index_->GetCacheSize(cache_name)); |
| 989 CacheStorageCache* cache_ptr = new_cache.get(); | 1014 CacheStorageCache* cache_ptr = new_cache.get(); |
| 990 map_iter->second = std::move(new_cache); | 1015 map_iter->second = std::move(new_cache); |
| 991 | 1016 |
| 992 return CreateCacheHandle(cache_ptr); | 1017 return CreateCacheHandle(cache_ptr); |
| 993 } | 1018 } |
| 994 | 1019 |
| 995 return CreateCacheHandle(cache); | 1020 return CreateCacheHandle(cache); |
| 996 } | 1021 } |
| 997 | 1022 |
| 1023 void CacheStorage::SizeRetrievedFromCache( | |
| 1024 std::unique_ptr<CacheStorageCacheHandle> cache_handle, | |
| 1025 const base::Closure& closure, | |
| 1026 int64_t* accumulator, | |
| 1027 int64_t size) { | |
| 1028 index_->SetCacheSize(cache_handle->value()->cache_name(), size); | |
| 1029 *accumulator += size; | |
| 1030 closure.Run(); | |
| 1031 } | |
| 1032 | |
| 998 void CacheStorage::GetSizeThenCloseAllCachesImpl(const SizeCallback& callback) { | 1033 void CacheStorage::GetSizeThenCloseAllCachesImpl(const SizeCallback& callback) { |
| 999 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1034 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1000 DCHECK(initialized_); | 1035 DCHECK(initialized_); |
| 1001 | 1036 |
| 1002 std::unique_ptr<int64_t> accumulator(new int64_t(0)); | 1037 std::unique_ptr<int64_t> accumulator(new int64_t(0)); |
| 1003 int64_t* accumulator_ptr = accumulator.get(); | 1038 int64_t* accumulator_ptr = accumulator.get(); |
| 1004 | 1039 |
| 1005 base::Closure barrier_closure = base::BarrierClosure( | 1040 base::Closure barrier_closure = base::BarrierClosure( |
| 1006 ordered_cache_names_.size(), | 1041 index_->num_entries(), |
| 1007 base::Bind(&SizeRetrievedFromAllCaches, | 1042 base::Bind(&SizeRetrievedFromAllCaches, |
| 1008 base::Passed(std::move(accumulator)), callback)); | 1043 base::Passed(std::move(accumulator)), callback)); |
| 1009 | 1044 |
| 1010 for (const std::string& cache_name : ordered_cache_names_) { | 1045 for (const auto& cache_metadata : index_->ordered_cache_metadata()) { |
| 1011 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 1046 auto cache_handle = GetLoadedCache(cache_metadata.name); |
| 1012 GetLoadedCache(cache_name); | |
| 1013 CacheStorageCache* cache = cache_handle->value(); | 1047 CacheStorageCache* cache = cache_handle->value(); |
| 1014 cache->GetSizeThenClose(base::Bind(&SizeRetrievedFromCache, | 1048 cache->GetSizeThenClose(base::Bind(&CacheStorage::SizeRetrievedFromCache, |
| 1049 weak_factory_.GetWeakPtr(), | |
| 1015 base::Passed(std::move(cache_handle)), | 1050 base::Passed(std::move(cache_handle)), |
| 1016 barrier_closure, accumulator_ptr)); | 1051 barrier_closure, accumulator_ptr)); |
| 1017 } | 1052 } |
| 1018 } | 1053 } |
| 1019 | 1054 |
| 1020 void CacheStorage::SizeImpl(const SizeCallback& callback) { | 1055 void CacheStorage::SizeImpl(const SizeCallback& callback) { |
| 1021 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1056 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1022 DCHECK(initialized_); | 1057 DCHECK(initialized_); |
| 1023 | 1058 |
| 1059 if (index_->GetStorageSize() != kSizeUnknown) { | |
| 1060 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 1061 FROM_HERE, base::Bind(callback, index_->GetStorageSize())); | |
| 1062 return; | |
| 1063 } | |
| 1064 | |
| 1024 std::unique_ptr<int64_t> accumulator(new int64_t(0)); | 1065 std::unique_ptr<int64_t> accumulator(new int64_t(0)); |
| 1025 int64_t* accumulator_ptr = accumulator.get(); | 1066 int64_t* accumulator_ptr = accumulator.get(); |
| 1026 | 1067 |
| 1027 base::Closure barrier_closure = base::BarrierClosure( | 1068 base::Closure barrier_closure = base::BarrierClosure( |
| 1028 ordered_cache_names_.size(), | 1069 index_->num_entries(), |
| 1029 base::Bind(&SizeRetrievedFromAllCaches, | 1070 base::Bind(&SizeRetrievedFromAllCaches, |
| 1030 base::Passed(std::move(accumulator)), callback)); | 1071 base::Passed(std::move(accumulator)), callback)); |
| 1031 | 1072 |
| 1032 for (const std::string& cache_name : ordered_cache_names_) { | 1073 for (const auto& cache_metadata : index_->ordered_cache_metadata()) { |
| 1074 if (cache_metadata.size != CacheStorage::kSizeUnknown) { | |
| 1075 *accumulator_ptr += cache_metadata.size; | |
| 1076 barrier_closure.Run(); | |
| 1077 continue; | |
| 1078 } | |
| 1033 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 1079 std::unique_ptr<CacheStorageCacheHandle> cache_handle = |
| 1034 GetLoadedCache(cache_name); | 1080 GetLoadedCache(cache_metadata.name); |
| 1035 CacheStorageCache* cache = cache_handle->value(); | 1081 CacheStorageCache* cache = cache_handle->value(); |
| 1036 cache->Size(base::Bind(&SizeRetrievedFromCache, | 1082 cache->Size(base::Bind(&CacheStorage::SizeRetrievedFromCache, |
| 1083 weak_factory_.GetWeakPtr(), | |
| 1037 base::Passed(std::move(cache_handle)), | 1084 base::Passed(std::move(cache_handle)), |
| 1038 barrier_closure, accumulator_ptr)); | 1085 barrier_closure, accumulator_ptr)); |
| 1039 } | 1086 } |
| 1040 } | 1087 } |
| 1041 | 1088 |
| 1042 } // namespace content | 1089 } // namespace content |
| OLD | NEW |