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