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 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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> #include <string>
...@@ -11,29 +11,29 @@ ...@@ -11,29 +11,29 @@
namespace content { namespace content {
// static // static
ServiceWorkerFetchStore* ServiceWorkerFetchStore::CreateMemoryStore( ServiceWorkerCache* ServiceWorkerCache::CreateMemoryCache(
const std::string& name) { const std::string& name) {
return new ServiceWorkerFetchStore(base::FilePath(), name); return new ServiceWorkerCache(base::FilePath(), name);
} }
// static // static
ServiceWorkerFetchStore* ServiceWorkerFetchStore::CreatePersistentStore( ServiceWorkerCache* ServiceWorkerCache::CreatePersistentCache(
const base::FilePath& path, const base::FilePath& path,
const std::string& name) { 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) { const base::Callback<void(bool)>& callback) {
callback.Run(true); callback.Run(true);
} }
ServiceWorkerFetchStore::ServiceWorkerFetchStore(const base::FilePath& path, ServiceWorkerCache::ServiceWorkerCache(const base::FilePath& path,
const std::string& name) const std::string& name)
: path_(path), name_(name), id_(0) { : path_(path), name_(name), id_(0) {
} }
ServiceWorkerFetchStore::~ServiceWorkerFetchStore() { ServiceWorkerCache::~ServiceWorkerCache() {
} }
} // namespace content } // namespace content
...@@ -2,30 +2,29 @@ ...@@ -2,30 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef 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_FETCH_STORE_H_ #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_
#include "base/callback.h" #include "base/callback.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
namespace content { 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 // specified in
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html. // 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. // 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. // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html.
// InitializeIfNeeded must be called before calling the other public members. // InitializeIfNeeded must be called before calling the other public members.
class ServiceWorkerFetchStore { class ServiceWorkerCache {
public: public:
static ServiceWorkerFetchStore* CreateMemoryStore(const std::string& name); static ServiceWorkerCache* CreateMemoryCache(const std::string& name);
static ServiceWorkerFetchStore* CreatePersistentStore( static ServiceWorkerCache* CreatePersistentCache(const base::FilePath& path,
const base::FilePath& path,
const std::string& name); const std::string& name);
virtual ~ServiceWorkerFetchStore(); virtual ~ServiceWorkerCache();
// Loads the backend and calls the callback with the result (true for // Loads the backend and calls the callback with the result (true for
// success). This must be called before member functions that require a // success). This must be called before member functions that require a
...@@ -38,15 +37,15 @@ class ServiceWorkerFetchStore { ...@@ -38,15 +37,15 @@ class ServiceWorkerFetchStore {
void set_id(int32 id) { id_ = id; } void set_id(int32 id) { id_ = id; }
private: private:
ServiceWorkerFetchStore(const base::FilePath& path, const std::string& name); ServiceWorkerCache(const base::FilePath& path, const std::string& name);
base::FilePath path_; base::FilePath path_;
std::string name_; std::string name_;
int32 id_; int32 id_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFetchStore); DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache);
}; };
} // namespace content } // 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 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef 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_FETCH_STORES_H_ #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_H_
#include <map> #include <map>
#include <string> #include <string>
...@@ -19,88 +19,88 @@ class MessageLoopProxy; ...@@ -19,88 +19,88 @@ class MessageLoopProxy;
namespace content { namespace content {
class ServiceWorkerFetchStore; class ServiceWorkerCache;
// TODO(jkarlin): Constrain the total bytes used per origin. // TODO(jkarlin): Constrain the total bytes used per origin.
// The set of stores for a given origin. It is owned by the // The set of caches for a given origin. It is owned by the
// ServiceWorkerFetchStoresManager. Provided callbacks are called on the // ServiceWorkerCacheStorageManager. Provided callbacks are called on the
// |callback_loop| provided in the constructor. // |callback_loop| provided in the constructor.
class ServiceWorkerFetchStores { class ServiceWorkerCacheStorage {
public: public:
enum FetchStoresError { enum CacheStorageError {
FETCH_STORES_ERROR_NO_ERROR, CACHE_STORAGE_ERROR_NO_ERROR,
FETCH_STORES_ERROR_NOT_IMPLEMENTED, CACHE_STORAGE_ERROR_NOT_IMPLEMENTED,
FETCH_STORES_ERROR_NOT_FOUND, CACHE_STORAGE_ERROR_NOT_FOUND,
FETCH_STORES_ERROR_EXISTS, CACHE_STORAGE_ERROR_EXISTS,
FETCH_STORES_ERROR_STORAGE, CACHE_STORAGE_ERROR_STORAGE,
FETCH_STORES_ERROR_EMPTY_KEY, CACHE_STORAGE_ERROR_EMPTY_KEY,
}; };
typedef base::Callback<void(bool, FetchStoresError)> BoolAndErrorCallback; typedef base::Callback<void(bool, CacheStorageError)> BoolAndErrorCallback;
typedef base::Callback<void(int, FetchStoresError)> StoreAndErrorCallback; typedef base::Callback<void(int, CacheStorageError)> CacheAndErrorCallback;
typedef base::Callback<void(const std::vector<std::string>&, typedef base::Callback<void(const std::vector<std::string>&,
FetchStoresError)> StringsAndErrorCallback; CacheStorageError)> StringsAndErrorCallback;
ServiceWorkerFetchStores( ServiceWorkerCacheStorage(
const base::FilePath& origin_path, const base::FilePath& origin_path,
bool memory_only, bool memory_only,
const scoped_refptr<base::MessageLoopProxy>& callback_loop); 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 // callback with the cache's id. If it already
// exists the callback is called with FETCH_STORES_ERROR_EXISTS. // exists the callback is called with CACHE_STORAGE_ERROR_EXISTS.
void CreateStore(const std::string& store_name, void CreateCache(const std::string& cache_name,
const StoreAndErrorCallback& callback); const CacheAndErrorCallback& callback);
// Get the cache id for the given key. If not found returns // Get the cache id for the given key. If not found returns
// FETCH_STORES_ERROR_NOT_FOUND. // CACHE_STORAGE_ERROR_NOT_FOUND.
void GetStore(const std::string& store_name, void GetCache(const std::string& cache_name,
const StoreAndErrorCallback& callback); const CacheAndErrorCallback& callback);
// Calls the callback with whether or not the cache exists. // 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); const BoolAndErrorCallback& callback);
// Deletes the cache if it exists. If it doesn't exist, // Deletes the cache if it exists. If it doesn't exist,
// FETCH_STORES_ERROR_NOT_FOUND is returned. // CACHE_STORAGE_ERROR_NOT_FOUND is returned.
void DeleteStore(const std::string& store_name, void DeleteCache(const std::string& cache_name,
const BoolAndErrorCallback& callback); const BoolAndErrorCallback& callback);
// Calls the callback with a vector of cache names (keys) available. // 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. // TODO(jkarlin): Add match() function.
void InitializeStoreCallback(const ServiceWorkerFetchStore* store, void InitializeCacheCallback(const ServiceWorkerCache* cache,
const StoreAndErrorCallback& callback, const CacheAndErrorCallback& callback,
bool success); bool success);
private: private:
class MemoryLoader; class MemoryLoader;
class SimpleCacheLoader; class SimpleCacheLoader;
class StoresLoader; class CacheLoader;
typedef IDMap<ServiceWorkerFetchStore, IDMapOwnPointer> StoreMap; typedef IDMap<ServiceWorkerCache, IDMapOwnPointer> CacheMap;
typedef StoreMap::KeyType StoreID; typedef CacheMap::KeyType CacheID;
typedef std::map<std::string, StoreID> NameMap; 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 LazyInit();
void InitStore(ServiceWorkerFetchStore* store); void InitCache(ServiceWorkerCache* cache);
bool initialized_; bool initialized_;
StoreMap store_map_; CacheMap cache_map_;
NameMap name_map_; NameMap name_map_;
base::FilePath origin_path_; base::FilePath origin_path_;
scoped_refptr<base::MessageLoopProxy> callback_loop_; 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 } // 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 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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 <map>
#include <string> #include <string>
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
#include "base/sha1.h" #include "base/sha1.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.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_context_core.h"
#include "content/browser/service_worker/service_worker_fetch_stores.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -32,137 +32,136 @@ base::FilePath ConstructOriginPath(const base::FilePath& root_path, ...@@ -32,137 +32,136 @@ base::FilePath ConstructOriginPath(const base::FilePath& root_path,
namespace content { namespace content {
// static // static
scoped_ptr<ServiceWorkerFetchStoresManager> scoped_ptr<ServiceWorkerCacheStorageManager>
ServiceWorkerFetchStoresManager::Create( ServiceWorkerCacheStorageManager::Create(
const base::FilePath& path, const base::FilePath& path,
base::SequencedTaskRunner* stores_task_runner) { base::SequencedTaskRunner* cache_task_runner) {
base::FilePath root_path = path; base::FilePath root_path = path;
if (!path.empty()) { if (!path.empty()) {
root_path = path.Append(ServiceWorkerContextCore::kServiceWorkerDirectory) root_path = path.Append(ServiceWorkerContextCore::kServiceWorkerDirectory)
.AppendASCII("Stores"); .AppendASCII("CacheStorage");
} }
return make_scoped_ptr( return make_scoped_ptr(
new ServiceWorkerFetchStoresManager(root_path, stores_task_runner)); new ServiceWorkerCacheStorageManager(root_path, cache_task_runner));
} }
// static // static
scoped_ptr<ServiceWorkerFetchStoresManager> scoped_ptr<ServiceWorkerCacheStorageManager>
ServiceWorkerFetchStoresManager::Create( ServiceWorkerCacheStorageManager::Create(
ServiceWorkerFetchStoresManager* old_manager) { ServiceWorkerCacheStorageManager* old_manager) {
return make_scoped_ptr(new ServiceWorkerFetchStoresManager( return make_scoped_ptr(new ServiceWorkerCacheStorageManager(
old_manager->root_path(), old_manager->stores_task_runner())); old_manager->root_path(), old_manager->cache_task_runner()));
} }
ServiceWorkerFetchStoresManager::~ServiceWorkerFetchStoresManager() { ServiceWorkerCacheStorageManager::~ServiceWorkerCacheStorageManager() {
for (ServiceWorkerFetchStoresMap::iterator it = for (ServiceWorkerCacheStorageMap::iterator it = cache_storage_map_.begin();
service_worker_fetch_stores_.begin(); it != cache_storage_map_.end();
it != service_worker_fetch_stores_.end();
++it) { ++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 GURL& origin,
const std::string& store_name, const std::string& cache_name,
const ServiceWorkerFetchStores::StoreAndErrorCallback& callback) { const ServiceWorkerCacheStorage::CacheAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerFetchStores* stores = ServiceWorkerCacheStorage* cache_storage =
FindOrCreateServiceWorkerFetchStores(origin); FindOrCreateServiceWorkerCacheManager(origin);
stores_task_runner_->PostTask( cache_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&ServiceWorkerFetchStores::CreateStore, base::Bind(&ServiceWorkerCacheStorage::CreateCache,
base::Unretained(stores), base::Unretained(cache_storage),
store_name, cache_name,
callback)); callback));
} }
void ServiceWorkerFetchStoresManager::GetStore( void ServiceWorkerCacheStorageManager::GetCache(
const GURL& origin, const GURL& origin,
const std::string& store_name, const std::string& cache_name,
const ServiceWorkerFetchStores::StoreAndErrorCallback& callback) { const ServiceWorkerCacheStorage::CacheAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerFetchStores* stores = ServiceWorkerCacheStorage* cache_storage =
FindOrCreateServiceWorkerFetchStores(origin); FindOrCreateServiceWorkerCacheManager(origin);
stores_task_runner_->PostTask(FROM_HERE, cache_task_runner_->PostTask(FROM_HERE,
base::Bind(&ServiceWorkerFetchStores::GetStore, base::Bind(&ServiceWorkerCacheStorage::GetCache,
base::Unretained(stores), base::Unretained(cache_storage),
store_name, cache_name,
callback)); callback));
} }
void ServiceWorkerFetchStoresManager::HasStore( void ServiceWorkerCacheStorageManager::HasCache(
const GURL& origin, const GURL& origin,
const std::string& store_name, const std::string& cache_name,
const ServiceWorkerFetchStores::BoolAndErrorCallback& callback) { const ServiceWorkerCacheStorage::BoolAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerFetchStores* stores = ServiceWorkerCacheStorage* cache_storage =
FindOrCreateServiceWorkerFetchStores(origin); FindOrCreateServiceWorkerCacheManager(origin);
stores_task_runner_->PostTask(FROM_HERE, cache_task_runner_->PostTask(FROM_HERE,
base::Bind(&ServiceWorkerFetchStores::HasStore, base::Bind(&ServiceWorkerCacheStorage::HasCache,
base::Unretained(stores), base::Unretained(cache_storage),
store_name, cache_name,
callback)); callback));
} }
void ServiceWorkerFetchStoresManager::DeleteStore( void ServiceWorkerCacheStorageManager::DeleteCache(
const GURL& origin, const GURL& origin,
const std::string& store_name, const std::string& cache_name,
const ServiceWorkerFetchStores::BoolAndErrorCallback& callback) { const ServiceWorkerCacheStorage::BoolAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerFetchStores* stores = ServiceWorkerCacheStorage* cache_storage =
FindOrCreateServiceWorkerFetchStores(origin); FindOrCreateServiceWorkerCacheManager(origin);
stores_task_runner_->PostTask( cache_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&ServiceWorkerFetchStores::DeleteStore, base::Bind(&ServiceWorkerCacheStorage::DeleteCache,
base::Unretained(stores), base::Unretained(cache_storage),
store_name, cache_name,
callback)); callback));
} }
void ServiceWorkerFetchStoresManager::EnumerateStores( void ServiceWorkerCacheStorageManager::EnumerateCaches(
const GURL& origin, const GURL& origin,
const ServiceWorkerFetchStores::StringsAndErrorCallback& callback) { const ServiceWorkerCacheStorage::StringsAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerFetchStores* stores = ServiceWorkerCacheStorage* cache_storage =
FindOrCreateServiceWorkerFetchStores(origin); FindOrCreateServiceWorkerCacheManager(origin);
stores_task_runner_->PostTask( cache_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&ServiceWorkerFetchStores::EnumerateStores, base::Bind(&ServiceWorkerCacheStorage::EnumerateCaches,
base::Unretained(stores), base::Unretained(cache_storage),
callback)); callback));
} }
ServiceWorkerFetchStoresManager::ServiceWorkerFetchStoresManager( ServiceWorkerCacheStorageManager::ServiceWorkerCacheStorageManager(
const base::FilePath& path, const base::FilePath& path,
base::SequencedTaskRunner* stores_task_runner) base::SequencedTaskRunner* cache_task_runner)
: root_path_(path), stores_task_runner_(stores_task_runner) { : root_path_(path), cache_task_runner_(cache_task_runner) {
} }
ServiceWorkerFetchStores* ServiceWorkerCacheStorage*
ServiceWorkerFetchStoresManager::FindOrCreateServiceWorkerFetchStores( ServiceWorkerCacheStorageManager::FindOrCreateServiceWorkerCacheManager(
const GURL& origin) { const GURL& origin) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerFetchStoresMap::const_iterator it = ServiceWorkerCacheStorageMap::const_iterator it =
service_worker_fetch_stores_.find(origin); cache_storage_map_.find(origin);
if (it == service_worker_fetch_stores_.end()) { if (it == cache_storage_map_.end()) {
bool memory_only = root_path_.empty(); bool memory_only = root_path_.empty();
ServiceWorkerFetchStores* fetch_stores = ServiceWorkerCacheStorage* cache_storage =
new ServiceWorkerFetchStores(ConstructOriginPath(root_path_, origin), new ServiceWorkerCacheStorage(ConstructOriginPath(root_path_, origin),
memory_only, memory_only,
base::MessageLoopProxy::current()); base::MessageLoopProxy::current());
// The map owns fetch_stores. // The map owns fetch_stores.
service_worker_fetch_stores_.insert(std::make_pair(origin, fetch_stores)); cache_storage_map_.insert(std::make_pair(origin, cache_storage));
return fetch_stores; return cache_storage;
} }
return it->second; 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 @@ ...@@ -8,9 +8,9 @@
#include "base/message_loop/message_loop_proxy.h" #include "base/message_loop/message_loop_proxy.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "content/browser/service_worker/embedded_worker_registry.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_observer.h"
#include "content/browser/service_worker/service_worker_context_wrapper.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_info.h"
#include "content/browser/service_worker/service_worker_job_coordinator.h" #include "content/browser/service_worker/service_worker_job_coordinator.h"
#include "content/browser/service_worker/service_worker_process_manager.h" #include "content/browser/service_worker/service_worker_process_manager.h"
...@@ -92,14 +92,13 @@ ServiceWorkerContextCore::ServiceWorkerContextCore( ...@@ -92,14 +92,13 @@ ServiceWorkerContextCore::ServiceWorkerContextCore(
: weak_factory_(this), : weak_factory_(this),
wrapper_(wrapper), wrapper_(wrapper),
providers_(new ProcessToProviderMap), providers_(new ProcessToProviderMap),
storage_(ServiceWorkerStorage::Create( storage_(ServiceWorkerStorage::Create(path,
path,
AsWeakPtr(), AsWeakPtr(),
database_task_runner, database_task_runner,
disk_cache_thread, disk_cache_thread,
quota_manager_proxy)), quota_manager_proxy)),
fetch_stores_manager_( fetch_stores_manager_(
ServiceWorkerFetchStoresManager::Create(path, stores_task_runner)), ServiceWorkerCacheStorageManager::Create(path, stores_task_runner)),
embedded_worker_registry_(EmbeddedWorkerRegistry::Create(AsWeakPtr())), embedded_worker_registry_(EmbeddedWorkerRegistry::Create(AsWeakPtr())),
job_coordinator_(new ServiceWorkerJobCoordinator(AsWeakPtr())), job_coordinator_(new ServiceWorkerJobCoordinator(AsWeakPtr())),
next_handle_id_(0), next_handle_id_(0),
...@@ -114,7 +113,7 @@ ServiceWorkerContextCore::ServiceWorkerContextCore( ...@@ -114,7 +113,7 @@ ServiceWorkerContextCore::ServiceWorkerContextCore(
providers_(old_context->providers_.release()), providers_(old_context->providers_.release()),
storage_( storage_(
ServiceWorkerStorage::Create(AsWeakPtr(), old_context->storage())), ServiceWorkerStorage::Create(AsWeakPtr(), old_context->storage())),
fetch_stores_manager_(ServiceWorkerFetchStoresManager::Create( fetch_stores_manager_(ServiceWorkerCacheStorageManager::Create(
old_context->fetch_stores_manager())), old_context->fetch_stores_manager())),
embedded_worker_registry_(EmbeddedWorkerRegistry::Create( embedded_worker_registry_(EmbeddedWorkerRegistry::Create(
AsWeakPtr(), AsWeakPtr(),
......
...@@ -36,7 +36,7 @@ class QuotaManagerProxy; ...@@ -36,7 +36,7 @@ class QuotaManagerProxy;
namespace content { namespace content {
class EmbeddedWorkerRegistry; class EmbeddedWorkerRegistry;
class ServiceWorkerFetchStoresManager; class ServiceWorkerCacheStorageManager;
class ServiceWorkerContextObserver; class ServiceWorkerContextObserver;
class ServiceWorkerContextWrapper; class ServiceWorkerContextWrapper;
class ServiceWorkerHandle; class ServiceWorkerHandle;
...@@ -121,7 +121,7 @@ class CONTENT_EXPORT ServiceWorkerContextCore ...@@ -121,7 +121,7 @@ class CONTENT_EXPORT ServiceWorkerContextCore
const GURL& source_url) OVERRIDE; const GURL& source_url) OVERRIDE;
ServiceWorkerStorage* storage() { return storage_.get(); } ServiceWorkerStorage* storage() { return storage_.get(); }
ServiceWorkerFetchStoresManager* fetch_stores_manager() { ServiceWorkerCacheStorageManager* fetch_stores_manager() {
return fetch_stores_manager_.get(); return fetch_stores_manager_.get();
} }
ServiceWorkerProcessManager* process_manager(); ServiceWorkerProcessManager* process_manager();
...@@ -202,7 +202,7 @@ class CONTENT_EXPORT ServiceWorkerContextCore ...@@ -202,7 +202,7 @@ class CONTENT_EXPORT ServiceWorkerContextCore
ServiceWorkerContextWrapper* wrapper_; ServiceWorkerContextWrapper* wrapper_;
scoped_ptr<ProcessToProviderMap> providers_; scoped_ptr<ProcessToProviderMap> providers_;
scoped_ptr<ServiceWorkerStorage> storage_; scoped_ptr<ServiceWorkerStorage> storage_;
scoped_ptr<ServiceWorkerFetchStoresManager> fetch_stores_manager_; scoped_ptr<ServiceWorkerCacheStorageManager> fetch_stores_manager_;
scoped_refptr<EmbeddedWorkerRegistry> embedded_worker_registry_; scoped_refptr<EmbeddedWorkerRegistry> embedded_worker_registry_;
scoped_ptr<ServiceWorkerJobCoordinator> job_coordinator_; scoped_ptr<ServiceWorkerJobCoordinator> job_coordinator_;
std::map<int64, ServiceWorkerRegistration*> live_registrations_; 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 @@ ...@@ -1121,8 +1121,14 @@
'browser/service_worker/embedded_worker_instance.h', 'browser/service_worker/embedded_worker_instance.h',
'browser/service_worker/embedded_worker_registry.cc', 'browser/service_worker/embedded_worker_registry.cc',
'browser/service_worker/embedded_worker_registry.h', '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.cc',
'browser/service_worker/service_worker_cache_listener.h', '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.cc',
'browser/service_worker/service_worker_context_core.h', 'browser/service_worker/service_worker_context_core.h',
'browser/service_worker/service_worker_context_observer.h', 'browser/service_worker/service_worker_context_observer.h',
...@@ -1140,12 +1146,6 @@ ...@@ -1140,12 +1146,6 @@
'browser/service_worker/service_worker_dispatcher_host.h', 'browser/service_worker/service_worker_dispatcher_host.h',
'browser/service_worker/service_worker_fetch_dispatcher.cc', 'browser/service_worker/service_worker_fetch_dispatcher.cc',
'browser/service_worker/service_worker_fetch_dispatcher.h', '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.cc',
'browser/service_worker/service_worker_handle.h', 'browser/service_worker/service_worker_handle.h',
'browser/service_worker/service_worker_info.cc', 'browser/service_worker/service_worker_info.cc',
......
...@@ -591,11 +591,11 @@ ...@@ -591,11 +591,11 @@
'browser/service_worker/embedded_worker_instance_unittest.cc', 'browser/service_worker/embedded_worker_instance_unittest.cc',
'browser/service_worker/embedded_worker_test_helper.cc', 'browser/service_worker/embedded_worker_test_helper.cc',
'browser/service_worker/embedded_worker_test_helper.h', '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_context_unittest.cc',
'browser/service_worker/service_worker_controllee_request_handler_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_database_unittest.cc',
'browser/service_worker/service_worker_dispatcher_host_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_handle_unittest.cc',
'browser/service_worker/service_worker_job_unittest.cc', 'browser/service_worker/service_worker_job_unittest.cc',
'browser/service_worker/service_worker_provider_host_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