Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/disk_cache/simple/simple_backend_impl.h" | 5 #include "net/disk_cache/simple/simple_backend_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 namespace disk_cache { | 38 namespace disk_cache { |
| 39 | 39 |
| 40 SimpleBackendImpl::SimpleBackendImpl( | 40 SimpleBackendImpl::SimpleBackendImpl( |
| 41 const FilePath& path, | 41 const FilePath& path, |
| 42 int max_bytes, | 42 int max_bytes, |
| 43 net::CacheType type, | 43 net::CacheType type, |
| 44 const scoped_refptr<base::TaskRunner>& cache_thread, | 44 const scoped_refptr<base::TaskRunner>& cache_thread, |
| 45 net::NetLog* net_log) | 45 net::NetLog* net_log) |
| 46 : path_(path), | 46 : path_(path), |
| 47 cache_thread_(cache_thread) { | 47 cache_thread_(cache_thread) { |
| 48 index_.reset(new SimpleIndex(cache_thread, path)); | 48 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.
| |
| 49 MessageLoopProxy::current(), // io_thread | |
| 50 path)); | |
| 51 | |
| 49 } | 52 } |
| 50 | 53 |
| 51 int SimpleBackendImpl::Init(const CompletionCallback& callback) { | 54 int SimpleBackendImpl::Init(const CompletionCallback& completition_callback) { |
| 55 InitializeIndexCallback initialize_index_callback = | |
| 56 base::Bind(&SimpleBackendImpl::InitializeIndex, | |
| 57 base::Unretained(this), | |
| 58 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.
| |
| 52 cache_thread_->PostTask(FROM_HERE, | 59 cache_thread_->PostTask(FROM_HERE, |
| 53 base::Bind(&SimpleBackendImpl::InitializeIndex, | 60 base::Bind(&SimpleBackendImpl::CreateDirectory, |
| 54 base::Unretained(this), | 61 MessageLoopProxy::current(), // io_thread |
| 55 MessageLoopProxy::current(), | 62 path_, |
| 56 callback)); | 63 initialize_index_callback)); |
| 57 return net::ERR_IO_PENDING; | 64 return net::ERR_IO_PENDING; |
| 58 } | 65 } |
| 59 | 66 |
| 60 SimpleBackendImpl::~SimpleBackendImpl() { | 67 SimpleBackendImpl::~SimpleBackendImpl() { |
| 61 index_->Cleanup(); | 68 index_->WriteToDisk(); |
| 62 } | 69 } |
| 63 | 70 |
| 64 net::CacheType SimpleBackendImpl::GetCacheType() const { | 71 net::CacheType SimpleBackendImpl::GetCacheType() const { |
| 65 return net::DISK_CACHE; | 72 return net::DISK_CACHE; |
| 66 } | 73 } |
| 67 | 74 |
| 68 int32 SimpleBackendImpl::GetEntryCount() const { | 75 int32 SimpleBackendImpl::GetEntryCount() const { |
| 69 NOTIMPLEMENTED(); | 76 NOTIMPLEMENTED(); |
| 70 return 0; | 77 return 0; |
| 71 } | 78 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 | 129 |
| 123 void SimpleBackendImpl::GetStats( | 130 void SimpleBackendImpl::GetStats( |
| 124 std::vector<std::pair<std::string, std::string> >* stats) { | 131 std::vector<std::pair<std::string, std::string> >* stats) { |
| 125 NOTIMPLEMENTED(); | 132 NOTIMPLEMENTED(); |
| 126 } | 133 } |
| 127 | 134 |
| 128 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { | 135 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { |
| 129 NOTIMPLEMENTED(); | 136 NOTIMPLEMENTED(); |
| 130 } | 137 } |
| 131 | 138 |
| 132 void SimpleBackendImpl::InitializeIndex(MessageLoopProxy* io_thread, | 139 void SimpleBackendImpl::InitializeIndex( |
| 133 const CompletionCallback& callback) { | 140 const CompletionCallback& callback, int rv) { |
| 141 if (rv == net::OK) | |
| 142 index_->Initialize(); | |
| 143 callback.Run(rv); | |
| 144 } | |
| 145 | |
| 146 // static | |
| 147 void SimpleBackendImpl::CreateDirectory( | |
| 148 MessageLoopProxy* io_thread, | |
| 149 const base::FilePath& path, | |
| 150 const InitializeIndexCallback& initialize_index_callback) { | |
| 134 int rv = net::OK; | 151 int rv = net::OK; |
| 135 if (!file_util::PathExists(path_) && !file_util::CreateDirectory(path_)) { | 152 if (!file_util::PathExists(path) && !file_util::CreateDirectory(path)) { |
| 136 LOG(ERROR) << "Simple Cache Backend: failed to create: " << path_.value(); | 153 LOG(ERROR) << "Simple Cache Backend: failed to create: " << path.value(); |
| 137 rv = net::ERR_FAILED; | 154 rv = net::ERR_FAILED; |
| 138 } else | 155 } |
| 139 rv = index_->Initialize() ? net::OK : net::ERR_FAILED; | 156 |
| 140 io_thread->PostTask(FROM_HERE, base::Bind(callback, rv)); | 157 io_thread->PostTask(FROM_HERE, base::Bind(initialize_index_callback, rv)); |
| 141 } | 158 } |
| 142 | 159 |
| 143 } // namespace disk_cache | 160 } // namespace disk_cache |
| OLD | NEW |