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