summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-20 00:00:21 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-20 00:00:21 +0000
commit93794a7e23b578fac1cd41b232f6018268cd21fa (patch)
treed75981f821084772ff488a60b1da0b86c6ed2a98 /net
parent5471c7aacd182997567ee7ee5c78328b98b933ab (diff)
downloadchromium_src-93794a7e23b578fac1cd41b232f6018268cd21fa.zip
chromium_src-93794a7e23b578fac1cd41b232f6018268cd21fa.tar.gz
chromium_src-93794a7e23b578fac1cd41b232f6018268cd21fa.tar.bz2
Disk cache: Stop evictions while performing final cleanup.
The evictions code may post tasks for further processing and that is a problem at cache destruction, so add an explicit method to stop evictions. BUG=49547 TEST=none Review URL: http://codereview.chromium.org/2854053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52964 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/disk_cache/backend_impl.cc11
-rw-r--r--net/disk_cache/backend_impl.h3
-rw-r--r--net/disk_cache/eviction.cc13
-rw-r--r--net/disk_cache/eviction.h6
4 files changed, 31 insertions, 2 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index c8f4a25..13b17f4 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -259,7 +259,7 @@ class FinalCleanup : public Task {
};
void FinalCleanup::Run() {
- backend_->CleanupCache();
+ backend_->StartCleanup();
}
} // namespace
@@ -525,6 +525,15 @@ int BackendImpl::SyncInit() {
return disabled_ ? net::ERR_FAILED : net::OK;
}
+void BackendImpl::StartCleanup() {
+ Trace("Backend StartCleanup");
+ eviction_.Stop();
+
+ // Give a chance for any posted evictions to be discarded.
+ MessageLoop::current()->PostTask(FROM_HERE,
+ factory_.NewRunnableMethod(&BackendImpl::CleanupCache));
+}
+
void BackendImpl::CleanupCache() {
Trace("Backend Cleanup");
if (init_) {
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index 98fc16d..90283fb 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -83,7 +83,10 @@ class BackendImpl : public Backend {
virtual void GetStats(StatsItems* stats);
// Performs the actual initialization and final cleanup on destruction.
+ // Cleanup is a two step process (with a trip to the message loop in between).
+ // Note that these methods are not intended for external consumption.
int SyncInit();
+ void StartCleanup();
void CleanupCache();
// Same bahavior as OpenNextEntry but walks the list from back to front.
diff --git a/net/disk_cache/eviction.cc b/net/disk_cache/eviction.cc
index e2e810a..91ef9b7 100644
--- a/net/disk_cache/eviction.cc
+++ b/net/disk_cache/eviction.cc
@@ -70,6 +70,19 @@ void Eviction::Init(BackendImpl* backend) {
trimming_ = false;
delay_trim_ = false;
trim_delays_ = 0;
+ init_ = true;
+}
+
+void Eviction::Stop() {
+ // It is possible for the backend initialization to fail, in which case this
+ // object was never initialized... and there is nothing to do.
+ if (!init_)
+ return;
+
+ // We want to stop further evictions, so let's pretend that we are busy from
+ // this point on.
+ DCHECK(!trimming_);
+ trimming_ = true;
}
void Eviction::TrimCache(bool empty) {
diff --git a/net/disk_cache/eviction.h b/net/disk_cache/eviction.h
index c86e33a..76ee00b 100644
--- a/net/disk_cache/eviction.h
+++ b/net/disk_cache/eviction.h
@@ -20,10 +20,13 @@ class EntryImpl;
// integrated with BackendImpl.
class Eviction {
public:
- Eviction() : backend_(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {}
+ Eviction()
+ : backend_(NULL), init_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {}
~Eviction() {}
void Init(BackendImpl* backend);
+ void Stop();
// Deletes entries from the cache until the current size is below the limit.
// If empty is true, the whole cache will be trimmed, regardless of being in
@@ -73,6 +76,7 @@ class Eviction {
bool first_trim_;
bool trimming_;
bool delay_trim_;
+ bool init_;
ScopedRunnableMethodFactory<Eviction> factory_;
DISALLOW_COPY_AND_ASSIGN(Eviction);