| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ | 5 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ |
| 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ | 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/id_map.h" | 16 #include "base/id_map.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "content/common/cache_storage/cache_storage_types.h" | 19 #include "content/common/cache_storage/cache_storage_types.h" |
| 20 #include "content/common/service_worker/service_worker_types.h" | 20 #include "content/common/service_worker/service_worker_types.h" |
| 21 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
| 22 #include "net/disk_cache/disk_cache.h" | 22 #include "net/disk_cache/disk_cache.h" |
| 23 #include "storage/common/quota/quota_status_code.h" | 23 #include "storage/common/quota/quota_status_code.h" |
| 24 | 24 |
| 25 namespace crypto { |
| 26 class SymmetricKey; |
| 27 } |
| 28 |
| 25 namespace net { | 29 namespace net { |
| 26 class URLRequestContextGetter; | 30 class URLRequestContextGetter; |
| 27 } | 31 } |
| 28 | 32 |
| 29 namespace storage { | 33 namespace storage { |
| 30 class BlobDataHandle; | 34 class BlobDataHandle; |
| 31 class BlobStorageContext; | 35 class BlobStorageContext; |
| 32 class QuotaManagerProxy; | 36 class QuotaManagerProxy; |
| 33 } | 37 } |
| 34 | 38 |
| 35 namespace content { | 39 namespace content { |
| 36 class CacheStorage; | 40 class CacheStorage; |
| 37 class CacheStorageBlobToDiskCache; | 41 class CacheStorageBlobToDiskCache; |
| 38 class CacheStorageCacheHandle; | 42 class CacheStorageCacheHandle; |
| 39 class CacheStorageCacheObserver; | 43 class CacheStorageCacheObserver; |
| 40 class CacheStorageScheduler; | 44 class CacheStorageScheduler; |
| 41 class TestCacheStorageCache; | 45 class TestCacheStorageCache; |
| 42 | 46 |
| 43 namespace proto { | 47 namespace proto { |
| 44 class CacheMetadata; | 48 class CacheMetadata; |
| 49 class CacheResponse; |
| 45 } | 50 } |
| 46 | 51 |
| 47 // Represents a ServiceWorker Cache as seen in | 52 // Represents a ServiceWorker Cache as seen in |
| 48 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/ The | 53 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/ The |
| 49 // asynchronous methods are executed serially. Callbacks to the public functions | 54 // asynchronous methods are executed serially. Callbacks to the public functions |
| 50 // will be called so long as the cache object lives. | 55 // will be called so long as the cache object lives. |
| 51 class CONTENT_EXPORT CacheStorageCache { | 56 class CONTENT_EXPORT CacheStorageCache { |
| 52 public: | 57 public: |
| 53 using ErrorCallback = base::OnceCallback<void(CacheStorageError)>; | 58 using ErrorCallback = base::OnceCallback<void(CacheStorageError)>; |
| 54 using ResponseCallback = | 59 using ResponseCallback = |
| 55 base::OnceCallback<void(CacheStorageError, | 60 base::OnceCallback<void(CacheStorageError, |
| 56 std::unique_ptr<ServiceWorkerResponse>, | 61 std::unique_ptr<ServiceWorkerResponse>, |
| 57 std::unique_ptr<storage::BlobDataHandle>)>; | 62 std::unique_ptr<storage::BlobDataHandle>)>; |
| 58 using Responses = std::vector<ServiceWorkerResponse>; | 63 using Responses = std::vector<ServiceWorkerResponse>; |
| 59 using BlobDataHandles = std::vector<std::unique_ptr<storage::BlobDataHandle>>; | 64 using BlobDataHandles = std::vector<std::unique_ptr<storage::BlobDataHandle>>; |
| 60 using ResponsesCallback = | 65 using ResponsesCallback = |
| 61 base::OnceCallback<void(CacheStorageError, | 66 base::OnceCallback<void(CacheStorageError, |
| 62 std::unique_ptr<Responses>, | 67 std::unique_ptr<Responses>, |
| 63 std::unique_ptr<BlobDataHandles>)>; | 68 std::unique_ptr<BlobDataHandles>)>; |
| 64 using Requests = std::vector<ServiceWorkerFetchRequest>; | 69 using Requests = std::vector<ServiceWorkerFetchRequest>; |
| 65 using RequestsCallback = | 70 using RequestsCallback = |
| 66 base::OnceCallback<void(CacheStorageError, std::unique_ptr<Requests>)>; | 71 base::OnceCallback<void(CacheStorageError, std::unique_ptr<Requests>)>; |
| 67 using SizeCallback = base::OnceCallback<void(int64_t)>; | 72 using SizeCallback = base::OnceCallback<void(int64_t)>; |
| 73 using SizePaddingCallback = base::OnceCallback<void(int64_t, int64_t)>; |
| 68 | 74 |
| 69 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA }; | 75 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA }; |
| 70 | 76 |
| 71 static std::unique_ptr<CacheStorageCache> CreateMemoryCache( | 77 static std::unique_ptr<CacheStorageCache> CreateMemoryCache( |
| 72 const GURL& origin, | 78 const GURL& origin, |
| 73 const std::string& cache_name, | 79 const std::string& cache_name, |
| 74 CacheStorage* cache_storage, | 80 CacheStorage* cache_storage, |
| 75 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 81 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 76 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 82 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| 77 base::WeakPtr<storage::BlobStorageContext> blob_context); | 83 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 84 std::unique_ptr<crypto::SymmetricKey> cache_padding_key); |
| 78 static std::unique_ptr<CacheStorageCache> CreatePersistentCache( | 85 static std::unique_ptr<CacheStorageCache> CreatePersistentCache( |
| 79 const GURL& origin, | 86 const GURL& origin, |
| 80 const std::string& cache_name, | 87 const std::string& cache_name, |
| 81 CacheStorage* cache_storage, | 88 CacheStorage* cache_storage, |
| 82 const base::FilePath& path, | 89 const base::FilePath& path, |
| 83 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 90 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 84 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 91 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| 85 base::WeakPtr<storage::BlobStorageContext> blob_context, | 92 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 86 int64_t cache_size); | 93 int64_t cache_size, |
| 94 int64_t cache_padding, |
| 95 std::unique_ptr<crypto::SymmetricKey> cache_padding_key); |
| 96 static int64_t CalculateResponsePadding( |
| 97 const ServiceWorkerResponse& response, |
| 98 const crypto::SymmetricKey* padding_key, |
| 99 int side_data_size); |
| 100 static int32_t GetResponsePaddingVersion(); |
| 87 | 101 |
| 88 // Returns ERROR_TYPE_NOT_FOUND if not found. | 102 // Returns ERROR_TYPE_NOT_FOUND if not found. |
| 89 void Match(std::unique_ptr<ServiceWorkerFetchRequest> request, | 103 void Match(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 90 const CacheStorageCacheQueryParams& match_params, | 104 const CacheStorageCacheQueryParams& match_params, |
| 91 ResponseCallback callback); | 105 ResponseCallback callback); |
| 92 | 106 |
| 93 // Returns CACHE_STORAGE_OK and matched responses in this cache. If there are | 107 // Returns CACHE_STORAGE_OK and matched responses in this cache. If there are |
| 94 // no responses, returns CACHE_STORAGE_OK and an empty vector. | 108 // no responses, returns CACHE_STORAGE_OK and an empty vector. |
| 95 void MatchAll(std::unique_ptr<ServiceWorkerFetchRequest> request, | 109 void MatchAll(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 96 const CacheStorageCacheQueryParams& match_params, | 110 const CacheStorageCacheQueryParams& match_params, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 172 |
| 159 // Async operations in progress will cancel and not run their callbacks. | 173 // Async operations in progress will cancel and not run their callbacks. |
| 160 virtual ~CacheStorageCache(); | 174 virtual ~CacheStorageCache(); |
| 161 | 175 |
| 162 base::FilePath path() const { return path_; } | 176 base::FilePath path() const { return path_; } |
| 163 | 177 |
| 164 std::string cache_name() const { return cache_name_; } | 178 std::string cache_name() const { return cache_name_; } |
| 165 | 179 |
| 166 int64_t cache_size() const { return cache_size_; } | 180 int64_t cache_size() const { return cache_size_; } |
| 167 | 181 |
| 182 int64_t cache_padding() const { return cache_padding_; } |
| 183 |
| 184 const crypto::SymmetricKey* cache_padding_key() const { |
| 185 return cache_padding_key_.get(); |
| 186 } |
| 187 |
| 188 // Return the total cache size (actual size + padding). If either is unknown |
| 189 // then CacheStorage::kSizeUnknown is returned. |
| 190 int64_t PaddedCacheSize() const; |
| 191 |
| 168 // Set the one observer that will be notified of changes to this cache. | 192 // Set the one observer that will be notified of changes to this cache. |
| 169 // Note: Either the observer must have a lifetime longer than this instance | 193 // Note: Either the observer must have a lifetime longer than this instance |
| 170 // or call SetObserver(nullptr) to stop receiving notification of changes. | 194 // or call SetObserver(nullptr) to stop receiving notification of changes. |
| 171 void SetObserver(CacheStorageCacheObserver* observer); | 195 void SetObserver(CacheStorageCacheObserver* observer); |
| 172 | 196 |
| 173 base::WeakPtr<CacheStorageCache> AsWeakPtr(); | 197 base::WeakPtr<CacheStorageCache> AsWeakPtr(); |
| 174 | 198 |
| 175 private: | 199 private: |
| 176 enum class QueryCacheType { REQUESTS, REQUESTS_AND_RESPONSES, CACHE_ENTRIES }; | 200 // QueryCache types: |
| 201 enum QueryCacheFlags { |
| 202 QUERY_CACHE_REQUESTS = 0x1, |
| 203 QUERY_CACHE_RESPONSES_WITH_BODIES = 0x2, |
| 204 QUERY_CACHE_RESPONSES_NO_BODIES = 0x4, |
| 205 QUERY_CACHE_ENTRIES = 0x8, |
| 206 }; |
| 177 | 207 |
| 178 // The backend progresses from uninitialized, to open, to closed, and cannot | 208 // The backend progresses from uninitialized, to open, to closed, and cannot |
| 179 // reverse direction. The open step may be skipped. | 209 // reverse direction. The open step may be skipped. |
| 180 enum BackendState { | 210 enum BackendState { |
| 181 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. | 211 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. |
| 182 BACKEND_OPEN, // Backend can be used. | 212 BACKEND_OPEN, // Backend can be used. |
| 183 BACKEND_CLOSED // Backend cannot be used. All ops should fail. | 213 BACKEND_CLOSED // Backend cannot be used. All ops should fail. |
| 184 }; | 214 }; |
| 185 | 215 |
| 186 friend class base::RefCounted<CacheStorageCache>; | 216 friend class base::RefCounted<CacheStorageCache>; |
| 187 friend class TestCacheStorageCache; | 217 friend class TestCacheStorageCache; |
| 188 friend class CacheStorageCacheTest; | 218 friend class CacheStorageCacheTest; |
| 189 | 219 |
| 190 struct PutContext; | 220 struct PutContext; |
| 191 struct QueryCacheContext; | 221 struct QueryCacheContext; |
| 192 struct QueryCacheResult; | 222 struct QueryCacheResult; |
| 193 | 223 |
| 224 using QueryTypes = int32_t; |
| 194 using QueryCacheResults = std::vector<QueryCacheResult>; | 225 using QueryCacheResults = std::vector<QueryCacheResult>; |
| 195 using QueryCacheCallback = | 226 using QueryCacheCallback = |
| 196 base::OnceCallback<void(CacheStorageError, | 227 base::OnceCallback<void(CacheStorageError, |
| 197 std::unique_ptr<QueryCacheResults>)>; | 228 std::unique_ptr<QueryCacheResults>)>; |
| 198 using Entries = std::vector<disk_cache::Entry*>; | 229 using Entries = std::vector<disk_cache::Entry*>; |
| 199 using ScopedBackendPtr = std::unique_ptr<disk_cache::Backend>; | 230 using ScopedBackendPtr = std::unique_ptr<disk_cache::Backend>; |
| 200 using BlobToDiskCacheIDMap = | 231 using BlobToDiskCacheIDMap = |
| 201 IDMap<std::unique_ptr<CacheStorageBlobToDiskCache>>; | 232 IDMap<std::unique_ptr<CacheStorageBlobToDiskCache>>; |
| 202 | 233 |
| 203 CacheStorageCache( | 234 CacheStorageCache( |
| 204 const GURL& origin, | 235 const GURL& origin, |
| 205 const std::string& cache_name, | 236 const std::string& cache_name, |
| 206 const base::FilePath& path, | 237 const base::FilePath& path, |
| 207 CacheStorage* cache_storage, | 238 CacheStorage* cache_storage, |
| 208 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 239 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 209 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 240 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| 210 base::WeakPtr<storage::BlobStorageContext> blob_context, | 241 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 211 int64_t cache_size); | 242 int64_t cache_size, |
| 243 int64_t cache_padding, |
| 244 std::unique_ptr<crypto::SymmetricKey> cache_padding_key); |
| 212 | 245 |
| 213 // Runs |callback| with matching requests/response data. The data provided | 246 // Runs |callback| with matching requests/response data. The data provided |
| 214 // in the QueryCacheResults depends on the |query_type|. If |query_type| is | 247 // in the QueryCacheResults depends on the |query_type|. If |query_type| is |
| 215 // CACHE_ENTRIES then only out_entries is valid. If |query_type| is REQUESTS | 248 // CACHE_ENTRIES then only out_entries is valid. If |query_type| is REQUESTS |
| 216 // then only out_requests is valid. If |query_type| is | 249 // then only out_requests is valid. If |query_type| is |
| 217 // REQUESTS_AND_RESPONSES then only out_requests, out_responses, and | 250 // REQUESTS_AND_RESPONSES then only out_requests, out_responses, and |
| 218 // out_blob_data_handles are valid. | 251 // out_blob_data_handles are valid. |
| 219 void QueryCache(std::unique_ptr<ServiceWorkerFetchRequest> request, | 252 void QueryCache(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 220 const CacheStorageCacheQueryParams& options, | 253 const CacheStorageCacheQueryParams& options, |
| 221 QueryCacheType query_type, | 254 QueryTypes query_types, |
| 222 QueryCacheCallback callback); | 255 QueryCacheCallback callback); |
| 223 void QueryCacheDidOpenFastPath( | 256 void QueryCacheDidOpenFastPath( |
| 224 std::unique_ptr<QueryCacheContext> query_cache_context, | 257 std::unique_ptr<QueryCacheContext> query_cache_context, |
| 225 int rv); | 258 int rv); |
| 226 void QueryCacheOpenNextEntry( | 259 void QueryCacheOpenNextEntry( |
| 227 std::unique_ptr<QueryCacheContext> query_cache_context); | 260 std::unique_ptr<QueryCacheContext> query_cache_context); |
| 228 void QueryCacheFilterEntry( | 261 void QueryCacheFilterEntry( |
| 229 std::unique_ptr<QueryCacheContext> query_cache_context, | 262 std::unique_ptr<QueryCacheContext> query_cache_context, |
| 230 int rv); | 263 int rv); |
| 231 void QueryCacheDidReadMetadata( | 264 void QueryCacheDidReadMetadata( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 int buf_len, | 315 int buf_len, |
| 283 std::unique_ptr<disk_cache::Entry*> entry_ptr, | 316 std::unique_ptr<disk_cache::Entry*> entry_ptr, |
| 284 int rv); | 317 int rv); |
| 285 void WriteSideDataDidReadMetaData( | 318 void WriteSideDataDidReadMetaData( |
| 286 ErrorCallback callback, | 319 ErrorCallback callback, |
| 287 base::Time expected_response_time, | 320 base::Time expected_response_time, |
| 288 scoped_refptr<net::IOBuffer> buffer, | 321 scoped_refptr<net::IOBuffer> buffer, |
| 289 int buf_len, | 322 int buf_len, |
| 290 disk_cache::ScopedEntryPtr entry, | 323 disk_cache::ScopedEntryPtr entry, |
| 291 std::unique_ptr<proto::CacheMetadata> headers); | 324 std::unique_ptr<proto::CacheMetadata> headers); |
| 292 void WriteSideDataDidWrite(ErrorCallback callback, | 325 void WriteSideDataDidWrite( |
| 293 disk_cache::ScopedEntryPtr entry, | 326 ErrorCallback callback, |
| 294 int expected_bytes, | 327 disk_cache::ScopedEntryPtr entry, |
| 295 int rv); | 328 int expected_bytes, |
| 329 std::unique_ptr<content::proto::CacheResponse> response, |
| 330 int side_data_size_before_write, |
| 331 int rv); |
| 296 | 332 |
| 297 // Puts the request and response object in the cache. The response body (if | 333 // Puts the request and response object in the cache. The response body (if |
| 298 // present) is stored in the cache, but not the request body. Returns OK on | 334 // present) is stored in the cache, but not the request body. Returns OK on |
| 299 // success. | 335 // success. |
| 300 void Put(const CacheStorageBatchOperation& operation, ErrorCallback callback); | 336 void Put(const CacheStorageBatchOperation& operation, ErrorCallback callback); |
| 301 void PutImpl(std::unique_ptr<PutContext> put_context); | 337 void PutImpl(std::unique_ptr<PutContext> put_context); |
| 302 void PutDidDoomEntry(std::unique_ptr<PutContext> put_context, int rv); | 338 void PutDidDeleteEntry(std::unique_ptr<PutContext> put_context, |
| 339 CacheStorageError error); |
| 303 void PutDidGetUsageAndQuota(std::unique_ptr<PutContext> put_context, | 340 void PutDidGetUsageAndQuota(std::unique_ptr<PutContext> put_context, |
| 304 storage::QuotaStatusCode status_code, | 341 storage::QuotaStatusCode status_code, |
| 305 int64_t usage, | 342 int64_t usage, |
| 306 int64_t quota); | 343 int64_t quota); |
| 307 void PutDidCreateEntry(std::unique_ptr<disk_cache::Entry*> entry_ptr, | 344 void PutDidCreateEntry(std::unique_ptr<disk_cache::Entry*> entry_ptr, |
| 308 std::unique_ptr<PutContext> put_context, | 345 std::unique_ptr<PutContext> put_context, |
| 309 int rv); | 346 int rv); |
| 310 void PutDidWriteHeaders(std::unique_ptr<PutContext> put_context, | 347 void PutDidWriteHeaders(std::unique_ptr<PutContext> put_context, |
| 311 int expected_bytes, | 348 int expected_bytes, |
| 312 int rv); | 349 int rv); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 | 386 |
| 350 void GetSizeThenCloseDidGetSize(SizeCallback callback, int64_t cache_size); | 387 void GetSizeThenCloseDidGetSize(SizeCallback callback, int64_t cache_size); |
| 351 | 388 |
| 352 // Loads the backend and calls the callback with the result (true for | 389 // Loads the backend and calls the callback with the result (true for |
| 353 // success). The callback will always be called. Virtual for tests. | 390 // success). The callback will always be called. Virtual for tests. |
| 354 virtual void CreateBackend(ErrorCallback callback); | 391 virtual void CreateBackend(ErrorCallback callback); |
| 355 void CreateBackendDidCreate(ErrorCallback callback, | 392 void CreateBackendDidCreate(ErrorCallback callback, |
| 356 std::unique_ptr<ScopedBackendPtr> backend_ptr, | 393 std::unique_ptr<ScopedBackendPtr> backend_ptr, |
| 357 int rv); | 394 int rv); |
| 358 | 395 |
| 396 // Calculate the size and padding of the cache. |
| 397 void CalculateCacheSizePadding(SizePaddingCallback callback); |
| 398 void CalculateCacheSizePaddingGotSize(SizePaddingCallback callback, |
| 399 int cache_size); |
| 400 void PaddingDidQueryCache( |
| 401 SizePaddingCallback callback, |
| 402 int cache_size, |
| 403 CacheStorageError error, |
| 404 std::unique_ptr<QueryCacheResults> query_cache_results); |
| 405 |
| 406 // Calculate the size (but not padding) of the cache. |
| 407 void CalculateCacheSize(const net::CompletionCallback& callback); |
| 408 |
| 359 void InitBackend(); | 409 void InitBackend(); |
| 360 void InitDidCreateBackend(base::OnceClosure callback, | 410 void InitDidCreateBackend(base::OnceClosure callback, |
| 361 CacheStorageError cache_create_error); | 411 CacheStorageError cache_create_error); |
| 362 void InitGotCacheSize(base::OnceClosure callback, | 412 void InitGotCacheSize(base::OnceClosure callback, |
| 363 CacheStorageError cache_create_error, | 413 CacheStorageError cache_create_error, |
| 364 int cache_size); | 414 int cache_size); |
| 415 void InitGotCacheSizeAndPadding(base::OnceClosure callback, |
| 416 CacheStorageError cache_create_error, |
| 417 int64_t cache_size, |
| 418 int64_t cache_padding); |
| 365 void DeleteBackendCompletedIO(); | 419 void DeleteBackendCompletedIO(); |
| 366 | 420 |
| 367 std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody( | 421 std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody( |
| 368 disk_cache::ScopedEntryPtr entry, | 422 disk_cache::ScopedEntryPtr entry, |
| 369 ServiceWorkerResponse* response); | 423 ServiceWorkerResponse* response); |
| 370 | 424 |
| 371 // Virtual for testing. | 425 // Virtual for testing. |
| 372 virtual std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle(); | 426 virtual std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle(); |
| 373 | 427 |
| 374 // Be sure to check |backend_state_| before use. | 428 // Be sure to check |backend_state_| before use. |
| 375 std::unique_ptr<disk_cache::Backend> backend_; | 429 std::unique_ptr<disk_cache::Backend> backend_; |
| 376 | 430 |
| 377 GURL origin_; | 431 GURL origin_; |
| 378 const std::string cache_name_; | 432 const std::string cache_name_; |
| 379 base::FilePath path_; | 433 base::FilePath path_; |
| 380 | 434 |
| 381 // Raw pointer is safe because CacheStorage owns this object. | 435 // Raw pointer is safe because CacheStorage owns this object. |
| 382 CacheStorage* cache_storage_; | 436 CacheStorage* cache_storage_; |
| 383 | 437 |
| 384 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 438 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 385 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; | 439 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
| 386 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 440 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
| 387 BackendState backend_state_ = BACKEND_UNINITIALIZED; | 441 BackendState backend_state_ = BACKEND_UNINITIALIZED; |
| 388 std::unique_ptr<CacheStorageScheduler> scheduler_; | 442 std::unique_ptr<CacheStorageScheduler> scheduler_; |
| 389 bool initializing_ = false; | 443 bool initializing_ = false; |
| 444 // The actual cache size (not including padding). |
| 390 int64_t cache_size_; | 445 int64_t cache_size_; |
| 446 int64_t cache_padding_ = 0; |
| 447 std::unique_ptr<crypto::SymmetricKey> cache_padding_key_; |
| 448 int64_t last_reported_size_ = 0; |
| 391 size_t max_query_size_bytes_; | 449 size_t max_query_size_bytes_; |
| 392 CacheStorageCacheObserver* cache_observer_; | 450 CacheStorageCacheObserver* cache_observer_; |
| 393 | 451 |
| 394 // Owns the elements of the list | 452 // Owns the elements of the list |
| 395 BlobToDiskCacheIDMap active_blob_to_disk_cache_writers_; | 453 BlobToDiskCacheIDMap active_blob_to_disk_cache_writers_; |
| 396 | 454 |
| 397 // Whether or not to store data in disk or memory. | 455 // Whether or not to store data in disk or memory. |
| 398 bool memory_only_; | 456 bool memory_only_; |
| 399 | 457 |
| 400 // Active while waiting for the backend to finish its closing up, and contains | 458 // Active while waiting for the backend to finish its closing up, and contains |
| 401 // the callback passed to CloseImpl. | 459 // the callback passed to CloseImpl. |
| 402 base::OnceClosure post_backend_closed_callback_; | 460 base::OnceClosure post_backend_closed_callback_; |
| 403 | 461 |
| 404 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; | 462 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; |
| 405 | 463 |
| 406 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); | 464 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); |
| 407 }; | 465 }; |
| 408 | 466 |
| 409 } // namespace content | 467 } // namespace content |
| 410 | 468 |
| 411 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ | 469 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ |
| OLD | NEW |