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

Unified Diff: content/browser/cache_storage/cache_storage_manager.cc

Issue 1039763002: Cache Storage: Move files to content/*/cache_storage, rename classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GN fix Created 5 years, 9 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/cache_storage/cache_storage_manager.cc
diff --git a/content/browser/service_worker/service_worker_cache_storage_manager.cc b/content/browser/cache_storage/cache_storage_manager.cc
similarity index 65%
rename from content/browser/service_worker/service_worker_cache_storage_manager.cc
rename to content/browser/cache_storage/cache_storage_manager.cc
index 93d5b6af6ac7b3ee694ad7cfd52d8fc458721a77..9b56c07954c8ffa895a80ad8e9bd548208eb2767 100644
--- a/content/browser/service_worker/service_worker_cache_storage_manager.cc
+++ b/content/browser/cache_storage/cache_storage_manager.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_cache_storage_manager.h"
+#include "content/browser/cache_storage/cache_storage_manager.h"
#include <map>
#include <string>
@@ -14,9 +14,9 @@
#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.pb.h"
-#include "content/browser/service_worker/service_worker_cache_quota_client.h"
-#include "content/browser/service_worker/service_worker_cache_storage.h"
+#include "content/browser/cache_storage/cache_storage.h"
+#include "content/browser/cache_storage/cache_storage.pb.h"
+#include "content/browser/cache_storage/cache_storage_quota_client.h"
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/net_util.h"
@@ -43,16 +43,16 @@ void DeleteOriginDidDeleteDir(
std::set<GURL> ListOriginsOnDisk(base::FilePath root_path_) {
std::set<GURL> origins;
- base::FileEnumerator file_enum(
- root_path_, false /* recursive */, base::FileEnumerator::DIRECTORIES);
+ base::FileEnumerator file_enum(root_path_, false /* recursive */,
+ base::FileEnumerator::DIRECTORIES);
base::FilePath path;
while (!(path = file_enum.Next()).empty()) {
std::string protobuf;
- base::ReadFileToString(
- path.AppendASCII(ServiceWorkerCacheStorage::kIndexFileName), &protobuf);
+ base::ReadFileToString(path.AppendASCII(CacheStorage::kIndexFileName),
+ &protobuf);
- ServiceWorkerCacheStorageIndex index;
+ CacheStorageIndex index;
if (index.ParseFromString(protobuf)) {
if (index.has_origin())
origins.insert(GURL(index.origin()));
@@ -77,8 +77,7 @@ void GetOriginsForHostDidListOrigins(
} // namespace
// static
-scoped_ptr<ServiceWorkerCacheStorageManager>
-ServiceWorkerCacheStorageManager::Create(
+scoped_ptr<CacheStorageManager> CacheStorageManager::Create(
const base::FilePath& path,
const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner,
const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy) {
@@ -88,19 +87,16 @@ ServiceWorkerCacheStorageManager::Create(
.AppendASCII("CacheStorage");
}
- return make_scoped_ptr(new ServiceWorkerCacheStorageManager(
- root_path, cache_task_runner, quota_manager_proxy));
+ return make_scoped_ptr(new CacheStorageManager(root_path, cache_task_runner,
+ quota_manager_proxy));
}
// static
-scoped_ptr<ServiceWorkerCacheStorageManager>
-ServiceWorkerCacheStorageManager::Create(
- ServiceWorkerCacheStorageManager* old_manager) {
- scoped_ptr<ServiceWorkerCacheStorageManager> manager(
- new ServiceWorkerCacheStorageManager(
- old_manager->root_path(),
- old_manager->cache_task_runner(),
- old_manager->quota_manager_proxy_.get()));
+scoped_ptr<CacheStorageManager> CacheStorageManager::Create(
+ CacheStorageManager* old_manager) {
+ scoped_ptr<CacheStorageManager> manager(new CacheStorageManager(
+ old_manager->root_path(), old_manager->cache_task_runner(),
+ old_manager->quota_manager_proxy_.get()));
// These values may be NULL, in which case this will be called again later by
// the dispatcher host per usual.
manager->SetBlobParametersForCache(old_manager->url_request_context(),
@@ -108,82 +104,75 @@ ServiceWorkerCacheStorageManager::Create(
return manager.Pass();
}
-ServiceWorkerCacheStorageManager::~ServiceWorkerCacheStorageManager() {
+CacheStorageManager::~CacheStorageManager() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- for (ServiceWorkerCacheStorageMap::iterator it = cache_storage_map_.begin();
- it != cache_storage_map_.end();
- ++it) {
+ for (CacheStorageMap::iterator it = cache_storage_map_.begin();
+ it != cache_storage_map_.end(); ++it) {
delete it->second;
}
}
-void ServiceWorkerCacheStorageManager::OpenCache(
+void CacheStorageManager::OpenCache(
const GURL& origin,
const std::string& cache_name,
- const ServiceWorkerCacheStorage::CacheAndErrorCallback& callback) {
+ const CacheStorage::CacheAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- ServiceWorkerCacheStorage* cache_storage =
- FindOrCreateServiceWorkerCacheManager(origin);
+ CacheStorage* cache_storage = FindOrCreateCacheStorage(origin);
cache_storage->OpenCache(cache_name, callback);
}
-void ServiceWorkerCacheStorageManager::HasCache(
+void CacheStorageManager::HasCache(
const GURL& origin,
const std::string& cache_name,
- const ServiceWorkerCacheStorage::BoolAndErrorCallback& callback) {
+ const CacheStorage::BoolAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- ServiceWorkerCacheStorage* cache_storage =
- FindOrCreateServiceWorkerCacheManager(origin);
+ CacheStorage* cache_storage = FindOrCreateCacheStorage(origin);
cache_storage->HasCache(cache_name, callback);
}
-void ServiceWorkerCacheStorageManager::DeleteCache(
+void CacheStorageManager::DeleteCache(
const GURL& origin,
const std::string& cache_name,
- const ServiceWorkerCacheStorage::BoolAndErrorCallback& callback) {
+ const CacheStorage::BoolAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- ServiceWorkerCacheStorage* cache_storage =
- FindOrCreateServiceWorkerCacheManager(origin);
+ CacheStorage* cache_storage = FindOrCreateCacheStorage(origin);
cache_storage->DeleteCache(cache_name, callback);
}
-void ServiceWorkerCacheStorageManager::EnumerateCaches(
+void CacheStorageManager::EnumerateCaches(
const GURL& origin,
- const ServiceWorkerCacheStorage::StringsAndErrorCallback& callback) {
+ const CacheStorage::StringsAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- ServiceWorkerCacheStorage* cache_storage =
- FindOrCreateServiceWorkerCacheManager(origin);
+ CacheStorage* cache_storage = FindOrCreateCacheStorage(origin);
cache_storage->EnumerateCaches(callback);
}
-void ServiceWorkerCacheStorageManager::MatchCache(
+void CacheStorageManager::MatchCache(
const GURL& origin,
const std::string& cache_name,
scoped_ptr<ServiceWorkerFetchRequest> request,
- const ServiceWorkerCache::ResponseCallback& callback) {
- ServiceWorkerCacheStorage* cache_storage =
- FindOrCreateServiceWorkerCacheManager(origin);
+ const CacheStorageCache::ResponseCallback& callback) {
+ CacheStorage* cache_storage = FindOrCreateCacheStorage(origin);
cache_storage->MatchCache(cache_name, request.Pass(), callback);
}
-void ServiceWorkerCacheStorageManager::MatchAllCaches(
+void CacheStorageManager::MatchAllCaches(
const GURL& origin,
scoped_ptr<ServiceWorkerFetchRequest> request,
- const ServiceWorkerCache::ResponseCallback& callback) {
- ServiceWorkerCacheStorage* cache_storage =
- FindOrCreateServiceWorkerCacheManager(origin);
+ const CacheStorageCache::ResponseCallback& callback) {
+ CacheStorage* cache_storage = FindOrCreateCacheStorage(origin);
cache_storage->MatchAllCaches(request.Pass(), callback);
}
-void ServiceWorkerCacheStorageManager::SetBlobParametersForCache(
+void CacheStorageManager::SetBlobParametersForCache(
net::URLRequestContext* request_context,
base::WeakPtr<storage::BlobStorageContext> blob_storage_context) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -194,7 +183,7 @@ void ServiceWorkerCacheStorageManager::SetBlobParametersForCache(
blob_context_ = blob_storage_context;
}
-void ServiceWorkerCacheStorageManager::GetOriginUsage(
+void CacheStorageManager::GetOriginUsage(
const GURL& origin_url,
const storage::QuotaClient::GetUsageCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -209,14 +198,13 @@ void ServiceWorkerCacheStorageManager::GetOriginUsage(
MigrateOrigin(origin_url);
PostTaskAndReplyWithResult(
- cache_task_runner_.get(),
- FROM_HERE,
+ cache_task_runner_.get(), FROM_HERE,
base::Bind(base::ComputeDirectorySize,
ConstructOriginPath(root_path_, origin_url)),
base::Bind(callback));
}
-void ServiceWorkerCacheStorageManager::GetOrigins(
+void CacheStorageManager::GetOrigins(
const storage::QuotaClient::GetOriginsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -229,13 +217,12 @@ void ServiceWorkerCacheStorageManager::GetOrigins(
return;
}
- PostTaskAndReplyWithResult(cache_task_runner_.get(),
- FROM_HERE,
+ PostTaskAndReplyWithResult(cache_task_runner_.get(), FROM_HERE,
base::Bind(&ListOriginsOnDisk, root_path_),
base::Bind(callback));
}
-void ServiceWorkerCacheStorageManager::GetOriginsForHost(
+void CacheStorageManager::GetOriginsForHost(
const std::string& host,
const storage::QuotaClient::GetOriginsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -251,32 +238,30 @@ void ServiceWorkerCacheStorageManager::GetOriginsForHost(
}
PostTaskAndReplyWithResult(
- cache_task_runner_.get(),
- FROM_HERE,
+ cache_task_runner_.get(), FROM_HERE,
base::Bind(&ListOriginsOnDisk, root_path_),
base::Bind(&GetOriginsForHostDidListOrigins, host, callback));
}
-void ServiceWorkerCacheStorageManager::DeleteOriginData(
+void CacheStorageManager::DeleteOriginData(
const GURL& origin,
const storage::QuotaClient::DeletionCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- ServiceWorkerCacheStorage* cache_storage =
- FindOrCreateServiceWorkerCacheManager(origin);
+ CacheStorage* cache_storage = FindOrCreateCacheStorage(origin);
cache_storage_map_.erase(origin);
cache_storage->CloseAllCaches(
- base::Bind(&ServiceWorkerCacheStorageManager::DeleteOriginDidClose,
- origin, callback, base::Passed(make_scoped_ptr(cache_storage)),
+ base::Bind(&CacheStorageManager::DeleteOriginDidClose, origin, callback,
+ base::Passed(make_scoped_ptr(cache_storage)),
weak_ptr_factory_.GetWeakPtr()));
}
// static
-void ServiceWorkerCacheStorageManager::DeleteOriginDidClose(
+void CacheStorageManager::DeleteOriginDidClose(
const GURL& origin,
const storage::QuotaClient::DeletionCallback& callback,
- scoped_ptr<ServiceWorkerCacheStorage> cache_storage,
- base::WeakPtr<ServiceWorkerCacheStorageManager> cache_manager) {
+ scoped_ptr<CacheStorage> cache_storage,
+ base::WeakPtr<CacheStorageManager> cache_manager) {
// TODO(jkarlin): Deleting the storage leaves any unfinished operations
// hanging, resulting in unresolved promises. Fix this by guaranteeing that
// callbacks are called in ServiceWorkerStorage.
@@ -300,7 +285,7 @@ void ServiceWorkerCacheStorageManager::DeleteOriginDidClose(
base::Bind(&DeleteOriginDidDeleteDir, callback));
}
-ServiceWorkerCacheStorageManager::ServiceWorkerCacheStorageManager(
+CacheStorageManager::CacheStorageManager(
const base::FilePath& path,
const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner,
const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy)
@@ -311,27 +296,21 @@ ServiceWorkerCacheStorageManager::ServiceWorkerCacheStorageManager(
weak_ptr_factory_(this) {
if (quota_manager_proxy_.get()) {
quota_manager_proxy_->RegisterClient(
- new ServiceWorkerCacheQuotaClient(weak_ptr_factory_.GetWeakPtr()));
+ new CacheStorageQuotaClient(weak_ptr_factory_.GetWeakPtr()));
}
}
-ServiceWorkerCacheStorage*
-ServiceWorkerCacheStorageManager::FindOrCreateServiceWorkerCacheManager(
+CacheStorage* CacheStorageManager::FindOrCreateCacheStorage(
const GURL& origin) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(request_context_);
- ServiceWorkerCacheStorageMap::const_iterator it =
- cache_storage_map_.find(origin);
+ CacheStorageMap::const_iterator it = cache_storage_map_.find(origin);
if (it == cache_storage_map_.end()) {
MigrateOrigin(origin);
- ServiceWorkerCacheStorage* cache_storage =
- new ServiceWorkerCacheStorage(ConstructOriginPath(root_path_, origin),
- IsMemoryBacked(),
- cache_task_runner_.get(),
- request_context_,
- quota_manager_proxy_,
- blob_context_,
- origin);
+ CacheStorage* cache_storage = new CacheStorage(
+ ConstructOriginPath(root_path_, origin), IsMemoryBacked(),
+ cache_task_runner_.get(), request_context_, quota_manager_proxy_,
+ blob_context_, origin);
// The map owns fetch_stores.
cache_storage_map_.insert(std::make_pair(origin, cache_storage));
return cache_storage;
@@ -340,7 +319,7 @@ ServiceWorkerCacheStorageManager::FindOrCreateServiceWorkerCacheManager(
}
// static
-base::FilePath ServiceWorkerCacheStorageManager::ConstructLegacyOriginPath(
+base::FilePath CacheStorageManager::ConstructLegacyOriginPath(
const base::FilePath& root_path,
const GURL& origin) {
const std::string origin_hash = base::SHA1HashString(origin.spec());
@@ -350,7 +329,7 @@ base::FilePath ServiceWorkerCacheStorageManager::ConstructLegacyOriginPath(
}
// static
-base::FilePath ServiceWorkerCacheStorageManager::ConstructOriginPath(
+base::FilePath CacheStorageManager::ConstructOriginPath(
const base::FilePath& root_path,
const GURL& origin) {
const std::string identifier = storage::GetIdentifierFromOrigin(origin);
@@ -362,7 +341,7 @@ base::FilePath ServiceWorkerCacheStorageManager::ConstructOriginPath(
// Migrate from old origin-based path to storage identifier-based path.
// TODO(jsbell); Remove after a few releases.
-void ServiceWorkerCacheStorageManager::MigrateOrigin(const GURL& origin) {
+void CacheStorageManager::MigrateOrigin(const GURL& origin) {
if (IsMemoryBacked())
return;
base::FilePath old_path = ConstructLegacyOriginPath(root_path_, origin);
@@ -372,7 +351,7 @@ void ServiceWorkerCacheStorageManager::MigrateOrigin(const GURL& origin) {
}
// static
-void ServiceWorkerCacheStorageManager::MigrateOriginOnTaskRunner(
+void CacheStorageManager::MigrateOriginOnTaskRunner(
const base::FilePath& old_path,
const base::FilePath& new_path) {
if (base::PathExists(old_path)) {
« no previous file with comments | « content/browser/cache_storage/cache_storage_manager.h ('k') | content/browser/cache_storage/cache_storage_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698