Chromium Code Reviews| 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, | |
| 340 std::unique_ptr<QueryCacheResults> query_results); | |
| 303 void PutDidGetUsageAndQuota(std::unique_ptr<PutContext> put_context, | 341 void PutDidGetUsageAndQuota(std::unique_ptr<PutContext> put_context, |
| 304 storage::QuotaStatusCode status_code, | 342 storage::QuotaStatusCode status_code, |
| 305 int64_t usage, | 343 int64_t usage, |
| 306 int64_t quota); | 344 int64_t quota); |
| 307 void PutDidCreateEntry(std::unique_ptr<disk_cache::Entry*> entry_ptr, | 345 void PutDidCreateEntry(std::unique_ptr<disk_cache::Entry*> entry_ptr, |
| 308 std::unique_ptr<PutContext> put_context, | 346 std::unique_ptr<PutContext> put_context, |
| 309 int rv); | 347 int rv); |
| 310 void PutDidWriteHeaders(std::unique_ptr<PutContext> put_context, | 348 void PutDidWriteHeaders(std::unique_ptr<PutContext> put_context, |
| 311 int expected_bytes, | 349 int expected_bytes, |
| 312 int rv); | 350 int rv); |
| 313 void PutDidWriteBlobToCache(std::unique_ptr<PutContext> put_context, | 351 void PutDidWriteBlobToCache(std::unique_ptr<PutContext> put_context, |
| 314 BlobToDiskCacheIDMap::KeyType blob_to_cache_key, | 352 BlobToDiskCacheIDMap::KeyType blob_to_cache_key, |
| 315 disk_cache::ScopedEntryPtr entry, | 353 disk_cache::ScopedEntryPtr entry, |
| 316 bool success); | 354 bool success); |
| 317 | 355 |
| 318 // Asynchronously calculates the current cache size, notifies the quota | 356 // Asynchronously calculates the current cache size, notifies the quota |
| 319 // manager of any change from the last report, and sets cache_size_ to the new | 357 // manager of any change from the last report, and sets cache_size_ to the new |
| 320 // size. | 358 // size. |
| 321 void UpdateCacheSize(base::OnceClosure callback); | 359 void UpdateCacheSize(base::OnceClosure callback); |
| 322 void UpdateCacheSizeGotSize(std::unique_ptr<CacheStorageCacheHandle>, | 360 void UpdateCacheSizeGotSize(std::unique_ptr<CacheStorageCacheHandle>, |
| 323 base::OnceClosure callback, | 361 base::OnceClosure callback, |
| 324 int current_cache_size); | 362 int current_cache_size); |
| 325 | 363 |
| 326 // Returns ERROR_NOT_FOUND if not found. Otherwise deletes and returns OK. | 364 // Returns ERROR_NOT_FOUND if not found. Otherwise deletes and returns OK. |
| 327 void Delete(const CacheStorageBatchOperation& operation, | 365 void Delete(const CacheStorageBatchOperation& operation, |
| 328 ErrorCallback callback); | 366 ErrorCallback callback); |
| 329 void DeleteImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 367 void DeleteImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 330 const CacheStorageCacheQueryParams& match_params, | 368 const CacheStorageCacheQueryParams& match_params, |
| 331 ErrorCallback callback); | 369 QueryCacheCallback callback); |
|
jkarlin
2017/07/31 14:03:24
Why not revert this back to an ErrorCallback? I do
cmumford
2017/08/10 16:37:11
Done.
| |
| 332 void DeleteDidQueryCache( | 370 void DeleteDidQueryCache( |
| 333 ErrorCallback callback, | 371 QueryCacheCallback callback, |
| 334 CacheStorageError error, | 372 CacheStorageError error, |
| 335 std::unique_ptr<QueryCacheResults> query_cache_results); | 373 std::unique_ptr<QueryCacheResults> query_cache_results); |
| 374 void DeleteDidDelete(ErrorCallback callback, | |
| 375 CacheStorageError error, | |
| 376 std::unique_ptr<QueryCacheResults> query_results); | |
| 336 | 377 |
| 337 // Keys callbacks. | 378 // Keys callbacks. |
| 338 void KeysImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 379 void KeysImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 339 const CacheStorageCacheQueryParams& options, | 380 const CacheStorageCacheQueryParams& options, |
| 340 RequestsCallback callback); | 381 RequestsCallback callback); |
| 341 void KeysDidQueryCache( | 382 void KeysDidQueryCache( |
| 342 RequestsCallback callback, | 383 RequestsCallback callback, |
| 343 CacheStorageError error, | 384 CacheStorageError error, |
| 344 std::unique_ptr<QueryCacheResults> query_cache_results); | 385 std::unique_ptr<QueryCacheResults> query_cache_results); |
| 345 | 386 |
| 346 void CloseImpl(base::OnceClosure callback); | 387 void CloseImpl(base::OnceClosure callback); |
| 347 | 388 |
| 348 void SizeImpl(SizeCallback callback); | 389 void SizeImpl(SizeCallback callback); |
| 349 | 390 |
| 350 void GetSizeThenCloseDidGetSize(SizeCallback callback, int64_t cache_size); | 391 void GetSizeThenCloseDidGetSize(SizeCallback callback, int64_t cache_size); |
| 351 | 392 |
| 352 // Loads the backend and calls the callback with the result (true for | 393 // Loads the backend and calls the callback with the result (true for |
| 353 // success). The callback will always be called. Virtual for tests. | 394 // success). The callback will always be called. Virtual for tests. |
| 354 virtual void CreateBackend(ErrorCallback callback); | 395 virtual void CreateBackend(ErrorCallback callback); |
| 355 void CreateBackendDidCreate(ErrorCallback callback, | 396 void CreateBackendDidCreate(ErrorCallback callback, |
| 356 std::unique_ptr<ScopedBackendPtr> backend_ptr, | 397 std::unique_ptr<ScopedBackendPtr> backend_ptr, |
| 357 int rv); | 398 int rv); |
| 358 | 399 |
| 400 // Calculate the size and padding of the cache. | |
| 401 void CalculateCacheSizePadding(SizePaddingCallback callback); | |
| 402 void CalculateCacheSizePaddingGotSize(SizePaddingCallback callback, | |
| 403 int cache_size); | |
| 404 void PaddingDidQueryCache( | |
| 405 SizePaddingCallback callback, | |
| 406 int cache_size, | |
| 407 CacheStorageError error, | |
| 408 std::unique_ptr<QueryCacheResults> query_cache_results); | |
| 409 | |
| 410 // Calculate the size (but not padding) of the cache. | |
| 411 void CalculateCacheSize(const net::CompletionCallback& callback); | |
| 412 | |
| 359 void InitBackend(); | 413 void InitBackend(); |
| 360 void InitDidCreateBackend(base::OnceClosure callback, | 414 void InitDidCreateBackend(base::OnceClosure callback, |
| 361 CacheStorageError cache_create_error); | 415 CacheStorageError cache_create_error); |
| 362 void InitGotCacheSize(base::OnceClosure callback, | 416 void InitGotCacheSize(base::OnceClosure callback, |
| 363 CacheStorageError cache_create_error, | 417 CacheStorageError cache_create_error, |
| 364 int cache_size); | 418 int cache_size); |
| 419 void InitGotCacheSizeAndPadding(base::OnceClosure callback, | |
| 420 CacheStorageError cache_create_error, | |
| 421 int64_t cache_size, | |
| 422 int64_t cache_padding); | |
| 365 | 423 |
| 366 std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody( | 424 std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody( |
| 367 disk_cache::ScopedEntryPtr entry, | 425 disk_cache::ScopedEntryPtr entry, |
| 368 ServiceWorkerResponse* response); | 426 ServiceWorkerResponse* response); |
| 369 | 427 |
| 370 // Virtual for testing. | 428 // Virtual for testing. |
| 371 virtual std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle(); | 429 virtual std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle(); |
| 372 | 430 |
| 373 // Be sure to check |backend_state_| before use. | 431 // Be sure to check |backend_state_| before use. |
| 374 std::unique_ptr<disk_cache::Backend> backend_; | 432 std::unique_ptr<disk_cache::Backend> backend_; |
| 375 | 433 |
| 376 GURL origin_; | 434 GURL origin_; |
| 377 const std::string cache_name_; | 435 const std::string cache_name_; |
| 378 base::FilePath path_; | 436 base::FilePath path_; |
| 379 | 437 |
| 380 // Raw pointer is safe because CacheStorage owns this object. | 438 // Raw pointer is safe because CacheStorage owns this object. |
| 381 CacheStorage* cache_storage_; | 439 CacheStorage* cache_storage_; |
| 382 | 440 |
| 383 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 441 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 384 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; | 442 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
| 385 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 443 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
| 386 BackendState backend_state_ = BACKEND_UNINITIALIZED; | 444 BackendState backend_state_ = BACKEND_UNINITIALIZED; |
| 387 std::unique_ptr<CacheStorageScheduler> scheduler_; | 445 std::unique_ptr<CacheStorageScheduler> scheduler_; |
| 388 bool initializing_ = false; | 446 bool initializing_ = false; |
| 447 // The actual physical cache size (not including padding). | |
|
jkarlin
2017/07/31 14:03:24
Remove the word physical?
cmumford
2017/08/10 16:37:11
Done.
| |
| 389 int64_t cache_size_; | 448 int64_t cache_size_; |
| 449 int64_t cache_padding_ = 0; | |
| 450 std::unique_ptr<crypto::SymmetricKey> cache_padding_key_; | |
| 451 int64_t last_reported_size_ = 0; | |
| 390 size_t max_query_size_bytes_; | 452 size_t max_query_size_bytes_; |
| 391 CacheStorageCacheObserver* cache_observer_; | 453 CacheStorageCacheObserver* cache_observer_; |
| 392 | 454 |
| 393 // Owns the elements of the list | 455 // Owns the elements of the list |
| 394 BlobToDiskCacheIDMap active_blob_to_disk_cache_writers_; | 456 BlobToDiskCacheIDMap active_blob_to_disk_cache_writers_; |
| 395 | 457 |
| 396 // Whether or not to store data in disk or memory. | 458 // Whether or not to store data in disk or memory. |
| 397 bool memory_only_; | 459 bool memory_only_; |
| 398 | 460 |
| 399 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; | 461 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; |
| 400 | 462 |
| 401 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); | 463 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); |
| 402 }; | 464 }; |
| 403 | 465 |
| 404 } // namespace content | 466 } // namespace content |
| 405 | 467 |
| 406 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ | 468 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ |
| OLD | NEW |