Chromium Code Reviews| Index: content/browser/cache_storage/cache_storage_manager.cc |
| diff --git a/content/browser/cache_storage/cache_storage_manager.cc b/content/browser/cache_storage/cache_storage_manager.cc |
| index a258bdcfc50c469d6eea164da9523aed3f753179..9d0216c6291a005ac81e667979f624b45e450727 100644 |
| --- a/content/browser/cache_storage/cache_storage_manager.cc |
| +++ b/content/browser/cache_storage/cache_storage_manager.cc |
| @@ -8,13 +8,13 @@ |
| #include <map> |
| #include <set> |
| -#include <string> |
| #include <utility> |
| #include "base/barrier_closure.h" |
| #include "base/bind.h" |
| #include "base/files/file_enumerator.h" |
| #include "base/files/file_util.h" |
| +#include "base/files/important_file_writer.h" |
|
jkarlin
2016/10/21 18:04:19
This is unused. I'm not sure we'd want an Importan
cmumford
2016/11/10 17:28:17
Acknowledged.
|
| #include "base/id_map.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/sha1.h" |
| @@ -51,8 +51,21 @@ void DeleteOriginDidDeleteDir( |
| : storage::kQuotaErrorAbort)); |
| } |
| -// Open the various cache directories' index files and extract their origins and |
| -// last modified times. |
| +// Calculate the sum of all cache sizes in this store, but only if all sizes are |
| +// known. If one or more sizes are not known then return kSizeUnknown. |
| +int64_t GetCacheStorageSize(const CacheStorageIndex& index) { |
| + int64_t storage_size = 0; |
| + for (int i = 0, max = index.cache_size(); i < max; ++i) { |
| + const content::CacheStorageIndex::Cache& cache = index.cache(i); |
| + if (!cache.has_size() || cache.size() == CacheStorage::kSizeUnknown) |
| + return CacheStorage::kSizeUnknown; |
| + storage_size += cache.size(); |
| + } |
| + return storage_size; |
| +} |
| + |
| +// Open the various cache directories' index files and extract their origins, |
| +// sizes (if current), and last modified times. |
| void ListOriginsAndLastModifiedOnTaskRunner( |
| std::vector<CacheStorageUsageInfo>* usages, |
| base::FilePath root_path) { |
| @@ -61,16 +74,23 @@ void ListOriginsAndLastModifiedOnTaskRunner( |
| base::FilePath path; |
| while (!(path = file_enum.Next()).empty()) { |
| + base::FilePath index_path = path.AppendASCII(CacheStorage::kIndexFileName); |
| + base::File::Info file_info; |
| + base::Time index_last_modified; |
| + if (GetFileInfo(index_path, &file_info)) |
| + index_last_modified = file_info.last_modified; |
| std::string protobuf; |
| base::ReadFileToString(path.AppendASCII(CacheStorage::kIndexFileName), |
| &protobuf); |
| CacheStorageIndex index; |
| if (index.ParseFromString(protobuf)) { |
| if (index.has_origin()) { |
| - base::File::Info file_info; |
| if (base::GetFileInfo(path, &file_info)) { |
| + int64_t storage_size = CacheStorage::kSizeUnknown; |
| + if (file_info.last_modified < index_last_modified) |
| + storage_size = GetCacheStorageSize(index); |
| usages->push_back(CacheStorageUsageInfo( |
| - GURL(index.origin()), 0 /* size */, file_info.last_modified)); |
| + GURL(index.origin()), storage_size, file_info.last_modified)); |
| } |
| } |
| } |
| @@ -117,6 +137,7 @@ void OneOriginSizeReported(const base::Closure& callback, |
| int64_t size) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + DCHECK_NE(size, CacheStorage::kSizeUnknown); |
| usage->total_size_bytes = size; |
| base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| } |
| @@ -186,7 +207,7 @@ void CacheStorageManager::DeleteCache( |
| void CacheStorageManager::EnumerateCaches( |
| const GURL& origin, |
| - const CacheStorage::StringsCallback& callback) { |
| + const CacheStorage::CacheInfoCallback& callback) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| CacheStorage* cache_storage = FindOrCreateCacheStorage(origin); |
| @@ -276,6 +297,10 @@ void CacheStorageManager::GetAllOriginsUsageGetSizes( |
| callback)); |
| for (CacheStorageUsageInfo& usage : *usages_ptr) { |
| + if (usage.total_size_bytes != CacheStorage::kSizeUnknown) { |
| + base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, barrier_closure); |
| + continue; |
| + } |
| CacheStorage* cache_storage = FindOrCreateCacheStorage(usage.origin); |
| cache_storage->Size( |
| base::Bind(&OneOriginSizeReported, barrier_closure, &usage)); |