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 24 matching lines...) Expand all Loading... |
35 class CONTENT_EXPORT ServiceWorkerCacheStorage { | 35 class CONTENT_EXPORT ServiceWorkerCacheStorage { |
36 public: | 36 public: |
37 enum CacheStorageError { | 37 enum CacheStorageError { |
38 CACHE_STORAGE_ERROR_NO_ERROR, | 38 CACHE_STORAGE_ERROR_NO_ERROR, |
39 CACHE_STORAGE_ERROR_NOT_IMPLEMENTED, | 39 CACHE_STORAGE_ERROR_NOT_IMPLEMENTED, |
40 CACHE_STORAGE_ERROR_NOT_FOUND, | 40 CACHE_STORAGE_ERROR_NOT_FOUND, |
41 CACHE_STORAGE_ERROR_EXISTS, | 41 CACHE_STORAGE_ERROR_EXISTS, |
42 CACHE_STORAGE_ERROR_STORAGE, | 42 CACHE_STORAGE_ERROR_STORAGE, |
43 CACHE_STORAGE_ERROR_CLOSING | 43 CACHE_STORAGE_ERROR_CLOSING |
44 }; | 44 }; |
45 | 45 typedef std::vector<std::string> StringVector; |
46 typedef base::Callback<void(bool, CacheStorageError)> BoolAndErrorCallback; | 46 typedef base::Callback<void(bool, CacheStorageError)> BoolAndErrorCallback; |
47 typedef base::Callback<void(const scoped_refptr<ServiceWorkerCache>&, | 47 typedef base::Callback<void(const scoped_refptr<ServiceWorkerCache>&, |
48 CacheStorageError)> CacheAndErrorCallback; | 48 CacheStorageError)> CacheAndErrorCallback; |
49 typedef base::Callback<void(const std::vector<std::string>&, | 49 typedef base::Callback<void(const StringVector&, CacheStorageError)> |
50 CacheStorageError)> StringsAndErrorCallback; | 50 StringsAndErrorCallback; |
51 | 51 |
52 ServiceWorkerCacheStorage( | 52 ServiceWorkerCacheStorage( |
53 const base::FilePath& origin_path, | 53 const base::FilePath& origin_path, |
54 bool memory_only, | 54 bool memory_only, |
55 base::SequencedTaskRunner* cache_task_runner, | 55 base::SequencedTaskRunner* cache_task_runner, |
56 net::URLRequestContext* request_context, | 56 net::URLRequestContext* request_context, |
57 base::WeakPtr<storage::BlobStorageContext> blob_context); | 57 base::WeakPtr<storage::BlobStorageContext> blob_context); |
58 | 58 |
59 virtual ~ServiceWorkerCacheStorage(); | 59 virtual ~ServiceWorkerCacheStorage(); |
60 | 60 |
(...skipping 27 matching lines...) Expand all Loading... |
88 class SimpleCacheLoader; | 88 class SimpleCacheLoader; |
89 class CacheLoader; | 89 class CacheLoader; |
90 | 90 |
91 typedef std::map<std::string, base::WeakPtr<ServiceWorkerCache> > CacheMap; | 91 typedef std::map<std::string, base::WeakPtr<ServiceWorkerCache> > CacheMap; |
92 | 92 |
93 // Return a ServiceWorkerCache for the given name if the name is known. If the | 93 // Return a ServiceWorkerCache for the given name if the name is known. If the |
94 // ServiceWorkerCache has been deleted, creates a new one. | 94 // ServiceWorkerCache has been deleted, creates a new one. |
95 scoped_refptr<ServiceWorkerCache> GetLoadedCache( | 95 scoped_refptr<ServiceWorkerCache> GetLoadedCache( |
96 const std::string& cache_name); | 96 const std::string& cache_name); |
97 | 97 |
98 // Initializer and its callback are below. | 98 // Initializer and its callback are below. While LazyInit is running any new |
| 99 // operations will be queued and started in order after initialization. |
99 void LazyInit(const base::Closure& closure); | 100 void LazyInit(const base::Closure& closure); |
100 void LazyInitDidLoadIndex( | 101 void LazyInitDidLoadIndex( |
101 const base::Closure& callback, | 102 const base::Closure& callback, |
102 scoped_ptr<std::vector<std::string> > indexed_cache_names); | 103 scoped_ptr<std::vector<std::string> > indexed_cache_names); |
103 | 104 |
104 void AddCacheToMap(const std::string& cache_name, | 105 void AddCacheToMap(const std::string& cache_name, |
105 base::WeakPtr<ServiceWorkerCache> cache); | 106 base::WeakPtr<ServiceWorkerCache> cache); |
106 | 107 |
107 // The CreateCache callbacks are below. | 108 // The CreateCache callbacks are below. |
108 void CreateCacheDidCreateCache( | 109 void CreateCacheDidCreateCache( |
(...skipping 13 matching lines...) Expand all Loading... |
122 | 123 |
123 // Whether or not we've loaded the list of cache names into memory. | 124 // Whether or not we've loaded the list of cache names into memory. |
124 bool initialized_; | 125 bool initialized_; |
125 | 126 |
126 // The list of operations waiting on initialization. | 127 // The list of operations waiting on initialization. |
127 std::vector<base::Closure> init_callbacks_; | 128 std::vector<base::Closure> init_callbacks_; |
128 | 129 |
129 // The map of cache names to ServiceWorkerCache objects. | 130 // The map of cache names to ServiceWorkerCache objects. |
130 CacheMap cache_map_; | 131 CacheMap cache_map_; |
131 | 132 |
| 133 // The names of caches in the order that they were created. |
| 134 StringVector ordered_cache_names_; |
| 135 |
132 // The file path for this CacheStorage. | 136 // The file path for this CacheStorage. |
133 base::FilePath origin_path_; | 137 base::FilePath origin_path_; |
134 | 138 |
135 // The TaskRunner to run file IO on. | 139 // The TaskRunner to run file IO on. |
136 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_; | 140 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_; |
137 | 141 |
138 // Whether or not to store data in disk or memory. | 142 // Whether or not to store data in disk or memory. |
139 bool memory_only_; | 143 bool memory_only_; |
140 | 144 |
141 // Performs backend specific operations (memory vs disk). | 145 // Performs backend specific operations (memory vs disk). |
142 scoped_ptr<CacheLoader> cache_loader_; | 146 scoped_ptr<CacheLoader> cache_loader_; |
143 | 147 |
144 base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_; | 148 base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_; |
145 | 149 |
146 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage); | 150 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage); |
147 }; | 151 }; |
148 | 152 |
149 } // namespace content | 153 } // namespace content |
150 | 154 |
151 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ | 155 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ |
OLD | NEW |