Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1047)

Unified Diff: content/browser/service_worker/service_worker_fetch_stores.h

Issue 424863002: Fill in some of ServiceWorkerFetchStores. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cache_storage
Patch Set: Updated license Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..84798dc462fb93c4508ea5c04e79617784396f8d 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,60 @@ class ServiceWorkerFetchStores {
ServiceWorkerFetchStores(
const base::FilePath& origin_path,
- BackendType backend,
+ bool memory_only,
const scoped_refptr<base::MessageLoopProxy>& callback_loop);
+
virtual ~ServiceWorkerFetchStores();
- void CreateStore(const std::string& key,
+ // 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& store_name,
const StoreAndErrorCallback& callback);
- 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;
+
+ // Get the cache id for the given key. If not found returns
+ // FETCH_STORES_ERROR_NOT_FOUND.
+ void GetStore(const std::string& store_name,
+ const StoreAndErrorCallback& callback);
+
+ // Calls the callback with whether or not the cache exists.
+ void HasStore(const std::string& store_name,
+ const BoolAndErrorCallback& callback);
+
+ // Deletes the cache if it exists. If it doesn't exist,
+ // FETCH_STORES_ERROR_NOT_FOUND is returned.
+ void DeleteStore(const std::string& store_name,
+ const BoolAndErrorCallback& callback);
+
+ // Calls the callback with a vector of cache names (keys) available.
+ void EnumerateStores(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);
};

Powered by Google App Engine
This is Rietveld 408576698