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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 const CacheStorage::SizeCallback& callback) { | 52 const CacheStorage::SizeCallback& callback) { |
53 base::ThreadTaskRunnerHandle::Get()->PostTask( | 53 base::ThreadTaskRunnerHandle::Get()->PostTask( |
54 FROM_HERE, base::Bind(callback, *accumulator)); | 54 FROM_HERE, base::Bind(callback, *accumulator)); |
55 } | 55 } |
56 | 56 |
57 void DoNothingWithBool(bool success) {} | 57 void DoNothingWithBool(bool success) {} |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 const char CacheStorage::kIndexFileName[] = "index.txt"; | 61 const char CacheStorage::kIndexFileName[] = "index.txt"; |
62 const int64_t CacheStorage::kSizeUnknown; | |
jkarlin
2017/01/03 13:06:25
Can this gcc issue be fixed by changing this const
Mostyn Bramley-Moore
2017/01/04 00:11:13
Seems to work. CQ dry run underway to confirm.
| |
63 | 62 |
64 struct CacheStorage::CacheMatchResponse { | 63 struct CacheStorage::CacheMatchResponse { |
65 CacheMatchResponse() = default; | 64 CacheMatchResponse() = default; |
66 ~CacheMatchResponse() = default; | 65 ~CacheMatchResponse() = default; |
67 | 66 |
68 CacheStorageError error; | 67 CacheStorageError error; |
69 std::unique_ptr<ServiceWorkerResponse> service_worker_response; | 68 std::unique_ptr<ServiceWorkerResponse> service_worker_response; |
70 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; | 69 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; |
71 }; | 70 }; |
72 | 71 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 | 270 |
272 void PrepareNewCacheCreateCache(const std::string& cache_name, | 271 void PrepareNewCacheCreateCache(const std::string& cache_name, |
273 const CacheCallback& callback, | 272 const CacheCallback& callback, |
274 const std::string& cache_dir) { | 273 const std::string& cache_dir) { |
275 if (cache_dir.empty()) { | 274 if (cache_dir.empty()) { |
276 callback.Run(std::unique_ptr<CacheStorageCache>()); | 275 callback.Run(std::unique_ptr<CacheStorageCache>()); |
277 return; | 276 return; |
278 } | 277 } |
279 | 278 |
280 cache_name_to_cache_dir_[cache_name] = cache_dir; | 279 cache_name_to_cache_dir_[cache_name] = cache_dir; |
281 callback.Run(CreateCache(cache_name, CacheStorage::kSizeUnknown)); | 280 callback.Run(CreateCache(cache_name, kCacheStorageSizeUnknown)); |
282 } | 281 } |
283 | 282 |
284 void CleanUpDeletedCache(CacheStorageCache* cache) override { | 283 void CleanUpDeletedCache(CacheStorageCache* cache) override { |
285 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 284 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
286 DCHECK(base::ContainsKey(doomed_cache_to_path_, cache)); | 285 DCHECK(base::ContainsKey(doomed_cache_to_path_, cache)); |
287 | 286 |
288 base::FilePath cache_path = | 287 base::FilePath cache_path = |
289 origin_path_.AppendASCII(doomed_cache_to_path_[cache]); | 288 origin_path_.AppendASCII(doomed_cache_to_path_[cache]); |
290 doomed_cache_to_path_.erase(cache); | 289 doomed_cache_to_path_.erase(cache); |
291 | 290 |
(...skipping 15 matching lines...) Expand all Loading... | |
307 | 306 |
308 proto::CacheStorageIndex protobuf_index; | 307 proto::CacheStorageIndex protobuf_index; |
309 protobuf_index.set_origin(origin_.spec()); | 308 protobuf_index.set_origin(origin_.spec()); |
310 | 309 |
311 for (const auto& cache_metadata : index.ordered_cache_metadata()) { | 310 for (const auto& cache_metadata : index.ordered_cache_metadata()) { |
312 DCHECK(base::ContainsKey(cache_name_to_cache_dir_, cache_metadata.name)); | 311 DCHECK(base::ContainsKey(cache_name_to_cache_dir_, cache_metadata.name)); |
313 | 312 |
314 proto::CacheStorageIndex::Cache* index_cache = protobuf_index.add_cache(); | 313 proto::CacheStorageIndex::Cache* index_cache = protobuf_index.add_cache(); |
315 index_cache->set_name(cache_metadata.name); | 314 index_cache->set_name(cache_metadata.name); |
316 index_cache->set_cache_dir(cache_name_to_cache_dir_[cache_metadata.name]); | 315 index_cache->set_cache_dir(cache_name_to_cache_dir_[cache_metadata.name]); |
317 if (cache_metadata.size == CacheStorage::kSizeUnknown) | 316 if (cache_metadata.size == kCacheStorageSizeUnknown) |
318 index_cache->clear_size(); | 317 index_cache->clear_size(); |
319 else | 318 else |
320 index_cache->set_size(cache_metadata.size); | 319 index_cache->set_size(cache_metadata.size); |
321 } | 320 } |
322 | 321 |
323 std::string serialized; | 322 std::string serialized; |
324 bool success = protobuf_index.SerializeToString(&serialized); | 323 bool success = protobuf_index.SerializeToString(&serialized); |
325 DCHECK(success); | 324 DCHECK(success); |
326 | 325 |
327 base::FilePath tmp_path = origin_path_.AppendASCII("index.txt.tmp"); | 326 base::FilePath tmp_path = origin_path_.AppendASCII("index.txt.tmp"); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 362 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
364 | 363 |
365 std::unique_ptr<std::set<std::string>> cache_dirs( | 364 std::unique_ptr<std::set<std::string>> cache_dirs( |
366 new std::set<std::string>); | 365 new std::set<std::string>); |
367 | 366 |
368 auto index = base::MakeUnique<CacheStorageIndex>(); | 367 auto index = base::MakeUnique<CacheStorageIndex>(); |
369 for (int i = 0, max = protobuf_index.cache_size(); i < max; ++i) { | 368 for (int i = 0, max = protobuf_index.cache_size(); i < max; ++i) { |
370 const proto::CacheStorageIndex::Cache& cache = protobuf_index.cache(i); | 369 const proto::CacheStorageIndex::Cache& cache = protobuf_index.cache(i); |
371 DCHECK(cache.has_cache_dir()); | 370 DCHECK(cache.has_cache_dir()); |
372 int64_t cache_size = | 371 int64_t cache_size = |
373 cache.has_size() ? cache.size() : CacheStorage::kSizeUnknown; | 372 cache.has_size() ? cache.size() : kCacheStorageSizeUnknown; |
374 index->Insert(CacheStorageIndex::CacheMetadata(cache.name(), cache_size)); | 373 index->Insert(CacheStorageIndex::CacheMetadata(cache.name(), cache_size)); |
375 cache_name_to_cache_dir_[cache.name()] = cache.cache_dir(); | 374 cache_name_to_cache_dir_[cache.name()] = cache.cache_dir(); |
376 cache_dirs->insert(cache.cache_dir()); | 375 cache_dirs->insert(cache.cache_dir()); |
377 } | 376 } |
378 | 377 |
379 cache_task_runner_->PostTask( | 378 cache_task_runner_->PostTask( |
380 FROM_HERE, base::Bind(&DeleteUnreferencedCachesInPool, origin_path_, | 379 FROM_HERE, base::Bind(&DeleteUnreferencedCachesInPool, origin_path_, |
381 base::Passed(&cache_dirs))); | 380 base::Passed(&cache_dirs))); |
382 callback.Run(std::move(index)); | 381 callback.Run(std::move(index)); |
383 } | 382 } |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1065 weak_factory_.GetWeakPtr(), | 1064 weak_factory_.GetWeakPtr(), |
1066 base::Passed(std::move(cache_handle)), | 1065 base::Passed(std::move(cache_handle)), |
1067 barrier_closure, accumulator_ptr)); | 1066 barrier_closure, accumulator_ptr)); |
1068 } | 1067 } |
1069 } | 1068 } |
1070 | 1069 |
1071 void CacheStorage::SizeImpl(const SizeCallback& callback) { | 1070 void CacheStorage::SizeImpl(const SizeCallback& callback) { |
1072 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1071 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1073 DCHECK(initialized_); | 1072 DCHECK(initialized_); |
1074 | 1073 |
1075 if (cache_index_->GetStorageSize() != kSizeUnknown) { | 1074 if (cache_index_->GetStorageSize() != kCacheStorageSizeUnknown) { |
1076 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1075 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1077 FROM_HERE, base::Bind(callback, cache_index_->GetStorageSize())); | 1076 FROM_HERE, base::Bind(callback, cache_index_->GetStorageSize())); |
1078 return; | 1077 return; |
1079 } | 1078 } |
1080 | 1079 |
1081 std::unique_ptr<int64_t> accumulator(new int64_t(0)); | 1080 std::unique_ptr<int64_t> accumulator(new int64_t(0)); |
1082 int64_t* accumulator_ptr = accumulator.get(); | 1081 int64_t* accumulator_ptr = accumulator.get(); |
1083 | 1082 |
1084 base::Closure barrier_closure = base::BarrierClosure( | 1083 base::Closure barrier_closure = base::BarrierClosure( |
1085 cache_index_->num_entries(), | 1084 cache_index_->num_entries(), |
1086 base::Bind(&SizeRetrievedFromAllCaches, | 1085 base::Bind(&SizeRetrievedFromAllCaches, |
1087 base::Passed(std::move(accumulator)), callback)); | 1086 base::Passed(std::move(accumulator)), callback)); |
1088 | 1087 |
1089 for (const auto& cache_metadata : cache_index_->ordered_cache_metadata()) { | 1088 for (const auto& cache_metadata : cache_index_->ordered_cache_metadata()) { |
1090 if (cache_metadata.size != CacheStorage::kSizeUnknown) { | 1089 if (cache_metadata.size != kCacheStorageSizeUnknown) { |
1091 *accumulator_ptr += cache_metadata.size; | 1090 *accumulator_ptr += cache_metadata.size; |
1092 barrier_closure.Run(); | 1091 barrier_closure.Run(); |
1093 continue; | 1092 continue; |
1094 } | 1093 } |
1095 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 1094 std::unique_ptr<CacheStorageCacheHandle> cache_handle = |
1096 GetLoadedCache(cache_metadata.name); | 1095 GetLoadedCache(cache_metadata.name); |
1097 CacheStorageCache* cache = cache_handle->value(); | 1096 CacheStorageCache* cache = cache_handle->value(); |
1098 cache->Size(base::Bind(&CacheStorage::SizeRetrievedFromCache, | 1097 cache->Size(base::Bind(&CacheStorage::SizeRetrievedFromCache, |
1099 weak_factory_.GetWeakPtr(), | 1098 weak_factory_.GetWeakPtr(), |
1100 base::Passed(std::move(cache_handle)), | 1099 base::Passed(std::move(cache_handle)), |
1101 barrier_closure, accumulator_ptr)); | 1100 barrier_closure, accumulator_ptr)); |
1102 } | 1101 } |
1103 } | 1102 } |
1104 | 1103 |
1105 } // namespace content | 1104 } // namespace content |
OLD | NEW |