Chromium Code Reviews| Index: base/timer/timer.h |
| diff --git a/base/timer/timer.h b/base/timer/timer.h |
| index c5bd9ced5ae277f614fc53b49b83441458ec5cdc..3f2f639e7af04fb455c07d91b7bac9639fbb5c51 100644 |
| --- a/base/timer/timer.h |
| +++ b/base/timer/timer.h |
| @@ -39,7 +39,8 @@ |
| // other words, Reset is shorthand for calling Stop and then Start again with |
| // the same arguments. |
| // |
| -// NOTE: These APIs are not thread safe. Always call from the same thread. |
| +// NOTE: These APIs are not thread safe. Always call from the same sequence |
| +// task runner. |
|
danakj
2015/11/16 22:46:42
can you still mention same-thread here somehow too
gab
2015/11/17 15:23:58
I think the new comment is actually correct. i.e.
|
| #ifndef BASE_TIMER_TIMER_H_ |
| #define BASE_TIMER_TIMER_H_ |
| @@ -55,17 +56,17 @@ |
| #include "base/bind_helpers.h" |
| #include "base/callback.h" |
| #include "base/location.h" |
| +#include "base/sequence_checker.h" |
| #include "base/time/time.h" |
| namespace base { |
| class BaseTimerTaskInternal; |
| -class SingleThreadTaskRunner; |
| //----------------------------------------------------------------------------- |
| -// This class wraps MessageLoop::PostDelayedTask to manage delayed and repeating |
| -// tasks. It must be destructed on the same thread that starts tasks. There are |
| -// DCHECKs in place to verify this. |
| +// This class wraps TaskRunner::PostDelayedTask to manage delayed and |
| +// repeating tasks. It must be destructed on the same task runner that starts |
| +// tasks. There are DCHECKs in place to verify this. |
| // |
| class BASE_EXPORT Timer { |
| public: |
| @@ -90,8 +91,8 @@ class BASE_EXPORT Timer { |
| // Set the task runner on which the task should be scheduled. This method can |
| // only be called before any tasks have been scheduled. The task runner must |
|
gab
2015/11/17 15:23:57
s/The task runner/|task_runner|
jsbell
2015/12/01 00:23:10
Done.
|
| - // run tasks on the same thread the timer is used on. |
| - virtual void SetTaskRunner(scoped_refptr<SingleThreadTaskRunner> task_runner); |
| + // run tasks on the sequenced runner the timer is used on. |
|
gab
2015/11/17 15:23:58
s/sequence runner/same sequence/ ?
jsbell
2015/12/01 00:23:10
Done.
|
| + virtual void SetTaskRunner(scoped_refptr<SequencedTaskRunner> task_runner); |
| // Start the timer to run at the given |delay| from now. If the timer is |
| // already running, it will be replaced to call the given |user_task|. |
| @@ -135,9 +136,9 @@ class BASE_EXPORT Timer { |
| void PostNewScheduledTask(TimeDelta delay); |
| // Returns the task runner on which the task should be scheduled. If the |
| - // corresponding task_runner_ field is null, the task runner for the current |
| - // thread is returned. |
| - scoped_refptr<SingleThreadTaskRunner> GetTaskRunner(); |
| + // corresponding task_runner_ field is null, the current task runner is |
|
gab
2015/11/17 15:23:57
s/task_runner_/|task_runner_|
gab
2015/11/17 15:23:58
s/current task runner/SequencedTaskRunner for the
jsbell
2015/12/01 00:23:10
Done.
|
| + // returned. |
| + scoped_refptr<SequencedTaskRunner> GetTaskRunner(); |
| // Disable scheduled_task_ and abandon it so that it no longer refers back to |
| // this object. |
| @@ -157,8 +158,8 @@ class BASE_EXPORT Timer { |
| BaseTimerTaskInternal* scheduled_task_; |
| // The task runner on which the task should be scheduled. If it is null, the |
| - // task runner for the current thread should be used. |
| - scoped_refptr<SingleThreadTaskRunner> task_runner_; |
| + // current sequenced task runner should be used. |
| + scoped_refptr<SequencedTaskRunner> task_runner_; |
| // Location in user code. |
| tracked_objects::Location posted_from_; |
| @@ -181,8 +182,11 @@ class BASE_EXPORT Timer { |
| // if the task must be run immediately. |
| TimeTicks desired_run_time_; |
| - // Thread ID of current MessageLoop for verifying single-threaded usage. |
| - int thread_id_; |
| + // Verify usage with a single SequencedTaskRunner. |
|
gab
2015/11/17 15:23:57
This comment in redundant in specifying what a Seq
jsbell
2015/12/01 00:23:10
Done.
|
| + SequenceChecker sequence_checker_; |
| + |
| + // Once the timer has been scheduled, the task runner may not be changed. |
| + bool was_scheduled_; |
| // Repeating timers automatically post the task again before calling the task |
| // callback. |
| @@ -242,8 +246,7 @@ class RepeatingTimer : public BaseTimerMethodPointer { |
| //----------------------------------------------------------------------------- |
| // A Delay timer is like The Button from Lost. Once started, you have to keep |
| -// calling Reset otherwise it will call the given method in the MessageLoop |
| -// thread. |
| +// calling Reset otherwise it will call the given method in task runner. |
| // |
| // Once created, it is inactive until Reset is called. Once |delay| seconds have |
| // passed since the last call to Reset, the callback is made. Once the callback |