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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 CACHE_STORAGE_ERROR_STORAGE, | 42 CACHE_STORAGE_ERROR_STORAGE, |
43 CACHE_STORAGE_ERROR_CLOSING | 43 CACHE_STORAGE_ERROR_CLOSING |
44 }; | 44 }; |
45 typedef std::vector<std::string> StringVector; | 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 StringVector&, CacheStorageError)> | 49 typedef base::Callback<void(const StringVector&, CacheStorageError)> |
50 StringsAndErrorCallback; | 50 StringsAndErrorCallback; |
51 | 51 |
52 static const char kIndexFileName[]; | |
53 | |
54 ServiceWorkerCacheStorage( | 52 ServiceWorkerCacheStorage( |
55 const base::FilePath& origin_path, | 53 const base::FilePath& origin_path, |
56 bool memory_only, | 54 bool memory_only, |
57 base::SequencedTaskRunner* cache_task_runner, | 55 base::SequencedTaskRunner* cache_task_runner, |
58 net::URLRequestContext* request_context, | 56 net::URLRequestContext* request_context, |
59 base::WeakPtr<storage::BlobStorageContext> blob_context, | 57 base::WeakPtr<storage::BlobStorageContext> blob_context); |
60 const GURL& origin); | |
61 | 58 |
62 // Any unfinished asynchronous operations may not complete or call their | |
63 // callbacks. | |
64 virtual ~ServiceWorkerCacheStorage(); | 59 virtual ~ServiceWorkerCacheStorage(); |
65 | 60 |
66 // Create a ServiceWorkerCache if it doesn't already exist and call the | 61 // Create a ServiceWorkerCache if it doesn't already exist and call the |
67 // callback with the cache. If it already | 62 // callback with the cache. If it already |
68 // exists the callback is called with CACHE_STORAGE_ERROR_EXISTS. | 63 // exists the callback is called with CACHE_STORAGE_ERROR_EXISTS. |
69 void CreateCache(const std::string& cache_name, | 64 void CreateCache(const std::string& cache_name, |
70 const CacheAndErrorCallback& callback); | 65 const CacheAndErrorCallback& callback); |
71 | 66 |
72 // Get the cache for the given key. If not found returns | 67 // Get the cache for the given key. If not found returns |
73 // CACHE_STORAGE_ERROR_NOT_FOUND. | 68 // CACHE_STORAGE_ERROR_NOT_FOUND. |
(...skipping 12 matching lines...) Expand all Loading... |
86 // Deletes the cache if it exists. If it doesn't exist, | 81 // Deletes the cache if it exists. If it doesn't exist, |
87 // CACHE_STORAGE_ERROR_NOT_FOUND is returned. | 82 // CACHE_STORAGE_ERROR_NOT_FOUND is returned. |
88 void DeleteCache(const std::string& cache_name, | 83 void DeleteCache(const std::string& cache_name, |
89 const BoolAndErrorCallback& callback); | 84 const BoolAndErrorCallback& callback); |
90 | 85 |
91 // Calls the callback with a vector of cache names (keys) available. | 86 // Calls the callback with a vector of cache names (keys) available. |
92 void EnumerateCaches(const StringsAndErrorCallback& callback); | 87 void EnumerateCaches(const StringsAndErrorCallback& callback); |
93 | 88 |
94 // TODO(jkarlin): Add match() function. | 89 // TODO(jkarlin): Add match() function. |
95 | 90 |
96 void CloseAllCaches(); | |
97 | |
98 private: | 91 private: |
99 class MemoryLoader; | 92 class MemoryLoader; |
100 class SimpleCacheLoader; | 93 class SimpleCacheLoader; |
101 class CacheLoader; | 94 class CacheLoader; |
102 | 95 |
103 typedef std::map<std::string, base::WeakPtr<ServiceWorkerCache> > CacheMap; | 96 typedef std::map<std::string, base::WeakPtr<ServiceWorkerCache> > CacheMap; |
104 | 97 |
105 // Return a ServiceWorkerCache for the given name if the name is known. If the | 98 // Return a ServiceWorkerCache for the given name if the name is known. If the |
106 // ServiceWorkerCache has been deleted, creates a new one. | 99 // ServiceWorkerCache has been deleted, creates a new one. |
107 scoped_refptr<ServiceWorkerCache> GetLoadedCache( | 100 scoped_refptr<ServiceWorkerCache> GetLoadedCache( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 scoped_ptr<CacheLoader> cache_loader_; | 151 scoped_ptr<CacheLoader> cache_loader_; |
159 | 152 |
160 base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_; | 153 base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_; |
161 | 154 |
162 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage); | 155 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage); |
163 }; | 156 }; |
164 | 157 |
165 } // namespace content | 158 } // namespace content |
166 | 159 |
167 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ | 160 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ |
OLD | NEW |