Chromium Code Reviews| Index: content/browser/cache_storage/cache_storage_index.cc |
| diff --git a/content/browser/cache_storage/cache_storage_index.cc b/content/browser/cache_storage/cache_storage_index.cc |
| index a5ddcb33692b53b986a8859949b64c4e3ce19730..ff4aead59ce6854fb08ba6d39befdc9eafa7110e 100644 |
| --- a/content/browser/cache_storage/cache_storage_index.cc |
| +++ b/content/browser/cache_storage/cache_storage_index.cc |
| @@ -9,7 +9,10 @@ |
| namespace content { |
| CacheStorageIndex::CacheStorageIndex() |
| - : doomed_cache_metadata_("", CacheStorage::kSizeUnknown) { |
| + : doomed_cache_metadata_("", |
| + CacheStorage::kSizeUnknown, |
| + CacheStorage::kSizeUnknown, |
| + "") { |
| ClearDoomedCache(); |
| } |
| @@ -20,7 +23,9 @@ CacheStorageIndex& CacheStorageIndex::operator=(CacheStorageIndex&& rhs) { |
| ordered_cache_metadata_ = std::move(rhs.ordered_cache_metadata_); |
| cache_metadata_map_ = std::move(rhs.cache_metadata_map_); |
| storage_size_ = rhs.storage_size_; |
| + storage_padding_ = rhs.storage_padding_; |
| rhs.storage_size_ = CacheStorage::kSizeUnknown; |
| + rhs.storage_padding_ = CacheStorage::kSizeUnknown; |
| return *this; |
| } |
| @@ -31,6 +36,7 @@ void CacheStorageIndex::Insert(const CacheMetadata& cache_metadata) { |
| ordered_cache_metadata_.push_back(cache_metadata); |
| cache_metadata_map_[cache_metadata.name] = --ordered_cache_metadata_.end(); |
| storage_size_ = CacheStorage::kSizeUnknown; |
| + storage_padding_ = CacheStorage::kSizeUnknown; |
| } |
| void CacheStorageIndex::Delete(const std::string& cache_name) { |
| @@ -40,6 +46,7 @@ void CacheStorageIndex::Delete(const std::string& cache_name) { |
| ordered_cache_metadata_.erase(it->second); |
| cache_metadata_map_.erase(it); |
| storage_size_ = CacheStorage::kSizeUnknown; |
| + storage_padding_ = CacheStorage::kSizeUnknown; |
| } |
| bool CacheStorageIndex::SetCacheSize(const std::string& cache_name, |
| @@ -55,6 +62,14 @@ bool CacheStorageIndex::SetCacheSize(const std::string& cache_name, |
| return true; |
| } |
| +const CacheStorageIndex::CacheMetadata* CacheStorageIndex::FindMetadata( |
| + const std::string& cache_name) const { |
| + const auto& it = cache_metadata_map_.find(cache_name); |
| + if (it == cache_metadata_map_.end()) |
| + return nullptr; |
| + return &*it->second; |
| +} |
| + |
| int64_t CacheStorageIndex::GetCacheSize(const std::string& cache_name) const { |
| const auto& it = cache_metadata_map_.find(cache_name); |
| if (it == cache_metadata_map_.end()) |
| @@ -62,10 +77,37 @@ int64_t CacheStorageIndex::GetCacheSize(const std::string& cache_name) const { |
| return it->second->size; |
| } |
| -int64_t CacheStorageIndex::GetStorageSize() { |
| +bool CacheStorageIndex::SetCachePadding(const std::string& cache_name, |
| + int64_t padding) { |
| + if (has_doomed_cache_) |
| + DCHECK_NE(cache_name, doomed_cache_metadata_.name); |
|
jkarlin
2017/06/08 18:58:48
DCHECK(!has_doomed_cache || cache_name == doomed_c
cmumford
2017/06/12 18:09:31
Done.
|
| + auto it = cache_metadata_map_.find(cache_name); |
| + DCHECK(it != cache_metadata_map_.end()); |
| + if (it->second->padding == padding) |
| + return false; |
| + it->second->padding = padding; |
| + storage_padding_ = CacheStorage::kSizeUnknown; |
| + return true; |
| +} |
| + |
| +int64_t CacheStorageIndex::GetCachePadding( |
| + const std::string& cache_name) const { |
| + const auto& it = cache_metadata_map_.find(cache_name); |
| + if (it == cache_metadata_map_.end()) |
| + return CacheStorage::kSizeUnknown; |
| + return it->second->padding; |
| +} |
| + |
| +int64_t CacheStorageIndex::GetPaddedStorageSize() { |
| if (storage_size_ == CacheStorage::kSizeUnknown) |
| UpdateStorageSize(); |
| - return storage_size_; |
| + if (storage_padding_ == CacheStorage::kSizeUnknown) |
| + UpdateStoragePadding(); |
| + if (storage_size_ == CacheStorage::kSizeUnknown || |
| + storage_padding_ == CacheStorage::kSizeUnknown) { |
| + return CacheStorage::kSizeUnknown; |
| + } |
| + return storage_size_ + storage_padding_; |
| } |
| void CacheStorageIndex::UpdateStorageSize() { |
| @@ -79,6 +121,17 @@ void CacheStorageIndex::UpdateStorageSize() { |
| storage_size_ = storage_size; |
| } |
| +void CacheStorageIndex::UpdateStoragePadding() { |
| + int64_t storage_padding = 0; |
| + storage_padding_ = CacheStorage::kSizeUnknown; |
| + for (const CacheMetadata& info : ordered_cache_metadata_) { |
| + if (info.padding == CacheStorage::kSizeUnknown) |
| + return; |
| + storage_padding += info.padding; |
| + } |
| + storage_padding_ = storage_padding; |
| +} |
| + |
| void CacheStorageIndex::DoomCache(const std::string& cache_name) { |
| DCHECK(!has_doomed_cache_); |
| auto map_it = cache_metadata_map_.find(cache_name); |
| @@ -87,6 +140,7 @@ void CacheStorageIndex::DoomCache(const std::string& cache_name) { |
| after_doomed_cache_metadata_ = ordered_cache_metadata_.erase(map_it->second); |
| cache_metadata_map_.erase(map_it); |
| storage_size_ = CacheStorage::kSizeUnknown; |
| + storage_padding_ = CacheStorage::kSizeUnknown; |
| has_doomed_cache_ = true; |
| } |
| @@ -102,6 +156,7 @@ void CacheStorageIndex::RestoreDoomedCache() { |
| after_doomed_cache_metadata_, std::move(doomed_cache_metadata_)); |
| after_doomed_cache_metadata_ = ordered_cache_metadata_.end(); |
| storage_size_ = CacheStorage::kSizeUnknown; |
| + storage_padding_ = CacheStorage::kSizeUnknown; |
| ClearDoomedCache(); |
| } |