| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 void Size(const SizeCallback& callback); | 105 void Size(const SizeCallback& callback); |
| 106 | 106 |
| 107 // The functions below are for tests to verify that the operations run | 107 // The functions below are for tests to verify that the operations run |
| 108 // serially. | 108 // serially. |
| 109 void StartAsyncOperationForTesting(); | 109 void StartAsyncOperationForTesting(); |
| 110 void CompleteAsyncOperationForTesting(); | 110 void CompleteAsyncOperationForTesting(); |
| 111 | 111 |
| 112 private: | 112 private: |
| 113 friend class CacheStorageCacheHandle; | 113 friend class CacheStorageCacheHandle; |
| 114 friend class CacheStorageCache; | 114 friend class CacheStorageCache; |
| 115 friend class TestCacheStorage; | |
| 116 class CacheLoader; | 115 class CacheLoader; |
| 117 class MemoryLoader; | 116 class MemoryLoader; |
| 118 class SimpleCacheLoader; | 117 class SimpleCacheLoader; |
| 119 struct CacheMatchResponse; | 118 struct CacheMatchResponse; |
| 120 | 119 |
| 121 typedef std::map<std::string, std::unique_ptr<CacheStorageCache>> CacheMap; | 120 typedef std::map<std::string, std::unique_ptr<CacheStorageCache>> CacheMap; |
| 122 | 121 |
| 123 // Functions for exposing handles to CacheStorageCache to clients. | 122 // Functions for exposing handles to CacheStorageCache to clients. |
| 124 std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle( | 123 std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle( |
| 125 CacheStorageCache* cache); | 124 CacheStorageCache* cache); |
| 126 void AddCacheHandleRef(CacheStorageCache* cache); | 125 void AddCacheHandleRef(CacheStorageCache* cache); |
| 127 void DropCacheHandleRef(CacheStorageCache* cache); | 126 void DropCacheHandleRef(CacheStorageCache* cache); |
| 128 | 127 |
| 129 // Returns a CacheStorageCacheHandle for the given name if the name is known. | 128 // Returns a CacheStorageCacheHandle for the given name if the name is known. |
| 130 // If the CacheStorageCache has been deleted, creates a new one. | 129 // If the CacheStorageCache has been deleted, creates a new one. |
| 131 std::unique_ptr<CacheStorageCacheHandle> GetLoadedCache( | 130 std::unique_ptr<CacheStorageCacheHandle> GetLoadedCache( |
| 132 const std::string& cache_name); | 131 const std::string& cache_name); |
| 133 | 132 |
| 134 // Holds a reference to a cache for a short period in case they're used again | |
| 135 // soon. | |
| 136 void TemporarilyPreserveCache( | |
| 137 std::unique_ptr<CacheStorageCacheHandle> cache_handle); | |
| 138 virtual void SchedulePreservedCacheRemoval( | |
| 139 const base::Closure& callback); // Virtual for testing. | |
| 140 void RemovePreservedCache(const CacheStorageCache* cache); | |
| 141 | |
| 142 // Initializer and its callback are below. | 133 // Initializer and its callback are below. |
| 143 void LazyInit(); | 134 void LazyInit(); |
| 144 void LazyInitImpl(); | 135 void LazyInitImpl(); |
| 145 void LazyInitDidLoadIndex( | 136 void LazyInitDidLoadIndex( |
| 146 std::unique_ptr<std::vector<std::string>> indexed_cache_names); | 137 std::unique_ptr<std::vector<std::string>> indexed_cache_names); |
| 147 | 138 |
| 148 // The Open and CreateCache callbacks are below. | 139 // The Open and CreateCache callbacks are below. |
| 149 void OpenCacheImpl(const std::string& cache_name, | 140 void OpenCacheImpl(const std::string& cache_name, |
| 150 const CacheAndErrorCallback& callback); | 141 const CacheAndErrorCallback& callback); |
| 151 void CreateCacheDidCreateCache(const std::string& cache_name, | 142 void CreateCacheDidCreateCache(const std::string& cache_name, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 244 |
| 254 // The file path for this CacheStorage. | 245 // The file path for this CacheStorage. |
| 255 base::FilePath origin_path_; | 246 base::FilePath origin_path_; |
| 256 | 247 |
| 257 // The TaskRunner to run file IO on. | 248 // The TaskRunner to run file IO on. |
| 258 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_; | 249 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_; |
| 259 | 250 |
| 260 // Performs backend specific operations (memory vs disk). | 251 // Performs backend specific operations (memory vs disk). |
| 261 std::unique_ptr<CacheLoader> cache_loader_; | 252 std::unique_ptr<CacheLoader> cache_loader_; |
| 262 | 253 |
| 263 // Holds handles to recently opened caches so that they can be reused | |
| 264 // without having to open the cache again. | |
| 265 std::map<const CacheStorageCache*, std::unique_ptr<CacheStorageCacheHandle>> | |
| 266 preserved_caches_; | |
| 267 | |
| 268 // The quota manager. | 254 // The quota manager. |
| 269 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; | 255 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
| 270 | 256 |
| 271 // The origin that this CacheStorage is associated with. | 257 // The origin that this CacheStorage is associated with. |
| 272 GURL origin_; | 258 GURL origin_; |
| 273 | 259 |
| 274 base::WeakPtrFactory<CacheStorage> weak_factory_; | 260 base::WeakPtrFactory<CacheStorage> weak_factory_; |
| 275 | 261 |
| 276 DISALLOW_COPY_AND_ASSIGN(CacheStorage); | 262 DISALLOW_COPY_AND_ASSIGN(CacheStorage); |
| 277 }; | 263 }; |
| 278 | 264 |
| 279 } // namespace content | 265 } // namespace content |
| 280 | 266 |
| 281 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_H_ | 267 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_H_ |
| OLD | NEW |