| 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 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/id_map.h" | 13 #include "base/id_map.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class SequencedTaskRunner; | 17 class SequencedTaskRunner; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace net { |
| 21 class URLRequestContext; |
| 22 } |
| 23 |
| 20 namespace content { | 24 namespace content { |
| 25 class ChromeBlobStorageContext; |
| 21 class ServiceWorkerCache; | 26 class ServiceWorkerCache; |
| 22 | 27 |
| 23 // TODO(jkarlin): Constrain the total bytes used per origin. | 28 // TODO(jkarlin): Constrain the total bytes used per origin. |
| 24 | 29 |
| 25 // ServiceWorkerCacheStorage holds the set of caches for a given origin. It is | 30 // ServiceWorkerCacheStorage holds the set of caches for a given origin. It is |
| 26 // owned by the ServiceWorkerCacheStorageManager. This class expects to be run | 31 // owned by the ServiceWorkerCacheStorageManager. This class expects to be run |
| 27 // on the IO thread. | 32 // on the IO thread. |
| 28 class ServiceWorkerCacheStorage { | 33 class ServiceWorkerCacheStorage { |
| 29 public: | 34 public: |
| 30 enum CacheStorageError { | 35 enum CacheStorageError { |
| 31 CACHE_STORAGE_ERROR_NO_ERROR, | 36 CACHE_STORAGE_ERROR_NO_ERROR, |
| 32 CACHE_STORAGE_ERROR_NOT_IMPLEMENTED, | 37 CACHE_STORAGE_ERROR_NOT_IMPLEMENTED, |
| 33 CACHE_STORAGE_ERROR_NOT_FOUND, | 38 CACHE_STORAGE_ERROR_NOT_FOUND, |
| 34 CACHE_STORAGE_ERROR_EXISTS, | 39 CACHE_STORAGE_ERROR_EXISTS, |
| 35 CACHE_STORAGE_ERROR_STORAGE, | 40 CACHE_STORAGE_ERROR_STORAGE, |
| 36 CACHE_STORAGE_ERROR_EMPTY_KEY, | 41 CACHE_STORAGE_ERROR_EMPTY_KEY, |
| 37 }; | 42 }; |
| 38 | 43 |
| 39 typedef base::Callback<void(bool, CacheStorageError)> BoolAndErrorCallback; | 44 typedef base::Callback<void(bool, CacheStorageError)> BoolAndErrorCallback; |
| 40 typedef base::Callback<void(int, CacheStorageError)> CacheAndErrorCallback; | 45 typedef base::Callback<void(int, CacheStorageError)> CacheAndErrorCallback; |
| 41 typedef base::Callback<void(const std::vector<std::string>&, | 46 typedef base::Callback<void(const std::vector<std::string>&, |
| 42 CacheStorageError)> StringsAndErrorCallback; | 47 CacheStorageError)> StringsAndErrorCallback; |
| 43 | 48 |
| 44 ServiceWorkerCacheStorage(const base::FilePath& origin_path, | 49 ServiceWorkerCacheStorage(const base::FilePath& origin_path, |
| 45 bool memory_only, | 50 bool memory_only, |
| 46 base::SequencedTaskRunner* cache_task_runner); | 51 base::SequencedTaskRunner* cache_task_runner, |
| 52 net::URLRequestContext* request_context, |
| 53 ChromeBlobStorageContext* blob_context); |
| 47 | 54 |
| 48 virtual ~ServiceWorkerCacheStorage(); | 55 virtual ~ServiceWorkerCacheStorage(); |
| 49 | 56 |
| 50 // Create a ServiceWorkerCache if it doesn't already exist and call the | 57 // Create a ServiceWorkerCache if it doesn't already exist and call the |
| 51 // callback with the cache's id. If it already | 58 // callback with the cache's id. If it already |
| 52 // exists the callback is called with CACHE_STORAGE_ERROR_EXISTS. | 59 // exists the callback is called with CACHE_STORAGE_ERROR_EXISTS. |
| 53 void CreateCache(const std::string& cache_name, | 60 void CreateCache(const std::string& cache_name, |
| 54 const CacheAndErrorCallback& callback); | 61 const CacheAndErrorCallback& callback); |
| 55 | 62 |
| 56 // Get the cache id for the given key. If not found returns | 63 // Get the cache id for the given key. If not found returns |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 scoped_refptr<CacheLoader> cache_loader_; | 146 scoped_refptr<CacheLoader> cache_loader_; |
| 140 | 147 |
| 141 base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_; | 148 base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_; |
| 142 | 149 |
| 143 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage); | 150 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage); |
| 144 }; | 151 }; |
| 145 | 152 |
| 146 } // namespace content | 153 } // namespace content |
| 147 | 154 |
| 148 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ | 155 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_ |
| OLD | NEW |