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