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 |
52 ServiceWorkerCacheStorage( | 54 ServiceWorkerCacheStorage( |
53 const base::FilePath& origin_path, | 55 const base::FilePath& origin_path, |
54 bool memory_only, | 56 bool memory_only, |
55 base::SequencedTaskRunner* cache_task_runner, | 57 base::SequencedTaskRunner* cache_task_runner, |
56 net::URLRequestContext* request_context, | 58 net::URLRequestContext* request_context, |
57 base::WeakPtr<storage::BlobStorageContext> blob_context); | 59 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 60 const GURL& origin); |
58 | 61 |
| 62 // Any unfinished asynchronous operations may not complete or call their |
| 63 // callbacks. |
59 virtual ~ServiceWorkerCacheStorage(); | 64 virtual ~ServiceWorkerCacheStorage(); |
60 | 65 |
61 // Get the cache for the given key. If the cache is not found it is | 66 // Get the cache for the given key. If the cache is not found it is |
62 // created. | 67 // created. |
63 void OpenCache(const std::string& cache_name, | 68 void OpenCache(const std::string& cache_name, |
64 const CacheAndErrorCallback& callback); | 69 const CacheAndErrorCallback& callback); |
65 | 70 |
66 // Calls the callback with whether or not the cache exists. | 71 // Calls the callback with whether or not the cache exists. |
67 void HasCache(const std::string& cache_name, | 72 void HasCache(const std::string& cache_name, |
68 const BoolAndErrorCallback& callback); | 73 const BoolAndErrorCallback& callback); |
69 | 74 |
70 // Deletes the cache if it exists. If it doesn't exist, | 75 // Deletes the cache if it exists. If it doesn't exist, |
71 // CACHE_STORAGE_ERROR_NOT_FOUND is returned. | 76 // CACHE_STORAGE_ERROR_NOT_FOUND is returned. |
72 void DeleteCache(const std::string& cache_name, | 77 void DeleteCache(const std::string& cache_name, |
73 const BoolAndErrorCallback& callback); | 78 const BoolAndErrorCallback& callback); |
74 | 79 |
75 // Calls the callback with a vector of cache names (keys) available. | 80 // Calls the callback with a vector of cache names (keys) available. |
76 void EnumerateCaches(const StringsAndErrorCallback& callback); | 81 void EnumerateCaches(const StringsAndErrorCallback& callback); |
77 | 82 |
78 // TODO(jkarlin): Add match() function. | 83 // TODO(jkarlin): Add match() function. |
79 | 84 |
| 85 void CloseAllCaches(); |
| 86 |
80 private: | 87 private: |
81 class MemoryLoader; | 88 class MemoryLoader; |
82 class SimpleCacheLoader; | 89 class SimpleCacheLoader; |
83 class CacheLoader; | 90 class CacheLoader; |
84 | 91 |
85 typedef std::map<std::string, base::WeakPtr<ServiceWorkerCache> > CacheMap; | 92 typedef std::map<std::string, base::WeakPtr<ServiceWorkerCache> > CacheMap; |
86 | 93 |
87 // Return a ServiceWorkerCache for the given name if the name is known. If the | 94 // Return a ServiceWorkerCache for the given name if the name is known. If the |
88 // ServiceWorkerCache has been deleted, creates a new one. | 95 // ServiceWorkerCache has been deleted, creates a new one. |
89 scoped_refptr<ServiceWorkerCache> GetLoadedCache( | 96 scoped_refptr<ServiceWorkerCache> GetLoadedCache( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 scoped_ptr<CacheLoader> cache_loader_; | 147 scoped_ptr<CacheLoader> cache_loader_; |
141 | 148 |
142 base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_; | 149 base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_; |
143 | 150 |
144 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage); | 151 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage); |
145 }; | 152 }; |
146 | 153 |
147 } // namespace content | 154 } // namespace content |
148 | 155 |
149 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ | 156 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ |
OLD | NEW |