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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 86 |
87 // Returns ERROR_TYPE_NOT_FOUND if not found. | 87 // Returns ERROR_TYPE_NOT_FOUND if not found. |
88 void Match(std::unique_ptr<ServiceWorkerFetchRequest> request, | 88 void Match(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 89 const CacheStorageCacheQueryParams& match_params, |
89 const ResponseCallback& callback); | 90 const ResponseCallback& callback); |
90 | 91 |
91 // Returns CACHE_STORAGE_OK and matched responses in this cache. If there are | 92 // Returns CACHE_STORAGE_OK and matched responses in this cache. If there are |
92 // no responses, returns CACHE_STORAGE_OK and an empty vector. | 93 // no responses, returns CACHE_STORAGE_OK and an empty vector. |
93 void MatchAll(std::unique_ptr<ServiceWorkerFetchRequest> request, | 94 void MatchAll(std::unique_ptr<ServiceWorkerFetchRequest> request, |
94 const CacheStorageCacheQueryParams& match_params, | 95 const CacheStorageCacheQueryParams& match_params, |
95 const ResponsesCallback& callback); | 96 const ResponsesCallback& callback); |
96 | 97 |
97 // Writes the side data (ex: V8 code cache) for the specified cache entry. | 98 // Writes the side data (ex: V8 code cache) for the specified cache entry. |
98 // If it doesn't exist, or the |expected_response_time| differs from the | 99 // If it doesn't exist, or the |expected_response_time| differs from the |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // Async operations in progress will cancel and not run their callbacks. | 153 // Async operations in progress will cancel and not run their callbacks. |
153 virtual ~CacheStorageCache(); | 154 virtual ~CacheStorageCache(); |
154 | 155 |
155 base::FilePath path() const { return path_; } | 156 base::FilePath path() const { return path_; } |
156 | 157 |
157 std::string cache_name() const { return cache_name_; } | 158 std::string cache_name() const { return cache_name_; } |
158 | 159 |
159 base::WeakPtr<CacheStorageCache> AsWeakPtr(); | 160 base::WeakPtr<CacheStorageCache> AsWeakPtr(); |
160 | 161 |
161 private: | 162 private: |
| 163 enum class QueryCacheType { REQUESTS_AND_RESPONSES, CACHE_ENTRIES }; |
| 164 |
162 friend class base::RefCounted<CacheStorageCache>; | 165 friend class base::RefCounted<CacheStorageCache>; |
163 friend class TestCacheStorageCache; | 166 friend class TestCacheStorageCache; |
164 | 167 |
165 struct OpenAllEntriesContext; | 168 struct OpenAllEntriesContext; |
166 struct PutContext; | 169 struct PutContext; |
167 | 170 |
168 // The backend progresses from uninitialized, to open, to closed, and cannot | 171 // The backend progresses from uninitialized, to open, to closed, and cannot |
169 // reverse direction. The open step may be skipped. | 172 // reverse direction. The open step may be skipped. |
170 enum BackendState { | 173 enum BackendState { |
171 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. | 174 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. |
(...skipping 17 matching lines...) Expand all Loading... |
189 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 192 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
190 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 193 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
191 base::WeakPtr<storage::BlobStorageContext> blob_context); | 194 base::WeakPtr<storage::BlobStorageContext> blob_context); |
192 | 195 |
193 // Returns all entries in this cache. | 196 // Returns all entries in this cache. |
194 void OpenAllEntries(const OpenAllEntriesCallback& callback); | 197 void OpenAllEntries(const OpenAllEntriesCallback& callback); |
195 void DidOpenNextEntry(std::unique_ptr<OpenAllEntriesContext> entries_context, | 198 void DidOpenNextEntry(std::unique_ptr<OpenAllEntriesContext> entries_context, |
196 const OpenAllEntriesCallback& callback, | 199 const OpenAllEntriesCallback& callback, |
197 int rv); | 200 int rv); |
198 | 201 |
| 202 // Runs |callback| with matching requests/response data. The data provided |
| 203 // in the QueryCacheResults depends on the |query_type|. If |query_type| is |
| 204 // CACHE_ENTRIES then only out_entries is valid. If |query_type| is |
| 205 // REQUESTS_AND_RESPONSES then only out_requests, out_responses, and |
| 206 // out_blob_data_handles are valid. |
199 void QueryCache(std::unique_ptr<ServiceWorkerFetchRequest> request, | 207 void QueryCache(std::unique_ptr<ServiceWorkerFetchRequest> request, |
200 const CacheStorageCacheQueryParams& options, | 208 const CacheStorageCacheQueryParams& options, |
| 209 QueryCacheType query_type, |
201 const QueryCacheResultsCallback& callback); | 210 const QueryCacheResultsCallback& callback); |
| 211 void QueryCacheDidOpenEntry( |
| 212 std::unique_ptr<QueryCacheResults> query_cache_results, |
| 213 std::unique_ptr<disk_cache::Entry*> entry, |
| 214 int rv); |
202 void QueryCacheDidOpenAllEntries( | 215 void QueryCacheDidOpenAllEntries( |
203 std::unique_ptr<QueryCacheResults> query_cache_results, | 216 std::unique_ptr<QueryCacheResults> query_cache_results, |
204 std::unique_ptr<OpenAllEntriesContext> entries_context, | 217 std::unique_ptr<OpenAllEntriesContext> entries_context, |
205 CacheStorageError error); | 218 CacheStorageError error); |
206 void QueryCacheProcessNextEntry( | 219 void QueryCacheProcessNextEntry( |
207 std::unique_ptr<QueryCacheResults> query_cache_results, | 220 std::unique_ptr<QueryCacheResults> query_cache_results, |
208 const Entries::iterator& iter); | 221 const Entries::iterator& iter); |
209 void QueryCacheDidReadMetadata( | 222 void QueryCacheDidReadMetadata( |
210 std::unique_ptr<QueryCacheResults> query_cache_results, | 223 std::unique_ptr<QueryCacheResults> query_cache_results, |
211 const Entries::iterator& iter, | 224 const Entries::iterator& iter, |
212 std::unique_ptr<CacheMetadata> metadata); | 225 std::unique_ptr<CacheMetadata> metadata); |
213 | 226 |
214 // Match callbacks | 227 // Match callbacks |
215 void MatchImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 228 void MatchImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 229 const CacheStorageCacheQueryParams& match_params, |
216 const ResponseCallback& callback); | 230 const ResponseCallback& callback); |
217 void MatchDidOpenEntry(std::unique_ptr<ServiceWorkerFetchRequest> request, | 231 void MatchDidMatchAll(const ResponseCallback& callback, |
218 const ResponseCallback& callback, | 232 CacheStorageError match_all_error, |
219 std::unique_ptr<disk_cache::Entry*> entry_ptr, | 233 std::unique_ptr<Responses> match_all_responses, |
220 int rv); | 234 std::unique_ptr<BlobDataHandles> match_all_handles); |
221 void MatchDidReadMetadata(std::unique_ptr<ServiceWorkerFetchRequest> request, | |
222 const ResponseCallback& callback, | |
223 disk_cache::ScopedEntryPtr entry, | |
224 std::unique_ptr<CacheMetadata> headers); | |
225 | 235 |
226 // MatchAll callbacks | 236 // MatchAll callbacks |
227 void MatchAllImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 237 void MatchAllImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
228 const CacheStorageCacheQueryParams& options, | 238 const CacheStorageCacheQueryParams& options, |
229 const ResponsesCallback& callback); | 239 const ResponsesCallback& callback); |
230 void MatchAllDidQueryCache( | 240 void MatchAllDidQueryCache( |
231 const ResponsesCallback& callback, | 241 const ResponsesCallback& callback, |
232 CacheStorageError error, | 242 CacheStorageError error, |
233 std::unique_ptr<QueryCacheResults> query_cache_results); | 243 std::unique_ptr<QueryCacheResults> query_cache_results); |
234 | 244 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 disk_cache::ScopedEntryPtr entry, | 281 disk_cache::ScopedEntryPtr entry, |
272 int expected_bytes, | 282 int expected_bytes, |
273 int rv); | 283 int rv); |
274 | 284 |
275 // Puts the request and response object in the cache. The response body (if | 285 // Puts the request and response object in the cache. The response body (if |
276 // present) is stored in the cache, but not the request body. Returns OK on | 286 // present) is stored in the cache, but not the request body. Returns OK on |
277 // success. | 287 // success. |
278 void Put(const CacheStorageBatchOperation& operation, | 288 void Put(const CacheStorageBatchOperation& operation, |
279 const ErrorCallback& callback); | 289 const ErrorCallback& callback); |
280 void PutImpl(std::unique_ptr<PutContext> put_context); | 290 void PutImpl(std::unique_ptr<PutContext> put_context); |
281 void PutDidDelete(std::unique_ptr<PutContext> put_context, | 291 void PutDidDoomEntry(std::unique_ptr<PutContext> put_context, int rv); |
282 CacheStorageError delete_error); | |
283 void PutDidGetUsageAndQuota(std::unique_ptr<PutContext> put_context, | 292 void PutDidGetUsageAndQuota(std::unique_ptr<PutContext> put_context, |
284 storage::QuotaStatusCode status_code, | 293 storage::QuotaStatusCode status_code, |
285 int64_t usage, | 294 int64_t usage, |
286 int64_t quota); | 295 int64_t quota); |
287 void PutDidCreateEntry(std::unique_ptr<disk_cache::Entry*> entry_ptr, | 296 void PutDidCreateEntry(std::unique_ptr<disk_cache::Entry*> entry_ptr, |
288 std::unique_ptr<PutContext> put_context, | 297 std::unique_ptr<PutContext> put_context, |
289 int rv); | 298 int rv); |
290 void PutDidWriteHeaders(std::unique_ptr<PutContext> put_context, | 299 void PutDidWriteHeaders(std::unique_ptr<PutContext> put_context, |
291 int expected_bytes, | 300 int expected_bytes, |
292 int rv); | 301 int rv); |
293 void PutDidWriteBlobToCache(std::unique_ptr<PutContext> put_context, | 302 void PutDidWriteBlobToCache(std::unique_ptr<PutContext> put_context, |
294 BlobToDiskCacheIDMap::KeyType blob_to_cache_key, | 303 BlobToDiskCacheIDMap::KeyType blob_to_cache_key, |
295 disk_cache::ScopedEntryPtr entry, | 304 disk_cache::ScopedEntryPtr entry, |
296 bool success); | 305 bool success); |
297 | 306 |
298 // Asynchronously calculates the current cache size, notifies the quota | 307 // Asynchronously calculates the current cache size, notifies the quota |
299 // manager of any change from the last report, and sets cache_size_ to the new | 308 // manager of any change from the last report, and sets cache_size_ to the new |
300 // size. | 309 // size. |
301 void UpdateCacheSize(); | 310 void UpdateCacheSize(); |
302 void UpdateCacheSizeGotSize(std::unique_ptr<CacheStorageCacheHandle>, | 311 void UpdateCacheSizeGotSize(std::unique_ptr<CacheStorageCacheHandle>, |
303 int current_cache_size); | 312 int current_cache_size); |
304 | 313 |
305 // Returns ERROR_NOT_FOUND if not found. Otherwise deletes and returns OK. | 314 // Returns ERROR_NOT_FOUND if not found. Otherwise deletes and returns OK. |
306 void Delete(const CacheStorageBatchOperation& operation, | 315 void Delete(const CacheStorageBatchOperation& operation, |
307 const ErrorCallback& callback); | 316 const ErrorCallback& callback); |
308 void DeleteImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 317 void DeleteImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
309 const CacheStorageCacheQueryParams& match_params, | 318 const CacheStorageCacheQueryParams& match_params, |
310 const ErrorCallback& callback); | 319 const ErrorCallback& callback); |
311 void DeleteDidOpenAllEntries( | 320 void DeleteDidQueryCache( |
312 std::unique_ptr<ServiceWorkerFetchRequest> request, | |
313 const ErrorCallback& callback, | 321 const ErrorCallback& callback, |
314 std::unique_ptr<OpenAllEntriesContext> entries_context, | 322 CacheStorageError error, |
315 CacheStorageError error); | 323 std::unique_ptr<QueryCacheResults> query_cache_results); |
316 void DeleteDidOpenEntry(const GURL& origin, | |
317 std::unique_ptr<ServiceWorkerFetchRequest> request, | |
318 const CacheStorageCache::ErrorCallback& callback, | |
319 std::unique_ptr<disk_cache::Entry*> entryptr, | |
320 int rv); | |
321 | 324 |
322 // Keys callbacks. | 325 // Keys callbacks. |
323 void KeysImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 326 void KeysImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
324 const CacheStorageCacheQueryParams& options, | 327 const CacheStorageCacheQueryParams& options, |
325 const RequestsCallback& callback); | 328 const RequestsCallback& callback); |
326 void KeysDidQueryCache( | 329 void KeysDidQueryCache( |
327 const RequestsCallback& callback, | 330 const RequestsCallback& callback, |
328 CacheStorageError error, | 331 CacheStorageError error, |
329 std::unique_ptr<QueryCacheResults> query_cache_results); | 332 std::unique_ptr<QueryCacheResults> query_cache_results); |
330 | 333 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 bool memory_only_; | 389 bool memory_only_; |
387 | 390 |
388 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; | 391 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; |
389 | 392 |
390 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); | 393 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); |
391 }; | 394 }; |
392 | 395 |
393 } // namespace content | 396 } // namespace content |
394 | 397 |
395 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ | 398 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ |
OLD | NEW |