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