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

Unified Diff: content/browser/cache_storage/cache_storage_cache.h

Issue 2901083002: [CacheStorage] Pad and bin opaque resource sizes. (Closed)
Patch Set: Storing padding key in cache. Created 3 years, 6 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_cache.h
diff --git a/content/browser/cache_storage/cache_storage_cache.h b/content/browser/cache_storage/cache_storage_cache.h
index 1afe338c2ac94353655b9a9712ce3f4721a8c6bf..86d3d9aeb4013c91e00a161c27f5e058b6f8464d 100644
--- a/content/browser/cache_storage/cache_storage_cache.h
+++ b/content/browser/cache_storage/cache_storage_cache.h
@@ -83,7 +83,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,
+ const std::string& cache_padding_key);
+ static int64_t CalculateResponsePadding(const ServiceWorkerResponse& response,
+ const std::string& padding_key);
+ static const std::string& SessionPaddingHMACKey();
// Returns ERROR_TYPE_NOT_FOUND if not found.
void Match(std::unique_ptr<ServiceWorkerFetchRequest> request,
@@ -160,6 +165,14 @@ class CONTENT_EXPORT CacheStorageCache {
int64_t cache_size() const { return cache_size_; }
+ int64_t cache_padding() const { return cache_padding_; }
+
+ const std::string& cache_padding_key() const { return cache_padding_key_; }
+
+ // 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 +181,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;
+ 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 +215,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 +226,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,
+ const std::string& cache_padding_key);
// Returns all entries in this cache.
void OpenAllEntries(const OpenAllEntriesCallback& callback);
@@ -223,7 +244,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 +326,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 +357,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 +389,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 +437,9 @@ class CONTENT_EXPORT CacheStorageCache {
std::unique_ptr<CacheStorageScheduler> scheduler_;
bool initializing_ = false;
int64_t cache_size_;
+ int64_t cache_padding_ = 0;
+ const std::string cache_padding_key_;
+ int64_t last_reported_size_ = 0;
size_t max_query_size_bytes_;
CacheStorageCacheObserver* cache_observer_;

Powered by Google App Engine
This is Rietveld 408576698