| 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_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 class MemoryLoader; | 94 class MemoryLoader; |
| 95 class SimpleCacheLoader; | 95 class SimpleCacheLoader; |
| 96 class CacheLoader; | 96 class CacheLoader; |
| 97 struct CacheContext; | 97 struct CacheContext; |
| 98 | 98 |
| 99 typedef std::map<CacheID, CacheContext*> CacheMap; | 99 typedef std::map<CacheID, CacheContext*> CacheMap; |
| 100 typedef std::map<std::string, CacheID> NameMap; | 100 typedef std::map<std::string, CacheID> NameMap; |
| 101 | 101 |
| 102 // Scans the filesystem for stored caches and creates a CacheContext (without |
| 103 // instantiating a backend) for each. |
| 104 void LazyInit(const base::Closure& closure); |
| 105 |
| 102 CacheContext* GetLoadedCache(const std::string& cache_name) const; | 106 CacheContext* GetLoadedCache(const std::string& cache_name) const; |
| 107 CacheContext* AddCacheToMaps(const std::string& cache_name, |
| 108 scoped_ptr<ServiceWorkerCache> cache); |
| 103 | 109 |
| 104 // Initializer and its callback are below. | 110 // The initialization callbacks are below. |
| 105 void LazyInit(const base::Closure& closure); | |
| 106 static void LazyInitDidLoadIndex( | 111 static void LazyInitDidLoadIndex( |
| 107 const base::Closure& callback, | 112 const base::Closure& callback, |
| 108 base::WeakPtr<ServiceWorkerCacheStorage> storage, | 113 base::WeakPtr<ServiceWorkerCacheStorage> storage, |
| 109 scoped_ptr<std::vector<std::string> > indexed_cache_names); | 114 scoped_ptr<std::vector<std::string> > indexed_cache_names); |
| 110 static void LazyInitIterateAndLoadCacheName( | 115 static void LazyInitIterateAndLoadCacheName( |
| 111 const base::Closure& callback, | 116 const base::Closure& callback, |
| 112 base::WeakPtr<ServiceWorkerCacheStorage> storage, | 117 base::WeakPtr<ServiceWorkerCacheStorage> storage, |
| 113 scoped_ptr<std::vector<std::string> > indexed_cache_names, | 118 scoped_ptr<std::vector<std::string> > indexed_cache_names, |
| 114 const std::vector<std::string>::const_iterator& iter, | 119 const std::vector<std::string>::const_iterator& iter, |
| 115 const std::string& cache_name, | 120 const std::string& cache_name, |
| 116 scoped_ptr<ServiceWorkerCache> cache); | 121 scoped_ptr<ServiceWorkerCache> cache); |
| 117 static void LazyInitDone(base::WeakPtr<ServiceWorkerCacheStorage> storage); | 122 static void LazyInitDone(base::WeakPtr<ServiceWorkerCacheStorage> storage); |
| 118 | 123 |
| 119 static void DidCreateBackend(base::WeakPtr<ServiceWorkerCache> cache, | |
| 120 CacheID cache_id, | |
| 121 const CacheAndErrorCallback& callback, | |
| 122 ServiceWorkerCache::ErrorType error); | |
| 123 | |
| 124 CacheContext* AddCacheToMaps(const std::string& cache_name, | |
| 125 scoped_ptr<ServiceWorkerCache> cache); | |
| 126 | |
| 127 // The CreateCache callbacks are below. | 124 // The CreateCache callbacks are below. |
| 128 static void CreateCacheDidCreateCache( | 125 static void CreateCacheDidCreateCache( |
| 129 const std::string& cache_name, | 126 const std::string& cache_name, |
| 130 const CacheAndErrorCallback& callback, | 127 const CacheAndErrorCallback& callback, |
| 131 base::WeakPtr<ServiceWorkerCacheStorage> storage, | 128 base::WeakPtr<ServiceWorkerCacheStorage> storage, |
| 132 scoped_ptr<ServiceWorkerCache> cache); | 129 scoped_ptr<ServiceWorkerCache> cache); |
| 133 static void CreateCacheDidWriteIndex(const CacheAndErrorCallback& callback, | 130 static void CreateCacheDidWriteIndex(const CacheAndErrorCallback& callback, |
| 134 base::WeakPtr<ServiceWorkerCache> cache, | 131 base::WeakPtr<ServiceWorkerCache> cache, |
| 135 CacheID id, | 132 CacheID id, |
| 136 bool success); | 133 bool success); |
| 137 | 134 |
| 138 // The DeleteCache callbacks are below. | 135 // The DeleteCache callbacks are below. |
| 139 static void DeleteCacheDidWriteIndex( | 136 static void DeleteCacheDidWriteIndex( |
| 140 const std::string& cache_name, | 137 const std::string& cache_name, |
| 141 const BoolAndErrorCallback& callback, | 138 const BoolAndErrorCallback& callback, |
| 142 base::WeakPtr<ServiceWorkerCacheStorage> storage, | 139 base::WeakPtr<ServiceWorkerCacheStorage> storage, |
| 143 bool success); | 140 bool success); |
| 144 static void DeleteCacheDidCleanUp(const BoolAndErrorCallback& callback, | 141 static void DeleteCacheDidCleanUp(const BoolAndErrorCallback& callback, |
| 145 bool success); | 142 bool success); |
| 146 | 143 |
| 144 static void DidCreateBackend(base::WeakPtr<ServiceWorkerCache> cache, |
| 145 CacheID cache_id, |
| 146 const CacheAndErrorCallback& callback, |
| 147 ServiceWorkerCache::ErrorType error); |
| 148 |
| 147 // Whether or not we've loaded the list of cache names into memory. | 149 // Whether or not we've loaded the list of cache names into memory. |
| 148 bool initialized_; | 150 bool initialized_; |
| 149 | 151 |
| 150 // The list of operations waiting on initialization. | 152 // The list of operations waiting on initialization. |
| 151 std::vector<base::Closure> init_callbacks_; | 153 std::vector<base::Closure> init_callbacks_; |
| 152 | 154 |
| 153 // The map of CacheIDs to their CacheContext objects. Owns the CacheContext | 155 // The map of CacheIDs to their CacheContext objects. Owns the CacheContext |
| 154 // object. The CacheIDs are used by JavaScript to reference a | 156 // object. The CacheIDs are used by JavaScript to reference a |
| 155 // ServiceWorkerCache. | 157 // ServiceWorkerCache. |
| 156 CacheMap cache_map_; | 158 CacheMap cache_map_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 169 scoped_refptr<CacheLoader> cache_loader_; | 171 scoped_refptr<CacheLoader> cache_loader_; |
| 170 | 172 |
| 171 base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_; | 173 base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_; |
| 172 | 174 |
| 173 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage); | 175 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage); |
| 174 }; | 176 }; |
| 175 | 177 |
| 176 } // namespace content | 178 } // namespace content |
| 177 | 179 |
| 178 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ | 180 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ |
| OLD | NEW |