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 { |
Mark Mentovai
2014/03/13 15:17:34
Do all of these need to become virtual? What about
Elly Fong-Jones
2014/03/13 15:30:09
I could make is_running_ and delay_ protected, may
Mark Mentovai
2014/03/13 15:48:56
Elly Jones wrote:
| |
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 virtual 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 // TODO(tim): We should remove uses of BaseTimerMethodPointer::Start below | 190 // TODO(tim): We should remove uses of BaseTimerMethodPointer::Start below |
191 // and convert callers to use the base::Closure version in Timer::Start, | 191 // and convert callers to use the base::Closure version in Timer::Start, |
192 // see bug 148832. | 192 // see bug 148832. |
193 using Timer::Start; | 193 using Timer::Start; |
194 | 194 |
195 BaseTimerMethodPointer() : Timer(kIsRepeating, kIsRepeating) {} | 195 BaseTimerMethodPointer() : Timer(kIsRepeating, kIsRepeating) {} |
196 | 196 |
197 // Start the timer to run at the given |delay| from now. If the timer is | 197 // Start the timer to run at the given |delay| from now. If the timer is |
198 // already running, it will be replaced to call a task formed from | 198 // already running, it will be replaced to call a task formed from |
199 // |reviewer->*method|. | 199 // |reviewer->*method|. |
200 void Start(const tracked_objects::Location& posted_from, | 200 virtual void Start(const tracked_objects::Location& posted_from, |
201 TimeDelta delay, | 201 TimeDelta delay, |
202 Receiver* receiver, | 202 Receiver* receiver, |
203 ReceiverMethod method) { | 203 ReceiverMethod method) { |
204 Timer::Start(posted_from, delay, | 204 Timer::Start(posted_from, delay, |
205 base::Bind(method, base::Unretained(receiver))); | 205 base::Bind(method, base::Unretained(receiver))); |
206 } | 206 } |
207 }; | 207 }; |
208 | 208 |
209 //----------------------------------------------------------------------------- | 209 //----------------------------------------------------------------------------- |
210 // A simple, one-shot timer. See usage notes at the top of the file. | 210 // A simple, one-shot timer. See usage notes at the top of the file. |
(...skipping 28 matching lines...) Expand all 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 |