summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/backend_impl.cc12
-rw-r--r--net/disk_cache/backend_impl.h7
-rw-r--r--net/disk_cache/backend_unittest.cc5
3 files changed, 19 insertions, 5 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 5806822..5993187 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -881,7 +881,8 @@ void BackendImpl::CriticalError(int error) {
disabled_ = true;
if (!num_refs_)
- RestartCache();
+ MessageLoop::current()->PostTask(FROM_HERE,
+ factory_.NewRunnableMethod(&BackendImpl::RestartCache));
}
void BackendImpl::ReportError(int error) {
@@ -1066,7 +1067,11 @@ void BackendImpl::AdjustMaxCacheSize(int table_len) {
max_size_= current_max_size;
}
+// We always execute this method from the message loop so that we can freely
+// release files, memory pointers etc.
void BackendImpl::RestartCache() {
+ DCHECK(!num_refs_);
+ DCHECK(!open_entries_.size());
PrepareForRestart();
DelayedCacheCleanup(path_);
@@ -1324,7 +1329,7 @@ bool BackendImpl::OpenFollowingEntryFromList(bool forward, Rankings::List list,
EntryImpl* BackendImpl::GetEnumeratedEntry(CacheRankingsBlock* next,
bool to_evict) {
- if (!next)
+ if (!next || disabled_)
return NULL;
EntryImpl* entry;
@@ -1440,7 +1445,8 @@ void BackendImpl::DecreaseNumRefs() {
num_refs_--;
if (!num_refs_ && disabled_)
- RestartCache();
+ MessageLoop::current()->PostTask(FROM_HERE,
+ factory_.NewRunnableMethod(&BackendImpl::RestartCache));
}
void BackendImpl::IncreaseNumEntries() {
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index ef282779..2ab582d 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -35,13 +35,15 @@ class BackendImpl : public Backend {
: path_(path), block_files_(path), mask_(0), max_size_(0),
cache_type_(net::DISK_CACHE), uma_report_(0), user_flags_(0),
init_(false), restarted_(false), unit_test_(false), read_only_(false),
- new_eviction_(false), first_timer_(true) {}
+ new_eviction_(false), first_timer_(true),
+ ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {}
// mask can be used to limit the usable size of the hash table, for testing.
BackendImpl(const std::wstring& path, uint32 mask)
: path_(path), block_files_(path), mask_(mask), max_size_(0),
cache_type_(net::DISK_CACHE), uma_report_(0), user_flags_(kMask),
init_(false), restarted_(false), unit_test_(false), read_only_(false),
- new_eviction_(false), first_timer_(true) {}
+ new_eviction_(false), first_timer_(true),
+ ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {}
~BackendImpl();
// Performs general initialization for this current instance of the cache.
@@ -272,6 +274,7 @@ class BackendImpl : public Backend {
Stats stats_; // Usage statistcs.
base::RepeatingTimer<BackendImpl> timer_; // Usage timer.
scoped_refptr<TraceObject> trace_object_; // Inits internal tracing.
+ ScopedRunnableMethodFactory<BackendImpl> factory_;
DISALLOW_EVIL_CONSTRUCTORS(BackendImpl);
};
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index a1127a6..31df938 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -1099,6 +1099,7 @@ void DiskCacheBackendTest::BackendInvalidRankings() {
EXPECT_EQ(2, cache_->GetEntryCount());
EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry));
+ MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -1149,6 +1150,7 @@ void DiskCacheBackendTest::BackendDisable() {
EXPECT_FALSE(cache_->CreateEntry("Something new", &entry2));
entry1->Close();
+ MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -1203,6 +1205,7 @@ void DiskCacheBackendTest::BackendDisable2() {
ASSERT_LT(count, 9);
};
+ MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -1251,6 +1254,8 @@ void DiskCacheBackendTest::BackendDisable3() {
entry1->Close();
EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2));
+ MessageLoop::current()->RunAllPending();
+
ASSERT_TRUE(cache_->CreateEntry("Something new", &entry2));
entry2->Close();