Index: net/disk_cache/backend_impl.cc |
=================================================================== |
--- net/disk_cache/backend_impl.cc (revision 6178) |
+++ net/disk_cache/backend_impl.cc (working copy) |
@@ -432,51 +432,7 @@ |
} |
bool BackendImpl::OpenNextEntry(void** iter, Entry** next_entry) { |
- if (disabled_) |
- return false; |
- |
- Rankings::ScopedRankingsBlock rankings(&rankings_, |
- reinterpret_cast<CacheRankingsBlock*>(*iter)); |
- Rankings::ScopedRankingsBlock next(&rankings_, |
- rankings_.GetNext(rankings.get())); |
- *next_entry = NULL; |
- *iter = NULL; |
- if (!next.get()) |
- return false; |
- |
- scoped_refptr<EntryImpl> entry; |
- if (next->Data()->pointer) { |
- entry = reinterpret_cast<EntryImpl*>(next->Data()->pointer); |
- } else { |
- bool dirty; |
- EntryImpl* temp = NULL; |
- if (NewEntry(Addr(next->Data()->contents), &temp, &dirty)) |
- return false; |
- entry.swap(&temp); |
- |
- if (dirty) { |
- // We cannot trust this entry. Call MatchEntry to go through the regular |
- // path and take the appropriate action. |
- std::string key = entry->GetKey(); |
- uint32 hash = entry->GetHash(); |
- entry = NULL; // Release the entry. |
- temp = MatchEntry(key, hash, false); |
- if (temp) |
- temp->Release(); |
- |
- return false; |
- } |
- |
- entry.swap(&temp); |
- temp = EntryImpl::Update(temp); // Update returns an adref'd entry. |
- entry.swap(&temp); |
- if (!entry.get()) |
- return false; |
- } |
- |
- entry.swap(reinterpret_cast<EntryImpl**>(next_entry)); |
- *iter = next.release(); |
- return true; |
+ return OpenFollowingEntry(true, iter, next_entry); |
} |
void BackendImpl::EndEnumeration(void** iter) { |
@@ -547,7 +503,7 @@ |
int file_number = data_->header.last_file + 1; |
Addr file_address(0); |
bool success = false; |
- for (int i = 0; (i < 0x0fffffff) && !success; i++, file_number++) { |
+ for (int i = 0; i < 0x0fffffff; i++, file_number++) { |
if (!file_address.SetFileNumber(file_number)) { |
file_number = 1; |
continue; |
@@ -563,6 +519,7 @@ |
continue; |
success = true; |
+ break; |
} |
DCHECK(success); |
@@ -584,7 +541,8 @@ |
} |
void BackendImpl::UpdateRank(CacheRankingsBlock* node, bool modified) { |
- rankings_.UpdateRank(node, modified); |
+ if (!read_only_) |
+ rankings_.UpdateRank(node, modified); |
} |
void BackendImpl::RecoveredEntry(CacheRankingsBlock* rankings) { |
@@ -708,6 +666,10 @@ |
unit_test_ = true; |
} |
+void BackendImpl::SetUpgradeMode() { |
+ read_only_ = true; |
+} |
+ |
void BackendImpl::ClearRefCountForTest() { |
num_refs_ = 0; |
} |
@@ -732,6 +694,10 @@ |
return CheckAllEntries(); |
} |
+bool BackendImpl::OpenPrevEntry(void** iter, Entry** prev_entry) { |
+ return OpenFollowingEntry(false, iter, prev_entry); |
+} |
+ |
// ------------------------------------------------------------------------ |
// We just created a new file so we're going to write the header and set the |
@@ -866,7 +832,7 @@ |
} |
EntryImpl* BackendImpl::MatchEntry(const std::string& key, uint32 hash, |
- bool find_parent) { |
+ bool find_parent) { |
Addr address(data_->table[hash & mask_]); |
EntryImpl* cache_entry = NULL; |
EntryImpl* parent_entry = NULL; |
@@ -944,6 +910,57 @@ |
return find_parent ? parent_entry : cache_entry; |
} |
+// This is the actual implementation for OpenNextEntry and OpenPrevEntry. |
+bool BackendImpl::OpenFollowingEntry(bool forward, void** iter, |
+ Entry** next_entry) { |
+ if (disabled_) |
+ return false; |
+ |
+ Rankings::ScopedRankingsBlock rankings(&rankings_, |
+ reinterpret_cast<CacheRankingsBlock*>(*iter)); |
+ CacheRankingsBlock* next_block = forward ? rankings_.GetNext(rankings.get()) : |
+ rankings_.GetPrev(rankings.get()); |
+ Rankings::ScopedRankingsBlock next(&rankings_, next_block); |
+ *next_entry = NULL; |
+ *iter = NULL; |
+ if (!next.get()) |
+ return false; |
+ |
+ scoped_refptr<EntryImpl> entry; |
+ if (next->Data()->pointer) { |
+ entry = reinterpret_cast<EntryImpl*>(next->Data()->pointer); |
+ } else { |
+ bool dirty; |
+ EntryImpl* temp = NULL; |
+ if (NewEntry(Addr(next->Data()->contents), &temp, &dirty)) |
+ return false; |
+ entry.swap(&temp); |
+ |
+ if (dirty) { |
+ // We cannot trust this entry. Call MatchEntry to go through the regular |
+ // path and take the appropriate action. |
+ std::string key = entry->GetKey(); |
+ uint32 hash = entry->GetHash(); |
+ entry = NULL; // Release the entry. |
+ temp = MatchEntry(key, hash, false); |
+ if (temp) |
+ temp->Release(); |
+ |
+ return false; |
+ } |
+ |
+ entry.swap(&temp); |
+ temp = EntryImpl::Update(temp); // Update returns an adref'd entry. |
+ entry.swap(&temp); |
+ if (!entry.get()) |
+ return false; |
+ } |
+ |
+ entry.swap(reinterpret_cast<EntryImpl**>(next_entry)); |
+ *iter = next.release(); |
+ return true; |
+} |
+ |
void BackendImpl::DestroyInvalidEntry(Addr address, EntryImpl* entry) { |
LOG(WARNING) << "Destroying invalid entry."; |
Trace("Destroying invalid entry 0x%p", entry); |