Chromium Code Reviews| 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..ec88a4c3b2f7be67a1ca9051f71b83534c2cd0d7 100644 |
| --- a/net/disk_cache/simple/simple_backend_impl.cc |
| +++ b/net/disk_cache/simple/simple_backend_impl.cc |
| @@ -45,20 +45,27 @@ SimpleBackendImpl::SimpleBackendImpl( |
| net::NetLog* net_log) |
| : path_(path), |
| cache_thread_(cache_thread) { |
| - index_.reset(new SimpleIndex(cache_thread, path)); |
| + index_.reset(new SimpleIndex(cache_thread, |
|
gavinp
2013/04/11 09:56:32
Move this into the ctor list.
felipeg
2013/04/11 11:25:45
Done.
felipeg
2013/04/11 11:25:45
Done.
|
| + MessageLoopProxy::current(), // io_thread |
| + path)); |
| + |
| } |
| -int SimpleBackendImpl::Init(const CompletionCallback& callback) { |
| +int SimpleBackendImpl::Init(const CompletionCallback& completition_callback) { |
| + InitializeIndexCallback initialize_index_callback = |
| + base::Bind(&SimpleBackendImpl::InitializeIndex, |
| + base::Unretained(this), |
| + completition_callback); |
|
pasko-google - do not use
2013/04/10 17:51:01
s/completition_callback/completion_callback/
felipeg
2013/04/11 09:41:35
Done.
|
| 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 +136,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 rv) { |
| + if (rv == net::OK) |
| + index_->Initialize(); |
| + callback.Run(rv); |
| +} |
| + |
| +// 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 |