| Index: content/browser/cache_storage/cache_storage_index.h
|
| diff --git a/content/browser/cache_storage/cache_storage_index.h b/content/browser/cache_storage/cache_storage_index.h
|
| index 4d4f64d3bf4868f011d0c50713cb70f7873e63ed..ed5bff33fc6bf46fa7f58158d0c6194698474357 100644
|
| --- a/content/browser/cache_storage/cache_storage_index.h
|
| +++ b/content/browser/cache_storage/cache_storage_index.h
|
| @@ -9,6 +9,7 @@
|
| #include <string>
|
| #include <unordered_map>
|
|
|
| +#include "base/gtest_prod_util.h"
|
| #include "base/macros.h"
|
| #include "content/browser/cache_storage/cache_storage.h"
|
|
|
| @@ -20,12 +21,25 @@ namespace content {
|
| class CONTENT_EXPORT CacheStorageIndex {
|
| public:
|
| struct CacheMetadata {
|
| - CacheMetadata(const std::string& name, int64_t size)
|
| - : name(name), size(size) {}
|
| + CacheMetadata(const std::string& name,
|
| + int64_t size,
|
| + int64_t padding,
|
| + const std::string& padding_key)
|
| + : name(name), size(size), padding(padding), padding_key(padding_key) {}
|
| std::string name;
|
| // The size (in bytes) of the cache. Set to CacheStorage::kSizeUnknown if
|
| // size not known.
|
| int64_t size;
|
| +
|
| + // The padding (in bytes) of the cache. Set to CacheStorage::kSizeUnknown
|
| + // if padding not known.
|
| + int64_t padding;
|
| +
|
| + // The raw key used to calculate padding for some cache entries.
|
| + std::string padding_key;
|
| +
|
| + // The algorithm version used to calculate this padding.
|
| + int32_t padding_version;
|
| };
|
|
|
| CacheStorageIndex();
|
| @@ -36,13 +50,17 @@ class CONTENT_EXPORT CacheStorageIndex {
|
| void Insert(const CacheMetadata& cache_metadata);
|
| void Delete(const std::string& cache_name);
|
|
|
| - // Sets the cache size. Returns true if the new size is different than the
|
| - // current size else false.
|
| + // Sets the actual (unpadded) cache size. Returns true if the new size is
|
| + // different than the current size else false.
|
| bool SetCacheSize(const std::string& cache_name, int64_t size);
|
|
|
| - // Return the size (in bytes) of the specified cache. Will return
|
| - // CacheStorage::kSizeUnknown if the specified cache does not exist.
|
| - int64_t GetCacheSize(const std::string& cache_name) const;
|
| + // Get the cache metadata for a given cache name. If not found nullptr is
|
| + // returned.
|
| + const CacheMetadata* GetMetadata(const std::string& cache_name) const;
|
| +
|
| + // Sets the cache padding. Returns true if the new padding is different than
|
| + // the current padding else false.
|
| + bool SetCachePadding(const std::string& cache_name, int64_t padding);
|
|
|
| const std::list<CacheMetadata>& ordered_cache_metadata() const {
|
| return ordered_cache_metadata_;
|
| @@ -51,7 +69,7 @@ class CONTENT_EXPORT CacheStorageIndex {
|
| size_t num_entries() const { return ordered_cache_metadata_.size(); }
|
|
|
| // Will calculate (if necessary), and return the total sum of all cache sizes.
|
| - int64_t GetStorageSize();
|
| + int64_t GetPaddedStorageSize();
|
|
|
| // Mark the cache as doomed. This removes the cache metadata from the index.
|
| // All const methods (eg: num_entries) will behave as if the doomed cache is
|
| @@ -66,18 +84,33 @@ class CONTENT_EXPORT CacheStorageIndex {
|
| void RestoreDoomedCache();
|
|
|
| private:
|
| + FRIEND_TEST_ALL_PREFIXES(CacheStorageIndexTest, TestSetCacheSize);
|
| + FRIEND_TEST_ALL_PREFIXES(CacheStorageIndexTest, TestSetCachePadding);
|
| +
|
| void UpdateStorageSize();
|
| + void CalculateStoragePadding();
|
| void ClearDoomedCache();
|
|
|
| + // Return the size (in bytes) of the specified cache. Will return
|
| + // CacheStorage::kSizeUnknown if the specified cache does not exist.
|
| + int64_t GetCacheSizeForTesting(const std::string& cache_name) const;
|
| +
|
| + // Return the padding (in bytes) of the specified cache. Will return
|
| + // CacheStorage::kSizeUnknown if the specified cache does not exist.
|
| + int64_t GetCachePaddingForTesting(const std::string& cache_name) const;
|
| +
|
| // Use a list to keep saved iterators valid during insert/erase.
|
| // Note: ordered by cache creation.
|
| std::list<CacheMetadata> ordered_cache_metadata_;
|
| std::unordered_map<std::string, std::list<CacheMetadata>::iterator>
|
| cache_metadata_map_;
|
|
|
| - // The total size of all caches in this store.
|
| + // The total unpadded size of all caches in this store.
|
| int64_t storage_size_ = CacheStorage::kSizeUnknown;
|
|
|
| + // The total padding of all caches in this store.
|
| + int64_t storage_padding_ = CacheStorage::kSizeUnknown;
|
| +
|
| // The doomed cache metadata saved when calling DoomCache.
|
| CacheMetadata doomed_cache_metadata_;
|
| std::list<CacheMetadata>::iterator after_doomed_cache_metadata_;
|
|
|