Chromium Code Reviews| Index: content/browser/service_worker/service_worker_fetch_stores.h |
| diff --git a/content/browser/service_worker/service_worker_fetch_stores.h b/content/browser/service_worker/service_worker_fetch_stores.h |
| index c5be0a8eabdfd288db602fa354b25c7d97fb1599..cfdcf551cf29ea6b1478eb826333712afe73707a 100644 |
| --- a/content/browser/service_worker/service_worker_fetch_stores.h |
| +++ b/content/browser/service_worker/service_worker_fetch_stores.h |
| @@ -5,10 +5,12 @@ |
| #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORES_H_ |
| #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORES_H_ |
| +#include <map> |
| #include <string> |
| #include "base/callback.h" |
| #include "base/files/file_path.h" |
| +#include "base/id_map.h" |
| #include "base/threading/thread_checker.h" |
| namespace base { |
| @@ -29,11 +31,10 @@ class ServiceWorkerFetchStores { |
| FETCH_STORES_ERROR_NOT_IMPLEMENTED, |
| FETCH_STORES_ERROR_NOT_FOUND, |
| FETCH_STORES_ERROR_EXISTS, |
| - FETCH_STORES_ERROR_STORAGE |
| + FETCH_STORES_ERROR_STORAGE, |
| + FETCH_STORES_ERROR_EMPTY_KEY, |
| }; |
| - enum BackendType { BACKEND_TYPE_SIMPLE_CACHE, BACKEND_TYPE_MEMORY }; |
| - |
| typedef base::Callback<void(bool, FetchStoresError)> BoolAndErrorCallback; |
| typedef base::Callback<void(int, FetchStoresError)> StoreAndErrorCallback; |
| typedef base::Callback<void(const std::vector<std::string>&, |
| @@ -41,22 +42,52 @@ class ServiceWorkerFetchStores { |
| ServiceWorkerFetchStores( |
| const base::FilePath& origin_path, |
| - BackendType backend, |
| + bool memory_only, |
| const scoped_refptr<base::MessageLoopProxy>& callback_loop); |
| virtual ~ServiceWorkerFetchStores(); |
| + // Create a ServiceWorkerFetchStore if it doesn't already exist and call the |
| + // callback with the cache's id. If it already |
| + // exists the callback is called with FETCH_STORES_ERROR_EXISTS. |
| void CreateStore(const std::string& key, |
| const StoreAndErrorCallback& callback); |
| + |
| + // Get the cache id for the given key. If not found returns |
|
michaeln
2014/08/05 23:34:30
nit: extra space after the first sentence
jkarlin
2014/08/06 18:56:00
Done.
|
| + // FETCH_STORES_ERROR_NOT_FOUND. |
| void Get(const std::string& key, const StoreAndErrorCallback& callback); |
| - void Has(const std::string& key, const BoolAndErrorCallback& callback) const; |
| - void Delete(const std::string& key, const StoreAndErrorCallback& callback); |
| - void Keys(const StringsAndErrorCallback& callback) const; |
| + |
| + // Calls the callback with whether or not the cache exists. |
| + void Has(const std::string& key, const BoolAndErrorCallback& callback); |
| + |
| + // Deletes the cache if it exists. If it doesn't exist, |
| + // FETCH_STORES_ERROR_NOT_FOUND is returned. |
| + void Delete(const std::string& key, const BoolAndErrorCallback& callback); |
| + |
| + // Calls the callback with a vector of cache names (keys) available. |
| + void Keys(const StringsAndErrorCallback& callback); |
| + |
| // TODO(jkarlin): Add match() function. |
| private: |
| + class MemoryLoader; |
| + class SimpleCacheLoader; |
| + class StoresLoader; |
| + |
| + typedef IDMap<ServiceWorkerFetchStore, IDMapOwnPointer> StoreMap; |
| + typedef StoreMap::KeyType StoreID; |
| + typedef std::map<std::string, StoreID> NameMap; |
| + |
| + ServiceWorkerFetchStore* GetLoadedStore(const std::string& key) const; |
| + |
| + void LazyInit(); |
| + void InitStore(ServiceWorkerFetchStore* store); |
| + |
| + StoreMap loaded_store_ids_; |
|
michaeln
2014/08/05 23:34:30
i think the name of this data member is misleading
jkarlin
2014/08/06 18:56:00
Done.
|
| + NameMap loaded_store_names_; |
| + bool initialized_; |
| base::FilePath origin_path_; |
| - BackendType backend_type_; |
| scoped_refptr<base::MessageLoopProxy> callback_loop_; |
| + scoped_ptr<StoresLoader> stores_loader_; |
| DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchStores); |
| }; |