Chromium Code Reviews| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 | 75 |
| 76 // Construct a timer with retained task info. | 76 // Construct a timer with retained task info. |
| 77 Timer(const tracked_objects::Location& posted_from, | 77 Timer(const tracked_objects::Location& posted_from, |
| 78 TimeDelta delay, | 78 TimeDelta delay, |
| 79 const base::Closure& user_task, | 79 const base::Closure& user_task, |
| 80 bool is_repeating); | 80 bool is_repeating); |
| 81 | 81 |
| 82 virtual ~Timer(); | 82 virtual ~Timer(); |
| 83 | 83 |
| 84 // Returns true if the timer is running (i.e., not stopped). | 84 // Returns true if the timer is running (i.e., not stopped). |
| 85 bool IsRunning() const { | 85 virtual bool IsRunning() const { |
|
Randy Smith (Not in Mondays)
2014/02/13 18:47:40
I'd be a little surprised if this didn't get pushb
mmenke
2014/02/13 20:42:17
You don't seem to be making use of these changes a
Elly Fong-Jones
2014/02/25 19:19:52
Yeah, I did this while I was experimenting and for
| |
| 86 return is_running_; | 86 return is_running_; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Returns the current delay for this timer. | 89 // Returns the current delay for this timer. |
| 90 TimeDelta GetCurrentDelay() const { | 90 TimeDelta GetCurrentDelay() const { |
| 91 return delay_; | 91 return delay_; |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Start the timer to run at the given |delay| from now. If the timer is | 94 // Start the timer to run at the given |delay| from now. If the timer is |
| 95 // already running, it will be replaced to call the given |user_task|. | 95 // already running, it will be replaced to call the given |user_task|. |
| 96 void Start(const tracked_objects::Location& posted_from, | 96 virtual void Start(const tracked_objects::Location& posted_from, |
| 97 TimeDelta delay, | 97 TimeDelta delay, |
| 98 const base::Closure& user_task); | 98 const base::Closure& user_task); |
| 99 | 99 |
| 100 // Call this method to stop and cancel the timer. It is a no-op if the timer | 100 // Call this method to stop and cancel the timer. It is a no-op if the timer |
| 101 // is not running. | 101 // is not running. |
| 102 void Stop(); | 102 virtual void Stop(); |
| 103 | 103 |
| 104 // Call this method to reset the timer delay. The user_task_ must be set. If | 104 // Call this method to reset the timer delay. The user_task_ must be set. If |
| 105 // the timer is not running, this will start it by posting a task. | 105 // the timer is not running, this will start it by posting a task. |
| 106 void Reset(); | 106 virtual void Reset(); |
| 107 | 107 |
| 108 const base::Closure& user_task() const { return user_task_; } | 108 const base::Closure& user_task() const { return user_task_; } |
| 109 const TimeTicks& desired_run_time() const { return desired_run_time_; } | 109 const TimeTicks& desired_run_time() const { return desired_run_time_; } |
| 110 | 110 |
| 111 protected: | 111 protected: |
| 112 // Used to initiate a new delayed task. This has the side-effect of disabling | 112 // Used to initiate a new delayed task. This has the side-effect of disabling |
| 113 // scheduled_task_ if it is non-null. | 113 // scheduled_task_ if it is non-null. |
| 114 void SetTaskInfo(const tracked_objects::Location& posted_from, | 114 void SetTaskInfo(const tracked_objects::Location& posted_from, |
| 115 TimeDelta delay, | 115 TimeDelta delay, |
| 116 const base::Closure& user_task); | 116 const base::Closure& user_task); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 : Timer(posted_from, delay, | 239 : Timer(posted_from, delay, |
| 240 base::Bind(method, base::Unretained(receiver)), | 240 base::Bind(method, base::Unretained(receiver)), |
| 241 false) {} | 241 false) {} |
| 242 | 242 |
| 243 void Reset() { Timer::Reset(); } | 243 void Reset() { Timer::Reset(); } |
| 244 }; | 244 }; |
| 245 | 245 |
| 246 } // namespace base | 246 } // namespace base |
| 247 | 247 |
| 248 #endif // BASE_TIMER_TIMER_H_ | 248 #endif // BASE_TIMER_TIMER_H_ |
| OLD | NEW |