Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(594)

Unified Diff: content/browser/cache_storage/cache_storage_index.cc

Issue 2901083002: [CacheStorage] Pad and bin opaque resource sizes. (Closed)
Patch Set: s/also also/also/ and EXPECT_GT ↔ EXPECT_LT Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8993958aa917085989c1faf32c2db991b4446148 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,17 +62,53 @@ bool CacheStorageIndex::SetCacheSize(const std::string& cache_name,
return true;
}
-int64_t CacheStorageIndex::GetCacheSize(const std::string& cache_name) const {
+const CacheStorageIndex::CacheMetadata* CacheStorageIndex::GetMetadata(
+ 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::GetCacheSizeForTesting(
+ 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->size;
}
-int64_t CacheStorageIndex::GetStorageSize() {
+bool CacheStorageIndex::SetCachePadding(const std::string& cache_name,
+ int64_t padding) {
+ DCHECK(!has_doomed_cache_ || cache_name == doomed_cache_metadata_.name)
+ << cache_name << " != " << doomed_cache_metadata_.name;
+ 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::GetCachePaddingForTesting(
+ 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)
+ CalculateStoragePadding();
+ if (storage_size_ == CacheStorage::kSizeUnknown ||
+ storage_padding_ == CacheStorage::kSizeUnknown) {
+ return CacheStorage::kSizeUnknown;
+ }
+ return storage_size_ + storage_padding_;
}
void CacheStorageIndex::UpdateStorageSize() {
@@ -79,6 +122,17 @@ void CacheStorageIndex::UpdateStorageSize() {
storage_size_ = storage_size;
}
+void CacheStorageIndex::CalculateStoragePadding() {
+ 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 +141,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 +157,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();
}
« no previous file with comments | « content/browser/cache_storage/cache_storage_index.h ('k') | content/browser/cache_storage/cache_storage_index_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698