| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 namespace proto { | 43 namespace proto { |
| 44 class CacheMetadata; | 44 class CacheMetadata; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Represents a ServiceWorker Cache as seen in | 47 // Represents a ServiceWorker Cache as seen in |
| 48 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/ The | 48 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/ The |
| 49 // asynchronous methods are executed serially. Callbacks to the public functions | 49 // asynchronous methods are executed serially. Callbacks to the public functions |
| 50 // will be called so long as the cache object lives. | 50 // will be called so long as the cache object lives. |
| 51 class CONTENT_EXPORT CacheStorageCache { | 51 class CONTENT_EXPORT CacheStorageCache { |
| 52 public: | 52 public: |
| 53 using ErrorCallback = base::Callback<void(CacheStorageError)>; | 53 using ErrorCallback = base::OnceCallback<void(CacheStorageError)>; |
| 54 using ResponseCallback = | 54 using ResponseCallback = |
| 55 base::Callback<void(CacheStorageError, | 55 base::OnceCallback<void(CacheStorageError, |
| 56 std::unique_ptr<ServiceWorkerResponse>, | 56 std::unique_ptr<ServiceWorkerResponse>, |
| 57 std::unique_ptr<storage::BlobDataHandle>)>; | 57 std::unique_ptr<storage::BlobDataHandle>)>; |
| 58 using Responses = std::vector<ServiceWorkerResponse>; | 58 using Responses = std::vector<ServiceWorkerResponse>; |
| 59 using BlobDataHandles = std::vector<std::unique_ptr<storage::BlobDataHandle>>; | 59 using BlobDataHandles = std::vector<std::unique_ptr<storage::BlobDataHandle>>; |
| 60 using ResponsesCallback = | 60 using ResponsesCallback = |
| 61 base::Callback<void(CacheStorageError, | 61 base::OnceCallback<void(CacheStorageError, |
| 62 std::unique_ptr<Responses>, | 62 std::unique_ptr<Responses>, |
| 63 std::unique_ptr<BlobDataHandles>)>; | 63 std::unique_ptr<BlobDataHandles>)>; |
| 64 using Requests = std::vector<ServiceWorkerFetchRequest>; | 64 using Requests = std::vector<ServiceWorkerFetchRequest>; |
| 65 using RequestsCallback = | 65 using RequestsCallback = |
| 66 base::Callback<void(CacheStorageError, std::unique_ptr<Requests>)>; | 66 base::OnceCallback<void(CacheStorageError, std::unique_ptr<Requests>)>; |
| 67 using SizeCallback = base::Callback<void(int64_t)>; | 67 using SizeCallback = base::OnceCallback<void(int64_t)>; |
| 68 | 68 |
| 69 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA }; | 69 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA }; |
| 70 | 70 |
| 71 static std::unique_ptr<CacheStorageCache> CreateMemoryCache( | 71 static std::unique_ptr<CacheStorageCache> CreateMemoryCache( |
| 72 const GURL& origin, | 72 const GURL& origin, |
| 73 const std::string& cache_name, | 73 const std::string& cache_name, |
| 74 CacheStorage* cache_storage, | 74 CacheStorage* cache_storage, |
| 75 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 75 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 76 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 76 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| 77 base::WeakPtr<storage::BlobStorageContext> blob_context); | 77 base::WeakPtr<storage::BlobStorageContext> blob_context); |
| 78 static std::unique_ptr<CacheStorageCache> CreatePersistentCache( | 78 static std::unique_ptr<CacheStorageCache> CreatePersistentCache( |
| 79 const GURL& origin, | 79 const GURL& origin, |
| 80 const std::string& cache_name, | 80 const std::string& cache_name, |
| 81 CacheStorage* cache_storage, | 81 CacheStorage* cache_storage, |
| 82 const base::FilePath& path, | 82 const base::FilePath& path, |
| 83 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 83 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 84 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 84 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| 85 base::WeakPtr<storage::BlobStorageContext> blob_context, | 85 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 86 int64_t cache_size); | 86 int64_t cache_size); |
| 87 | 87 |
| 88 // Returns ERROR_TYPE_NOT_FOUND if not found. | 88 // Returns ERROR_TYPE_NOT_FOUND if not found. |
| 89 void Match(std::unique_ptr<ServiceWorkerFetchRequest> request, | 89 void Match(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 90 const CacheStorageCacheQueryParams& match_params, | 90 const CacheStorageCacheQueryParams& match_params, |
| 91 const ResponseCallback& callback); | 91 ResponseCallback callback); |
| 92 | 92 |
| 93 // Returns CACHE_STORAGE_OK and matched responses in this cache. If there are | 93 // Returns CACHE_STORAGE_OK and matched responses in this cache. If there are |
| 94 // no responses, returns CACHE_STORAGE_OK and an empty vector. | 94 // no responses, returns CACHE_STORAGE_OK and an empty vector. |
| 95 void MatchAll(std::unique_ptr<ServiceWorkerFetchRequest> request, | 95 void MatchAll(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 96 const CacheStorageCacheQueryParams& match_params, | 96 const CacheStorageCacheQueryParams& match_params, |
| 97 const ResponsesCallback& callback); | 97 ResponsesCallback callback); |
| 98 | 98 |
| 99 // Writes the side data (ex: V8 code cache) for the specified cache entry. | 99 // Writes the side data (ex: V8 code cache) for the specified cache entry. |
| 100 // If it doesn't exist, or the |expected_response_time| differs from the | 100 // If it doesn't exist, or the |expected_response_time| differs from the |
| 101 // entry's, CACHE_STORAGE_ERROR_NOT_FOUND is returned. | 101 // entry's, CACHE_STORAGE_ERROR_NOT_FOUND is returned. |
| 102 // Note: This "side data" is same meaning as "metadata" in HTTPCache. We use | 102 // Note: This "side data" is same meaning as "metadata" in HTTPCache. We use |
| 103 // "metadata" in cache_storage.proto for the pair of headers of a request and | 103 // "metadata" in cache_storage.proto for the pair of headers of a request and |
| 104 // a response. To avoid the confusion we use "side data" here. | 104 // a response. To avoid the confusion we use "side data" here. |
| 105 void WriteSideData(const CacheStorageCache::ErrorCallback& callback, | 105 void WriteSideData(CacheStorageCache::ErrorCallback callback, |
| 106 const GURL& url, | 106 const GURL& url, |
| 107 base::Time expected_response_time, | 107 base::Time expected_response_time, |
| 108 scoped_refptr<net::IOBuffer> buffer, | 108 scoped_refptr<net::IOBuffer> buffer, |
| 109 int buf_len); | 109 int buf_len); |
| 110 | 110 |
| 111 // Runs given batch operations. This corresponds to the Batch Cache Operations | 111 // Runs given batch operations. This corresponds to the Batch Cache Operations |
| 112 // algorithm in the spec. | 112 // algorithm in the spec. |
| 113 // | 113 // |
| 114 // |operations| cannot mix PUT and DELETE operations and cannot contain | 114 // |operations| cannot mix PUT and DELETE operations and cannot contain |
| 115 // multiple DELETE operations. | 115 // multiple DELETE operations. |
| 116 // | 116 // |
| 117 // In the case of the PUT operation, puts request and response objects in the | 117 // In the case of the PUT operation, puts request and response objects in the |
| 118 // cache and returns OK when all operations are successfully completed. | 118 // cache and returns OK when all operations are successfully completed. |
| 119 // In the case of the DELETE operation, returns ERROR_NOT_FOUND if a specified | 119 // In the case of the DELETE operation, returns ERROR_NOT_FOUND if a specified |
| 120 // entry is not found. Otherwise deletes it and returns OK. | 120 // entry is not found. Otherwise deletes it and returns OK. |
| 121 // | 121 // |
| 122 // TODO(nhiroki): This function should run all operations atomically. | 122 // TODO(nhiroki): This function should run all operations atomically. |
| 123 // http://crbug.com/486637 | 123 // http://crbug.com/486637 |
| 124 void BatchOperation(const std::vector<CacheStorageBatchOperation>& operations, | 124 void BatchOperation(const std::vector<CacheStorageBatchOperation>& operations, |
| 125 const ErrorCallback& callback); | 125 ErrorCallback callback); |
| 126 void BatchDidGetUsageAndQuota( | 126 void BatchDidGetUsageAndQuota( |
| 127 const std::vector<CacheStorageBatchOperation>& operations, | 127 const std::vector<CacheStorageBatchOperation>& operations, |
| 128 const ErrorCallback& callback, | 128 ErrorCallback callback, |
| 129 int64_t space_required, | 129 int64_t space_required, |
| 130 storage::QuotaStatusCode status_code, | 130 storage::QuotaStatusCode status_code, |
| 131 int64_t usage, | 131 int64_t usage, |
| 132 int64_t quota); | 132 int64_t quota); |
| 133 void BatchDidOneOperation(const base::Closure& barrier_closure, | 133 // Callback passed to operations. If |error| is a real error, invokes |
| 134 ErrorCallback* callback, | 134 // |error_callback|. Always invokes |completion_closure| to signal |
| 135 // completion. |
| 136 void BatchDidOneOperation(base::OnceClosure completion_closure, |
| 137 ErrorCallback error_callback, |
| 135 CacheStorageError error); | 138 CacheStorageError error); |
| 136 void BatchDidAllOperations(std::unique_ptr<ErrorCallback> callback); | 139 // Callback invoked once all BatchDidOneOperation() calls have run. |
| 140 // Invokes |error_callback|. |
| 141 void BatchDidAllOperations(ErrorCallback error_callback); |
| 137 | 142 |
| 138 // Returns CACHE_STORAGE_OK and a vector of requests if there are no errors. | 143 // Returns CACHE_STORAGE_OK and a vector of requests if there are no errors. |
| 139 void Keys(std::unique_ptr<ServiceWorkerFetchRequest> request, | 144 void Keys(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 140 const CacheStorageCacheQueryParams& options, | 145 const CacheStorageCacheQueryParams& options, |
| 141 const RequestsCallback& callback); | 146 RequestsCallback callback); |
| 142 | 147 |
| 143 // Closes the backend. Future operations that require the backend | 148 // Closes the backend. Future operations that require the backend |
| 144 // will exit early. Close should only be called once per CacheStorageCache. | 149 // will exit early. Close should only be called once per CacheStorageCache. |
| 145 void Close(const base::Closure& callback); | 150 void Close(base::OnceClosure callback); |
| 146 | 151 |
| 147 // The size of the cache's contents. | 152 // The size of the cache's contents. |
| 148 void Size(const SizeCallback& callback); | 153 void Size(SizeCallback callback); |
| 149 | 154 |
| 150 // Gets the cache's size, closes the backend, and then runs |callback| with | 155 // Gets the cache's size, closes the backend, and then runs |callback| with |
| 151 // the cache's size. | 156 // the cache's size. |
| 152 void GetSizeThenClose(const SizeCallback& callback); | 157 void GetSizeThenClose(SizeCallback callback); |
| 153 | 158 |
| 154 // Async operations in progress will cancel and not run their callbacks. | 159 // Async operations in progress will cancel and not run their callbacks. |
| 155 virtual ~CacheStorageCache(); | 160 virtual ~CacheStorageCache(); |
| 156 | 161 |
| 157 base::FilePath path() const { return path_; } | 162 base::FilePath path() const { return path_; } |
| 158 | 163 |
| 159 std::string cache_name() const { return cache_name_; } | 164 std::string cache_name() const { return cache_name_; } |
| 160 | 165 |
| 161 int64_t cache_size() const { return cache_size_; } | 166 int64_t cache_size() const { return cache_size_; } |
| 162 | 167 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 175 enum BackendState { | 180 enum BackendState { |
| 176 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. | 181 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. |
| 177 BACKEND_OPEN, // Backend can be used. | 182 BACKEND_OPEN, // Backend can be used. |
| 178 BACKEND_CLOSED // Backend cannot be used. All ops should fail. | 183 BACKEND_CLOSED // Backend cannot be used. All ops should fail. |
| 179 }; | 184 }; |
| 180 | 185 |
| 181 friend class base::RefCounted<CacheStorageCache>; | 186 friend class base::RefCounted<CacheStorageCache>; |
| 182 friend class TestCacheStorageCache; | 187 friend class TestCacheStorageCache; |
| 183 friend class CacheStorageCacheTest; | 188 friend class CacheStorageCacheTest; |
| 184 | 189 |
| 185 struct OpenAllEntriesContext; | |
| 186 struct PutContext; | 190 struct PutContext; |
| 187 struct QueryCacheContext; | 191 struct QueryCacheContext; |
| 188 struct QueryCacheResult; | 192 struct QueryCacheResult; |
| 189 | 193 |
| 190 using QueryCacheResults = std::vector<QueryCacheResult>; | 194 using QueryCacheResults = std::vector<QueryCacheResult>; |
| 191 using QueryCacheCallback = | 195 using QueryCacheCallback = |
| 192 base::Callback<void(CacheStorageError, | 196 base::OnceCallback<void(CacheStorageError, |
| 193 std::unique_ptr<QueryCacheResults>)>; | 197 std::unique_ptr<QueryCacheResults>)>; |
| 194 using Entries = std::vector<disk_cache::Entry*>; | 198 using Entries = std::vector<disk_cache::Entry*>; |
| 195 using ScopedBackendPtr = std::unique_ptr<disk_cache::Backend>; | 199 using ScopedBackendPtr = std::unique_ptr<disk_cache::Backend>; |
| 196 using BlobToDiskCacheIDMap = | 200 using BlobToDiskCacheIDMap = |
| 197 IDMap<std::unique_ptr<CacheStorageBlobToDiskCache>>; | 201 IDMap<std::unique_ptr<CacheStorageBlobToDiskCache>>; |
| 198 using OpenAllEntriesCallback = | |
| 199 base::Callback<void(std::unique_ptr<OpenAllEntriesContext>, | |
| 200 CacheStorageError)>; | |
| 201 | 202 |
| 202 CacheStorageCache( | 203 CacheStorageCache( |
| 203 const GURL& origin, | 204 const GURL& origin, |
| 204 const std::string& cache_name, | 205 const std::string& cache_name, |
| 205 const base::FilePath& path, | 206 const base::FilePath& path, |
| 206 CacheStorage* cache_storage, | 207 CacheStorage* cache_storage, |
| 207 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 208 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 208 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 209 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| 209 base::WeakPtr<storage::BlobStorageContext> blob_context, | 210 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 210 int64_t cache_size); | 211 int64_t cache_size); |
| 211 | 212 |
| 212 // Returns all entries in this cache. | |
| 213 void OpenAllEntries(const OpenAllEntriesCallback& callback); | |
| 214 void DidOpenNextEntry(std::unique_ptr<OpenAllEntriesContext> entries_context, | |
| 215 const OpenAllEntriesCallback& callback, | |
| 216 int rv); | |
| 217 | |
| 218 // Runs |callback| with matching requests/response data. The data provided | 213 // Runs |callback| with matching requests/response data. The data provided |
| 219 // 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 |
| 220 // 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 |
| 221 // then only out_requests is valid. If |query_type| is | 216 // then only out_requests is valid. If |query_type| is |
| 222 // REQUESTS_AND_RESPONSES then only out_requests, out_responses, and | 217 // REQUESTS_AND_RESPONSES then only out_requests, out_responses, and |
| 223 // out_blob_data_handles are valid. | 218 // out_blob_data_handles are valid. |
| 224 void QueryCache(std::unique_ptr<ServiceWorkerFetchRequest> request, | 219 void QueryCache(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 225 const CacheStorageCacheQueryParams& options, | 220 const CacheStorageCacheQueryParams& options, |
| 226 QueryCacheType query_type, | 221 QueryCacheType query_type, |
| 227 const QueryCacheCallback& callback); | 222 QueryCacheCallback callback); |
| 228 void QueryCacheDidOpenFastPath( | 223 void QueryCacheDidOpenFastPath( |
| 229 std::unique_ptr<QueryCacheContext> query_cache_context, | 224 std::unique_ptr<QueryCacheContext> query_cache_context, |
| 230 int rv); | 225 int rv); |
| 231 void QueryCacheOpenNextEntry( | 226 void QueryCacheOpenNextEntry( |
| 232 std::unique_ptr<QueryCacheContext> query_cache_context); | 227 std::unique_ptr<QueryCacheContext> query_cache_context); |
| 233 void QueryCacheFilterEntry( | 228 void QueryCacheFilterEntry( |
| 234 std::unique_ptr<QueryCacheContext> query_cache_context, | 229 std::unique_ptr<QueryCacheContext> query_cache_context, |
| 235 int rv); | 230 int rv); |
| 236 void QueryCacheDidReadMetadata( | 231 void QueryCacheDidReadMetadata( |
| 237 std::unique_ptr<QueryCacheContext> query_cache_context, | 232 std::unique_ptr<QueryCacheContext> query_cache_context, |
| 238 disk_cache::ScopedEntryPtr entry, | 233 disk_cache::ScopedEntryPtr entry, |
| 239 std::unique_ptr<proto::CacheMetadata> metadata); | 234 std::unique_ptr<proto::CacheMetadata> metadata); |
| 240 static bool QueryCacheResultCompare(const QueryCacheResult& lhs, | 235 static bool QueryCacheResultCompare(const QueryCacheResult& lhs, |
| 241 const QueryCacheResult& rhs); | 236 const QueryCacheResult& rhs); |
| 242 | 237 |
| 243 // Match callbacks | 238 // Match callbacks |
| 244 void MatchImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 239 void MatchImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 245 const CacheStorageCacheQueryParams& match_params, | 240 const CacheStorageCacheQueryParams& match_params, |
| 246 const ResponseCallback& callback); | 241 ResponseCallback callback); |
| 247 void MatchDidMatchAll(const ResponseCallback& callback, | 242 void MatchDidMatchAll(ResponseCallback callback, |
| 248 CacheStorageError match_all_error, | 243 CacheStorageError match_all_error, |
| 249 std::unique_ptr<Responses> match_all_responses, | 244 std::unique_ptr<Responses> match_all_responses, |
| 250 std::unique_ptr<BlobDataHandles> match_all_handles); | 245 std::unique_ptr<BlobDataHandles> match_all_handles); |
| 251 | 246 |
| 252 // MatchAll callbacks | 247 // MatchAll callbacks |
| 253 void MatchAllImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 248 void MatchAllImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 254 const CacheStorageCacheQueryParams& options, | 249 const CacheStorageCacheQueryParams& options, |
| 255 const ResponsesCallback& callback); | 250 ResponsesCallback callback); |
| 256 void MatchAllDidQueryCache( | 251 void MatchAllDidQueryCache( |
| 257 const ResponsesCallback& callback, | 252 ResponsesCallback callback, |
| 258 CacheStorageError error, | 253 CacheStorageError error, |
| 259 std::unique_ptr<QueryCacheResults> query_cache_results); | 254 std::unique_ptr<QueryCacheResults> query_cache_results); |
| 260 | 255 |
| 261 // WriteSideData callbacks | 256 // WriteSideData callbacks |
| 262 void WriteSideDataDidGetQuota(const ErrorCallback& callback, | 257 void WriteSideDataDidGetQuota(ErrorCallback callback, |
| 263 const GURL& url, | 258 const GURL& url, |
| 264 base::Time expected_response_time, | 259 base::Time expected_response_time, |
| 265 scoped_refptr<net::IOBuffer> buffer, | 260 scoped_refptr<net::IOBuffer> buffer, |
| 266 int buf_len, | 261 int buf_len, |
| 267 storage::QuotaStatusCode status_code, | 262 storage::QuotaStatusCode status_code, |
| 268 int64_t usage, | 263 int64_t usage, |
| 269 int64_t quota); | 264 int64_t quota); |
| 270 | 265 |
| 271 void WriteSideDataImpl(const ErrorCallback& callback, | 266 void WriteSideDataImpl(ErrorCallback callback, |
| 272 const GURL& url, | 267 const GURL& url, |
| 273 base::Time expected_response_time, | 268 base::Time expected_response_time, |
| 274 scoped_refptr<net::IOBuffer> buffer, | 269 scoped_refptr<net::IOBuffer> buffer, |
| 275 int buf_len); | 270 int buf_len); |
| 276 void WriteSideDataDidGetUsageAndQuota(const ErrorCallback& callback, | 271 void WriteSideDataDidGetUsageAndQuota(ErrorCallback callback, |
| 277 const GURL& url, | 272 const GURL& url, |
| 278 base::Time expected_response_time, | 273 base::Time expected_response_time, |
| 279 scoped_refptr<net::IOBuffer> buffer, | 274 scoped_refptr<net::IOBuffer> buffer, |
| 280 int buf_len, | 275 int buf_len, |
| 281 storage::QuotaStatusCode status_code, | 276 storage::QuotaStatusCode status_code, |
| 282 int64_t usage, | 277 int64_t usage, |
| 283 int64_t quota); | 278 int64_t quota); |
| 284 void WriteSideDataDidOpenEntry(const ErrorCallback& callback, | 279 void WriteSideDataDidOpenEntry(ErrorCallback callback, |
| 285 base::Time expected_response_time, | 280 base::Time expected_response_time, |
| 286 scoped_refptr<net::IOBuffer> buffer, | 281 scoped_refptr<net::IOBuffer> buffer, |
| 287 int buf_len, | 282 int buf_len, |
| 288 std::unique_ptr<disk_cache::Entry*> entry_ptr, | 283 std::unique_ptr<disk_cache::Entry*> entry_ptr, |
| 289 int rv); | 284 int rv); |
| 290 void WriteSideDataDidReadMetaData( | 285 void WriteSideDataDidReadMetaData( |
| 291 const ErrorCallback& callback, | 286 ErrorCallback callback, |
| 292 base::Time expected_response_time, | 287 base::Time expected_response_time, |
| 293 scoped_refptr<net::IOBuffer> buffer, | 288 scoped_refptr<net::IOBuffer> buffer, |
| 294 int buf_len, | 289 int buf_len, |
| 295 disk_cache::ScopedEntryPtr entry, | 290 disk_cache::ScopedEntryPtr entry, |
| 296 std::unique_ptr<proto::CacheMetadata> headers); | 291 std::unique_ptr<proto::CacheMetadata> headers); |
| 297 void WriteSideDataDidWrite(const ErrorCallback& callback, | 292 void WriteSideDataDidWrite(ErrorCallback callback, |
| 298 disk_cache::ScopedEntryPtr entry, | 293 disk_cache::ScopedEntryPtr entry, |
| 299 int expected_bytes, | 294 int expected_bytes, |
| 300 int rv); | 295 int rv); |
| 301 | 296 |
| 302 // Puts the request and response object in the cache. The response body (if | 297 // Puts the request and response object in the cache. The response body (if |
| 303 // present) is stored in the cache, but not the request body. Returns OK on | 298 // present) is stored in the cache, but not the request body. Returns OK on |
| 304 // success. | 299 // success. |
| 305 void Put(const CacheStorageBatchOperation& operation, | 300 void Put(const CacheStorageBatchOperation& operation, ErrorCallback callback); |
| 306 const ErrorCallback& callback); | |
| 307 void PutImpl(std::unique_ptr<PutContext> put_context); | 301 void PutImpl(std::unique_ptr<PutContext> put_context); |
| 308 void PutDidDoomEntry(std::unique_ptr<PutContext> put_context, int rv); | 302 void PutDidDoomEntry(std::unique_ptr<PutContext> put_context, int rv); |
| 309 void PutDidGetUsageAndQuota(std::unique_ptr<PutContext> put_context, | 303 void PutDidGetUsageAndQuota(std::unique_ptr<PutContext> put_context, |
| 310 storage::QuotaStatusCode status_code, | 304 storage::QuotaStatusCode status_code, |
| 311 int64_t usage, | 305 int64_t usage, |
| 312 int64_t quota); | 306 int64_t quota); |
| 313 void PutDidCreateEntry(std::unique_ptr<disk_cache::Entry*> entry_ptr, | 307 void PutDidCreateEntry(std::unique_ptr<disk_cache::Entry*> entry_ptr, |
| 314 std::unique_ptr<PutContext> put_context, | 308 std::unique_ptr<PutContext> put_context, |
| 315 int rv); | 309 int rv); |
| 316 void PutDidWriteHeaders(std::unique_ptr<PutContext> put_context, | 310 void PutDidWriteHeaders(std::unique_ptr<PutContext> put_context, |
| 317 int expected_bytes, | 311 int expected_bytes, |
| 318 int rv); | 312 int rv); |
| 319 void PutDidWriteBlobToCache(std::unique_ptr<PutContext> put_context, | 313 void PutDidWriteBlobToCache(std::unique_ptr<PutContext> put_context, |
| 320 BlobToDiskCacheIDMap::KeyType blob_to_cache_key, | 314 BlobToDiskCacheIDMap::KeyType blob_to_cache_key, |
| 321 disk_cache::ScopedEntryPtr entry, | 315 disk_cache::ScopedEntryPtr entry, |
| 322 bool success); | 316 bool success); |
| 323 | 317 |
| 324 // Asynchronously calculates the current cache size, notifies the quota | 318 // Asynchronously calculates the current cache size, notifies the quota |
| 325 // manager of any change from the last report, and sets cache_size_ to the new | 319 // manager of any change from the last report, and sets cache_size_ to the new |
| 326 // size. | 320 // size. |
| 327 void UpdateCacheSize(const base::Closure& callback); | 321 void UpdateCacheSize(base::OnceClosure callback); |
| 328 void UpdateCacheSizeGotSize(std::unique_ptr<CacheStorageCacheHandle>, | 322 void UpdateCacheSizeGotSize(std::unique_ptr<CacheStorageCacheHandle>, |
| 329 const base::Closure& callback, | 323 base::OnceClosure callback, |
| 330 int current_cache_size); | 324 int current_cache_size); |
| 331 | 325 |
| 332 // Returns ERROR_NOT_FOUND if not found. Otherwise deletes and returns OK. | 326 // Returns ERROR_NOT_FOUND if not found. Otherwise deletes and returns OK. |
| 333 void Delete(const CacheStorageBatchOperation& operation, | 327 void Delete(const CacheStorageBatchOperation& operation, |
| 334 const ErrorCallback& callback); | 328 ErrorCallback callback); |
| 335 void DeleteImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 329 void DeleteImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 336 const CacheStorageCacheQueryParams& match_params, | 330 const CacheStorageCacheQueryParams& match_params, |
| 337 const ErrorCallback& callback); | 331 ErrorCallback callback); |
| 338 void DeleteDidQueryCache( | 332 void DeleteDidQueryCache( |
| 339 const ErrorCallback& callback, | 333 ErrorCallback callback, |
| 340 CacheStorageError error, | 334 CacheStorageError error, |
| 341 std::unique_ptr<QueryCacheResults> query_cache_results); | 335 std::unique_ptr<QueryCacheResults> query_cache_results); |
| 342 | 336 |
| 343 // Keys callbacks. | 337 // Keys callbacks. |
| 344 void KeysImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 338 void KeysImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 345 const CacheStorageCacheQueryParams& options, | 339 const CacheStorageCacheQueryParams& options, |
| 346 const RequestsCallback& callback); | 340 RequestsCallback callback); |
| 347 void KeysDidQueryCache( | 341 void KeysDidQueryCache( |
| 348 const RequestsCallback& callback, | 342 RequestsCallback callback, |
| 349 CacheStorageError error, | 343 CacheStorageError error, |
| 350 std::unique_ptr<QueryCacheResults> query_cache_results); | 344 std::unique_ptr<QueryCacheResults> query_cache_results); |
| 351 | 345 |
| 352 void CloseImpl(const base::Closure& callback); | 346 void CloseImpl(base::OnceClosure callback); |
| 353 | 347 |
| 354 void SizeImpl(const SizeCallback& callback); | 348 void SizeImpl(SizeCallback callback); |
| 355 | 349 |
| 356 void GetSizeThenCloseDidGetSize(const SizeCallback& callback, | 350 void GetSizeThenCloseDidGetSize(SizeCallback callback, int64_t cache_size); |
| 357 int64_t cache_size); | |
| 358 | 351 |
| 359 // Loads the backend and calls the callback with the result (true for | 352 // Loads the backend and calls the callback with the result (true for |
| 360 // success). The callback will always be called. Virtual for tests. | 353 // success). The callback will always be called. Virtual for tests. |
| 361 virtual void CreateBackend(const ErrorCallback& callback); | 354 virtual void CreateBackend(ErrorCallback callback); |
| 362 void CreateBackendDidCreate(const CacheStorageCache::ErrorCallback& callback, | 355 void CreateBackendDidCreate(ErrorCallback callback, |
| 363 std::unique_ptr<ScopedBackendPtr> backend_ptr, | 356 std::unique_ptr<ScopedBackendPtr> backend_ptr, |
| 364 int rv); | 357 int rv); |
| 365 | 358 |
| 366 void InitBackend(); | 359 void InitBackend(); |
| 367 void InitDidCreateBackend(const base::Closure& callback, | 360 void InitDidCreateBackend(base::OnceClosure callback, |
| 368 CacheStorageError cache_create_error); | 361 CacheStorageError cache_create_error); |
| 369 void InitGotCacheSize(const base::Closure& callback, | 362 void InitGotCacheSize(base::OnceClosure callback, |
| 370 CacheStorageError cache_create_error, | 363 CacheStorageError cache_create_error, |
| 371 int cache_size); | 364 int cache_size); |
| 372 | 365 |
| 373 std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody( | 366 std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody( |
| 374 disk_cache::ScopedEntryPtr entry, | 367 disk_cache::ScopedEntryPtr entry, |
| 375 ServiceWorkerResponse* response); | 368 ServiceWorkerResponse* response); |
| 376 | 369 |
| 377 // Virtual for testing. | 370 // Virtual for testing. |
| 378 virtual std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle(); | 371 virtual std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle(); |
| 379 | 372 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 404 bool memory_only_; | 397 bool memory_only_; |
| 405 | 398 |
| 406 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; | 399 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; |
| 407 | 400 |
| 408 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); | 401 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); |
| 409 }; | 402 }; |
| 410 | 403 |
| 411 } // namespace content | 404 } // namespace content |
| 412 | 405 |
| 413 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ | 406 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ |
| OLD | NEW |