OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // OneShotTimer and RepeatingTimer provide a simple timer API. As the names | 5 // OneShotTimer and RepeatingTimer provide a simple timer API. As the names |
6 // suggest, OneShotTimer calls you back once after a time delay expires. | 6 // suggest, OneShotTimer calls you back once after a time delay expires. |
7 // RepeatingTimer on the other hand calls you back periodically with the | 7 // RepeatingTimer on the other hand calls you back periodically with the |
8 // prescribed time interval. | 8 // prescribed time interval. |
9 // | 9 // |
10 // OneShotTimer and RepeatingTimer both cancel the timer when they go out of | 10 // OneShotTimer and RepeatingTimer both cancel the timer when they go out of |
(...skipping 27 matching lines...) Expand all Loading... | |
38 // calling Reset on |timer_| would postpone DoStuff by another 1 second. In | 38 // calling Reset on |timer_| would postpone DoStuff by another 1 second. In |
39 // other words, Reset is shorthand for calling Stop and then Start again with | 39 // other words, Reset is shorthand for calling Stop and then Start again with |
40 // the same arguments. | 40 // the same arguments. |
41 // | 41 // |
42 // These APIs are not thread safe. All methods must be called from the same | 42 // These APIs are not thread safe. All methods must be called from the same |
43 // sequence (not necessarily the construction sequence), except for the | 43 // sequence (not necessarily the construction sequence), except for the |
44 // destructor and SetTaskRunner() which may be called from any sequence when the | 44 // destructor and SetTaskRunner() which may be called from any sequence when the |
45 // timer is not running (i.e. when Start() has never been called or Stop() has | 45 // timer is not running (i.e. when Start() has never been called or Stop() has |
46 // been called since the last Start()). By default, the scheduled tasks will be | 46 // been called since the last Start()). By default, the scheduled tasks will be |
47 // run on the same sequence that the Timer was *started on*, but this can be | 47 // run on the same sequence that the Timer was *started on*, but this can be |
48 // changed *prior* to Start() via SetTaskRunner(). | 48 // changed *prior* to Start() via SetTaskRunner(). |
gab
2017/06/01 16:29:49
The documentation was already mentioning this as o
| |
49 | 49 |
50 #ifndef BASE_TIMER_TIMER_H_ | 50 #ifndef BASE_TIMER_TIMER_H_ |
51 #define BASE_TIMER_TIMER_H_ | 51 #define BASE_TIMER_TIMER_H_ |
52 | 52 |
53 // IMPORTANT: If you change timer code, make sure that all tests (including | 53 // IMPORTANT: If you change timer code, make sure that all tests (including |
54 // disabled ones) from timer_unittests.cc pass locally. Some are disabled | 54 // disabled ones) from timer_unittests.cc pass locally. Some are disabled |
55 // because they're flaky on the buildbot, but when you run them locally you | 55 // because they're flaky on the buildbot, but when you run them locally you |
56 // should be able to tell the difference. | 56 // should be able to tell the difference. |
57 | 57 |
58 #include <memory> | 58 #include <memory> |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 // The desired run time of |user_task_|. The user may update this at any time, | 196 // The desired run time of |user_task_|. The user may update this at any time, |
197 // even if their previous request has not run yet. If |desired_run_time_| is | 197 // even if their previous request has not run yet. If |desired_run_time_| is |
198 // greater than |scheduled_run_time_|, a continuation task will be posted to | 198 // greater than |scheduled_run_time_|, a continuation task will be posted to |
199 // wait for the remaining time. This allows us to reuse the pending task so as | 199 // wait for the remaining time. This allows us to reuse the pending task so as |
200 // not to flood the delayed queues with orphaned tasks when the user code | 200 // not to flood the delayed queues with orphaned tasks when the user code |
201 // excessively Stops and Starts the timer. This time can be a "zero" TimeTicks | 201 // excessively Stops and Starts the timer. This time can be a "zero" TimeTicks |
202 // if the task must be run immediately. | 202 // if the task must be run immediately. |
203 TimeTicks desired_run_time_; | 203 TimeTicks desired_run_time_; |
204 | 204 |
205 // Timer isn't thread-safe and must only be used on its origin sequence | 205 // Timer isn't thread-safe and must only be used on its origin sequence |
206 // (sequence on which it was started). | 206 // (sequence on which it was started). Once fully Stop()'ed it may be |
207 // destroyed or even restarted on another sequence. | |
danakj
2017/06/06 20:07:12
s/even //
gab
2017/06/07 19:02:37
Done.
| |
207 SequenceChecker origin_sequence_checker_; | 208 SequenceChecker origin_sequence_checker_; |
208 | 209 |
209 // Repeating timers automatically post the task again before calling the task | 210 // Repeating timers automatically post the task again before calling the task |
210 // callback. | 211 // callback. |
211 const bool is_repeating_; | 212 const bool is_repeating_; |
212 | 213 |
213 // If true, hold on to the |user_task_| closure object for reuse. | 214 // If true, hold on to the |user_task_| closure object for reuse. |
214 const bool retain_user_task_; | 215 const bool retain_user_task_; |
215 | 216 |
216 // The tick clock used to calculate the run time for scheduled tasks. | 217 // The tick clock used to calculate the run time for scheduled tasks. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 // to link in MSVC. But clang-plugin does not allow inline definitions of | 309 // to link in MSVC. But clang-plugin does not allow inline definitions of |
309 // virtual methods, so the inline definition lives in the header file here | 310 // virtual methods, so the inline definition lives in the header file here |
310 // to satisfy both. | 311 // to satisfy both. |
311 inline void DelayTimer::Reset() { | 312 inline void DelayTimer::Reset() { |
312 Timer::Reset(); | 313 Timer::Reset(); |
313 } | 314 } |
314 | 315 |
315 } // namespace base | 316 } // namespace base |
316 | 317 |
317 #endif // BASE_TIMER_TIMER_H_ | 318 #endif // BASE_TIMER_TIMER_H_ |
OLD | NEW |