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> |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "base/stl_util.h" | 25 #include "base/stl_util.h" |
| 26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 28 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 29 #include "content/browser/cache_storage/cache_storage.pb.h" | 29 #include "content/browser/cache_storage/cache_storage.pb.h" |
| 30 #include "content/browser/cache_storage/cache_storage_cache.h" | 30 #include "content/browser/cache_storage/cache_storage_cache.h" |
| 31 #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" | 32 #include "content/browser/cache_storage/cache_storage_index.h" |
| 33 #include "content/browser/cache_storage/cache_storage_scheduler.h" | 33 #include "content/browser/cache_storage/cache_storage_scheduler.h" |
| 34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 35 #include "crypto/symmetric_key.h" | |
| 35 #include "net/base/directory_lister.h" | 36 #include "net/base/directory_lister.h" |
| 36 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
| 37 #include "net/url_request/url_request_context_getter.h" | 38 #include "net/url_request/url_request_context_getter.h" |
| 38 #include "storage/browser/blob/blob_storage_context.h" | 39 #include "storage/browser/blob/blob_storage_context.h" |
| 39 #include "storage/browser/quota/quota_manager_proxy.h" | 40 #include "storage/browser/quota/quota_manager_proxy.h" |
| 40 | 41 |
| 42 using crypto::SymmetricKey; | |
| 43 | |
| 41 namespace content { | 44 namespace content { |
| 42 | 45 |
| 43 namespace { | 46 namespace { |
| 44 | 47 |
| 48 const SymmetricKey::Algorithm kPaddingKeyAlgorithm = SymmetricKey::AES; | |
| 49 | |
| 45 std::string HexedHash(const std::string& value) { | 50 std::string HexedHash(const std::string& value) { |
| 46 std::string value_hash = base::SHA1HashString(value); | 51 std::string value_hash = base::SHA1HashString(value); |
| 47 std::string valued_hexed_hash = base::ToLowerASCII( | 52 std::string valued_hexed_hash = base::ToLowerASCII( |
| 48 base::HexEncode(value_hash.c_str(), value_hash.length())); | 53 base::HexEncode(value_hash.c_str(), value_hash.length())); |
| 49 return valued_hexed_hash; | 54 return valued_hexed_hash; |
| 50 } | 55 } |
| 51 | 56 |
| 52 void SizeRetrievedFromAllCaches(std::unique_ptr<int64_t> accumulator, | 57 void SizeRetrievedFromAllCaches(std::unique_ptr<int64_t> accumulator, |
| 53 const CacheStorage::SizeCallback& callback) { | 58 const CacheStorage::SizeCallback& callback) { |
| 54 base::ThreadTaskRunnerHandle::Get()->PostTask( | 59 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 55 FROM_HERE, base::Bind(callback, *accumulator)); | 60 FROM_HERE, base::Bind(callback, *accumulator)); |
| 56 } | 61 } |
| 57 | 62 |
| 58 void DoNothingWithBool(bool success) {} | 63 void DoNothingWithBool(bool success) {} |
| 59 | 64 |
| 65 std::unique_ptr<SymmetricKey> GeneratePaddingKey() { | |
|
jkarlin
2017/06/13 12:53:35
We want a single key per browser sesssion, not a k
cmumford
2017/06/13 22:50:42
Doh - of course <sigh>
| |
| 66 return SymmetricKey::GenerateRandomKey(kPaddingKeyAlgorithm, 128); | |
| 67 } | |
| 68 | |
| 69 std::unique_ptr<SymmetricKey> ImportPaddingKey(const std::string& raw_key) { | |
| 70 return SymmetricKey::Import(kPaddingKeyAlgorithm, raw_key); | |
| 71 } | |
| 72 | |
| 60 } // namespace | 73 } // namespace |
| 61 | 74 |
| 62 const char CacheStorage::kIndexFileName[] = "index.txt"; | 75 const char CacheStorage::kIndexFileName[] = "index.txt"; |
| 63 constexpr int64_t CacheStorage::kSizeUnknown; | 76 constexpr int64_t CacheStorage::kSizeUnknown; |
| 64 | 77 |
| 65 struct CacheStorage::CacheMatchResponse { | 78 struct CacheStorage::CacheMatchResponse { |
| 66 CacheMatchResponse() = default; | 79 CacheMatchResponse() = default; |
| 67 ~CacheMatchResponse() = default; | 80 ~CacheMatchResponse() = default; |
| 68 | 81 |
| 69 CacheStorageError error; | 82 CacheStorageError error; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 95 origin_(origin) { | 108 origin_(origin) { |
| 96 DCHECK(!origin_.is_empty()); | 109 DCHECK(!origin_.is_empty()); |
| 97 } | 110 } |
| 98 | 111 |
| 99 virtual ~CacheLoader() {} | 112 virtual ~CacheLoader() {} |
| 100 | 113 |
| 101 // Creates a CacheStorageCache with the given name. It does not attempt to | 114 // Creates a CacheStorageCache with the given name. It does not attempt to |
| 102 // load the backend, that happens lazily when the cache is used. | 115 // load the backend, that happens lazily when the cache is used. |
| 103 virtual std::unique_ptr<CacheStorageCache> CreateCache( | 116 virtual std::unique_ptr<CacheStorageCache> CreateCache( |
| 104 const std::string& cache_name, | 117 const std::string& cache_name, |
| 105 int64_t cache_size) = 0; | 118 int64_t cache_size, |
| 119 int64_t cache_padding, | |
| 120 std::unique_ptr<SymmetricKey> cache_padding_key) = 0; | |
| 106 | 121 |
| 107 // Deletes any pre-existing cache of the same name and then loads it. | 122 // Deletes any pre-existing cache of the same name and then loads it. |
| 108 virtual void PrepareNewCacheDestination(const std::string& cache_name, | 123 virtual void PrepareNewCacheDestination(const std::string& cache_name, |
| 109 const CacheCallback& callback) = 0; | 124 const CacheCallback& callback) = 0; |
| 110 | 125 |
| 111 // After the backend has been deleted, do any extra house keeping such as | 126 // After the backend has been deleted, do any extra house keeping such as |
| 112 // removing the cache's directory. | 127 // removing the cache's directory. |
| 113 virtual void CleanUpDeletedCache(CacheStorageCache* cache) = 0; | 128 virtual void CleanUpDeletedCache(CacheStorageCache* cache) = 0; |
| 114 | 129 |
| 115 // Writes the cache index to disk if applicable. | 130 // Writes the cache index to disk if applicable. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 base::WeakPtr<storage::BlobStorageContext> blob_context, | 172 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 158 CacheStorage* cache_storage, | 173 CacheStorage* cache_storage, |
| 159 const GURL& origin) | 174 const GURL& origin) |
| 160 : CacheLoader(cache_task_runner, | 175 : CacheLoader(cache_task_runner, |
| 161 request_context, | 176 request_context, |
| 162 quota_manager_proxy, | 177 quota_manager_proxy, |
| 163 blob_context, | 178 blob_context, |
| 164 cache_storage, | 179 cache_storage, |
| 165 origin) {} | 180 origin) {} |
| 166 | 181 |
| 167 std::unique_ptr<CacheStorageCache> CreateCache(const std::string& cache_name, | 182 std::unique_ptr<CacheStorageCache> CreateCache( |
| 168 int64_t cache_size) override { | 183 const std::string& cache_name, |
| 184 int64_t cache_size, | |
| 185 int64_t cache_padding, | |
| 186 std::unique_ptr<SymmetricKey> cache_padding_key) override { | |
| 169 return CacheStorageCache::CreateMemoryCache( | 187 return CacheStorageCache::CreateMemoryCache( |
| 170 origin_, cache_name, cache_storage_, request_context_getter_, | 188 origin_, cache_name, cache_storage_, request_context_getter_, |
| 171 quota_manager_proxy_, blob_context_); | 189 quota_manager_proxy_, blob_context_, GeneratePaddingKey()); |
| 172 } | 190 } |
| 173 | 191 |
| 174 void PrepareNewCacheDestination(const std::string& cache_name, | 192 void PrepareNewCacheDestination(const std::string& cache_name, |
| 175 const CacheCallback& callback) override { | 193 const CacheCallback& callback) override { |
| 176 std::unique_ptr<CacheStorageCache> cache = | 194 std::unique_ptr<CacheStorageCache> cache = |
| 177 CreateCache(cache_name, 0 /*cache_size*/); | 195 CreateCache(cache_name, 0 /*cache_size*/, 0 /* cache_padding */, |
| 196 GeneratePaddingKey()); | |
| 178 callback.Run(std::move(cache)); | 197 callback.Run(std::move(cache)); |
| 179 } | 198 } |
| 180 | 199 |
| 181 void CleanUpDeletedCache(CacheStorageCache* cache) override {} | 200 void CleanUpDeletedCache(CacheStorageCache* cache) override {} |
| 182 | 201 |
| 183 void WriteIndex(const CacheStorageIndex& index, | 202 void WriteIndex(const CacheStorageIndex& index, |
| 184 const BoolCallback& callback) override { | 203 const BoolCallback& callback) override { |
| 185 callback.Run(true); | 204 callback.Run(true); |
| 186 } | 205 } |
| 187 | 206 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 const GURL& origin) | 244 const GURL& origin) |
| 226 : CacheLoader(cache_task_runner, | 245 : CacheLoader(cache_task_runner, |
| 227 request_context, | 246 request_context, |
| 228 quota_manager_proxy, | 247 quota_manager_proxy, |
| 229 blob_context, | 248 blob_context, |
| 230 cache_storage, | 249 cache_storage, |
| 231 origin), | 250 origin), |
| 232 origin_path_(origin_path), | 251 origin_path_(origin_path), |
| 233 weak_ptr_factory_(this) {} | 252 weak_ptr_factory_(this) {} |
| 234 | 253 |
| 235 std::unique_ptr<CacheStorageCache> CreateCache(const std::string& cache_name, | 254 std::unique_ptr<CacheStorageCache> CreateCache( |
| 236 int64_t cache_size) override { | 255 const std::string& cache_name, |
| 256 int64_t cache_size, | |
| 257 int64_t cache_padding, | |
| 258 std::unique_ptr<SymmetricKey> cache_padding_key) override { | |
| 237 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 259 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 238 DCHECK(base::ContainsKey(cache_name_to_cache_dir_, cache_name)); | 260 DCHECK(base::ContainsKey(cache_name_to_cache_dir_, cache_name)); |
| 239 | 261 |
| 240 std::string cache_dir = cache_name_to_cache_dir_[cache_name]; | 262 std::string cache_dir = cache_name_to_cache_dir_[cache_name]; |
| 241 base::FilePath cache_path = origin_path_.AppendASCII(cache_dir); | 263 base::FilePath cache_path = origin_path_.AppendASCII(cache_dir); |
| 242 return CacheStorageCache::CreatePersistentCache( | 264 return CacheStorageCache::CreatePersistentCache( |
| 243 origin_, cache_name, cache_storage_, cache_path, | 265 origin_, cache_name, cache_storage_, cache_path, |
| 244 request_context_getter_, quota_manager_proxy_, blob_context_, | 266 request_context_getter_, quota_manager_proxy_, blob_context_, |
| 245 cache_size); | 267 cache_size, cache_padding, std::move(cache_padding_key)); |
| 246 } | 268 } |
| 247 | 269 |
| 248 void PrepareNewCacheDestination(const std::string& cache_name, | 270 void PrepareNewCacheDestination(const std::string& cache_name, |
| 249 const CacheCallback& callback) override { | 271 const CacheCallback& callback) override { |
| 250 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 272 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 251 | 273 |
| 252 PostTaskAndReplyWithResult( | 274 PostTaskAndReplyWithResult( |
| 253 cache_task_runner_.get(), FROM_HERE, | 275 cache_task_runner_.get(), FROM_HERE, |
| 254 base::Bind(&SimpleCacheLoader::PrepareNewCacheDirectoryInPool, | 276 base::Bind(&SimpleCacheLoader::PrepareNewCacheDirectoryInPool, |
| 255 origin_path_), | 277 origin_path_), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 272 | 294 |
| 273 void PrepareNewCacheCreateCache(const std::string& cache_name, | 295 void PrepareNewCacheCreateCache(const std::string& cache_name, |
| 274 const CacheCallback& callback, | 296 const CacheCallback& callback, |
| 275 const std::string& cache_dir) { | 297 const std::string& cache_dir) { |
| 276 if (cache_dir.empty()) { | 298 if (cache_dir.empty()) { |
| 277 callback.Run(std::unique_ptr<CacheStorageCache>()); | 299 callback.Run(std::unique_ptr<CacheStorageCache>()); |
| 278 return; | 300 return; |
| 279 } | 301 } |
| 280 | 302 |
| 281 cache_name_to_cache_dir_[cache_name] = cache_dir; | 303 cache_name_to_cache_dir_[cache_name] = cache_dir; |
| 282 callback.Run(CreateCache(cache_name, CacheStorage::kSizeUnknown)); | 304 callback.Run(CreateCache(cache_name, CacheStorage::kSizeUnknown, |
| 305 CacheStorage::kSizeUnknown, GeneratePaddingKey())); | |
| 283 } | 306 } |
| 284 | 307 |
| 285 void CleanUpDeletedCache(CacheStorageCache* cache) override { | 308 void CleanUpDeletedCache(CacheStorageCache* cache) override { |
| 286 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 309 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 287 DCHECK(base::ContainsKey(doomed_cache_to_path_, cache)); | 310 DCHECK(base::ContainsKey(doomed_cache_to_path_, cache)); |
| 288 | 311 |
| 289 base::FilePath cache_path = | 312 base::FilePath cache_path = |
| 290 origin_path_.AppendASCII(doomed_cache_to_path_[cache]); | 313 origin_path_.AppendASCII(doomed_cache_to_path_[cache]); |
| 291 doomed_cache_to_path_.erase(cache); | 314 doomed_cache_to_path_.erase(cache); |
| 292 | 315 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 | 388 |
| 366 std::unique_ptr<std::set<std::string>> cache_dirs( | 389 std::unique_ptr<std::set<std::string>> cache_dirs( |
| 367 new std::set<std::string>); | 390 new std::set<std::string>); |
| 368 | 391 |
| 369 auto index = base::MakeUnique<CacheStorageIndex>(); | 392 auto index = base::MakeUnique<CacheStorageIndex>(); |
| 370 for (int i = 0, max = protobuf_index.cache_size(); i < max; ++i) { | 393 for (int i = 0, max = protobuf_index.cache_size(); i < max; ++i) { |
| 371 const proto::CacheStorageIndex::Cache& cache = protobuf_index.cache(i); | 394 const proto::CacheStorageIndex::Cache& cache = protobuf_index.cache(i); |
| 372 DCHECK(cache.has_cache_dir()); | 395 DCHECK(cache.has_cache_dir()); |
| 373 int64_t cache_size = | 396 int64_t cache_size = |
| 374 cache.has_size() ? cache.size() : CacheStorage::kSizeUnknown; | 397 cache.has_size() ? cache.size() : CacheStorage::kSizeUnknown; |
| 375 index->Insert(CacheStorageIndex::CacheMetadata(cache.name(), cache_size)); | 398 int64_t cache_padding = |
| 399 cache.has_padding() ? cache.padding() : CacheStorage::kSizeUnknown; | |
| 400 std::string cache_padding_key = cache.has_padding_key() | |
| 401 ? cache.padding_key() | |
| 402 : GeneratePaddingKey()->key(); | |
| 403 | |
| 404 index->Insert(CacheStorageIndex::CacheMetadata( | |
| 405 cache.name(), cache_size, cache_padding, | |
| 406 std::move(cache_padding_key))); | |
| 376 cache_name_to_cache_dir_[cache.name()] = cache.cache_dir(); | 407 cache_name_to_cache_dir_[cache.name()] = cache.cache_dir(); |
| 377 cache_dirs->insert(cache.cache_dir()); | 408 cache_dirs->insert(cache.cache_dir()); |
| 378 } | 409 } |
| 379 | 410 |
| 380 cache_task_runner_->PostTask( | 411 cache_task_runner_->PostTask( |
| 381 FROM_HERE, base::Bind(&DeleteUnreferencedCachesInPool, origin_path_, | 412 FROM_HERE, base::Bind(&DeleteUnreferencedCachesInPool, origin_path_, |
| 382 base::Passed(&cache_dirs))); | 413 base::Passed(&cache_dirs))); |
| 383 callback.Run(std::move(index)); | 414 callback.Run(std::move(index)); |
| 384 } | 415 } |
| 385 | 416 |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 772 | 803 |
| 773 if (!cache) { | 804 if (!cache) { |
| 774 callback.Run(std::unique_ptr<CacheStorageCacheHandle>(), | 805 callback.Run(std::unique_ptr<CacheStorageCacheHandle>(), |
| 775 CACHE_STORAGE_ERROR_STORAGE); | 806 CACHE_STORAGE_ERROR_STORAGE); |
| 776 return; | 807 return; |
| 777 } | 808 } |
| 778 | 809 |
| 779 CacheStorageCache* cache_ptr = cache.get(); | 810 CacheStorageCache* cache_ptr = cache.get(); |
| 780 | 811 |
| 781 cache_map_.insert(std::make_pair(cache_name, std::move(cache))); | 812 cache_map_.insert(std::make_pair(cache_name, std::move(cache))); |
| 782 cache_index_->Insert( | 813 cache_index_->Insert(CacheStorageIndex::CacheMetadata( |
| 783 CacheStorageIndex::CacheMetadata(cache_name, cache_ptr->cache_size())); | 814 cache_name, cache_ptr->cache_size(), cache_ptr->cache_padding(), |
| 815 cache_ptr->cache_padding_key()->key())); | |
| 784 | 816 |
| 785 cache_loader_->WriteIndex( | 817 cache_loader_->WriteIndex( |
| 786 *cache_index_, base::Bind(&CacheStorage::CreateCacheDidWriteIndex, | 818 *cache_index_, base::Bind(&CacheStorage::CreateCacheDidWriteIndex, |
| 787 weak_factory_.GetWeakPtr(), callback, | 819 weak_factory_.GetWeakPtr(), callback, |
| 788 base::Passed(CreateCacheHandle(cache_ptr)))); | 820 base::Passed(CreateCacheHandle(cache_ptr)))); |
| 789 | 821 |
| 790 cache_loader_->NotifyCacheCreated(cache_name, CreateCacheHandle(cache_ptr)); | 822 cache_loader_->NotifyCacheCreated(cache_name, CreateCacheHandle(cache_ptr)); |
| 791 } | 823 } |
| 792 | 824 |
| 793 void CacheStorage::CreateCacheDidWriteIndex( | 825 void CacheStorage::CreateCacheDidWriteIndex( |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1019 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1051 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1020 DCHECK(initialized_); | 1052 DCHECK(initialized_); |
| 1021 | 1053 |
| 1022 CacheMap::iterator map_iter = cache_map_.find(cache_name); | 1054 CacheMap::iterator map_iter = cache_map_.find(cache_name); |
| 1023 if (map_iter == cache_map_.end()) | 1055 if (map_iter == cache_map_.end()) |
| 1024 return std::unique_ptr<CacheStorageCacheHandle>(); | 1056 return std::unique_ptr<CacheStorageCacheHandle>(); |
| 1025 | 1057 |
| 1026 CacheStorageCache* cache = map_iter->second.get(); | 1058 CacheStorageCache* cache = map_iter->second.get(); |
| 1027 | 1059 |
| 1028 if (!cache) { | 1060 if (!cache) { |
| 1061 const CacheStorageIndex::CacheMetadata* metadata = | |
| 1062 cache_index_->FindMetadata(cache_name); | |
| 1063 DCHECK(metadata); | |
| 1029 std::unique_ptr<CacheStorageCache> new_cache = cache_loader_->CreateCache( | 1064 std::unique_ptr<CacheStorageCache> new_cache = cache_loader_->CreateCache( |
| 1030 cache_name, cache_index_->GetCacheSize(cache_name)); | 1065 cache_name, metadata->size, metadata->padding, |
| 1066 ImportPaddingKey(metadata->padding_key)); | |
| 1031 CacheStorageCache* cache_ptr = new_cache.get(); | 1067 CacheStorageCache* cache_ptr = new_cache.get(); |
| 1032 map_iter->second = std::move(new_cache); | 1068 map_iter->second = std::move(new_cache); |
| 1033 | 1069 |
| 1034 return CreateCacheHandle(cache_ptr); | 1070 return CreateCacheHandle(cache_ptr); |
| 1035 } | 1071 } |
| 1036 | 1072 |
| 1037 return CreateCacheHandle(cache); | 1073 return CreateCacheHandle(cache); |
| 1038 } | 1074 } |
| 1039 | 1075 |
| 1040 void CacheStorage::SizeRetrievedFromCache( | 1076 void CacheStorage::SizeRetrievedFromCache( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1066 weak_factory_.GetWeakPtr(), | 1102 weak_factory_.GetWeakPtr(), |
| 1067 base::Passed(std::move(cache_handle)), | 1103 base::Passed(std::move(cache_handle)), |
| 1068 barrier_closure, accumulator_ptr)); | 1104 barrier_closure, accumulator_ptr)); |
| 1069 } | 1105 } |
| 1070 } | 1106 } |
| 1071 | 1107 |
| 1072 void CacheStorage::SizeImpl(const SizeCallback& callback) { | 1108 void CacheStorage::SizeImpl(const SizeCallback& callback) { |
| 1073 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1109 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1074 DCHECK(initialized_); | 1110 DCHECK(initialized_); |
| 1075 | 1111 |
| 1076 if (cache_index_->GetStorageSize() != kSizeUnknown) { | 1112 if (cache_index_->GetPaddedStorageSize() != kSizeUnknown) { |
| 1077 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1113 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1078 FROM_HERE, base::Bind(callback, cache_index_->GetStorageSize())); | 1114 FROM_HERE, base::Bind(callback, cache_index_->GetPaddedStorageSize())); |
| 1079 return; | 1115 return; |
| 1080 } | 1116 } |
| 1081 | 1117 |
| 1082 std::unique_ptr<int64_t> accumulator(new int64_t(0)); | 1118 std::unique_ptr<int64_t> accumulator(new int64_t(0)); |
| 1083 int64_t* accumulator_ptr = accumulator.get(); | 1119 int64_t* accumulator_ptr = accumulator.get(); |
| 1084 | 1120 |
| 1085 base::Closure barrier_closure = base::BarrierClosure( | 1121 base::Closure barrier_closure = base::BarrierClosure( |
| 1086 cache_index_->num_entries(), | 1122 cache_index_->num_entries(), |
| 1087 base::Bind(&SizeRetrievedFromAllCaches, | 1123 base::Bind(&SizeRetrievedFromAllCaches, |
| 1088 base::Passed(std::move(accumulator)), callback)); | 1124 base::Passed(std::move(accumulator)), callback)); |
| 1089 | 1125 |
| 1090 for (const auto& cache_metadata : cache_index_->ordered_cache_metadata()) { | 1126 for (const auto& cache_metadata : cache_index_->ordered_cache_metadata()) { |
| 1091 if (cache_metadata.size != CacheStorage::kSizeUnknown) { | 1127 if (cache_metadata.size != CacheStorage::kSizeUnknown) { |
| 1092 *accumulator_ptr += cache_metadata.size; | 1128 *accumulator_ptr += cache_metadata.size; |
| 1093 barrier_closure.Run(); | 1129 barrier_closure.Run(); |
| 1094 continue; | 1130 continue; |
| 1095 } | 1131 } |
| 1096 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 1132 std::unique_ptr<CacheStorageCacheHandle> cache_handle = |
| 1097 GetLoadedCache(cache_metadata.name); | 1133 GetLoadedCache(cache_metadata.name); |
| 1098 CacheStorageCache* cache = cache_handle->value(); | 1134 CacheStorageCache* cache = cache_handle->value(); |
| 1099 cache->Size(base::Bind(&CacheStorage::SizeRetrievedFromCache, | 1135 cache->Size(base::Bind(&CacheStorage::SizeRetrievedFromCache, |
| 1100 weak_factory_.GetWeakPtr(), | 1136 weak_factory_.GetWeakPtr(), |
| 1101 base::Passed(std::move(cache_handle)), | 1137 base::Passed(std::move(cache_handle)), |
| 1102 barrier_closure, accumulator_ptr)); | 1138 barrier_closure, accumulator_ptr)); |
| 1103 } | 1139 } |
| 1104 } | 1140 } |
| 1105 | 1141 |
| 1106 } // namespace content | 1142 } // namespace content |
| OLD | NEW |