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

Unified Diff: base/timer/timer.h

Issue 2958003002: Expose Timer::AbandonAndStop, so it can safely be destroyed on another thread. (Closed)
Patch Set: Expose AbandonAndStop and use it in AudioInputController. Created 3 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
« no previous file with comments | « no previous file | media/audio/audio_input_controller.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/timer/timer.h
diff --git a/base/timer/timer.h b/base/timer/timer.h
index 651ba39d9137d2a3814fe6859d6dce953aef994e..a531fdd97fc755060d4b819c509863018c1ec253 100644
--- a/base/timer/timer.h
+++ b/base/timer/timer.h
@@ -41,11 +41,17 @@
//
// These APIs are not thread safe. All methods must be called from the same
// sequence (not necessarily the construction sequence), except for the
-// destructor and SetTaskRunner() which may be called from any sequence when the
-// timer is not running (i.e. when Start() has never been called or Stop() has
-// been called since the last Start()). By default, the scheduled tasks will be
-// run on the same sequence that the Timer was *started on*, but this can be
-// changed *prior* to Start() via SetTaskRunner().
+// destructor and SetTaskRunner().
+// - The destructor may be called from any sequence when the timer is not
+// running and there is no scheduled task active, i.e. when Start() has never
+// been called or after AbandonAndStop() has been called.
+// - SetTaskRunner() may be called from any sequence when the timer is not
+// running, i.e. when Start() has never been called or Stop() has been called
+// since the last Start().
+//
+// By default, the scheduled tasks will be run on the same sequence that the
+// Timer was *started on*, but this can be changed *prior* to Start() via
+// SetTaskRunner().
#ifndef BASE_TIMER_TIMER_H_
#define BASE_TIMER_TIMER_H_
@@ -126,6 +132,14 @@ class BASE_EXPORT Timer {
// is not running.
virtual void Stop();
+ // Stop running task (if any) and abandon scheduled task (if any).
+ void AbandonAndStop() {
+ AbandonScheduledTask();
+
+ Stop();
+ // No more member accesses here: |this| could be deleted at this point.
+ }
+
// Call this method to reset the timer delay. The |user_task_| must be set. If
// the timer is not running, this will start it by posting a task.
virtual void Reset();
@@ -166,14 +180,6 @@ class BASE_EXPORT Timer {
// Called by BaseTimerTaskInternal when the delayed task fires.
void RunScheduledTask();
- // Stop running task (if any) and abandon scheduled task (if any).
- void AbandonAndStop() {
- AbandonScheduledTask();
-
- Stop();
- // No more member accesses here: |this| could be deleted at this point.
- }
-
// When non-null, the |scheduled_task_| was posted to call RunScheduledTask()
// at |scheduled_run_time_|.
BaseTimerTaskInternal* scheduled_task_;
« no previous file with comments | « no previous file | media/audio/audio_input_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698