| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // asynchronous methods are executed serially. Callbacks to the public functions | 44 // asynchronous methods are executed serially. Callbacks to the public functions |
| 45 // will be called so long as the cache object lives. | 45 // will be called so long as the cache object lives. |
| 46 class CONTENT_EXPORT CacheStorageCache { | 46 class CONTENT_EXPORT CacheStorageCache { |
| 47 public: | 47 public: |
| 48 using ErrorCallback = base::Callback<void(CacheStorageError)>; | 48 using ErrorCallback = base::Callback<void(CacheStorageError)>; |
| 49 using ResponseCallback = | 49 using ResponseCallback = |
| 50 base::Callback<void(CacheStorageError, | 50 base::Callback<void(CacheStorageError, |
| 51 std::unique_ptr<ServiceWorkerResponse>, | 51 std::unique_ptr<ServiceWorkerResponse>, |
| 52 std::unique_ptr<storage::BlobDataHandle>)>; | 52 std::unique_ptr<storage::BlobDataHandle>)>; |
| 53 using Responses = std::vector<ServiceWorkerResponse>; | 53 using Responses = std::vector<ServiceWorkerResponse>; |
| 54 using BlobDataHandles = std::vector<storage::BlobDataHandle>; | 54 using BlobDataHandles = std::vector<std::unique_ptr<storage::BlobDataHandle>>; |
| 55 using ResponsesCallback = | 55 using ResponsesCallback = |
| 56 base::Callback<void(CacheStorageError, | 56 base::Callback<void(CacheStorageError, |
| 57 std::unique_ptr<Responses>, | 57 std::unique_ptr<Responses>, |
| 58 std::unique_ptr<BlobDataHandles>)>; | 58 std::unique_ptr<BlobDataHandles>)>; |
| 59 using Requests = std::vector<ServiceWorkerFetchRequest>; | 59 using Requests = std::vector<ServiceWorkerFetchRequest>; |
| 60 using RequestsCallback = | 60 using RequestsCallback = |
| 61 base::Callback<void(CacheStorageError, std::unique_ptr<Requests>)>; | 61 base::Callback<void(CacheStorageError, std::unique_ptr<Requests>)>; |
| 62 using SizeCallback = base::Callback<void(int64_t)>; | 62 using SizeCallback = base::Callback<void(int64_t)>; |
| 63 | 63 |
| 64 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA }; | 64 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA }; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 // Async operations in progress will cancel and not run their callbacks. | 148 // Async operations in progress will cancel and not run their callbacks. |
| 149 virtual ~CacheStorageCache(); | 149 virtual ~CacheStorageCache(); |
| 150 | 150 |
| 151 base::FilePath path() const { return path_; } | 151 base::FilePath path() const { return path_; } |
| 152 | 152 |
| 153 std::string cache_name() const { return cache_name_; } | 153 std::string cache_name() const { return cache_name_; } |
| 154 | 154 |
| 155 base::WeakPtr<CacheStorageCache> AsWeakPtr(); | 155 base::WeakPtr<CacheStorageCache> AsWeakPtr(); |
| 156 | 156 |
| 157 private: | 157 private: |
| 158 friend class base::RefCounted<CacheStorageCache>; | |
| 159 friend class TestCacheStorageCache; | |
| 160 friend class CacheStorageCacheTest; | |
| 161 | |
| 162 struct OpenAllEntriesContext; | |
| 163 struct PutContext; | |
| 164 struct QueryCacheResults; | |
| 165 | |
| 166 using QueryCacheResultsCallback = | |
| 167 base::Callback<void(CacheStorageError, | |
| 168 std::unique_ptr<QueryCacheResults>)>; | |
| 169 | |
| 170 enum class QueryCacheType { REQUESTS, REQUESTS_AND_RESPONSES, CACHE_ENTRIES }; | 158 enum class QueryCacheType { REQUESTS, REQUESTS_AND_RESPONSES, CACHE_ENTRIES }; |
| 171 | 159 |
| 172 // The backend progresses from uninitialized, to open, to closed, and cannot | 160 // The backend progresses from uninitialized, to open, to closed, and cannot |
| 173 // reverse direction. The open step may be skipped. | 161 // reverse direction. The open step may be skipped. |
| 174 enum BackendState { | 162 enum BackendState { |
| 175 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. | 163 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. |
| 176 BACKEND_OPEN, // Backend can be used. | 164 BACKEND_OPEN, // Backend can be used. |
| 177 BACKEND_CLOSED // Backend cannot be used. All ops should fail. | 165 BACKEND_CLOSED // Backend cannot be used. All ops should fail. |
| 178 }; | 166 }; |
| 179 | 167 |
| 168 friend class base::RefCounted<CacheStorageCache>; |
| 169 friend class TestCacheStorageCache; |
| 170 friend class CacheStorageCacheTest; |
| 171 |
| 172 struct OpenAllEntriesContext; |
| 173 struct PutContext; |
| 174 struct QueryCacheContext; |
| 175 struct QueryCacheResult; |
| 176 |
| 177 using QueryCacheResults = std::vector<QueryCacheResult>; |
| 178 using QueryCacheCallback = |
| 179 base::Callback<void(CacheStorageError, |
| 180 std::unique_ptr<QueryCacheResults>)>; |
| 180 using Entries = std::vector<disk_cache::Entry*>; | 181 using Entries = std::vector<disk_cache::Entry*>; |
| 181 using ScopedBackendPtr = std::unique_ptr<disk_cache::Backend>; | 182 using ScopedBackendPtr = std::unique_ptr<disk_cache::Backend>; |
| 182 using BlobToDiskCacheIDMap = | 183 using BlobToDiskCacheIDMap = |
| 183 IDMap<CacheStorageBlobToDiskCache, IDMapOwnPointer>; | 184 IDMap<CacheStorageBlobToDiskCache, IDMapOwnPointer>; |
| 184 using OpenAllEntriesCallback = | 185 using OpenAllEntriesCallback = |
| 185 base::Callback<void(std::unique_ptr<OpenAllEntriesContext>, | 186 base::Callback<void(std::unique_ptr<OpenAllEntriesContext>, |
| 186 CacheStorageError)>; | 187 CacheStorageError)>; |
| 187 | 188 |
| 188 CacheStorageCache( | 189 CacheStorageCache( |
| 189 const GURL& origin, | 190 const GURL& origin, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 202 | 203 |
| 203 // Runs |callback| with matching requests/response data. The data provided | 204 // Runs |callback| with matching requests/response data. The data provided |
| 204 // in the QueryCacheResults depends on the |query_type|. If |query_type| is | 205 // in the QueryCacheResults depends on the |query_type|. If |query_type| is |
| 205 // CACHE_ENTRIES then only out_entries is valid. If |query_type| is REQUESTS | 206 // CACHE_ENTRIES then only out_entries is valid. If |query_type| is REQUESTS |
| 206 // then only out_requests is valid. If |query_type| is | 207 // then only out_requests is valid. If |query_type| is |
| 207 // REQUESTS_AND_RESPONSES then only out_requests, out_responses, and | 208 // REQUESTS_AND_RESPONSES then only out_requests, out_responses, and |
| 208 // out_blob_data_handles are valid. | 209 // out_blob_data_handles are valid. |
| 209 void QueryCache(std::unique_ptr<ServiceWorkerFetchRequest> request, | 210 void QueryCache(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 210 const CacheStorageCacheQueryParams& options, | 211 const CacheStorageCacheQueryParams& options, |
| 211 QueryCacheType query_type, | 212 QueryCacheType query_type, |
| 212 const QueryCacheResultsCallback& callback); | 213 const QueryCacheCallback& callback); |
| 213 void QueryCacheDidOpenFastPath( | 214 void QueryCacheDidOpenFastPath( |
| 214 std::unique_ptr<QueryCacheResults> query_cache_results, | 215 std::unique_ptr<QueryCacheContext> query_cache_context, |
| 215 int rv); | 216 int rv); |
| 216 void QueryCacheOpenNextEntry( | 217 void QueryCacheOpenNextEntry( |
| 217 std::unique_ptr<QueryCacheResults> query_cache_results); | 218 std::unique_ptr<QueryCacheContext> query_cache_context); |
| 218 void QueryCacheFilterEntry( | 219 void QueryCacheFilterEntry( |
| 219 std::unique_ptr<QueryCacheResults> query_cache_results, | 220 std::unique_ptr<QueryCacheContext> query_cache_context, |
| 220 int rv); | 221 int rv); |
| 221 void QueryCacheDidReadMetadata( | 222 void QueryCacheDidReadMetadata( |
| 222 std::unique_ptr<QueryCacheResults> query_cache_results, | 223 std::unique_ptr<QueryCacheContext> query_cache_context, |
| 223 disk_cache::ScopedEntryPtr entry, | 224 disk_cache::ScopedEntryPtr entry, |
| 224 std::unique_ptr<CacheMetadata> metadata); | 225 std::unique_ptr<CacheMetadata> metadata); |
| 226 static bool QueryCacheResultCompare(const QueryCacheResult& lhs, |
| 227 const QueryCacheResult& rhs); |
| 225 | 228 |
| 226 // Match callbacks | 229 // Match callbacks |
| 227 void MatchImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 230 void MatchImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 228 const CacheStorageCacheQueryParams& match_params, | 231 const CacheStorageCacheQueryParams& match_params, |
| 229 const ResponseCallback& callback); | 232 const ResponseCallback& callback); |
| 230 void MatchDidMatchAll(const ResponseCallback& callback, | 233 void MatchDidMatchAll(const ResponseCallback& callback, |
| 231 CacheStorageError match_all_error, | 234 CacheStorageError match_all_error, |
| 232 std::unique_ptr<Responses> match_all_responses, | 235 std::unique_ptr<Responses> match_all_responses, |
| 233 std::unique_ptr<BlobDataHandles> match_all_handles); | 236 std::unique_ptr<BlobDataHandles> match_all_handles); |
| 234 | 237 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 bool memory_only_; | 392 bool memory_only_; |
| 390 | 393 |
| 391 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; | 394 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; |
| 392 | 395 |
| 393 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); | 396 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); |
| 394 }; | 397 }; |
| 395 | 398 |
| 396 } // namespace content | 399 } // namespace content |
| 397 | 400 |
| 398 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ | 401 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ |
| OLD | NEW |