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..3c6acf16a04dcd74b477437400f1a2a17ba1454e 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 { |
@@ -19,7 +21,8 @@ namespace content { |
class ServiceWorkerFetchStore; |
-// The set of stores for a given ServiceWorker. It is owned by the |
+// TODO(jkarlin): Constrain the total bytes used per origin. |
+// The set of stores for a given origin. It is owned by the |
// ServiceWorkerFetchStoresManager. Provided callbacks are called on the |
// |callback_loop| provided in the constructor. |
class ServiceWorkerFetchStores { |
@@ -29,11 +32,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 +43,57 @@ 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 |
+ // 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. |
+ void InitializeStoreCallback(const ServiceWorkerFetchStore* store, |
+ const StoreAndErrorCallback& callback, |
+ bool success); |
+ |
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); |
+ |
+ bool initialized_; |
+ StoreMap store_map_; |
+ NameMap name_map_; |
base::FilePath origin_path_; |
- BackendType backend_type_; |
scoped_refptr<base::MessageLoopProxy> callback_loop_; |
+ scoped_ptr<StoresLoader> stores_loader_; |
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchStores); |
}; |