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

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

Issue 542733002: Remove void** from disk_cache interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: now even less dumb Created 6 years, 3 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 ffdc9b185b366ef95a2f1b6ca91a89714e6423f5..a211c634ca095cc4b1bb466b990a298bedb64f1f 100644
--- a/net/disk_cache/simple/simple_backend_impl.cc
+++ b/net/disk_cache/simple/simple_backend_impl.cc
@@ -473,20 +473,77 @@ int SimpleBackendImpl::DoomEntriesSince(
return DoomEntriesBetween(initial_time, Time(), callback);
}
-int SimpleBackendImpl::OpenNextEntry(void** iter,
- Entry** next_entry,
- const CompletionCallback& callback) {
- CompletionCallback get_next_entry =
- base::Bind(&SimpleBackendImpl::GetNextEntryInIterator, AsWeakPtr(), iter,
- next_entry, callback);
- return index_->ExecuteWhenReady(get_next_entry);
-}
+class SimpleBackendImpl::SimpleIterator : public Iterator {
+ public:
+ explicit SimpleIterator(base::WeakPtr<SimpleBackendImpl> backend)
+ : backend_(backend),
+ weak_factory_(this) {}
+
+ // From Backend::Iterator:
+ virtual int OpenNextEntry(Entry** next_entry,
+ const CompletionCallback& callback) OVERRIDE {
+ CompletionCallback open_next_entry_impl =
+ base::Bind(&SimpleIterator::OpenNextEntryImpl,
+ weak_factory_.GetWeakPtr(), next_entry, callback);
+ return backend_->index_->ExecuteWhenReady(open_next_entry_impl);
+ }
+
+ void OpenNextEntryImpl(Entry** next_entry,
pasko 2014/09/12 08:10:26 This has a lot in common with SimpleBackendImpl::G
gavinp 2014/09/12 14:15:32 You're right, that would have been a good way to p
+ const CompletionCallback& callback,
+ int index_initialization_error_code) {
+ if (!backend_) {
+ callback.Run(net::ERR_FAILED);
+ return;
+ }
+ if (index_initialization_error_code != net::OK) {
+ callback.Run(index_initialization_error_code);
+ return;
+ }
+ if (!hashes_to_enumerate_)
+ hashes_to_enumerate_ = backend_->index()->GetAllHashes().Pass();
+
+ while (!hashes_to_enumerate_->empty()) {
+ uint64 entry_hash = hashes_to_enumerate_->back();
+ hashes_to_enumerate_->pop_back();
+ if (backend_->index()->Has(entry_hash)) {
+ *next_entry = NULL;
+ CompletionCallback continue_iteration = base::Bind(
+ &SimpleIterator::CheckIterationReturnValue,
+ weak_factory_.GetWeakPtr(),
+ next_entry,
+ callback);
+ int error_code_open = backend_->OpenEntryFromHash(entry_hash,
+ next_entry,
+ continue_iteration);
+ if (error_code_open == net::ERR_IO_PENDING)
+ return;
+ if (error_code_open != net::ERR_FAILED) {
+ callback.Run(error_code_open);
+ return;
+ }
+ }
+ }
+ callback.Run(net::ERR_FAILED);
+ }
-void SimpleBackendImpl::EndEnumeration(void** iter) {
- SimpleIndex::HashList* entry_list =
- static_cast<SimpleIndex::HashList*>(*iter);
- delete entry_list;
- *iter = NULL;
+ void CheckIterationReturnValue(Entry** entry,
+ const CompletionCallback& callback,
+ int error_code) {
+ if (error_code == net::ERR_FAILED) {
+ OpenNextEntry(entry, callback);
+ return;
+ }
+ callback.Run(error_code);
+ }
+
+ private:
+ base::WeakPtr<SimpleBackendImpl> backend_;
+ scoped_ptr<std::vector<uint64> > hashes_to_enumerate_;
+ base::WeakPtrFactory<SimpleIterator> weak_factory_;
+};
+
+scoped_ptr<Backend::Iterator> SimpleBackendImpl::CreateIterator() {
+ return scoped_ptr<Iterator>(new SimpleIterator(AsWeakPtr()));
}
void SimpleBackendImpl::GetStats(
@@ -614,45 +671,6 @@ int SimpleBackendImpl::DoomEntryFromHash(uint64 entry_hash,
return net::ERR_IO_PENDING;
}
-void SimpleBackendImpl::GetNextEntryInIterator(
- void** iter,
- Entry** next_entry,
- const CompletionCallback& callback,
- int error_code) {
- if (error_code != net::OK) {
- callback.Run(error_code);
- return;
- }
- if (*iter == NULL) {
- *iter = index()->GetAllHashes().release();
- }
- SimpleIndex::HashList* entry_list =
- static_cast<SimpleIndex::HashList*>(*iter);
- while (entry_list->size() > 0) {
- uint64 entry_hash = entry_list->back();
- entry_list->pop_back();
- if (index()->Has(entry_hash)) {
- *next_entry = NULL;
- CompletionCallback continue_iteration = base::Bind(
- &SimpleBackendImpl::CheckIterationReturnValue,
- AsWeakPtr(),
- iter,
- next_entry,
- callback);
- int error_code_open = OpenEntryFromHash(entry_hash,
- next_entry,
- continue_iteration);
- if (error_code_open == net::ERR_IO_PENDING)
- return;
- if (error_code_open != net::ERR_FAILED) {
- callback.Run(error_code_open);
- return;
- }
- }
- }
- callback.Run(net::ERR_FAILED);
-}
-
void SimpleBackendImpl::OnEntryOpenedFromHash(
uint64 hash,
Entry** entry,
@@ -706,18 +724,6 @@ void SimpleBackendImpl::OnEntryOpenedFromKey(
callback.Run(final_code);
}
-void SimpleBackendImpl::CheckIterationReturnValue(
- void** iter,
- Entry** entry,
- const CompletionCallback& callback,
- int error_code) {
- if (error_code == net::ERR_FAILED) {
- OpenNextEntry(iter, entry, callback);
- return;
- }
- callback.Run(error_code);
-}
-
void SimpleBackendImpl::DoomEntriesComplete(
scoped_ptr<std::vector<uint64> > entry_hashes,
const net::CompletionCallback& callback,

Powered by Google App Engine
This is Rietveld 408576698