| 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 <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 namespace content { | 28 namespace content { |
| 29 class CacheStorageScheduler; | 29 class CacheStorageScheduler; |
| 30 | 30 |
| 31 // TODO(jkarlin): Constrain the total bytes used per origin. | 31 // TODO(jkarlin): Constrain the total bytes used per origin. |
| 32 | 32 |
| 33 // CacheStorage holds the set of caches for a given origin. It is | 33 // CacheStorage holds the set of caches for a given origin. It is |
| 34 // owned by the CacheStorageManager. This class expects to be run | 34 // owned by the CacheStorageManager. This class expects to be run |
| 35 // on the IO thread. The asynchronous methods are executed serially. | 35 // on the IO thread. The asynchronous methods are executed serially. |
| 36 class CONTENT_EXPORT CacheStorage { | 36 class CONTENT_EXPORT CacheStorage { |
| 37 public: | 37 public: |
| 38 enum CacheStorageError { | |
| 39 CACHE_STORAGE_ERROR_NO_ERROR, | |
| 40 CACHE_STORAGE_ERROR_NOT_IMPLEMENTED, | |
| 41 CACHE_STORAGE_ERROR_NOT_FOUND, | |
| 42 CACHE_STORAGE_ERROR_EXISTS, | |
| 43 CACHE_STORAGE_ERROR_STORAGE, | |
| 44 CACHE_STORAGE_ERROR_CLOSING | |
| 45 }; | |
| 46 typedef std::vector<std::string> StringVector; | 38 typedef std::vector<std::string> StringVector; |
| 47 typedef base::Callback<void(bool, CacheStorageError)> BoolAndErrorCallback; | 39 typedef base::Callback<void(bool, CacheStorageError)> BoolAndErrorCallback; |
| 48 typedef base::Callback<void(const scoped_refptr<CacheStorageCache>&, | 40 typedef base::Callback<void(const scoped_refptr<CacheStorageCache>&, |
| 49 CacheStorageError)> CacheAndErrorCallback; | 41 CacheStorageError)> CacheAndErrorCallback; |
| 50 typedef base::Callback<void(const StringVector&, CacheStorageError)> | 42 typedef base::Callback<void(const StringVector&, CacheStorageError)> |
| 51 StringsAndErrorCallback; | 43 StringsAndErrorCallback; |
| 52 | 44 |
| 53 static const char kIndexFileName[]; | 45 static const char kIndexFileName[]; |
| 54 | 46 |
| 55 CacheStorage( | 47 CacheStorage( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 84 | 76 |
| 85 // Calls match on the cache with the given |cache_name|. | 77 // Calls match on the cache with the given |cache_name|. |
| 86 void MatchCache(const std::string& cache_name, | 78 void MatchCache(const std::string& cache_name, |
| 87 scoped_ptr<ServiceWorkerFetchRequest> request, | 79 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 88 const CacheStorageCache::ResponseCallback& callback); | 80 const CacheStorageCache::ResponseCallback& callback); |
| 89 | 81 |
| 90 // Calls match on all of the caches in parallel, calling |callback| with the | 82 // Calls match on all of the caches in parallel, calling |callback| with the |
| 91 // first response found. Note that if multiple caches have the same | 83 // first response found. Note that if multiple caches have the same |
| 92 // request/response then it is not defined which cache's response will be | 84 // request/response then it is not defined which cache's response will be |
| 93 // returned. If no response is found then |callback| is called with | 85 // returned. If no response is found then |callback| is called with |
| 94 // CacheStorageCache::ErrorTypeNotFound. | 86 // CACHE_STORAGE_ERROR_NOT_FOUND. |
| 95 void MatchAllCaches(scoped_ptr<ServiceWorkerFetchRequest> request, | 87 void MatchAllCaches(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 96 const CacheStorageCache::ResponseCallback& callback); | 88 const CacheStorageCache::ResponseCallback& callback); |
| 97 | 89 |
| 98 // Calls close on each cache and runs the callback after all of them have | 90 // Calls close on each cache and runs the callback after all of them have |
| 99 // closed. | 91 // closed. |
| 100 void CloseAllCaches(const base::Closure& callback); | 92 void CloseAllCaches(const base::Closure& callback); |
| 101 | 93 |
| 102 // The size of all of the origin's contents in memory. Returns 0 if the cache | 94 // The size of all of the origin's contents in memory. Returns 0 if the cache |
| 103 // backend is not a memory backend. Runs synchronously. | 95 // backend is not a memory backend. Runs synchronously. |
| 104 int64 MemoryBackedSize() const; | 96 int64 MemoryBackedSize() const; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 148 |
| 157 // The EnumerateCache callbacks are below. | 149 // The EnumerateCache callbacks are below. |
| 158 void EnumerateCachesImpl(const StringsAndErrorCallback& callback); | 150 void EnumerateCachesImpl(const StringsAndErrorCallback& callback); |
| 159 | 151 |
| 160 // The MatchCache callbacks are below. | 152 // The MatchCache callbacks are below. |
| 161 void MatchCacheImpl(const std::string& cache_name, | 153 void MatchCacheImpl(const std::string& cache_name, |
| 162 scoped_ptr<ServiceWorkerFetchRequest> request, | 154 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 163 const CacheStorageCache::ResponseCallback& callback); | 155 const CacheStorageCache::ResponseCallback& callback); |
| 164 void MatchCacheDidMatch(const scoped_refptr<CacheStorageCache>& cache, | 156 void MatchCacheDidMatch(const scoped_refptr<CacheStorageCache>& cache, |
| 165 const CacheStorageCache::ResponseCallback& callback, | 157 const CacheStorageCache::ResponseCallback& callback, |
| 166 CacheStorageCache::ErrorType error, | 158 CacheStorageError error, |
| 167 scoped_ptr<ServiceWorkerResponse> response, | 159 scoped_ptr<ServiceWorkerResponse> response, |
| 168 scoped_ptr<storage::BlobDataHandle> handle); | 160 scoped_ptr<storage::BlobDataHandle> handle); |
| 169 | 161 |
| 170 // The MatchAllCaches callbacks are below. | 162 // The MatchAllCaches callbacks are below. |
| 171 void MatchAllCachesImpl(scoped_ptr<ServiceWorkerFetchRequest> request, | 163 void MatchAllCachesImpl(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 172 const CacheStorageCache::ResponseCallback& callback); | 164 const CacheStorageCache::ResponseCallback& callback); |
| 173 void MatchAllCachesDidMatch(scoped_refptr<CacheStorageCache> cache, | 165 void MatchAllCachesDidMatch(scoped_refptr<CacheStorageCache> cache, |
| 174 const base::Closure& barrier_closure, | 166 const base::Closure& barrier_closure, |
| 175 CacheStorageCache::ResponseCallback* callback, | 167 CacheStorageCache::ResponseCallback* callback, |
| 176 CacheStorageCache::ErrorType error, | 168 CacheStorageError error, |
| 177 scoped_ptr<ServiceWorkerResponse> response, | 169 scoped_ptr<ServiceWorkerResponse> response, |
| 178 scoped_ptr<storage::BlobDataHandle> handle); | 170 scoped_ptr<storage::BlobDataHandle> handle); |
| 179 void MatchAllCachesDidMatchAll( | 171 void MatchAllCachesDidMatchAll( |
| 180 scoped_ptr<CacheStorageCache::ResponseCallback> callback); | 172 scoped_ptr<CacheStorageCache::ResponseCallback> callback); |
| 181 | 173 |
| 182 // The CloseAllCaches callbacks are below. | 174 // The CloseAllCaches callbacks are below. |
| 183 void CloseAllCachesImpl(const base::Closure& callback); | 175 void CloseAllCachesImpl(const base::Closure& callback); |
| 184 | 176 |
| 185 void PendingClosure(const base::Closure& callback); | 177 void PendingClosure(const base::Closure& callback); |
| 186 void PendingBoolAndErrorCallback(const BoolAndErrorCallback& callback, | 178 void PendingBoolAndErrorCallback(const BoolAndErrorCallback& callback, |
| 187 bool found, | 179 bool found, |
| 188 CacheStorageError error); | 180 CacheStorageError error); |
| 189 void PendingCacheAndErrorCallback( | 181 void PendingCacheAndErrorCallback( |
| 190 const CacheAndErrorCallback& callback, | 182 const CacheAndErrorCallback& callback, |
| 191 const scoped_refptr<CacheStorageCache>& cache, | 183 const scoped_refptr<CacheStorageCache>& cache, |
| 192 CacheStorageError error); | 184 CacheStorageError error); |
| 193 void PendingStringsAndErrorCallback(const StringsAndErrorCallback& callback, | 185 void PendingStringsAndErrorCallback(const StringsAndErrorCallback& callback, |
| 194 const StringVector& strings, | 186 const StringVector& strings, |
| 195 CacheStorageError error); | 187 CacheStorageError error); |
| 196 void PendingResponseCallback( | 188 void PendingResponseCallback( |
| 197 const CacheStorageCache::ResponseCallback& callback, | 189 const CacheStorageCache::ResponseCallback& callback, |
| 198 CacheStorageCache::ErrorType error, | 190 CacheStorageError error, |
| 199 scoped_ptr<ServiceWorkerResponse> response, | 191 scoped_ptr<ServiceWorkerResponse> response, |
| 200 scoped_ptr<storage::BlobDataHandle> blob_data_handle); | 192 scoped_ptr<storage::BlobDataHandle> blob_data_handle); |
| 201 | 193 |
| 202 // Whether or not we've loaded the list of cache names into memory. | 194 // Whether or not we've loaded the list of cache names into memory. |
| 203 bool initialized_; | 195 bool initialized_; |
| 204 bool initializing_; | 196 bool initializing_; |
| 205 | 197 |
| 206 // The pending operation scheduler. | 198 // The pending operation scheduler. |
| 207 scoped_ptr<CacheStorageScheduler> scheduler_; | 199 scoped_ptr<CacheStorageScheduler> scheduler_; |
| 208 | 200 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 225 scoped_ptr<CacheLoader> cache_loader_; | 217 scoped_ptr<CacheLoader> cache_loader_; |
| 226 | 218 |
| 227 base::WeakPtrFactory<CacheStorage> weak_factory_; | 219 base::WeakPtrFactory<CacheStorage> weak_factory_; |
| 228 | 220 |
| 229 DISALLOW_COPY_AND_ASSIGN(CacheStorage); | 221 DISALLOW_COPY_AND_ASSIGN(CacheStorage); |
| 230 }; | 222 }; |
| 231 | 223 |
| 232 } // namespace content | 224 } // namespace content |
| 233 | 225 |
| 234 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_H_ | 226 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_H_ |
| OLD | NEW |