| 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 <vector> | 10 #include <vector> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 | 36 |
| 37 class CacheStorageBlobToDiskCache; | 37 class CacheStorageBlobToDiskCache; |
| 38 class CacheMetadata; | 38 class CacheMetadata; |
| 39 class CacheStorageScheduler; | 39 class CacheStorageScheduler; |
| 40 class TestCacheStorageCache; | 40 class TestCacheStorageCache; |
| 41 | 41 |
| 42 // Represents a ServiceWorker Cache as seen in | 42 // Represents a ServiceWorker Cache as seen in |
| 43 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/ The | 43 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/ The |
| 44 // asynchronous methods are executed serially (except for Size). Callbacks to | 44 // asynchronous methods are executed serially. Callbacks to the public functions |
| 45 // the public functions will be called so long as the cache object lives. | 45 // will be called so long as the cache object lives. |
| 46 class CONTENT_EXPORT CacheStorageCache | 46 class CONTENT_EXPORT CacheStorageCache |
| 47 : public base::RefCounted<CacheStorageCache> { | 47 : public base::RefCounted<CacheStorageCache> { |
| 48 public: | 48 public: |
| 49 using ErrorCallback = base::Callback<void(CacheStorageError)>; | 49 using ErrorCallback = base::Callback<void(CacheStorageError)>; |
| 50 using ResponseCallback = | 50 using ResponseCallback = |
| 51 base::Callback<void(CacheStorageError, | 51 base::Callback<void(CacheStorageError, |
| 52 std::unique_ptr<ServiceWorkerResponse>, | 52 std::unique_ptr<ServiceWorkerResponse>, |
| 53 std::unique_ptr<storage::BlobDataHandle>)>; | 53 std::unique_ptr<storage::BlobDataHandle>)>; |
| 54 using Responses = std::vector<ServiceWorkerResponse>; | 54 using Responses = std::vector<ServiceWorkerResponse>; |
| 55 using BlobDataHandles = std::vector<storage::BlobDataHandle>; | 55 using BlobDataHandles = std::vector<storage::BlobDataHandle>; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // | 108 // |
| 109 // In the case of the PUT operation, puts request and response objects in the | 109 // In the case of the PUT operation, puts request and response objects in the |
| 110 // cache and returns OK when all operations are successfully completed. | 110 // cache and returns OK when all operations are successfully completed. |
| 111 // In the case of the DELETE operation, returns ERROR_NOT_FOUND if a specified | 111 // In the case of the DELETE operation, returns ERROR_NOT_FOUND if a specified |
| 112 // entry is not found. Otherwise deletes it and returns OK. | 112 // entry is not found. Otherwise deletes it and returns OK. |
| 113 // | 113 // |
| 114 // TODO(nhiroki): This function should run all operations atomically. | 114 // TODO(nhiroki): This function should run all operations atomically. |
| 115 // http://crbug.com/486637 | 115 // http://crbug.com/486637 |
| 116 void BatchOperation(const std::vector<CacheStorageBatchOperation>& operations, | 116 void BatchOperation(const std::vector<CacheStorageBatchOperation>& operations, |
| 117 const ErrorCallback& callback); | 117 const ErrorCallback& callback); |
| 118 void BatchDidGetUsageAndQuota( |
| 119 const std::vector<CacheStorageBatchOperation>& operations, |
| 120 const ErrorCallback& callback, |
| 121 int64_t space_required, |
| 122 storage::QuotaStatusCode status_code, |
| 123 int64_t usage, |
| 124 int64_t quota); |
| 118 void BatchDidOneOperation(const base::Closure& barrier_closure, | 125 void BatchDidOneOperation(const base::Closure& barrier_closure, |
| 119 ErrorCallback* callback, | 126 ErrorCallback* callback, |
| 120 CacheStorageError error); | 127 CacheStorageError error); |
| 121 void BatchDidAllOperations(std::unique_ptr<ErrorCallback> callback); | 128 void BatchDidAllOperations(std::unique_ptr<ErrorCallback> callback); |
| 122 | 129 |
| 123 // TODO(jkarlin): Have keys take an optional ServiceWorkerFetchRequest. | 130 // TODO(jkarlin): Have keys take an optional ServiceWorkerFetchRequest. |
| 124 // Returns CACHE_STORAGE_OK and a vector of requests if there are no errors. | 131 // Returns CACHE_STORAGE_OK and a vector of requests if there are no errors. |
| 125 void Keys(const RequestsCallback& callback); | 132 void Keys(const RequestsCallback& callback); |
| 126 | 133 |
| 127 // Closes the backend. Future operations that require the backend | 134 // Closes the backend. Future operations that require the backend |
| 128 // will exit early. Close should only be called once per CacheStorageCache. | 135 // will exit early. Close should only be called once per CacheStorageCache. |
| 129 void Close(const base::Closure& callback); | 136 void Close(const base::Closure& callback); |
| 130 | 137 |
| 131 // The size of the cache's contents. This runs in parallel with other Cache | 138 // The size of the cache's contents. |
| 132 // operations. This is because QuotaManager is a dependency of the Put | |
| 133 // operation and QuotaManager calls Size. If the cache isn't yet initialized, | |
| 134 // runs immediately after initialization, before any pending operations in the | |
| 135 // scheduler are run. | |
| 136 void Size(const SizeCallback& callback); | 139 void Size(const SizeCallback& callback); |
| 137 | 140 |
| 138 // Gets the cache's size, closes the backend, and then runs |callback| with | 141 // Gets the cache's size, closes the backend, and then runs |callback| with |
| 139 // the cache's size. | 142 // the cache's size. |
| 140 void GetSizeThenClose(const SizeCallback& callback); | 143 void GetSizeThenClose(const SizeCallback& callback); |
| 141 | 144 |
| 142 base::FilePath path() const { return path_; } | 145 base::FilePath path() const { return path_; } |
| 143 | 146 |
| 144 base::WeakPtr<CacheStorageCache> AsWeakPtr(); | 147 base::WeakPtr<CacheStorageCache> AsWeakPtr(); |
| 145 | 148 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 std::unique_ptr<MatchAllContext> context, | 209 std::unique_ptr<MatchAllContext> context, |
| 207 std::unique_ptr<OpenAllEntriesContext> entries_context, | 210 std::unique_ptr<OpenAllEntriesContext> entries_context, |
| 208 CacheStorageError error); | 211 CacheStorageError error); |
| 209 void MatchAllProcessNextEntry(std::unique_ptr<MatchAllContext> context, | 212 void MatchAllProcessNextEntry(std::unique_ptr<MatchAllContext> context, |
| 210 const Entries::iterator& iter); | 213 const Entries::iterator& iter); |
| 211 void MatchAllDidReadMetadata(std::unique_ptr<MatchAllContext> context, | 214 void MatchAllDidReadMetadata(std::unique_ptr<MatchAllContext> context, |
| 212 const Entries::iterator& iter, | 215 const Entries::iterator& iter, |
| 213 std::unique_ptr<CacheMetadata> metadata); | 216 std::unique_ptr<CacheMetadata> metadata); |
| 214 | 217 |
| 215 // WriteSideData callbacks | 218 // WriteSideData callbacks |
| 219 void WriteSideDataDidGetQuota(const ErrorCallback& callback, |
| 220 const GURL& url, |
| 221 base::Time expected_response_time, |
| 222 scoped_refptr<net::IOBuffer> buffer, |
| 223 int buf_len, |
| 224 storage::QuotaStatusCode status_code, |
| 225 int64_t usage, |
| 226 int64_t quota); |
| 227 |
| 216 void WriteSideDataImpl(const ErrorCallback& callback, | 228 void WriteSideDataImpl(const ErrorCallback& callback, |
| 217 const GURL& url, | 229 const GURL& url, |
| 218 base::Time expected_response_time, | 230 base::Time expected_response_time, |
| 219 scoped_refptr<net::IOBuffer> buffer, | 231 scoped_refptr<net::IOBuffer> buffer, |
| 220 int buf_len); | 232 int buf_len); |
| 221 void WriteSideDataDidGetUsageAndQuota(const ErrorCallback& callback, | 233 void WriteSideDataDidGetUsageAndQuota(const ErrorCallback& callback, |
| 222 const GURL& url, | 234 const GURL& url, |
| 223 base::Time expected_response_time, | 235 base::Time expected_response_time, |
| 224 scoped_refptr<net::IOBuffer> buffer, | 236 scoped_refptr<net::IOBuffer> buffer, |
| 225 int buf_len, | 237 int buf_len, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 std::unique_ptr<disk_cache::Backend> backend_; | 359 std::unique_ptr<disk_cache::Backend> backend_; |
| 348 | 360 |
| 349 GURL origin_; | 361 GURL origin_; |
| 350 const std::string cache_name_; | 362 const std::string cache_name_; |
| 351 base::FilePath path_; | 363 base::FilePath path_; |
| 352 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 364 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 353 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; | 365 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
| 354 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 366 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
| 355 BackendState backend_state_ = BACKEND_UNINITIALIZED; | 367 BackendState backend_state_ = BACKEND_UNINITIALIZED; |
| 356 std::unique_ptr<CacheStorageScheduler> scheduler_; | 368 std::unique_ptr<CacheStorageScheduler> scheduler_; |
| 357 std::vector<SizeCallback> pending_size_callbacks_; | |
| 358 bool initializing_ = false; | 369 bool initializing_ = false; |
| 359 int64_t cache_size_ = 0; | 370 int64_t cache_size_ = 0; |
| 360 | 371 |
| 361 // Owns the elements of the list | 372 // Owns the elements of the list |
| 362 BlobToDiskCacheIDMap active_blob_to_disk_cache_writers_; | 373 BlobToDiskCacheIDMap active_blob_to_disk_cache_writers_; |
| 363 | 374 |
| 364 // Whether or not to store data in disk or memory. | 375 // Whether or not to store data in disk or memory. |
| 365 bool memory_only_; | 376 bool memory_only_; |
| 366 | 377 |
| 367 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; | 378 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; |
| 368 | 379 |
| 369 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); | 380 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); |
| 370 }; | 381 }; |
| 371 | 382 |
| 372 } // namespace content | 383 } // namespace content |
| 373 | 384 |
| 374 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ | 385 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ |
| OLD | NEW |