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

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

Issue 13839011: Asynchronous initialization in Simple Index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_disk_format.h » ('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 1f88e0f3f19b982e1c1b8f9ecd2ad7fc98367991..8b8bef4ca48e8a918fea0d6d0e2eda28b3eee16a 100644
--- a/net/disk_cache/simple/simple_backend_impl.cc
+++ b/net/disk_cache/simple/simple_backend_impl.cc
@@ -44,23 +44,28 @@ SimpleBackendImpl::SimpleBackendImpl(
const scoped_refptr<base::TaskRunner>& cache_thread,
net::NetLog* net_log)
: path_(path),
- cache_thread_(cache_thread) {
- index_.reset(new SimpleIndex(cache_thread, path));
+ index_(new SimpleIndex(cache_thread,
+ MessageLoopProxy::current(), // io_thread
+ path)),
+ cache_thread_(cache_thread) {}
+
+SimpleBackendImpl::~SimpleBackendImpl() {
+ index_->WriteToDisk();
}
-int SimpleBackendImpl::Init(const CompletionCallback& callback) {
+int SimpleBackendImpl::Init(const CompletionCallback& completion_callback) {
+ InitializeIndexCallback initialize_index_callback =
+ base::Bind(&SimpleBackendImpl::InitializeIndex,
+ base::Unretained(this),
+ completion_callback);
cache_thread_->PostTask(FROM_HERE,
- base::Bind(&SimpleBackendImpl::InitializeIndex,
- base::Unretained(this),
- MessageLoopProxy::current(),
- callback));
+ base::Bind(&SimpleBackendImpl::CreateDirectory,
+ MessageLoopProxy::current(), // io_thread
+ path_,
+ initialize_index_callback));
return net::ERR_IO_PENDING;
}
-SimpleBackendImpl::~SimpleBackendImpl() {
- index_->Cleanup();
-}
-
net::CacheType SimpleBackendImpl::GetCacheType() const {
return net::DISK_CACHE;
}
@@ -129,15 +134,25 @@ void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) {
NOTIMPLEMENTED();
}
-void SimpleBackendImpl::InitializeIndex(MessageLoopProxy* io_thread,
- const CompletionCallback& callback) {
+void SimpleBackendImpl::InitializeIndex(
+ const CompletionCallback& callback, int result) {
+ if (result == net::OK)
+ index_->Initialize();
+ callback.Run(result);
+}
+
+// static
+void SimpleBackendImpl::CreateDirectory(
+ MessageLoopProxy* io_thread,
+ const base::FilePath& path,
+ const InitializeIndexCallback& initialize_index_callback) {
int rv = net::OK;
- if (!file_util::PathExists(path_) && !file_util::CreateDirectory(path_)) {
- LOG(ERROR) << "Simple Cache Backend: failed to create: " << path_.value();
+ 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));
+ }
+
+ io_thread->PostTask(FROM_HERE, base::Bind(initialize_index_callback, rv));
}
} // namespace disk_cache
« no previous file with comments | « net/disk_cache/simple/simple_backend_impl.h ('k') | net/disk_cache/simple/simple_disk_format.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698