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

Unified Diff: net/disk_cache/blockfile/backend_impl.cc

Issue 547513002: Remove disk_cache::BackendImpl::OpenPrevEntry() and all users. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: narrower 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/blockfile/backend_impl.cc
diff --git a/net/disk_cache/blockfile/backend_impl.cc b/net/disk_cache/blockfile/backend_impl.cc
index 0d258351a351bd4a5bddf186e750cac9fc4a324a..c38b2bb9e33b49fa7e4945edc7380b235b5d3b8a 100644
--- a/net/disk_cache/blockfile/backend_impl.cc
+++ b/net/disk_cache/blockfile/backend_impl.cc
@@ -328,13 +328,6 @@ void BackendImpl::CleanupCache() {
// ------------------------------------------------------------------------
-int BackendImpl::OpenPrevEntry(void** iter, Entry** prev_entry,
- const CompletionCallback& callback) {
- DCHECK(!callback.is_null());
- background_queue_.OpenPrevEntry(iter, prev_entry, callback);
- return net::ERR_IO_PENDING;
-}
-
int BackendImpl::SyncOpenEntry(const std::string& key, Entry** entry) {
DCHECK(entry);
*entry = OpenEntryImpl(key);
@@ -444,11 +437,6 @@ int BackendImpl::SyncOpenNextEntry(void** iter, Entry** next_entry) {
return (*next_entry) ? net::OK : net::ERR_FAILED;
}
-int BackendImpl::SyncOpenPrevEntry(void** iter, Entry** prev_entry) {
- *prev_entry = OpenPrevEntryImpl(iter);
- return (*prev_entry) ? net::OK : net::ERR_FAILED;
-}
-
void BackendImpl::SyncEndEnumeration(void* iter) {
scoped_ptr<Rankings::Iterator> iterator(
reinterpret_cast<Rankings::Iterator*>(iter));
@@ -617,11 +605,74 @@ EntryImpl* BackendImpl::CreateEntryImpl(const std::string& key) {
}
EntryImpl* BackendImpl::OpenNextEntryImpl(void** iter) {
- return OpenFollowingEntry(true, iter);
-}
+ if (disabled_)
+ return NULL;
+
+ DCHECK(iter);
+
+ const int kListsToSearch = 3;
+ scoped_refptr<EntryImpl> entries[kListsToSearch];
+ scoped_ptr<Rankings::Iterator> iterator(
+ reinterpret_cast<Rankings::Iterator*>(*iter));
+ *iter = NULL;
-EntryImpl* BackendImpl::OpenPrevEntryImpl(void** iter) {
- return OpenFollowingEntry(false, iter);
+ if (!iterator.get()) {
+ iterator.reset(new Rankings::Iterator(&rankings_));
+ bool ret = false;
+
+ // Get an entry from each list.
+ for (int i = 0; i < kListsToSearch; i++) {
+ EntryImpl* temp = NULL;
+ ret |= OpenFollowingEntryFromList(static_cast<Rankings::List>(i),
+ &iterator->nodes[i], &temp);
+ entries[i].swap(&temp); // The entry was already addref'd.
+ }
+ if (!ret)
+ return NULL;
+ } else {
+ // Get the next entry from the last list, and the actual entries for the
+ // elements on the other lists.
+ for (int i = 0; i < kListsToSearch; i++) {
+ EntryImpl* temp = NULL;
+ if (iterator->list == i) {
+ OpenFollowingEntryFromList(
+ iterator->list, &iterator->nodes[i], &temp);
+ } else {
+ temp = GetEnumeratedEntry(iterator->nodes[i],
+ static_cast<Rankings::List>(i));
+ }
+
+ entries[i].swap(&temp); // The entry was already addref'd.
+ }
+ }
+
+ int newest = -1;
+ int oldest = -1;
+ Time access_times[kListsToSearch];
+ for (int i = 0; i < kListsToSearch; i++) {
+ if (entries[i].get()) {
+ access_times[i] = entries[i]->GetLastUsed();
+ if (newest < 0) {
+ DCHECK_LT(oldest, 0);
+ newest = oldest = i;
+ continue;
+ }
+ if (access_times[i] > access_times[newest])
+ newest = i;
+ if (access_times[i] < access_times[oldest])
+ oldest = i;
+ }
+ }
+
+ if (newest < 0 || oldest < 0)
+ return NULL;
+
+ EntryImpl* next_entry;
+ next_entry = entries[newest].get();
+ iterator->list = static_cast<Rankings::List>(newest);
+ *iter = iterator.release();
+ next_entry->AddRef();
+ return next_entry;
}
bool BackendImpl::SetMaxSize(int max_bytes) {
@@ -1619,85 +1670,7 @@ EntryImpl* BackendImpl::MatchEntry(const std::string& key, uint32 hash,
return tmp;
}
-// This is the actual implementation for OpenNextEntry and OpenPrevEntry.
-EntryImpl* BackendImpl::OpenFollowingEntry(bool forward, void** iter) {
- if (disabled_)
- return NULL;
-
- DCHECK(iter);
-
- const int kListsToSearch = 3;
- scoped_refptr<EntryImpl> entries[kListsToSearch];
- scoped_ptr<Rankings::Iterator> iterator(
- reinterpret_cast<Rankings::Iterator*>(*iter));
- *iter = NULL;
-
- if (!iterator.get()) {
- iterator.reset(new Rankings::Iterator(&rankings_));
- bool ret = false;
-
- // Get an entry from each list.
- for (int i = 0; i < kListsToSearch; i++) {
- EntryImpl* temp = NULL;
- ret |= OpenFollowingEntryFromList(forward, static_cast<Rankings::List>(i),
- &iterator->nodes[i], &temp);
- entries[i].swap(&temp); // The entry was already addref'd.
- }
- if (!ret)
- return NULL;
- } else {
- // Get the next entry from the last list, and the actual entries for the
- // elements on the other lists.
- for (int i = 0; i < kListsToSearch; i++) {
- EntryImpl* temp = NULL;
- if (iterator->list == i) {
- OpenFollowingEntryFromList(forward, iterator->list,
- &iterator->nodes[i], &temp);
- } else {
- temp = GetEnumeratedEntry(iterator->nodes[i],
- static_cast<Rankings::List>(i));
- }
-
- entries[i].swap(&temp); // The entry was already addref'd.
- }
- }
-
- int newest = -1;
- int oldest = -1;
- Time access_times[kListsToSearch];
- for (int i = 0; i < kListsToSearch; i++) {
- if (entries[i].get()) {
- access_times[i] = entries[i]->GetLastUsed();
- if (newest < 0) {
- DCHECK_LT(oldest, 0);
- newest = oldest = i;
- continue;
- }
- if (access_times[i] > access_times[newest])
- newest = i;
- if (access_times[i] < access_times[oldest])
- oldest = i;
- }
- }
-
- if (newest < 0 || oldest < 0)
- return NULL;
-
- EntryImpl* next_entry;
- if (forward) {
- next_entry = entries[newest].get();
- iterator->list = static_cast<Rankings::List>(newest);
- } else {
- next_entry = entries[oldest].get();
- iterator->list = static_cast<Rankings::List>(oldest);
- }
-
- *iter = iterator.release();
- next_entry->AddRef();
- return next_entry;
-}
-
-bool BackendImpl::OpenFollowingEntryFromList(bool forward, Rankings::List list,
+bool BackendImpl::OpenFollowingEntryFromList(Rankings::List list,
CacheRankingsBlock** from_entry,
EntryImpl** next_entry) {
if (disabled_)
@@ -1707,9 +1680,7 @@ bool BackendImpl::OpenFollowingEntryFromList(bool forward, Rankings::List list,
return false;
Rankings::ScopedRankingsBlock rankings(&rankings_, *from_entry);
- CacheRankingsBlock* next_block = forward ?
- rankings_.GetNext(rankings.get(), list) :
- rankings_.GetPrev(rankings.get(), list);
+ CacheRankingsBlock* next_block = rankings_.GetNext(rankings.get(), list);
Rankings::ScopedRankingsBlock next(&rankings_, next_block);
*from_entry = NULL;

Powered by Google App Engine
This is Rietveld 408576698