Commit 10e9d5dc authored by jkarlin@chromium.org's avatar jkarlin@chromium.org

Rename ServiceWorkerFetchStore/FetchStores/FetchStoresManager

to
ServiceWorkerCache/CacheStorage/CacheStorageManager to sync up with the spec: https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#cache-objects

BUG=392621

Review URL: https://codereview.chromium.org/444333006

Cr-Commit-Position: refs/heads/master@{#288511}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288511 0039d316-1c4b-4281-b951-d872f2087c98
parent 5c4fa4dd
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/service_worker/service_worker_fetch_store.h"
#include "content/browser/service_worker/service_worker_cache.h"
#include <string>
......@@ -11,29 +11,29 @@
namespace content {
// static
ServiceWorkerFetchStore* ServiceWorkerFetchStore::CreateMemoryStore(
ServiceWorkerCache* ServiceWorkerCache::CreateMemoryCache(
const std::string& name) {
return new ServiceWorkerFetchStore(base::FilePath(), name);
return new ServiceWorkerCache(base::FilePath(), name);
}
// static
ServiceWorkerFetchStore* ServiceWorkerFetchStore::CreatePersistentStore(
ServiceWorkerCache* ServiceWorkerCache::CreatePersistentCache(
const base::FilePath& path,
const std::string& name) {
return new ServiceWorkerFetchStore(path, name);
return new ServiceWorkerCache(path, name);
}
void ServiceWorkerFetchStore::CreateBackend(
void ServiceWorkerCache::CreateBackend(
const base::Callback<void(bool)>& callback) {
callback.Run(true);
}
ServiceWorkerFetchStore::ServiceWorkerFetchStore(const base::FilePath& path,
const std::string& name)
ServiceWorkerCache::ServiceWorkerCache(const base::FilePath& path,
const std::string& name)
: path_(path), name_(name), id_(0) {
}
ServiceWorkerFetchStore::~ServiceWorkerFetchStore() {
ServiceWorkerCache::~ServiceWorkerCache() {
}
} // namespace content
......@@ -2,30 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORE_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORE_H_
#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_
#include "base/callback.h"
#include "base/files/file_path.h"
namespace content {
// TODO(jkarlin): Fill this in with a real FetchStore implementation as
// TODO(jkarlin): Fill this in with a real Cache implementation as
// specified in
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html.
// TODO(jkarlin): Unload store backend from memory once the store object is no
// TODO(jkarlin): Unload cache backend from memory once the cache object is no
// longer referenced in javascript.
// Represents a ServiceWorker FetchStore as seen in
// Represents a ServiceWorker Cache as seen in
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html.
// InitializeIfNeeded must be called before calling the other public members.
class ServiceWorkerFetchStore {
class ServiceWorkerCache {
public:
static ServiceWorkerFetchStore* CreateMemoryStore(const std::string& name);
static ServiceWorkerFetchStore* CreatePersistentStore(
const base::FilePath& path,
const std::string& name);
virtual ~ServiceWorkerFetchStore();
static ServiceWorkerCache* CreateMemoryCache(const std::string& name);
static ServiceWorkerCache* CreatePersistentCache(const base::FilePath& path,
const std::string& name);
virtual ~ServiceWorkerCache();
// Loads the backend and calls the callback with the result (true for
// success). This must be called before member functions that require a
......@@ -38,15 +37,15 @@ class ServiceWorkerFetchStore {
void set_id(int32 id) { id_ = id; }
private:
ServiceWorkerFetchStore(const base::FilePath& path, const std::string& name);
ServiceWorkerCache(const base::FilePath& path, const std::string& name);
base::FilePath path_;
std::string name_;
int32 id_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchStore);
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache);
};
} // namespace content
#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORE_H_
#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORES_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORES_H_
#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_
#include <map>
#include <string>
......@@ -19,88 +19,88 @@ class MessageLoopProxy;
namespace content {
class ServiceWorkerFetchStore;
class ServiceWorkerCache;
// 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
// 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.
class ServiceWorkerFetchStores {
class ServiceWorkerCacheStorage {
public:
enum FetchStoresError {
FETCH_STORES_ERROR_NO_ERROR,
FETCH_STORES_ERROR_NOT_IMPLEMENTED,
FETCH_STORES_ERROR_NOT_FOUND,
FETCH_STORES_ERROR_EXISTS,
FETCH_STORES_ERROR_STORAGE,
FETCH_STORES_ERROR_EMPTY_KEY,
enum CacheStorageError {
CACHE_STORAGE_ERROR_NO_ERROR,
CACHE_STORAGE_ERROR_NOT_IMPLEMENTED,
CACHE_STORAGE_ERROR_NOT_FOUND,
CACHE_STORAGE_ERROR_EXISTS,
CACHE_STORAGE_ERROR_STORAGE,
CACHE_STORAGE_ERROR_EMPTY_KEY,
};
typedef base::Callback<void(bool, FetchStoresError)> BoolAndErrorCallback;
typedef base::Callback<void(int, FetchStoresError)> StoreAndErrorCallback;
typedef base::Callback<void(bool, CacheStorageError)> BoolAndErrorCallback;
typedef base::Callback<void(int, CacheStorageError)> CacheAndErrorCallback;
typedef base::Callback<void(const std::vector<std::string>&,
FetchStoresError)> StringsAndErrorCallback;
CacheStorageError)> StringsAndErrorCallback;
ServiceWorkerFetchStores(
ServiceWorkerCacheStorage(
const base::FilePath& origin_path,
bool memory_only,
const scoped_refptr<base::MessageLoopProxy>& callback_loop);
virtual ~ServiceWorkerFetchStores();
virtual ~ServiceWorkerCacheStorage();
// Create a ServiceWorkerFetchStore if it doesn't already exist and call the
// Create a ServiceWorkerCache 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);
// exists the callback is called with CACHE_STORAGE_ERROR_EXISTS.
void CreateCache(const std::string& cache_name,
const CacheAndErrorCallback& callback);
// 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);
// CACHE_STORAGE_ERROR_NOT_FOUND.
void GetCache(const std::string& cache_name,
const CacheAndErrorCallback& callback);
// Calls the callback with whether or not the cache exists.
void HasStore(const std::string& store_name,
void HasCache(const std::string& cache_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,
// CACHE_STORAGE_ERROR_NOT_FOUND is returned.
void DeleteCache(const std::string& cache_name,
const BoolAndErrorCallback& callback);
// Calls the callback with a vector of cache names (keys) available.
void EnumerateStores(const StringsAndErrorCallback& callback);
void EnumerateCaches(const StringsAndErrorCallback& callback);
// TODO(jkarlin): Add match() function.
void InitializeStoreCallback(const ServiceWorkerFetchStore* store,
const StoreAndErrorCallback& callback,
void InitializeCacheCallback(const ServiceWorkerCache* cache,
const CacheAndErrorCallback& callback,
bool success);
private:
class MemoryLoader;
class SimpleCacheLoader;
class StoresLoader;
class CacheLoader;
typedef IDMap<ServiceWorkerFetchStore, IDMapOwnPointer> StoreMap;
typedef StoreMap::KeyType StoreID;
typedef std::map<std::string, StoreID> NameMap;
typedef IDMap<ServiceWorkerCache, IDMapOwnPointer> CacheMap;
typedef CacheMap::KeyType CacheID;
typedef std::map<std::string, CacheID> NameMap;
ServiceWorkerFetchStore* GetLoadedStore(const std::string& key) const;
ServiceWorkerCache* GetLoadedCache(const std::string& cache_name) const;
void LazyInit();
void InitStore(ServiceWorkerFetchStore* store);
void InitCache(ServiceWorkerCache* cache);
bool initialized_;
StoreMap store_map_;
CacheMap cache_map_;
NameMap name_map_;
base::FilePath origin_path_;
scoped_refptr<base::MessageLoopProxy> callback_loop_;
scoped_ptr<StoresLoader> stores_loader_;
scoped_ptr<CacheLoader> cache_loader_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchStores);
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorage);
};
} // namespace content
#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORES_H_
#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/service_worker/service_worker_fetch_stores_manager.h"
#include "content/browser/service_worker/service_worker_cache_storage_manager.h"
#include <map>
#include <string>
......@@ -12,8 +12,8 @@
#include "base/sha1.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "content/browser/service_worker/service_worker_cache_storage.h"
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_fetch_stores.h"
#include "content/public/browser/browser_thread.h"
#include "url/gurl.h"
......@@ -32,137 +32,136 @@ base::FilePath ConstructOriginPath(const base::FilePath& root_path,
namespace content {
// static
scoped_ptr<ServiceWorkerFetchStoresManager>
ServiceWorkerFetchStoresManager::Create(
scoped_ptr<ServiceWorkerCacheStorageManager>
ServiceWorkerCacheStorageManager::Create(
const base::FilePath& path,
base::SequencedTaskRunner* stores_task_runner) {
base::SequencedTaskRunner* cache_task_runner) {
base::FilePath root_path = path;
if (!path.empty()) {
root_path = path.Append(ServiceWorkerContextCore::kServiceWorkerDirectory)
.AppendASCII("Stores");
.AppendASCII("CacheStorage");
}
return make_scoped_ptr(
new ServiceWorkerFetchStoresManager(root_path, stores_task_runner));
new ServiceWorkerCacheStorageManager(root_path, cache_task_runner));
}
// static
scoped_ptr<ServiceWorkerFetchStoresManager>
ServiceWorkerFetchStoresManager::Create(
ServiceWorkerFetchStoresManager* old_manager) {
return make_scoped_ptr(new ServiceWorkerFetchStoresManager(
old_manager->root_path(), old_manager->stores_task_runner()));
scoped_ptr<ServiceWorkerCacheStorageManager>
ServiceWorkerCacheStorageManager::Create(
ServiceWorkerCacheStorageManager* old_manager) {
return make_scoped_ptr(new ServiceWorkerCacheStorageManager(
old_manager->root_path(), old_manager->cache_task_runner()));
}
ServiceWorkerFetchStoresManager::~ServiceWorkerFetchStoresManager() {
for (ServiceWorkerFetchStoresMap::iterator it =
service_worker_fetch_stores_.begin();
it != service_worker_fetch_stores_.end();
ServiceWorkerCacheStorageManager::~ServiceWorkerCacheStorageManager() {
for (ServiceWorkerCacheStorageMap::iterator it = cache_storage_map_.begin();
it != cache_storage_map_.end();
++it) {
stores_task_runner_->DeleteSoon(FROM_HERE, it->second);
cache_task_runner_->DeleteSoon(FROM_HERE, it->second);
}
}
void ServiceWorkerFetchStoresManager::CreateStore(
void ServiceWorkerCacheStorageManager::CreateCache(
const GURL& origin,
const std::string& store_name,
const ServiceWorkerFetchStores::StoreAndErrorCallback& callback) {
const std::string& cache_name,
const ServiceWorkerCacheStorage::CacheAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerFetchStores* stores =
FindOrCreateServiceWorkerFetchStores(origin);
ServiceWorkerCacheStorage* cache_storage =
FindOrCreateServiceWorkerCacheManager(origin);
stores_task_runner_->PostTask(
cache_task_runner_->PostTask(
FROM_HERE,
base::Bind(&ServiceWorkerFetchStores::CreateStore,
base::Unretained(stores),
store_name,
base::Bind(&ServiceWorkerCacheStorage::CreateCache,
base::Unretained(cache_storage),
cache_name,
callback));
}
void ServiceWorkerFetchStoresManager::GetStore(
void ServiceWorkerCacheStorageManager::GetCache(
const GURL& origin,
const std::string& store_name,
const ServiceWorkerFetchStores::StoreAndErrorCallback& callback) {
const std::string& cache_name,
const ServiceWorkerCacheStorage::CacheAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerFetchStores* stores =
FindOrCreateServiceWorkerFetchStores(origin);
stores_task_runner_->PostTask(FROM_HERE,
base::Bind(&ServiceWorkerFetchStores::GetStore,
base::Unretained(stores),
store_name,
callback));
ServiceWorkerCacheStorage* cache_storage =
FindOrCreateServiceWorkerCacheManager(origin);
cache_task_runner_->PostTask(FROM_HERE,
base::Bind(&ServiceWorkerCacheStorage::GetCache,
base::Unretained(cache_storage),
cache_name,
callback));
}
void ServiceWorkerFetchStoresManager::HasStore(
void ServiceWorkerCacheStorageManager::HasCache(
const GURL& origin,
const std::string& store_name,
const ServiceWorkerFetchStores::BoolAndErrorCallback& callback) {
const std::string& cache_name,
const ServiceWorkerCacheStorage::BoolAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerFetchStores* stores =
FindOrCreateServiceWorkerFetchStores(origin);
stores_task_runner_->PostTask(FROM_HERE,
base::Bind(&ServiceWorkerFetchStores::HasStore,
base::Unretained(stores),
store_name,
callback));
ServiceWorkerCacheStorage* cache_storage =
FindOrCreateServiceWorkerCacheManager(origin);
cache_task_runner_->PostTask(FROM_HERE,
base::Bind(&ServiceWorkerCacheStorage::HasCache,
base::Unretained(cache_storage),
cache_name,
callback));
}
void ServiceWorkerFetchStoresManager::DeleteStore(
void ServiceWorkerCacheStorageManager::DeleteCache(
const GURL& origin,
const std::string& store_name,
const ServiceWorkerFetchStores::BoolAndErrorCallback& callback) {
const std::string& cache_name,
const ServiceWorkerCacheStorage::BoolAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerFetchStores* stores =
FindOrCreateServiceWorkerFetchStores(origin);
stores_task_runner_->PostTask(
ServiceWorkerCacheStorage* cache_storage =
FindOrCreateServiceWorkerCacheManager(origin);
cache_task_runner_->PostTask(
FROM_HERE,
base::Bind(&ServiceWorkerFetchStores::DeleteStore,
base::Unretained(stores),
store_name,
base::Bind(&ServiceWorkerCacheStorage::DeleteCache,
base::Unretained(cache_storage),
cache_name,
callback));
}
void ServiceWorkerFetchStoresManager::EnumerateStores(
void ServiceWorkerCacheStorageManager::EnumerateCaches(
const GURL& origin,
const ServiceWorkerFetchStores::StringsAndErrorCallback& callback) {
const ServiceWorkerCacheStorage::StringsAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerFetchStores* stores =
FindOrCreateServiceWorkerFetchStores(origin);
ServiceWorkerCacheStorage* cache_storage =
FindOrCreateServiceWorkerCacheManager(origin);
stores_task_runner_->PostTask(
cache_task_runner_->PostTask(
FROM_HERE,
base::Bind(&ServiceWorkerFetchStores::EnumerateStores,
base::Unretained(stores),
base::Bind(&ServiceWorkerCacheStorage::EnumerateCaches,
base::Unretained(cache_storage),
callback));
}
ServiceWorkerFetchStoresManager::ServiceWorkerFetchStoresManager(
ServiceWorkerCacheStorageManager::ServiceWorkerCacheStorageManager(
const base::FilePath& path,
base::SequencedTaskRunner* stores_task_runner)
: root_path_(path), stores_task_runner_(stores_task_runner) {
base::SequencedTaskRunner* cache_task_runner)
: root_path_(path), cache_task_runner_(cache_task_runner) {
}
ServiceWorkerFetchStores*
ServiceWorkerFetchStoresManager::FindOrCreateServiceWorkerFetchStores(
ServiceWorkerCacheStorage*
ServiceWorkerCacheStorageManager::FindOrCreateServiceWorkerCacheManager(
const GURL& origin) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerFetchStoresMap::const_iterator it =
service_worker_fetch_stores_.find(origin);
if (it == service_worker_fetch_stores_.end()) {
ServiceWorkerCacheStorageMap::const_iterator it =
cache_storage_map_.find(origin);
if (it == cache_storage_map_.end()) {
bool memory_only = root_path_.empty();
ServiceWorkerFetchStores* fetch_stores =
new ServiceWorkerFetchStores(ConstructOriginPath(root_path_, origin),
memory_only,
base::MessageLoopProxy::current());
ServiceWorkerCacheStorage* cache_storage =
new ServiceWorkerCacheStorage(ConstructOriginPath(root_path_, origin),
memory_only,
base::MessageLoopProxy::current());
// The map owns fetch_stores.
service_worker_fetch_stores_.insert(std::make_pair(origin, fetch_stores));
return fetch_stores;
cache_storage_map_.insert(std::make_pair(origin, cache_storage));
return cache_storage;
}
return it->second;
}
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_MANAGER_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_MANAGER_H_
#include <map>
#include <string>
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "content/browser/service_worker/service_worker_cache_storage.h"
#include "content/common/content_export.h"
#include "url/gurl.h"
namespace base {
class SequencedTaskRunner;
} // namespace base
namespace content {
// Keeps track of a ServiceWorkerCacheStorage per origin. There is one
// ServiceWorkerCacheStorageManager per ServiceWorkerContextCore.
// TODO(jkarlin): Remove ServiceWorkerCacheStorage from memory once they're no
// longer in active use.
class CONTENT_EXPORT ServiceWorkerCacheStorageManager {
public:
static scoped_ptr<ServiceWorkerCacheStorageManager> Create(
const base::FilePath& path,
base::SequencedTaskRunner* cache_task_runner);
static scoped_ptr<ServiceWorkerCacheStorageManager> Create(
ServiceWorkerCacheStorageManager* old_manager);
virtual ~ServiceWorkerCacheStorageManager();
// Methods to support the CacheStorage spec. These methods call the
// corresponding ServiceWorkerCacheStorage method on the appropriate thread.
void CreateCache(
const GURL& origin,
const std::string& cache_name,
const ServiceWorkerCacheStorage::CacheAndErrorCallback& callback);
void GetCache(
const GURL& origin,
const std::string& cache_name,
const ServiceWorkerCacheStorage::CacheAndErrorCallback& callback);
void HasCache(
const GURL& origin,
const std::string& cache_name,
const ServiceWorkerCacheStorage::BoolAndErrorCallback& callback);
void DeleteCache(
const GURL& origin,
const std::string& cache_name,
const ServiceWorkerCacheStorage::BoolAndErrorCallback& callback);
void EnumerateCaches(
const GURL& origin,
const ServiceWorkerCacheStorage::StringsAndErrorCallback& callback);
// TODO(jkarlin): Add match() function.
base::FilePath root_path() const { return root_path_; }
scoped_refptr<base::SequencedTaskRunner> cache_task_runner() const {
return cache_task_runner_;
}
private:
typedef std::map<GURL, ServiceWorkerCacheStorage*>
ServiceWorkerCacheStorageMap;
ServiceWorkerCacheStorageManager(
const base::FilePath& path,
base::SequencedTaskRunner* cache_task_runner);
// The returned ServiceWorkerCacheStorage* is owned by
// service_worker_cache_storages_.
ServiceWorkerCacheStorage* FindOrCreateServiceWorkerCacheManager(
const GURL& origin);
base::FilePath root_path_;
scoped_refptr<base::SequencedTaskRunner> cache_task_runner_;
// The map owns the CacheStorages and the CacheStorages are only accessed on
// |cache_task_runner_|.
ServiceWorkerCacheStorageMap cache_storage_map_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorageManager);
};
} // namespace content
#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_MANAGER_H_
......@@ -8,9 +8,9 @@
#include "base/message_loop/message_loop_proxy.h"
#include "base/strings/string_util.h"
#include "content/browser/service_worker/embedded_worker_registry.h"
#include "content/browser/service_worker/service_worker_cache_storage_manager.h"
#include "content/browser/service_worker/service_worker_context_observer.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_fetch_stores_manager.h"
#include "content/browser/service_worker/service_worker_info.h"
#include "content/browser/service_worker/service_worker_job_coordinator.h"
#include "content/browser/service_worker/service_worker_process_manager.h"
......@@ -92,14 +92,13 @@ ServiceWorkerContextCore::ServiceWorkerContextCore(
: weak_factory_(this),
wrapper_(wrapper),
providers_(new ProcessToProviderMap),
storage_(ServiceWorkerStorage::Create(
path,
AsWeakPtr(),
database_task_runner,
disk_cache_thread,
quota_manager_proxy)),
storage_(ServiceWorkerStorage::Create(path,
AsWeakPtr(),
database_task_runner,
disk_cache_thread,
quota_manager_proxy)),
fetch_stores_manager_(
ServiceWorkerFetchStoresManager::Create(path, stores_task_runner)),
ServiceWorkerCacheStorageManager::Create(path, stores_task_runner)),
embedded_worker_registry_(EmbeddedWorkerRegistry::Create(AsWeakPtr())),
job_coordinator_(new ServiceWorkerJobCoordinator(AsWeakPtr())),
next_handle_id_(0),
......@@ -114,7 +113,7 @@ ServiceWorkerContextCore::ServiceWorkerContextCore(
providers_(old_context->providers_.release()),
storage_(
ServiceWorkerStorage::Create(AsWeakPtr(), old_context->storage())),
fetch_stores_manager_(ServiceWorkerFetchStoresManager::Create(
fetch_stores_manager_(ServiceWorkerCacheStorageManager::Create(
old_context->fetch_stores_manager())),
embedded_worker_registry_(EmbeddedWorkerRegistry::Create(
AsWeakPtr(),
......
......@@ -36,7 +36,7 @@ class QuotaManagerProxy;
namespace content {
class EmbeddedWorkerRegistry;
class ServiceWorkerFetchStoresManager;
class ServiceWorkerCacheStorageManager;
class ServiceWorkerContextObserver;
class ServiceWorkerContextWrapper;
class ServiceWorkerHandle;
......@@ -121,7 +121,7 @@ class CONTENT_EXPORT ServiceWorkerContextCore
const GURL& source_url) OVERRIDE;
ServiceWorkerStorage* storage() { return storage_.get(); }
ServiceWorkerFetchStoresManager* fetch_stores_manager() {
ServiceWorkerCacheStorageManager* fetch_stores_manager() {
return fetch_stores_manager_.get();
}
ServiceWorkerProcessManager* process_manager();
......@@ -202,7 +202,7 @@ class CONTENT_EXPORT ServiceWorkerContextCore
ServiceWorkerContextWrapper* wrapper_;
scoped_ptr<ProcessToProviderMap> providers_;
scoped_ptr<ServiceWorkerStorage> storage_;
scoped_ptr<ServiceWorkerFetchStoresManager> fetch_stores_manager_;
scoped_ptr<ServiceWorkerCacheStorageManager> fetch_stores_manager_;
scoped_refptr<EmbeddedWorkerRegistry> embedded_worker_registry_;
scoped_ptr<ServiceWorkerJobCoordinator> job_coordinator_;
std::map<int64, ServiceWorkerRegistration*> live_registrations_;
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORES_MANAGER_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORES_MANAGER_H_
#include <map>
#include <string>
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "content/browser/service_worker/service_worker_fetch_stores.h"
#include "content/common/content_export.h"
#include "url/gurl.h"
namespace base {
class SequencedTaskRunner;
} // namespace base
namespace content {
// Keeps track of a ServiceWorkerFetchStores per origin. There is one
// ServiceWorkerFetchStoresManager per ServiceWorkerContextCore.
// TODO(jkarlin): Remove ServiceWorkerFetchStores from memory once they're no
// longer in active use.
class CONTENT_EXPORT ServiceWorkerFetchStoresManager {
public:
static scoped_ptr<ServiceWorkerFetchStoresManager> Create(
const base::FilePath& path,
base::SequencedTaskRunner* stores_task_runner);
static scoped_ptr<ServiceWorkerFetchStoresManager> Create(
ServiceWorkerFetchStoresManager* old_manager);
virtual ~ServiceWorkerFetchStoresManager();
// Methods to support the FetchStores spec. These methods call the
// corresponding ServiceWorkerFetchStores method on the appropriate thread.
void CreateStore(
const GURL& origin,
const std::string& store_name,
const ServiceWorkerFetchStores::StoreAndErrorCallback& callback);
void GetStore(
const GURL& origin,
const std::string& store_name,
const ServiceWorkerFetchStores::StoreAndErrorCallback& callback);
void HasStore(const GURL& origin,
const std::string& store_name,
const ServiceWorkerFetchStores::BoolAndErrorCallback& callback);
void DeleteStore(
const GURL& origin,
const std::string& store_name,
const ServiceWorkerFetchStores::BoolAndErrorCallback& callback);
void EnumerateStores(
const GURL& origin,
const ServiceWorkerFetchStores::StringsAndErrorCallback& callback);
// TODO(jkarlin): Add match() function.
base::FilePath root_path() const { return root_path_; }
scoped_refptr<base::SequencedTaskRunner> stores_task_runner() const {
return stores_task_runner_;
}
private:
typedef std::map<GURL, ServiceWorkerFetchStores*> ServiceWorkerFetchStoresMap;
ServiceWorkerFetchStoresManager(
const base::FilePath& path,
base::SequencedTaskRunner* stores_task_runner);
// The returned ServiceWorkerFetchStores* is owned by
// service_worker_fetch_stores_.
ServiceWorkerFetchStores* FindOrCreateServiceWorkerFetchStores(
const GURL& origin);
base::FilePath root_path_;
scoped_refptr<base::SequencedTaskRunner> stores_task_runner_;
// The map owns the stores and the stores are only accessed on
// |stores_task_runner_|.
ServiceWorkerFetchStoresMap service_worker_fetch_stores_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchStoresManager);
};
} // namespace content
#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_FETCH_STORES_MANAGER_H_
......@@ -1121,8 +1121,14 @@
'browser/service_worker/embedded_worker_instance.h',
'browser/service_worker/embedded_worker_registry.cc',
'browser/service_worker/embedded_worker_registry.h',
'browser/service_worker/service_worker_cache.cc',
'browser/service_worker/service_worker_cache.h',
'browser/service_worker/service_worker_cache_listener.cc',
'browser/service_worker/service_worker_cache_listener.h',
'browser/service_worker/service_worker_cache_storage.cc',
'browser/service_worker/service_worker_cache_storage.h',
'browser/service_worker/service_worker_cache_storage_manager.cc',
'browser/service_worker/service_worker_cache_storage_manager.h',
'browser/service_worker/service_worker_context_core.cc',
'browser/service_worker/service_worker_context_core.h',
'browser/service_worker/service_worker_context_observer.h',
......@@ -1140,12 +1146,6 @@
'browser/service_worker/service_worker_dispatcher_host.h',
'browser/service_worker/service_worker_fetch_dispatcher.cc',
'browser/service_worker/service_worker_fetch_dispatcher.h',
'browser/service_worker/service_worker_fetch_store.cc',
'browser/service_worker/service_worker_fetch_store.h',
'browser/service_worker/service_worker_fetch_stores.cc',
'browser/service_worker/service_worker_fetch_stores.h',
'browser/service_worker/service_worker_fetch_stores_manager.cc',
'browser/service_worker/service_worker_fetch_stores_manager.h',
'browser/service_worker/service_worker_handle.cc',
'browser/service_worker/service_worker_handle.h',
'browser/service_worker/service_worker_info.cc',
......
......@@ -591,11 +591,11 @@
'browser/service_worker/embedded_worker_instance_unittest.cc',
'browser/service_worker/embedded_worker_test_helper.cc',
'browser/service_worker/embedded_worker_test_helper.h',
'browser/service_worker/service_worker_cache_storage_manager_unittest.cc',
'browser/service_worker/service_worker_context_unittest.cc',
'browser/service_worker/service_worker_controllee_request_handler_unittest.cc',
'browser/service_worker/service_worker_database_unittest.cc',
'browser/service_worker/service_worker_dispatcher_host_unittest.cc',
'browser/service_worker/service_worker_fetch_stores_manager_unittest.cc',
'browser/service_worker/service_worker_handle_unittest.cc',
'browser/service_worker/service_worker_job_unittest.cc',
'browser/service_worker/service_worker_provider_host_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment