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

Unified Diff: content/browser/service_worker/service_worker_cache_storage.cc

Issue 444333006: Rename ServiceWorkerFetchStore/FetchStores/FetchStoresManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fetch_stores3
Patch Set: Rebase 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_cache_storage.cc
diff --git a/content/browser/service_worker/service_worker_fetch_stores.cc b/content/browser/service_worker/service_worker_cache_storage.cc
similarity index 39%
rename from content/browser/service_worker/service_worker_fetch_stores.cc
rename to content/browser/service_worker/service_worker_cache_storage.cc
index 7f818398ca37083195d4a5ab6096f63ea773dad4..d679d3e6242b235f2bc67eab5e4251d334ef72ba 100644
--- a/content/browser/service_worker/service_worker_fetch_stores.cc
+++ b/content/browser/service_worker/service_worker_cache_storage.cc
@@ -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.h"
+#include "content/browser/service_worker/service_worker_cache_storage.h"
#include <string>
@@ -11,82 +11,86 @@
#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.h"
#include "content/browser/service_worker/service_worker_cache.pb.h"
-#include "content/browser/service_worker/service_worker_fetch_store.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/directory_lister.h"
namespace content {
-// Handles the loading of ServiceWorkerFetchStore and any extra clean up other
-// than deleting the ServiceWorkerFetchStore object.
-class ServiceWorkerFetchStores::StoresLoader {
+// Handles the loading and clean up of ServiceWorkerCache objects.
+class ServiceWorkerCacheStorage::CacheLoader {
public:
- virtual ~StoresLoader() {};
- virtual ServiceWorkerFetchStore* LoadStore(const std::string& key) = 0;
- // Creates a new store, deleting any pre-existing store of the same name.
- virtual ServiceWorkerFetchStore* CreateStore(const std::string& key) = 0;
- virtual bool CleanUpDeletedStore(const std::string& key) = 0;
- virtual bool WriteIndex(StoreMap* stores) = 0;
- virtual void LoadIndex(std::vector<std::string>* names) = 0;
+ virtual ~CacheLoader() {};
+ virtual ServiceWorkerCache* LoadCache(const std::string& cache_name) = 0;
+ // Creates a new cache, deleting any pre-existing cache of the same name.
+ virtual ServiceWorkerCache* CreateCache(const std::string& cache_name) = 0;
+ virtual bool CleanUpDeletedCache(const std::string& key) = 0;
+ virtual bool WriteIndex(CacheMap* caches) = 0;
+ virtual void LoadIndex(std::vector<std::string>* cache_names) = 0;
};
-class ServiceWorkerFetchStores::MemoryLoader
- : public ServiceWorkerFetchStores::StoresLoader {
+class ServiceWorkerCacheStorage::MemoryLoader
+ : public ServiceWorkerCacheStorage::CacheLoader {
public:
- virtual content::ServiceWorkerFetchStore* LoadStore(
- const std::string& key) OVERRIDE {
+ virtual content::ServiceWorkerCache* LoadCache(
+ const std::string& cache_name) OVERRIDE {
NOTREACHED();
return NULL;
}
- virtual ServiceWorkerFetchStore* CreateStore(
- const std::string& key) OVERRIDE {
- return ServiceWorkerFetchStore::CreateMemoryStore(key);
+ virtual ServiceWorkerCache* CreateCache(
+ const std::string& cache_name) OVERRIDE {
+ return ServiceWorkerCache::CreateMemoryCache(cache_name);
}
- virtual bool CleanUpDeletedStore(const std::string& key) OVERRIDE {
+ virtual bool CleanUpDeletedCache(const std::string& cache_name) OVERRIDE {
return true;
}
- virtual bool WriteIndex(StoreMap* stores) OVERRIDE { return false; }
+ virtual bool WriteIndex(CacheMap* caches) OVERRIDE { return false; }
- virtual void LoadIndex(std::vector<std::string>* names) OVERRIDE { return; }
+ virtual void LoadIndex(std::vector<std::string>* cache_names) OVERRIDE {
+ return;
+ }
};
-class ServiceWorkerFetchStores::SimpleCacheLoader
- : public ServiceWorkerFetchStores::StoresLoader {
+class ServiceWorkerCacheStorage::SimpleCacheLoader
+ : public ServiceWorkerCacheStorage::CacheLoader {
public:
explicit SimpleCacheLoader(const base::FilePath& origin_path)
: origin_path_(origin_path) {}
- virtual ServiceWorkerFetchStore* LoadStore(const std::string& key) OVERRIDE {
- base::CreateDirectory(CreatePersistentStorePath(origin_path_, key));
- return ServiceWorkerFetchStore::CreatePersistentStore(
- CreatePersistentStorePath(origin_path_, key), key);
+ virtual ServiceWorkerCache* LoadCache(
+ const std::string& cache_name) OVERRIDE {
+ base::CreateDirectory(CreatePersistentCachePath(origin_path_, cache_name));
+ return ServiceWorkerCache::CreatePersistentCache(
+ CreatePersistentCachePath(origin_path_, cache_name), cache_name);
}
- virtual ServiceWorkerFetchStore* CreateStore(
- const std::string& key) OVERRIDE {
- base::FilePath store_path = CreatePersistentStorePath(origin_path_, key);
- if (base::PathExists(store_path))
- base::DeleteFile(store_path, /* recursive */ true);
- return LoadStore(key);
+ virtual ServiceWorkerCache* CreateCache(
+ const std::string& cache_name) OVERRIDE {
+ base::FilePath cache_path =
+ CreatePersistentCachePath(origin_path_, cache_name);
+ if (base::PathExists(cache_path))
+ base::DeleteFile(cache_path, /* recursive */ true);
+ return LoadCache(cache_name);
}
- virtual bool CleanUpDeletedStore(const std::string& key) OVERRIDE {
- return base::DeleteFile(CreatePersistentStorePath(origin_path_, key), true);
+ virtual bool CleanUpDeletedCache(const std::string& cache_name) OVERRIDE {
+ return base::DeleteFile(CreatePersistentCachePath(origin_path_, cache_name),
+ true);
}
- virtual bool WriteIndex(StoreMap* stores) OVERRIDE {
+ virtual bool WriteIndex(CacheMap* caches) OVERRIDE {
ServiceWorkerCacheStorageIndex index;
- for (StoreMap::const_iterator iter(stores); !iter.IsAtEnd();
+ for (CacheMap::const_iterator iter(caches); !iter.IsAtEnd();
iter.Advance()) {
- const ServiceWorkerFetchStore* store = iter.GetCurrentValue();
- ServiceWorkerCacheStorageIndex::Cache* cache = index.add_cache();
- cache->set_name(store->name());
- cache->set_size(0); // TODO(jkarlin): Make this real.
+ const ServiceWorkerCache* cache = iter.GetCurrentValue();
+ ServiceWorkerCacheStorageIndex::Cache* index_cache = index.add_cache();
+ index_cache->set_name(cache->name());
+ index_cache->set_size(0); // TODO(jkarlin): Make this real.
}
std::string serialized;
@@ -122,7 +126,7 @@ class ServiceWorkerFetchStores::SimpleCacheLoader
names->push_back(cache.name());
}
- // TODO(jkarlin): Delete stores that are in the directory and not returned
+ // TODO(jkarlin): Delete caches that are in the directory and not returned
// in LoadIndex.
return;
}
@@ -135,136 +139,137 @@ class ServiceWorkerFetchStores::SimpleCacheLoader
return valued_hexed_hash;
}
- base::FilePath CreatePersistentStorePath(const base::FilePath& origin_path,
- const std::string& store_name) {
- return origin_path.AppendASCII(HexedHash(store_name));
+ base::FilePath CreatePersistentCachePath(const base::FilePath& origin_path,
+ const std::string& cache_name) {
+ return origin_path.AppendASCII(HexedHash(cache_name));
}
const base::FilePath origin_path_;
};
-ServiceWorkerFetchStores::ServiceWorkerFetchStores(
+ServiceWorkerCacheStorage::ServiceWorkerCacheStorage(
const base::FilePath& path,
bool memory_only,
const scoped_refptr<base::MessageLoopProxy>& callback_loop)
: initialized_(false), origin_path_(path), callback_loop_(callback_loop) {
if (memory_only)
- stores_loader_.reset(new MemoryLoader());
+ cache_loader_.reset(new MemoryLoader());
else
- stores_loader_.reset(new SimpleCacheLoader(origin_path_));
+ cache_loader_.reset(new SimpleCacheLoader(origin_path_));
}
-ServiceWorkerFetchStores::~ServiceWorkerFetchStores() {
+ServiceWorkerCacheStorage::~ServiceWorkerCacheStorage() {
}
-void ServiceWorkerFetchStores::CreateStore(
- const std::string& store_name,
- const StoreAndErrorCallback& callback) {
+void ServiceWorkerCacheStorage::CreateCache(
+ const std::string& cache_name,
+ const CacheAndErrorCallback& callback) {
LazyInit();
- if (store_name.empty()) {
+ if (cache_name.empty()) {
callback_loop_->PostTask(
- FROM_HERE, base::Bind(callback, 0, FETCH_STORES_ERROR_EMPTY_KEY));
+ FROM_HERE, base::Bind(callback, 0, CACHE_STORAGE_ERROR_EMPTY_KEY));
return;
}
- if (GetLoadedStore(store_name)) {
+ if (GetLoadedCache(cache_name)) {
callback_loop_->PostTask(
- FROM_HERE, base::Bind(callback, 0, FETCH_STORES_ERROR_EXISTS));
+ FROM_HERE, base::Bind(callback, 0, CACHE_STORAGE_ERROR_EXISTS));
return;
}
- ServiceWorkerFetchStore* store = stores_loader_->CreateStore(store_name);
+ ServiceWorkerCache* cache = cache_loader_->CreateCache(cache_name);
- if (!store) {
+ if (!cache) {
callback_loop_->PostTask(
- FROM_HERE, base::Bind(callback, 0, FETCH_STORES_ERROR_STORAGE));
+ FROM_HERE, base::Bind(callback, 0, CACHE_STORAGE_ERROR_STORAGE));
return;
}
- InitStore(store);
+ InitCache(cache);
- stores_loader_->WriteIndex(&store_map_);
+ cache_loader_->WriteIndex(&cache_map_);
- store->CreateBackend(
- base::Bind(&ServiceWorkerFetchStores::InitializeStoreCallback,
+ cache->CreateBackend(
+ base::Bind(&ServiceWorkerCacheStorage::InitializeCacheCallback,
base::Unretained(this),
- store,
+ cache,
callback));
}
-void ServiceWorkerFetchStores::GetStore(const std::string& store_name,
- const StoreAndErrorCallback& callback) {
+void ServiceWorkerCacheStorage::GetCache(
+ const std::string& cache_name,
+ const CacheAndErrorCallback& callback) {
LazyInit();
- if (store_name.empty()) {
+ if (cache_name.empty()) {
callback_loop_->PostTask(
- FROM_HERE, base::Bind(callback, 0, FETCH_STORES_ERROR_EMPTY_KEY));
+ FROM_HERE, base::Bind(callback, 0, CACHE_STORAGE_ERROR_EMPTY_KEY));
return;
}
- ServiceWorkerFetchStore* store = GetLoadedStore(store_name);
- if (!store) {
+ ServiceWorkerCache* cache = GetLoadedCache(cache_name);
+ if (!cache) {
callback_loop_->PostTask(
- FROM_HERE, base::Bind(callback, 0, FETCH_STORES_ERROR_NOT_FOUND));
+ FROM_HERE, base::Bind(callback, 0, CACHE_STORAGE_ERROR_NOT_FOUND));
return;
}
- store->CreateBackend(
- base::Bind(&ServiceWorkerFetchStores::InitializeStoreCallback,
+ cache->CreateBackend(
+ base::Bind(&ServiceWorkerCacheStorage::InitializeCacheCallback,
base::Unretained(this),
- store,
+ cache,
callback));
}
-void ServiceWorkerFetchStores::HasStore(const std::string& store_name,
- const BoolAndErrorCallback& callback) {
+void ServiceWorkerCacheStorage::HasCache(const std::string& cache_name,
+ const BoolAndErrorCallback& callback) {
LazyInit();
- if (store_name.empty()) {
+ if (cache_name.empty()) {
callback_loop_->PostTask(
- FROM_HERE, base::Bind(callback, false, FETCH_STORES_ERROR_EMPTY_KEY));
+ FROM_HERE, base::Bind(callback, false, CACHE_STORAGE_ERROR_EMPTY_KEY));
return;
}
- bool has_store = GetLoadedStore(store_name) != NULL;
+ bool has_cache = GetLoadedCache(cache_name) != NULL;
callback_loop_->PostTask(
FROM_HERE,
base::Bind(
- callback, has_store, FETCH_STORES_ERROR_NO_ERROR));
+ callback, has_cache, CACHE_STORAGE_ERROR_NO_ERROR));
}
-void ServiceWorkerFetchStores::DeleteStore(
- const std::string& store_name,
+void ServiceWorkerCacheStorage::DeleteCache(
+ const std::string& cache_name,
const BoolAndErrorCallback& callback) {
LazyInit();
- if (store_name.empty()) {
+ if (cache_name.empty()) {
callback_loop_->PostTask(
- FROM_HERE, base::Bind(callback, false, FETCH_STORES_ERROR_EMPTY_KEY));
+ FROM_HERE, base::Bind(callback, false, CACHE_STORAGE_ERROR_EMPTY_KEY));
return;
}
- ServiceWorkerFetchStore* store = GetLoadedStore(store_name);
- if (!store) {
+ ServiceWorkerCache* cache = GetLoadedCache(cache_name);
+ if (!cache) {
callback_loop_->PostTask(
- FROM_HERE, base::Bind(callback, false, FETCH_STORES_ERROR_NOT_FOUND));
+ FROM_HERE, base::Bind(callback, false, CACHE_STORAGE_ERROR_NOT_FOUND));
return;
}
- name_map_.erase(store_name);
- store_map_.Remove(store->id()); // deletes store
+ name_map_.erase(cache_name);
+ cache_map_.Remove(cache->id()); // deletes cache
- stores_loader_->WriteIndex(&store_map_); // Update the index.
+ cache_loader_->WriteIndex(&cache_map_); // Update the index.
- stores_loader_->CleanUpDeletedStore(store_name);
+ cache_loader_->CleanUpDeletedCache(cache_name);
callback_loop_->PostTask(
- FROM_HERE, base::Bind(callback, true, FETCH_STORES_ERROR_NO_ERROR));
+ FROM_HERE, base::Bind(callback, true, CACHE_STORAGE_ERROR_NO_ERROR));
}
-void ServiceWorkerFetchStores::EnumerateStores(
+void ServiceWorkerCacheStorage::EnumerateCaches(
const StringsAndErrorCallback& callback) {
LazyInit();
@@ -275,60 +280,60 @@ void ServiceWorkerFetchStores::EnumerateStores(
}
callback_loop_->PostTask(
- FROM_HERE, base::Bind(callback, names, FETCH_STORES_ERROR_NO_ERROR));
+ FROM_HERE, base::Bind(callback, names, CACHE_STORAGE_ERROR_NO_ERROR));
}
-void ServiceWorkerFetchStores::InitializeStoreCallback(
- const ServiceWorkerFetchStore* store,
- const StoreAndErrorCallback& callback,
+void ServiceWorkerCacheStorage::InitializeCacheCallback(
+ const ServiceWorkerCache* cache,
+ const CacheAndErrorCallback& callback,
bool success) {
if (!success) {
// TODO(jkarlin): This should delete the directory and try again in case
// the cache is simply corrupt.
callback_loop_->PostTask(
- FROM_HERE, base::Bind(callback, 0, FETCH_STORES_ERROR_STORAGE));
+ FROM_HERE, base::Bind(callback, 0, CACHE_STORAGE_ERROR_STORAGE));
return;
}
callback_loop_->PostTask(
FROM_HERE,
- base::Bind(callback, store->id(), FETCH_STORES_ERROR_NO_ERROR));
+ base::Bind(callback, cache->id(), CACHE_STORAGE_ERROR_NO_ERROR));
}
// Init is run lazily so that it is called on the proper MessageLoop.
-void ServiceWorkerFetchStores::LazyInit() {
+void ServiceWorkerCacheStorage::LazyInit() {
if (initialized_)
return;
- std::vector<std::string> indexed_store_names;
- stores_loader_->LoadIndex(&indexed_store_names);
+ std::vector<std::string> indexed_cache_names;
+ cache_loader_->LoadIndex(&indexed_cache_names);
for (std::vector<std::string>::const_iterator it =
- indexed_store_names.begin();
- it != indexed_store_names.end();
+ indexed_cache_names.begin();
+ it != indexed_cache_names.end();
++it) {
- ServiceWorkerFetchStore* store = stores_loader_->LoadStore(*it);
- InitStore(store);
+ ServiceWorkerCache* cache = cache_loader_->LoadCache(*it);
+ InitCache(cache);
}
initialized_ = true;
}
-void ServiceWorkerFetchStores::InitStore(ServiceWorkerFetchStore* store) {
- StoreID id = store_map_.Add(store);
- name_map_.insert(std::make_pair(store->name(), id));
- store->set_id(id);
+void ServiceWorkerCacheStorage::InitCache(ServiceWorkerCache* cache) {
+ CacheID id = cache_map_.Add(cache);
+ name_map_.insert(std::make_pair(cache->name(), id));
+ cache->set_id(id);
}
-ServiceWorkerFetchStore* ServiceWorkerFetchStores::GetLoadedStore(
- const std::string& key) const {
+ServiceWorkerCache* ServiceWorkerCacheStorage::GetLoadedCache(
+ const std::string& cache_name) const {
DCHECK(initialized_);
- NameMap::const_iterator it = name_map_.find(key);
+ NameMap::const_iterator it = name_map_.find(cache_name);
if (it == name_map_.end())
return NULL;
- ServiceWorkerFetchStore* store = store_map_.Lookup(it->second);
- DCHECK(store);
- return store;
+ ServiceWorkerCache* cache = cache_map_.Lookup(it->second);
+ DCHECK(cache);
+ return cache;
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698