Chromium Code Reviews| Index: content/browser/cache_storage/cache_storage_cache.h |
| diff --git a/content/browser/cache_storage/cache_storage_cache.h b/content/browser/cache_storage/cache_storage_cache.h |
| index 1afe338c2ac94353655b9a9712ce3f4721a8c6bf..cdc3047cdb07a9420774b9f6238b6330fef01686 100644 |
| --- a/content/browser/cache_storage/cache_storage_cache.h |
| +++ b/content/browser/cache_storage/cache_storage_cache.h |
| @@ -22,6 +22,10 @@ |
| #include "net/disk_cache/disk_cache.h" |
| #include "storage/common/quota/quota_status_code.h" |
| +namespace crypto { |
| +class SymmetricKey; |
| +} |
| + |
| namespace net { |
| class URLRequestContextGetter; |
| } |
| @@ -74,7 +78,8 @@ class CONTENT_EXPORT CacheStorageCache { |
| CacheStorage* cache_storage, |
| scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| - base::WeakPtr<storage::BlobStorageContext> blob_context); |
| + base::WeakPtr<storage::BlobStorageContext> blob_context, |
| + std::unique_ptr<crypto::SymmetricKey> cache_padding_key); |
| static std::unique_ptr<CacheStorageCache> CreatePersistentCache( |
| const GURL& origin, |
| const std::string& cache_name, |
| @@ -83,7 +88,12 @@ class CONTENT_EXPORT CacheStorageCache { |
| scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| base::WeakPtr<storage::BlobStorageContext> blob_context, |
| - int64_t cache_size); |
| + int64_t cache_size, |
| + int64_t cache_padding, |
| + std::unique_ptr<crypto::SymmetricKey> cache_padding_key); |
| + static int64_t CalculateResponsePadding( |
| + const ServiceWorkerResponse& response, |
| + const crypto::SymmetricKey* padding_key); |
| // Returns ERROR_TYPE_NOT_FOUND if not found. |
| void Match(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| @@ -160,6 +170,16 @@ class CONTENT_EXPORT CacheStorageCache { |
| int64_t cache_size() const { return cache_size_; } |
| + int64_t cache_padding() const { return cache_padding_; } |
| + |
| + const crypto::SymmetricKey* cache_padding_key() const { |
| + return cache_padding_key_.get(); |
| + } |
| + |
| + // Return the total cache size (actual size + padding). If either is unknown |
| + // then CacheStorage::kSizeUnknown is returned. |
| + int64_t PaddedCacheSize() const; |
| + |
| // Set the one observer that will be notified of changes to this cache. |
| // Note: Either the observer must have a lifetime longer than this instance |
| // or call SetObserver(nullptr) to stop receiving notification of changes. |
| @@ -168,7 +188,11 @@ class CONTENT_EXPORT CacheStorageCache { |
| base::WeakPtr<CacheStorageCache> AsWeakPtr(); |
| private: |
| - enum class QueryCacheType { REQUESTS, REQUESTS_AND_RESPONSES, CACHE_ENTRIES }; |
| + // QueryCache types: |
| + const uint32_t QUERY_CACHE_REQUESTS = 0x1; |
|
jkarlin
2017/06/15 16:08:35
I'd prefer an enum (but not an enum class since th
cmumford
2017/06/20 18:22:04
Done.
|
| + const uint32_t QUERY_CACHE_RESPONSES_WITH_BODIES = 0x2; |
| + const uint32_t QUERY_CACHE_RESPONSES_NO_BODIES = 0x4; |
| + const uint32_t QUERY_CACHE_ENTRIES = 0x8; |
| // The backend progresses from uninitialized, to open, to closed, and cannot |
| // reverse direction. The open step may be skipped. |
| @@ -198,6 +222,8 @@ class CONTENT_EXPORT CacheStorageCache { |
| using OpenAllEntriesCallback = |
| base::Callback<void(std::unique_ptr<OpenAllEntriesContext>, |
| CacheStorageError)>; |
| + using SizePaddingCallback = |
| + base::Callback<void(int64_t cache_size, int64_t cache_padding)>; |
| CacheStorageCache( |
| const GURL& origin, |
| @@ -207,7 +233,9 @@ class CONTENT_EXPORT CacheStorageCache { |
| scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| base::WeakPtr<storage::BlobStorageContext> blob_context, |
| - int64_t cache_size); |
| + int64_t cache_size, |
| + int64_t cache_padding, |
| + std::unique_ptr<crypto::SymmetricKey> cache_padding_key); |
| // Returns all entries in this cache. |
| void OpenAllEntries(const OpenAllEntriesCallback& callback); |
| @@ -223,7 +251,7 @@ class CONTENT_EXPORT CacheStorageCache { |
| // out_blob_data_handles are valid. |
| void QueryCache(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| const CacheStorageCacheQueryParams& options, |
| - QueryCacheType query_type, |
| + uint32_t query_types, |
| const QueryCacheCallback& callback); |
| void QueryCacheDidOpenFastPath( |
| std::unique_ptr<QueryCacheContext> query_cache_context, |
| @@ -305,7 +333,9 @@ class CONTENT_EXPORT CacheStorageCache { |
| void Put(const CacheStorageBatchOperation& operation, |
| const ErrorCallback& callback); |
| void PutImpl(std::unique_ptr<PutContext> put_context); |
| - void PutDidDoomEntry(std::unique_ptr<PutContext> put_context, int rv); |
| + void PutDidDeleteEntry(std::unique_ptr<PutContext> put_context, |
| + CacheStorageError error, |
| + std::unique_ptr<QueryCacheResults> query_results); |
| void PutDidGetUsageAndQuota(std::unique_ptr<PutContext> put_context, |
| storage::QuotaStatusCode status_code, |
| int64_t usage, |
| @@ -334,11 +364,14 @@ class CONTENT_EXPORT CacheStorageCache { |
| const ErrorCallback& callback); |
| void DeleteImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| const CacheStorageCacheQueryParams& match_params, |
| - const ErrorCallback& callback); |
| + const QueryCacheCallback& callback); |
| void DeleteDidQueryCache( |
| - const ErrorCallback& callback, |
| + const QueryCacheCallback& callback, |
| CacheStorageError error, |
| std::unique_ptr<QueryCacheResults> query_cache_results); |
| + void DeleteDidDelete(const ErrorCallback& callback, |
| + CacheStorageError error, |
| + std::unique_ptr<QueryCacheResults> query_results); |
| // Keys callbacks. |
| void KeysImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| @@ -363,12 +396,29 @@ class CONTENT_EXPORT CacheStorageCache { |
| std::unique_ptr<ScopedBackendPtr> backend_ptr, |
| int rv); |
| + // Calculate the size and padding of the cache. |
| + void CalculateCacheSizePadding(const SizePaddingCallback& callback); |
| + void CalculateCacheSizePaddingGotSize(const SizePaddingCallback& callback, |
| + int cache_size); |
| + void PaddingDidQueryCache( |
| + const SizePaddingCallback& callback, |
| + int cache_size, |
| + CacheStorageError error, |
| + std::unique_ptr<QueryCacheResults> query_cache_results); |
| + |
| + // Calculate the size (but not padding) of the cache. |
| + void CalculateCacheSize(const net::CompletionCallback& callback); |
| + |
| void InitBackend(); |
| void InitDidCreateBackend(const base::Closure& callback, |
| CacheStorageError cache_create_error); |
| void InitGotCacheSize(const base::Closure& callback, |
| CacheStorageError cache_create_error, |
| int cache_size); |
| + void InitGotCacheSizeAndPadding(const base::Closure& callback, |
| + CacheStorageError cache_create_error, |
| + int64_t cache_size, |
| + int64_t cache_padding); |
| std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody( |
| disk_cache::ScopedEntryPtr entry, |
| @@ -394,6 +444,9 @@ class CONTENT_EXPORT CacheStorageCache { |
| std::unique_ptr<CacheStorageScheduler> scheduler_; |
| bool initializing_ = false; |
| int64_t cache_size_; |
| + int64_t cache_padding_ = 0; |
| + std::unique_ptr<crypto::SymmetricKey> cache_padding_key_; |
| + int64_t last_reported_size_ = 0; |
| size_t max_query_size_bytes_; |
| CacheStorageCacheObserver* cache_observer_; |