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

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

Issue 2901083002: [CacheStorage] Pad and bin opaque resource sizes. (Closed)
Patch Set: Rebased and resolved conflicts. Created 3 years, 7 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..d5fee5972dad4d5ae9d2514f06ca246da4e5caab 100644
--- a/content/browser/cache_storage/cache_storage_cache.h
+++ b/content/browser/cache_storage/cache_storage_cache.h
@@ -84,6 +84,8 @@ class CONTENT_EXPORT CacheStorageCache {
scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy,
base::WeakPtr<storage::BlobStorageContext> blob_context,
int64_t cache_size);
+ static int64_t CalculateResponsePadding(
+ const ServiceWorkerResponse& response);
// Returns ERROR_TYPE_NOT_FOUND if not found.
void Match(std::unique_ptr<ServiceWorkerFetchRequest> request,
@@ -158,7 +160,8 @@ class CONTENT_EXPORT CacheStorageCache {
std::string cache_name() const { return cache_name_; }
- int64_t cache_size() const { return cache_size_; }
+ // Return the total cache size (actual space used + padding).
+ int64_t CacheSize() 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
@@ -168,7 +171,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 +205,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,
@@ -223,7 +232,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 +314,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 +345,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 +377,26 @@ 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);
+ int64_t cache_size,
+ int64_t cache_padding);
std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody(
disk_cache::ScopedEntryPtr entry,
@@ -394,6 +422,8 @@ class CONTENT_EXPORT CacheStorageCache {
std::unique_ptr<CacheStorageScheduler> scheduler_;
bool initializing_ = false;
int64_t cache_size_;
+ int64_t cache_padding_ = 0;
+ int64_t last_reported_size_ = 0;
size_t max_query_size_bytes_;
CacheStorageCacheObserver* cache_observer_;

Powered by Google App Engine
This is Rietveld 408576698