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

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
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..c82fe5ca2ba2d0b63dd957e5890d015e0dbee5ae 100644
--- a/net/disk_cache/simple/simple_backend_impl.cc
+++ b/net/disk_cache/simple/simple_backend_impl.cc
@@ -44,21 +44,26 @@ 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));
-}
-
-int SimpleBackendImpl::Init(const CompletionCallback& callback) {
+ index_(new SimpleIndex(cache_thread,
+ MessageLoopProxy::current(), // io_thread
+ path)),
+ cache_thread_(cache_thread) {}
+
+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();
+ index_->WriteToDisk();
}
net::CacheType SimpleBackendImpl::GetCacheType() const {
@@ -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

Powered by Google App Engine
This is Rietveld 408576698