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

Unified Diff: net/disk_cache/simple/simple_backend_impl.cc

Issue 13813015: Separate Simple Backend creation from initialization. (Closed) Base URL: http://git.chromium.org/chromium/src.git@trace-2
Patch Set: updated the simple backend initialization according to the new interface in tests Created 7 years, 8 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
« no previous file with comments | « net/disk_cache/simple/simple_backend_impl.h ('k') | net/disk_cache/simple/simple_index.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/simple/simple_backend_impl.cc
diff --git a/net/disk_cache/simple/simple_backend_impl.cc b/net/disk_cache/simple/simple_backend_impl.cc
index fba0b5a9728eb6ead2535db10254605eaafc5261..1f88e0f3f19b982e1c1b8f9ecd2ad7fc98367991 100644
--- a/net/disk_cache/simple/simple_backend_impl.cc
+++ b/net/disk_cache/simple/simple_backend_impl.cc
@@ -23,8 +23,6 @@ using file_util::CreateDirectory;
namespace {
-const char* kSimpleBackendSubdirectory = "Simple";
-
// Must run on IO Thread.
void DeleteBackendImpl(disk_cache::Backend** backend,
const net::CompletionCallback& callback,
@@ -39,32 +37,23 @@ void DeleteBackendImpl(disk_cache::Backend** backend,
namespace disk_cache {
-// static
-int SimpleBackendImpl::CreateBackend(
- const FilePath& full_path,
+SimpleBackendImpl::SimpleBackendImpl(
+ const FilePath& path,
int max_bytes,
net::CacheType type,
- uint32 flags,
- scoped_refptr<base::TaskRunner> cache_thread,
- net::NetLog* net_log,
- Backend** backend,
- const CompletionCallback& callback) {
- // TODO(gavinp): Use the |net_log|.
- DCHECK_EQ(net::DISK_CACHE, type);
- FilePath simple_cache_path =
- full_path.AppendASCII(kSimpleBackendSubdirectory);
-
- // In order to not leak when the EnsureCachePathExists fails, we need to
- // delete this in DeleteBackendImpl on the IO Thread.
- *backend = new SimpleBackendImpl(cache_thread, simple_cache_path);
-
- cache_thread->PostTask(FROM_HERE,
- base::Bind(&SimpleBackendImpl::EnsureCachePathExists,
- simple_cache_path,
- cache_thread,
- MessageLoopProxy::current(),
- callback,
- backend));
+ const scoped_refptr<base::TaskRunner>& cache_thread,
+ net::NetLog* net_log)
+ : path_(path),
gavinp 2013/04/10 14:20:53 index_(new SimpleIndex(cache_thread, path)), and
+ cache_thread_(cache_thread) {
+ index_.reset(new SimpleIndex(cache_thread, path));
+}
+
+int SimpleBackendImpl::Init(const CompletionCallback& callback) {
+ cache_thread_->PostTask(FROM_HERE,
+ base::Bind(&SimpleBackendImpl::InitializeIndex,
+ base::Unretained(this),
+ MessageLoopProxy::current(),
+ callback));
return net::ERR_IO_PENDING;
}
@@ -140,40 +129,15 @@ void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) {
NOTIMPLEMENTED();
}
-SimpleBackendImpl::SimpleBackendImpl(
- const scoped_refptr<base::TaskRunner>& cache_thread,
- const FilePath& path) : path_(path) {
- index_.reset(new SimpleIndex(cache_thread, path));
-}
-
-void SimpleBackendImpl::Initialize() {
- index_->Initialize();
-}
-
-// static
-void SimpleBackendImpl::EnsureCachePathExists(
- const FilePath& path,
- const scoped_refptr<base::TaskRunner>& cache_thread,
- const scoped_refptr<base::TaskRunner>& io_thread,
- const CompletionCallback& callback,
- Backend** backend) {
- int result = net::OK;
- if (!DirectoryExists(path) && !CreateDirectory(path))
- result = net::ERR_FAILED;
-
- if (result == net::OK) {
- DCHECK(*backend);
- // TODO(pasko): Move the object creation and initalization out of
- // CreateBackend and fix this downcast.
- static_cast<SimpleBackendImpl*>(*backend)->Initialize();
- io_thread->PostTask(FROM_HERE,
- base::Bind(callback, result));
- } else {
- io_thread->PostTask(FROM_HERE,
- base::Bind(
- &DeleteBackendImpl,
- backend, callback, result));
- }
+void SimpleBackendImpl::InitializeIndex(MessageLoopProxy* io_thread,
+ const CompletionCallback& callback) {
+ int rv = net::OK;
+ if (!file_util::PathExists(path_) && !file_util::CreateDirectory(path_)) {
+ LOG(ERROR) << "Simple Cache Backend: failed to create: " << path_.value();
+ rv = net::ERR_FAILED;
+ } else
+ rv = index_->Initialize() ? net::OK : net::ERR_FAILED;
+ io_thread->PostTask(FROM_HERE, base::Bind(callback, rv));
}
} // namespace disk_cache
« no previous file with comments | « net/disk_cache/simple/simple_backend_impl.h ('k') | net/disk_cache/simple/simple_index.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698