| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 namespace content { | 34 namespace content { |
| 35 | 35 |
| 36 class CacheStorageBlobToDiskCache; | 36 class CacheStorageBlobToDiskCache; |
| 37 class CacheMetadata; | 37 class CacheMetadata; |
| 38 class CacheStorageScheduler; | 38 class CacheStorageScheduler; |
| 39 class TestCacheStorageCache; | 39 class TestCacheStorageCache; |
| 40 | 40 |
| 41 // Represents a ServiceWorker Cache as seen in | 41 // Represents a ServiceWorker Cache as seen in |
| 42 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/ The | 42 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/ The |
| 43 // asynchronous methods are executed serially (except for Size). Callbacks to | 43 // asynchronous methods are executed serially. Callbacks to the public functions |
| 44 // the public functions will be called so long as the cache object lives. | 44 // will be called so long as the cache object lives. |
| 45 class CONTENT_EXPORT CacheStorageCache | 45 class CONTENT_EXPORT CacheStorageCache |
| 46 : public base::RefCounted<CacheStorageCache> { | 46 : public base::RefCounted<CacheStorageCache> { |
| 47 public: | 47 public: |
| 48 using ErrorCallback = base::Callback<void(CacheStorageError)>; | 48 using ErrorCallback = base::Callback<void(CacheStorageError)>; |
| 49 using ResponseCallback = | 49 using ResponseCallback = |
| 50 base::Callback<void(CacheStorageError, | 50 base::Callback<void(CacheStorageError, |
| 51 scoped_ptr<ServiceWorkerResponse>, | 51 scoped_ptr<ServiceWorkerResponse>, |
| 52 scoped_ptr<storage::BlobDataHandle>)>; | 52 scoped_ptr<storage::BlobDataHandle>)>; |
| 53 using Responses = std::vector<ServiceWorkerResponse>; | 53 using Responses = std::vector<ServiceWorkerResponse>; |
| 54 using BlobDataHandles = std::vector<storage::BlobDataHandle>; | 54 using BlobDataHandles = std::vector<storage::BlobDataHandle>; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // | 92 // |
| 93 // In the case of the PUT operation, puts request and response objects in the | 93 // In the case of the PUT operation, puts request and response objects in the |
| 94 // cache and returns OK when all operations are successfully completed. | 94 // cache and returns OK when all operations are successfully completed. |
| 95 // In the case of the DELETE operation, returns ERROR_NOT_FOUND if a specified | 95 // In the case of the DELETE operation, returns ERROR_NOT_FOUND if a specified |
| 96 // entry is not found. Otherwise deletes it and returns OK. | 96 // entry is not found. Otherwise deletes it and returns OK. |
| 97 // | 97 // |
| 98 // TODO(nhiroki): This function should run all operations atomically. | 98 // TODO(nhiroki): This function should run all operations atomically. |
| 99 // http://crbug.com/486637 | 99 // http://crbug.com/486637 |
| 100 void BatchOperation(const std::vector<CacheStorageBatchOperation>& operations, | 100 void BatchOperation(const std::vector<CacheStorageBatchOperation>& operations, |
| 101 const ErrorCallback& callback); | 101 const ErrorCallback& callback); |
| 102 void BatchDidGetUsageAndQuota( |
| 103 const std::vector<CacheStorageBatchOperation>& operations, |
| 104 const ErrorCallback& callback, |
| 105 int64_t space_required, |
| 106 storage::QuotaStatusCode status_code, |
| 107 int64_t usage, |
| 108 int64_t quota); |
| 102 void BatchDidOneOperation(const base::Closure& barrier_closure, | 109 void BatchDidOneOperation(const base::Closure& barrier_closure, |
| 103 ErrorCallback* callback, | 110 ErrorCallback* callback, |
| 104 CacheStorageError error); | 111 CacheStorageError error); |
| 105 void BatchDidAllOperations(scoped_ptr<ErrorCallback> callback); | 112 void BatchDidAllOperations(scoped_ptr<ErrorCallback> callback); |
| 106 | 113 |
| 107 // TODO(jkarlin): Have keys take an optional ServiceWorkerFetchRequest. | 114 // TODO(jkarlin): Have keys take an optional ServiceWorkerFetchRequest. |
| 108 // Returns CACHE_STORAGE_OK and a vector of requests if there are no errors. | 115 // Returns CACHE_STORAGE_OK and a vector of requests if there are no errors. |
| 109 void Keys(const RequestsCallback& callback); | 116 void Keys(const RequestsCallback& callback); |
| 110 | 117 |
| 111 // Closes the backend. Future operations that require the backend | 118 // Closes the backend. Future operations that require the backend |
| 112 // will exit early. Close should only be called once per CacheStorageCache. | 119 // will exit early. Close should only be called once per CacheStorageCache. |
| 113 void Close(const base::Closure& callback); | 120 void Close(const base::Closure& callback); |
| 114 | 121 |
| 115 // The size of the cache's contents. This runs in parallel with other Cache | 122 // The size of the cache's contents. |
| 116 // operations. This is because QuotaManager is a dependency of the Put | |
| 117 // operation and QuotaManager calls Size. If the cache isn't yet initialized, | |
| 118 // runs immediately after initialization, before any pending operations in the | |
| 119 // scheduler are run. | |
| 120 void Size(const SizeCallback& callback); | 123 void Size(const SizeCallback& callback); |
| 121 | 124 |
| 122 // Gets the cache's size, closes the backend, and then runs |callback| with | 125 // Gets the cache's size, closes the backend, and then runs |callback| with |
| 123 // the cache's size. | 126 // the cache's size. |
| 124 void GetSizeThenClose(const SizeCallback& callback); | 127 void GetSizeThenClose(const SizeCallback& callback); |
| 125 | 128 |
| 126 base::FilePath path() const { return path_; } | 129 base::FilePath path() const { return path_; } |
| 127 | 130 |
| 128 base::WeakPtr<CacheStorageCache> AsWeakPtr(); | 131 base::WeakPtr<CacheStorageCache> AsWeakPtr(); |
| 129 | 132 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 scoped_ptr<disk_cache::Backend> backend_; | 301 scoped_ptr<disk_cache::Backend> backend_; |
| 299 | 302 |
| 300 GURL origin_; | 303 GURL origin_; |
| 301 const std::string cache_name_; | 304 const std::string cache_name_; |
| 302 base::FilePath path_; | 305 base::FilePath path_; |
| 303 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 306 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 304 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; | 307 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
| 305 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 308 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
| 306 BackendState backend_state_ = BACKEND_UNINITIALIZED; | 309 BackendState backend_state_ = BACKEND_UNINITIALIZED; |
| 307 scoped_ptr<CacheStorageScheduler> scheduler_; | 310 scoped_ptr<CacheStorageScheduler> scheduler_; |
| 308 std::vector<SizeCallback> pending_size_callbacks_; | |
| 309 bool initializing_ = false; | 311 bool initializing_ = false; |
| 310 int64_t cache_size_ = 0; | 312 int64_t cache_size_ = 0; |
| 311 | 313 |
| 312 // Owns the elements of the list | 314 // Owns the elements of the list |
| 313 BlobToDiskCacheIDMap active_blob_to_disk_cache_writers_; | 315 BlobToDiskCacheIDMap active_blob_to_disk_cache_writers_; |
| 314 | 316 |
| 315 // Whether or not to store data in disk or memory. | 317 // Whether or not to store data in disk or memory. |
| 316 bool memory_only_; | 318 bool memory_only_; |
| 317 | 319 |
| 318 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; | 320 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; |
| 319 | 321 |
| 320 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); | 322 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); |
| 321 }; | 323 }; |
| 322 | 324 |
| 323 } // namespace content | 325 } // namespace content |
| 324 | 326 |
| 325 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ | 327 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ |
| OLD | NEW |