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

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

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_cache.h
diff --git a/content/browser/cache_storage/cache_storage_cache.h b/content/browser/cache_storage/cache_storage_cache.h
index 46ea4f07fbe08ddf1be537a63624c6601e7b3619..2feda21a7daf3ed6792dbff95e7bdba0329cdad3 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;
}
@@ -42,6 +46,7 @@ class TestCacheStorageCache;
namespace proto {
class CacheMetadata;
+class CacheResponse;
}
// Represents a ServiceWorker Cache as seen in
@@ -65,6 +70,7 @@ class CONTENT_EXPORT CacheStorageCache {
using RequestsCallback =
base::OnceCallback<void(CacheStorageError, std::unique_ptr<Requests>)>;
using SizeCallback = base::OnceCallback<void(int64_t)>;
+ using SizePaddingCallback = base::OnceCallback<void(int64_t, int64_t)>;
enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA };
@@ -74,7 +80,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 +90,14 @@ 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,
+ int side_data_size);
+ static int32_t GetResponsePaddingVersion();
// Returns ERROR_TYPE_NOT_FOUND if not found.
void Match(std::unique_ptr<ServiceWorkerFetchRequest> request,
@@ -165,6 +179,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.
@@ -173,7 +197,13 @@ class CONTENT_EXPORT CacheStorageCache {
base::WeakPtr<CacheStorageCache> AsWeakPtr();
private:
- enum class QueryCacheType { REQUESTS, REQUESTS_AND_RESPONSES, CACHE_ENTRIES };
+ // QueryCache types:
+ enum QueryCacheFlags {
+ QUERY_CACHE_REQUESTS = 0x1,
+ QUERY_CACHE_RESPONSES_WITH_BODIES = 0x2,
+ QUERY_CACHE_RESPONSES_NO_BODIES = 0x4,
+ QUERY_CACHE_ENTRIES = 0x8,
+ };
// The backend progresses from uninitialized, to open, to closed, and cannot
// reverse direction. The open step may be skipped.
@@ -191,6 +221,7 @@ class CONTENT_EXPORT CacheStorageCache {
struct QueryCacheContext;
struct QueryCacheResult;
+ using QueryTypes = int32_t;
using QueryCacheResults = std::vector<QueryCacheResult>;
using QueryCacheCallback =
base::OnceCallback<void(CacheStorageError,
@@ -208,7 +239,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);
// Runs |callback| with matching requests/response data. The data provided
// in the QueryCacheResults depends on the |query_type|. If |query_type| is
@@ -218,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,
+ QueryTypes query_types,
QueryCacheCallback callback);
void QueryCacheDidOpenFastPath(
std::unique_ptr<QueryCacheContext> query_cache_context,
@@ -289,17 +322,21 @@ class CONTENT_EXPORT CacheStorageCache {
int buf_len,
disk_cache::ScopedEntryPtr entry,
std::unique_ptr<proto::CacheMetadata> headers);
- void WriteSideDataDidWrite(ErrorCallback callback,
- disk_cache::ScopedEntryPtr entry,
- int expected_bytes,
- int rv);
+ void WriteSideDataDidWrite(
+ ErrorCallback callback,
+ disk_cache::ScopedEntryPtr entry,
+ int expected_bytes,
+ std::unique_ptr<content::proto::CacheResponse> response,
+ int side_data_size_before_write,
+ int rv);
// Puts the request and response object in the cache. The response body (if
// present) is stored in the cache, but not the request body. Returns OK on
// success.
void Put(const CacheStorageBatchOperation& operation, 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);
void PutDidGetUsageAndQuota(std::unique_ptr<PutContext> put_context,
storage::QuotaStatusCode status_code,
int64_t usage,
@@ -356,12 +393,29 @@ class CONTENT_EXPORT CacheStorageCache {
std::unique_ptr<ScopedBackendPtr> backend_ptr,
int rv);
+ // Calculate the size and padding of the cache.
+ void CalculateCacheSizePadding(SizePaddingCallback callback);
+ void CalculateCacheSizePaddingGotSize(SizePaddingCallback callback,
+ int cache_size);
+ void PaddingDidQueryCache(
+ 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(base::OnceClosure callback,
CacheStorageError cache_create_error);
void InitGotCacheSize(base::OnceClosure callback,
CacheStorageError cache_create_error,
int cache_size);
+ void InitGotCacheSizeAndPadding(base::OnceClosure callback,
+ CacheStorageError cache_create_error,
+ int64_t cache_size,
+ int64_t cache_padding);
void DeleteBackendCompletedIO();
std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody(
@@ -387,7 +441,11 @@ class CONTENT_EXPORT CacheStorageCache {
BackendState backend_state_ = BACKEND_UNINITIALIZED;
std::unique_ptr<CacheStorageScheduler> scheduler_;
bool initializing_ = false;
+ // The actual cache size (not including padding).
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_;
« no previous file with comments | « content/browser/cache_storage/cache_storage.proto ('k') | content/browser/cache_storage/cache_storage_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698