diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 18:06:15 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 18:06:15 +0000 |
commit | b87b23727abd34f94fc25377424e4605b249fbc2 (patch) | |
tree | dd659392849e0b0fbbb90e3ee610437dfcc6b134 /net/disk_cache | |
parent | 6833846f5fc1334e8ce152e00bb80e0bfffce0c5 (diff) | |
download | chromium_src-b87b23727abd34f94fc25377424e4605b249fbc2.zip chromium_src-b87b23727abd34f94fc25377424e4605b249fbc2.tar.gz chromium_src-b87b23727abd34f94fc25377424e4605b249fbc2.tar.bz2 |
Disk cache: Avoid restarting the cache while it may be in use.
Now the code that releases resources runs from the message loop
so that methods can cause the cache to disable itself while
still being able to touch internal state.
BUG=17604
TEST=unittests.
Review URL: http://codereview.chromium.org/159327
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21550 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/backend_impl.cc | 12 | ||||
-rw-r--r-- | net/disk_cache/backend_impl.h | 7 | ||||
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 5 |
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(); |