| 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> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 class URLRequestContextGetter; | 26 class URLRequestContextGetter; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace storage { | 29 namespace storage { |
| 30 class BlobDataHandle; | 30 class BlobDataHandle; |
| 31 class BlobStorageContext; | 31 class BlobStorageContext; |
| 32 class QuotaManagerProxy; | 32 class QuotaManagerProxy; |
| 33 } | 33 } |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 class CacheMetadata; |
| 36 class CacheStorage; | 37 class CacheStorage; |
| 37 class CacheStorageBlobToDiskCache; | 38 class CacheStorageBlobToDiskCache; |
| 38 class CacheStorageCacheHandle; | 39 class CacheStorageCacheHandle; |
| 40 class CacheStorageCacheObserver; |
| 39 class CacheStorageScheduler; | 41 class CacheStorageScheduler; |
| 40 class TestCacheStorageCache; | 42 class TestCacheStorageCache; |
| 41 | 43 |
| 42 namespace proto { | 44 namespace proto { |
| 43 class CacheMetadata; | 45 class CacheMetadata; |
| 44 } | 46 } |
| 45 | 47 |
| 46 // Represents a ServiceWorker Cache as seen in | 48 // Represents a ServiceWorker Cache as seen in |
| 47 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/ The | 49 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/ The |
| 48 // asynchronous methods are executed serially. Callbacks to the public functions | 50 // asynchronous methods are executed serially. Callbacks to the public functions |
| (...skipping 25 matching lines...) Expand all Loading... |
| 74 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 76 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 75 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 77 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| 76 base::WeakPtr<storage::BlobStorageContext> blob_context); | 78 base::WeakPtr<storage::BlobStorageContext> blob_context); |
| 77 static std::unique_ptr<CacheStorageCache> CreatePersistentCache( | 79 static std::unique_ptr<CacheStorageCache> CreatePersistentCache( |
| 78 const GURL& origin, | 80 const GURL& origin, |
| 79 const std::string& cache_name, | 81 const std::string& cache_name, |
| 80 CacheStorage* cache_storage, | 82 CacheStorage* cache_storage, |
| 81 const base::FilePath& path, | 83 const base::FilePath& path, |
| 82 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 84 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 83 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 85 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| 84 base::WeakPtr<storage::BlobStorageContext> blob_context); | 86 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 87 int64_t cache_size); |
| 85 | 88 |
| 86 // Returns ERROR_TYPE_NOT_FOUND if not found. | 89 // Returns ERROR_TYPE_NOT_FOUND if not found. |
| 87 void Match(std::unique_ptr<ServiceWorkerFetchRequest> request, | 90 void Match(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 88 const CacheStorageCacheQueryParams& match_params, | 91 const CacheStorageCacheQueryParams& match_params, |
| 89 const ResponseCallback& callback); | 92 const ResponseCallback& callback); |
| 90 | 93 |
| 91 // Returns CACHE_STORAGE_OK and matched responses in this cache. If there are | 94 // Returns CACHE_STORAGE_OK and matched responses in this cache. If there are |
| 92 // no responses, returns CACHE_STORAGE_OK and an empty vector. | 95 // no responses, returns CACHE_STORAGE_OK and an empty vector. |
| 93 void MatchAll(std::unique_ptr<ServiceWorkerFetchRequest> request, | 96 void MatchAll(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 94 const CacheStorageCacheQueryParams& match_params, | 97 const CacheStorageCacheQueryParams& match_params, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // the cache's size. | 152 // the cache's size. |
| 150 void GetSizeThenClose(const SizeCallback& callback); | 153 void GetSizeThenClose(const SizeCallback& callback); |
| 151 | 154 |
| 152 // Async operations in progress will cancel and not run their callbacks. | 155 // Async operations in progress will cancel and not run their callbacks. |
| 153 virtual ~CacheStorageCache(); | 156 virtual ~CacheStorageCache(); |
| 154 | 157 |
| 155 base::FilePath path() const { return path_; } | 158 base::FilePath path() const { return path_; } |
| 156 | 159 |
| 157 std::string cache_name() const { return cache_name_; } | 160 std::string cache_name() const { return cache_name_; } |
| 158 | 161 |
| 162 int64_t cache_size() const { return cache_size_; } |
| 163 |
| 164 // Set the one observer that will be notified of changes to this cache. |
| 165 // Note: Either the observer must have a lifetime longer than this instance |
| 166 // or call SetObserver(nullptr) to stop receiving notification of changes. |
| 167 void SetObserver(CacheStorageCacheObserver* observer); |
| 168 |
| 159 base::WeakPtr<CacheStorageCache> AsWeakPtr(); | 169 base::WeakPtr<CacheStorageCache> AsWeakPtr(); |
| 160 | 170 |
| 161 private: | 171 private: |
| 162 enum class QueryCacheType { REQUESTS, REQUESTS_AND_RESPONSES, CACHE_ENTRIES }; | 172 enum class QueryCacheType { REQUESTS, REQUESTS_AND_RESPONSES, CACHE_ENTRIES }; |
| 163 | 173 |
| 164 // The backend progresses from uninitialized, to open, to closed, and cannot | 174 // The backend progresses from uninitialized, to open, to closed, and cannot |
| 165 // reverse direction. The open step may be skipped. | 175 // reverse direction. The open step may be skipped. |
| 166 enum BackendState { | 176 enum BackendState { |
| 167 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. | 177 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. |
| 168 BACKEND_OPEN, // Backend can be used. | 178 BACKEND_OPEN, // Backend can be used. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 190 base::Callback<void(std::unique_ptr<OpenAllEntriesContext>, | 200 base::Callback<void(std::unique_ptr<OpenAllEntriesContext>, |
| 191 CacheStorageError)>; | 201 CacheStorageError)>; |
| 192 | 202 |
| 193 CacheStorageCache( | 203 CacheStorageCache( |
| 194 const GURL& origin, | 204 const GURL& origin, |
| 195 const std::string& cache_name, | 205 const std::string& cache_name, |
| 196 const base::FilePath& path, | 206 const base::FilePath& path, |
| 197 CacheStorage* cache_storage, | 207 CacheStorage* cache_storage, |
| 198 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 208 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 199 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 209 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| 200 base::WeakPtr<storage::BlobStorageContext> blob_context); | 210 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 211 int64_t cache_size); |
| 201 | 212 |
| 202 // Returns all entries in this cache. | 213 // Returns all entries in this cache. |
| 203 void OpenAllEntries(const OpenAllEntriesCallback& callback); | 214 void OpenAllEntries(const OpenAllEntriesCallback& callback); |
| 204 void DidOpenNextEntry(std::unique_ptr<OpenAllEntriesContext> entries_context, | 215 void DidOpenNextEntry(std::unique_ptr<OpenAllEntriesContext> entries_context, |
| 205 const OpenAllEntriesCallback& callback, | 216 const OpenAllEntriesCallback& callback, |
| 206 int rv); | 217 int rv); |
| 207 | 218 |
| 208 // Runs |callback| with matching requests/response data. The data provided | 219 // Runs |callback| with matching requests/response data. The data provided |
| 209 // in the QueryCacheResults depends on the |query_type|. If |query_type| is | 220 // in the QueryCacheResults depends on the |query_type|. If |query_type| is |
| 210 // CACHE_ENTRIES then only out_entries is valid. If |query_type| is REQUESTS | 221 // CACHE_ENTRIES then only out_entries is valid. If |query_type| is REQUESTS |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 | 391 |
| 381 // Raw pointer is safe because CacheStorage owns this object. | 392 // Raw pointer is safe because CacheStorage owns this object. |
| 382 CacheStorage* cache_storage_; | 393 CacheStorage* cache_storage_; |
| 383 | 394 |
| 384 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 395 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 385 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; | 396 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
| 386 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 397 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
| 387 BackendState backend_state_ = BACKEND_UNINITIALIZED; | 398 BackendState backend_state_ = BACKEND_UNINITIALIZED; |
| 388 std::unique_ptr<CacheStorageScheduler> scheduler_; | 399 std::unique_ptr<CacheStorageScheduler> scheduler_; |
| 389 bool initializing_ = false; | 400 bool initializing_ = false; |
| 390 int64_t cache_size_ = 0; | 401 int64_t cache_size_; |
| 391 size_t max_query_size_bytes_; | 402 size_t max_query_size_bytes_; |
| 403 CacheStorageCacheObserver* cache_observer_; |
| 392 | 404 |
| 393 // Owns the elements of the list | 405 // Owns the elements of the list |
| 394 BlobToDiskCacheIDMap active_blob_to_disk_cache_writers_; | 406 BlobToDiskCacheIDMap active_blob_to_disk_cache_writers_; |
| 395 | 407 |
| 396 // Whether or not to store data in disk or memory. | 408 // Whether or not to store data in disk or memory. |
| 397 bool memory_only_; | 409 bool memory_only_; |
| 398 | 410 |
| 399 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; | 411 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; |
| 400 | 412 |
| 401 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); | 413 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); |
| 402 }; | 414 }; |
| 403 | 415 |
| 404 } // namespace content | 416 } // namespace content |
| 405 | 417 |
| 406 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ | 418 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ |
| OLD | NEW |