diff options
author | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-26 20:41:13 +0000 |
---|---|---|
committer | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-26 20:41:13 +0000 |
commit | 3ab9ea8ae36fcf4a37f8662844707f5a352935ff (patch) | |
tree | 36e740c520ddce40c65e3c17db0f5777d38ddd7b /net/disk_cache | |
parent | 95dbc762c3b3a4f2cb4234ff74b005cb223b7ee4 (diff) | |
download | chromium_src-3ab9ea8ae36fcf4a37f8662844707f5a352935ff.zip chromium_src-3ab9ea8ae36fcf4a37f8662844707f5a352935ff.tar.gz chromium_src-3ab9ea8ae36fcf4a37f8662844707f5a352935ff.tar.bz2 |
Refactor BaseTimer to avoid spamming the MessageLoop with orphaned tasks.
This change maintains the same API promises*, but instead of orphaning tasks when they are stopped, the BaseTimer_Helper class holds on to the task until either (1) it expires or (2) the user requests a delay that would arrive earlier than the pending task. If the user requests a longer delay than the pending task, a followup task will be posted when the pending task fires to span the remaining time.
* The one change of usage is related to threading. The threading requirements are now more strict. It is not allowed to destruct a timer on a different thread than the one used to post tasks. A thread ID DCHECK is now in place that will help catch misuse. Some existing instances are changed as part of this CL.
A side effect of this change is that the BaseTimer and DelayTimer are simplified to use features of BaseTimer_Helper (which is now called Timer).
As suggested in timer.h, I ran the disabled TimerTest tests from linux, and they pass consistently. I also added some new tests to verify correct run states.
BUG=117451,103667,119714,119750
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=128412
Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=128506
Review URL: https://chromiumcodereview.appspot.com/9655006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128993 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/backend_impl.cc | 7 | ||||
-rw-r--r-- | net/disk_cache/backend_impl.h | 2 |
2 files changed, 5 insertions, 4 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index aa232c3..1f08b15 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -423,8 +423,9 @@ int BackendImpl::SyncInit() { trace_object_ = TraceObject::GetTraceObject(); // Create a recurrent timer of 30 secs. int timer_delay = unit_test_ ? 1000 : 30000; - timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(timer_delay), this, - &BackendImpl::OnStatsTimer); + timer_.reset(new base::RepeatingTimer<BackendImpl>()); + timer_->Start(FROM_HERE, TimeDelta::FromMilliseconds(timer_delay), this, + &BackendImpl::OnStatsTimer); } init_ = true; @@ -497,7 +498,7 @@ int BackendImpl::SyncInit() { void BackendImpl::CleanupCache() { Trace("Backend Cleanup"); eviction_.Stop(); - timer_.Stop(); + timer_.reset(); if (init_) { stats_.Store(); diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h index e2fb6ef..663f7fc 100644 --- a/net/disk_cache/backend_impl.h +++ b/net/disk_cache/backend_impl.h @@ -383,7 +383,7 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend { net::NetLog* net_log_; Stats stats_; // Usage statistics. - base::RepeatingTimer<BackendImpl> timer_; // Usage timer. + scoped_ptr<base::RepeatingTimer<BackendImpl> > timer_; // Usage timer. base::WaitableEvent done_; // Signals the end of background work. scoped_refptr<TraceObject> trace_object_; // Initializes internal tracing. base::WeakPtrFactory<BackendImpl> ptr_factory_; |