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_H_ | 5 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_H_ |
6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_H_ | 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 // Calls the callback with a vector of cache names (keys) available. | 80 // Calls the callback with a vector of cache names (keys) available. |
81 void EnumerateCaches(const StringsAndErrorCallback& callback); | 81 void EnumerateCaches(const StringsAndErrorCallback& callback); |
82 | 82 |
83 // Calls match on the cache with the given |cache_name|. | 83 // Calls match on the cache with the given |cache_name|. |
84 void MatchCache(const std::string& cache_name, | 84 void MatchCache(const std::string& cache_name, |
85 scoped_ptr<ServiceWorkerFetchRequest> request, | 85 scoped_ptr<ServiceWorkerFetchRequest> request, |
86 const CacheStorageCache::ResponseCallback& callback); | 86 const CacheStorageCache::ResponseCallback& callback); |
87 | 87 |
88 // Calls match on all of the caches in parallel, calling |callback| with the | 88 // Calls match on all of the caches in parallel, calling |callback| with the |
89 // first response found. Note that if multiple caches have the same | 89 // response from the first cache (in order of cache creation) to have the |
90 // request/response then it is not defined which cache's response will be | 90 // entry. If no response is found then |callback| is called with |
91 // returned. If no response is found then |callback| is called with | |
92 // CACHE_STORAGE_ERROR_NOT_FOUND. | 91 // CACHE_STORAGE_ERROR_NOT_FOUND. |
93 void MatchAllCaches(scoped_ptr<ServiceWorkerFetchRequest> request, | 92 void MatchAllCaches(scoped_ptr<ServiceWorkerFetchRequest> request, |
94 const CacheStorageCache::ResponseCallback& callback); | 93 const CacheStorageCache::ResponseCallback& callback); |
95 | 94 |
96 // Sums the sizes of each cache and closes them. Runs |callback| with the | 95 // Sums the sizes of each cache and closes them. Runs |callback| with the |
97 // size. | 96 // size. |
98 void GetSizeThenCloseAllCaches(const SizeCallback& callback); | 97 void GetSizeThenCloseAllCaches(const SizeCallback& callback); |
99 | 98 |
100 // The size of all of the origin's contents. This value should be used as an | 99 // The size of all of the origin's contents. This value should be used as an |
101 // estimate only since the cache may be modified at any time. | 100 // estimate only since the cache may be modified at any time. |
102 void Size(const SizeCallback& callback); | 101 void Size(const SizeCallback& callback); |
103 | 102 |
104 // The functions below are for tests to verify that the operations run | 103 // The functions below are for tests to verify that the operations run |
105 // serially. | 104 // serially. |
106 void StartAsyncOperationForTesting(); | 105 void StartAsyncOperationForTesting(); |
107 void CompleteAsyncOperationForTesting(); | 106 void CompleteAsyncOperationForTesting(); |
108 | 107 |
109 private: | 108 private: |
110 friend class TestCacheStorage; | 109 friend class TestCacheStorage; |
111 | 110 class CacheLoader; |
112 class MemoryLoader; | 111 class MemoryLoader; |
113 class SimpleCacheLoader; | 112 class SimpleCacheLoader; |
114 class CacheLoader; | 113 struct CacheMatchResponse; |
115 | 114 |
116 typedef std::map<std::string, base::WeakPtr<CacheStorageCache>> CacheMap; | 115 typedef std::map<std::string, base::WeakPtr<CacheStorageCache>> CacheMap; |
117 | 116 |
118 // Return a CacheStorageCache for the given name if the name is known. If the | 117 // Return a CacheStorageCache for the given name if the name is known. If the |
119 // CacheStorageCache has been deleted, creates a new one. | 118 // CacheStorageCache has been deleted, creates a new one. |
120 scoped_refptr<CacheStorageCache> GetLoadedCache( | 119 scoped_refptr<CacheStorageCache> GetLoadedCache( |
121 const std::string& cache_name); | 120 const std::string& cache_name); |
122 | 121 |
123 // Holds a reference to a cache for thirty seconds. | 122 // Holds a reference to a cache for thirty seconds. |
124 void TemporarilyPreserveCache(scoped_refptr<CacheStorageCache> cache); | 123 void TemporarilyPreserveCache(scoped_refptr<CacheStorageCache> cache); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 const CacheStorageCache::ResponseCallback& callback); | 170 const CacheStorageCache::ResponseCallback& callback); |
172 void MatchCacheDidMatch(scoped_refptr<CacheStorageCache> cache, | 171 void MatchCacheDidMatch(scoped_refptr<CacheStorageCache> cache, |
173 const CacheStorageCache::ResponseCallback& callback, | 172 const CacheStorageCache::ResponseCallback& callback, |
174 CacheStorageError error, | 173 CacheStorageError error, |
175 scoped_ptr<ServiceWorkerResponse> response, | 174 scoped_ptr<ServiceWorkerResponse> response, |
176 scoped_ptr<storage::BlobDataHandle> handle); | 175 scoped_ptr<storage::BlobDataHandle> handle); |
177 | 176 |
178 // The MatchAllCaches callbacks are below. | 177 // The MatchAllCaches callbacks are below. |
179 void MatchAllCachesImpl(scoped_ptr<ServiceWorkerFetchRequest> request, | 178 void MatchAllCachesImpl(scoped_ptr<ServiceWorkerFetchRequest> request, |
180 const CacheStorageCache::ResponseCallback& callback); | 179 const CacheStorageCache::ResponseCallback& callback); |
181 void MatchAllCachesDidMatch(scoped_refptr<CacheStorageCache> cache, | 180 void MatchAllCachesDidMatch( |
182 const base::Closure& barrier_closure, | 181 scoped_refptr<CacheStorageCache> cache, |
183 CacheStorageCache::ResponseCallback* callback, | 182 CacheMatchResponse* out_match_response, |
184 CacheStorageError error, | 183 const base::Closure& barrier_closure, |
185 scoped_ptr<ServiceWorkerResponse> response, | 184 CacheStorageError error, |
186 scoped_ptr<storage::BlobDataHandle> handle); | 185 scoped_ptr<ServiceWorkerResponse> service_worker_response, |
| 186 scoped_ptr<storage::BlobDataHandle> handle); |
187 void MatchAllCachesDidMatchAll( | 187 void MatchAllCachesDidMatchAll( |
188 scoped_ptr<CacheStorageCache::ResponseCallback> callback); | 188 scoped_ptr<std::vector<CacheMatchResponse>> match_responses, |
| 189 const CacheStorageCache::ResponseCallback& callback); |
189 | 190 |
190 void GetSizeThenCloseAllCachesImpl(const SizeCallback& callback); | 191 void GetSizeThenCloseAllCachesImpl(const SizeCallback& callback); |
191 | 192 |
192 void SizeImpl(const SizeCallback& callback); | 193 void SizeImpl(const SizeCallback& callback); |
193 | 194 |
194 void PendingClosure(const base::Closure& callback); | 195 void PendingClosure(const base::Closure& callback); |
195 void PendingBoolAndErrorCallback(const BoolAndErrorCallback& callback, | 196 void PendingBoolAndErrorCallback(const BoolAndErrorCallback& callback, |
196 bool found, | 197 bool found, |
197 CacheStorageError error); | 198 CacheStorageError error); |
198 void PendingCacheAndErrorCallback(const CacheAndErrorCallback& callback, | 199 void PendingCacheAndErrorCallback(const CacheAndErrorCallback& callback, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 GURL origin_; | 247 GURL origin_; |
247 | 248 |
248 base::WeakPtrFactory<CacheStorage> weak_factory_; | 249 base::WeakPtrFactory<CacheStorage> weak_factory_; |
249 | 250 |
250 DISALLOW_COPY_AND_ASSIGN(CacheStorage); | 251 DISALLOW_COPY_AND_ASSIGN(CacheStorage); |
251 }; | 252 }; |
252 | 253 |
253 } // namespace content | 254 } // namespace content |
254 | 255 |
255 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_H_ | 256 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_H_ |
OLD | NEW |