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

Unified Diff: net/disk_cache/eviction.cc

Issue 6292011: Disk cache: Prevent obscure file corruption and deal... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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/eviction.cc
===================================================================
--- net/disk_cache/eviction.cc (revision 71365)
+++ net/disk_cache/eviction.cc (working copy)
@@ -82,6 +82,7 @@
delay_trim_ = false;
trim_delays_ = 0;
init_ = true;
+ test_mode_ = false;
in_experiment_ = (header_->experiment == EXPERIMENT_DELETED_LIST_IN);
}
@@ -125,11 +126,13 @@
// This entry is not being used by anybody.
// Do NOT use node as an iterator after this point.
rankings_->TrackRankingsBlock(node.get(), false);
- if (!EvictEntry(node.get(), empty))
+ if (!EvictEntry(node.get(), empty) && !test_mode_)
continue;
if (!empty) {
backend_->OnEvent(Stats::TRIM_ENTRY);
+ if (test_mode_)
+ break;
if ((TimeTicks::Now() - start).InMilliseconds() > 20) {
MessageLoop::current()->PostTask(FROM_HERE,
@@ -182,6 +185,15 @@
return OnDestroyEntryV2(entry);
}
+void Eviction::SetTestMode() {
+ test_mode_ = true;
+}
+
+void Eviction::TrimDeletedList(bool empty) {
+ DCHECK(test_mode_ && new_eviction_);
+ TrimDeleted(empty);
+}
+
void Eviction::PostDelayedTrim() {
// Prevent posting multiple tasks.
if (delay_trim_)
@@ -242,7 +254,7 @@
}
bool Eviction::EvictEntry(CacheRankingsBlock* node, bool empty) {
- EntryImpl* entry = backend_->GetEnumeratedEntry(node, true);
+ EntryImpl* entry = backend_->GetEnumeratedEntry(node);
if (!entry) {
Trace("NewEntry failed on Trim 0x%x", node->address().value());
return false;
@@ -320,9 +332,12 @@
// This entry is not being used by anybody.
// Do NOT use node as an iterator after this point.
rankings_->TrackRankingsBlock(node.get(), false);
- if (!EvictEntry(node.get(), empty))
+ if (!EvictEntry(node.get(), empty) && !test_mode_)
continue;
+ if (!empty && test_mode_)
+ break;
+
if (!empty && (TimeTicks::Now() - start).InMilliseconds() > 20) {
MessageLoop::current()->PostTask(FROM_HERE,
factory_.NewRunnableMethod(&Eviction::TrimCache, false));
@@ -336,7 +351,8 @@
if (empty) {
TrimDeleted(true);
- } else if (header_->lru.sizes[Rankings::DELETED] > header_->num_entries / 4) {
+ } else if (header_->lru.sizes[Rankings::DELETED] > header_->num_entries / 4 &&
+ !test_mode_) {
MessageLoop::current()->PostTask(FROM_HERE,
factory_.NewRunnableMethod(&Eviction::TrimDeleted, empty));
}
@@ -451,6 +467,8 @@
node.reset(next.release());
next.reset(rankings_->GetPrev(node.get(), Rankings::DELETED));
deleted |= RemoveDeletedNode(node.get());
+ if (test_mode_)
+ break;
}
// Normally we use 25% for each list. The experiment doubles the number of
@@ -459,10 +477,11 @@
// lists intact.
int max_length = in_experiment_ ? header_->num_entries * 2 / 5 :
header_->num_entries / 4;
- if (deleted && !empty &&
- header_->lru.sizes[Rankings::DELETED] > max_length)
+ if (deleted && !empty && !test_mode_ &&
+ header_->lru.sizes[Rankings::DELETED] > max_length) {
MessageLoop::current()->PostTask(FROM_HERE,
factory_.NewRunnableMethod(&Eviction::TrimDeleted, false));
+ }
CACHE_UMA(AGE_MS, "TotalTrimDeletedTime", 0, start);
Trace("*** Trim Deleted end ***");
@@ -470,19 +489,12 @@
}
bool Eviction::RemoveDeletedNode(CacheRankingsBlock* node) {
- EntryImpl* entry;
- bool dirty;
- if (backend_->NewEntry(Addr(node->Data()->contents), &entry, &dirty)) {
+ EntryImpl* entry = backend_->GetEnumeratedEntry(node);
+ if (!entry) {
Trace("NewEntry failed on Trim 0x%x", node->address().value());
return false;
}
- // TODO(rvargas): figure out how to deal with corruption at this point (dirty
- // entries that live in this list).
gavinp 2011/01/25 20:23:51 Awesome! I'm always happy to see TODOs go.
- if (node->Data()->dirty) {
- // We ignore the failure; we're removing the entry anyway.
- entry->Update();
- }
bool doomed = (entry->entry()->Data()->state == ENTRY_DOOMED);
entry->entry()->Data()->state = ENTRY_DOOMED;
entry->DoomImpl();

Powered by Google App Engine
This is Rietveld 408576698