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

Unified Diff: net/disk_cache/eviction.cc

Issue 155314: Disk cache: Don't evict entries if we are busy doing other stuff.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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
« net/disk_cache/backend_impl.cc ('K') | « net/disk_cache/eviction.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/eviction.cc
===================================================================
--- net/disk_cache/eviction.cc (revision 20196)
+++ net/disk_cache/eviction.cc (working copy)
@@ -66,6 +66,7 @@
new_eviction_ = backend->new_eviction_;
first_trim_ = true;
trimming_ = false;
+ delay_trim_ = false;
}
void Eviction::TrimCache(bool empty) {
@@ -76,6 +77,9 @@
if (backend_->disabled_ || trimming_)
return;
+ if (!empty && backend_->IsLoaded())
+ return PostDelayedTrim();
+
trimming_ = true;
Time start = Time::Now();
Rankings::ScopedRankingsBlock node(rankings_);
@@ -83,7 +87,6 @@
rankings_->GetPrev(node.get(), Rankings::NO_USE));
DCHECK(next.get());
int target_size = empty ? 0 : max_size_;
- int deleted = 0;
while (header_->num_bytes > target_size && next.get()) {
node.reset(next.release());
next.reset(rankings_->GetPrev(node.get(), Rankings::NO_USE));
@@ -92,14 +95,14 @@
if (!EvictEntry(node.get(), empty))
continue;
- if (!empty)
+ if (!empty) {
backend_->OnEvent(Stats::TRIM_ENTRY);
- if (++deleted == 4 && !empty) {
-#if defined(OS_WIN)
- MessageLoop::current()->PostTask(FROM_HERE,
- factory_.NewRunnableMethod(&Eviction::TrimCache, false));
- break;
-#endif
+
+ if ((Time::Now() - start).InMilliseconds() > 20) {
+ MessageLoop::current()->PostTask(FROM_HERE,
+ factory_.NewRunnableMethod(&Eviction::TrimCache, false));
+ break;
+ }
}
}
}
@@ -141,6 +144,20 @@
return OnDestroyEntryV2(entry);
}
+void Eviction::PostDelayedTrim() {
+ // Prevent posting multiple tasks.
+ if (delay_trim_)
+ return;
+ delay_trim_ = true;
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ factory_.NewRunnableMethod(&Eviction::DelayedTrim), 1000);
+}
+
+void Eviction::DelayedTrim() {
+ delay_trim_ = false;
+ TrimCache(false);
+}
+
void Eviction::ReportTrimTimes(EntryImpl* entry) {
if (first_trim_) {
first_trim_ = false;
@@ -211,6 +228,9 @@
if (backend_->disabled_ || trimming_)
return;
+ if (!empty && backend_->IsLoaded())
+ return PostDelayedTrim();
+
trimming_ = true;
Time start = Time::Now();
@@ -248,7 +268,6 @@
Rankings::ScopedRankingsBlock node(rankings_);
int target_size = empty ? 0 : max_size_;
- int deleted = 0;
for (; list < kListsToSearch; list++) {
while (header_->num_bytes > target_size && next[list].get()) {
node.reset(next[list].release());
@@ -259,7 +278,7 @@
if (!EvictEntry(node.get(), empty))
continue;
- if (++deleted == 4 && !empty) {
+ if (!empty && (Time::Now() - start).InMilliseconds() > 20) {
MessageLoop::current()->PostTask(FROM_HERE,
factory_.NewRunnableMethod(&Eviction::TrimCache, false));
break;
« net/disk_cache/backend_impl.cc ('K') | « net/disk_cache/eviction.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698