| Index: content/browser/service_worker/service_worker_cache_storage.h
|
| diff --git a/content/browser/service_worker/service_worker_cache_storage.h b/content/browser/service_worker/service_worker_cache_storage.h
|
| index 291d02958698ea56f71e610303ce06b9f0ef7e70..a518e7b855e5357dbb345aeecb79c5a785f4135d 100644
|
| --- a/content/browser/service_worker/service_worker_cache_storage.h
|
| +++ b/content/browser/service_worker/service_worker_cache_storage.h
|
| @@ -11,20 +11,20 @@
|
| #include "base/callback.h"
|
| #include "base/files/file_path.h"
|
| #include "base/id_map.h"
|
| -#include "base/threading/thread_checker.h"
|
| +#include "base/memory/weak_ptr.h"
|
|
|
| namespace base {
|
| -class MessageLoopProxy;
|
| +class SequencedTaskRunner;
|
| }
|
|
|
| namespace content {
|
| -
|
| class ServiceWorkerCache;
|
|
|
| // TODO(jkarlin): Constrain the total bytes used per origin.
|
| -// The set of caches for a given origin. It is owned by the
|
| -// ServiceWorkerCacheStorageManager. Provided callbacks are called on the
|
| -// |callback_loop| provided in the constructor.
|
| +
|
| +// ServiceWorkerCacheStorage holds the set of caches for a given origin. It is
|
| +// owned by the ServiceWorkerCacheStorageManager. This class expects to be run
|
| +// on the IO thread.
|
| class ServiceWorkerCacheStorage {
|
| public:
|
| enum CacheStorageError {
|
| @@ -41,10 +41,9 @@ class ServiceWorkerCacheStorage {
|
| typedef base::Callback<void(const std::vector<std::string>&,
|
| CacheStorageError)> StringsAndErrorCallback;
|
|
|
| - ServiceWorkerCacheStorage(
|
| - const base::FilePath& origin_path,
|
| - bool memory_only,
|
| - const scoped_refptr<base::MessageLoopProxy>& callback_loop);
|
| + ServiceWorkerCacheStorage(const base::FilePath& origin_path,
|
| + bool memory_only,
|
| + base::SequencedTaskRunner* cache_task_runner);
|
|
|
| virtual ~ServiceWorkerCacheStorage();
|
|
|
| @@ -73,10 +72,6 @@ class ServiceWorkerCacheStorage {
|
|
|
| // TODO(jkarlin): Add match() function.
|
|
|
| - void InitializeCacheCallback(const ServiceWorkerCache* cache,
|
| - const CacheAndErrorCallback& callback,
|
| - bool success);
|
| -
|
| private:
|
| class MemoryLoader;
|
| class SimpleCacheLoader;
|
| @@ -88,15 +83,62 @@ class ServiceWorkerCacheStorage {
|
|
|
| ServiceWorkerCache* GetLoadedCache(const std::string& cache_name) const;
|
|
|
| - void LazyInit();
|
| - void InitCache(ServiceWorkerCache* cache);
|
| -
|
| + // Initializer and its callback are below.
|
| + void LazyInit(const base::Closure& closure);
|
| + void LazyInitDidLoadIndex(
|
| + const base::Closure& callback,
|
| + scoped_ptr<std::vector<std::string> > indexed_cache_names);
|
| + void LazyInitIterateAndLoadCacheName(
|
| + const base::Closure& callback,
|
| + scoped_ptr<std::vector<std::string> > indexed_cache_names,
|
| + const std::vector<std::string>::const_iterator& iter,
|
| + scoped_ptr<ServiceWorkerCache> cache);
|
| + void LazyInitDone();
|
| +
|
| + void DidCreateBackend(base::WeakPtr<ServiceWorkerCache> cache,
|
| + const CacheAndErrorCallback& callback,
|
| + bool success);
|
| +
|
| + void AddCacheToMaps(scoped_ptr<ServiceWorkerCache> cache);
|
| +
|
| + // The CreateCache callbacks are below.
|
| + void CreateCacheDidCreateCache(const std::string& cache_name,
|
| + const CacheAndErrorCallback& callback,
|
| + scoped_ptr<ServiceWorkerCache> cache);
|
| + void CreateCacheDidWriteIndex(const CacheAndErrorCallback& callback,
|
| + base::WeakPtr<ServiceWorkerCache> cache,
|
| + bool success);
|
| +
|
| + // The DeleteCache callbacks are below.
|
| + void DeleteCacheDidWriteIndex(const std::string& cache_name,
|
| + const BoolAndErrorCallback& callback,
|
| + bool success);
|
| + void DeleteCacheDidCleanUp(const BoolAndErrorCallback& callback,
|
| + bool success);
|
| +
|
| + // Whether or not we've loaded the list of cache names into memory.
|
| bool initialized_;
|
| +
|
| + // The list of operations waiting on initialization.
|
| + std::vector<base::Closure> init_callbacks_;
|
| +
|
| + // The map of ServiceWorkerCache objects to their integer ids that
|
| + // ServiceWorkers reference. Owns the cache objects.
|
| CacheMap cache_map_;
|
| +
|
| + // The map of cache names to their integer ids.
|
| NameMap name_map_;
|
| +
|
| + // The file path for this CacheStorage.
|
| base::FilePath origin_path_;
|
| - scoped_refptr<base::MessageLoopProxy> callback_loop_;
|
| - scoped_ptr<CacheLoader> cache_loader_;
|
| +
|
| + // The TaskRunner to run file IO on.
|
| + scoped_refptr<base::SequencedTaskRunner> cache_task_runner_;
|
| +
|
| + // Performs backend specific operations (memory vs disk).
|
| + scoped_refptr<CacheLoader> cache_loader_;
|
| +
|
| + base::WeakPtrFactory<ServiceWorkerCacheStorage> weak_factory_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage);
|
| };
|
|
|