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 16:00:00
The (public, even) accessor already exists here.
Elly Fong-Jones
2014/03/13 16:07:17
Done.
| |
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 bool retain_user_task() const { return retain_user_task_; } | |
Mark Mentovai
2014/03/13 15:49:52
If nobody has needed these outside of a Timer subc
Elly Fong-Jones
2014/03/13 16:07:17
Done.
| |
111 bool is_repeating() const { return is_repeating_; } | |
110 | 112 |
111 protected: | 113 protected: |
112 // Used to initiate a new delayed task. This has the side-effect of disabling | 114 // Used to initiate a new delayed task. This has the side-effect of disabling |
113 // scheduled_task_ if it is non-null. | 115 // scheduled_task_ if it is non-null. |
114 void SetTaskInfo(const tracked_objects::Location& posted_from, | 116 void SetTaskInfo(const tracked_objects::Location& posted_from, |
115 TimeDelta delay, | 117 TimeDelta delay, |
116 const base::Closure& user_task); | 118 const base::Closure& user_task); |
117 | 119 |
118 private: | 120 private: |
119 friend class BaseTimerTaskInternal; | 121 friend class BaseTimerTaskInternal; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 // TODO(tim): We should remove uses of BaseTimerMethodPointer::Start below | 192 // TODO(tim): We should remove uses of BaseTimerMethodPointer::Start below |
191 // and convert callers to use the base::Closure version in Timer::Start, | 193 // and convert callers to use the base::Closure version in Timer::Start, |
192 // see bug 148832. | 194 // see bug 148832. |
193 using Timer::Start; | 195 using Timer::Start; |
194 | 196 |
195 BaseTimerMethodPointer() : Timer(kIsRepeating, kIsRepeating) {} | 197 BaseTimerMethodPointer() : Timer(kIsRepeating, kIsRepeating) {} |
196 | 198 |
197 // Start the timer to run at the given |delay| from now. If the timer is | 199 // 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 | 200 // already running, it will be replaced to call a task formed from |
199 // |reviewer->*method|. | 201 // |reviewer->*method|. |
200 void Start(const tracked_objects::Location& posted_from, | 202 virtual void Start(const tracked_objects::Location& posted_from, |
201 TimeDelta delay, | 203 TimeDelta delay, |
202 Receiver* receiver, | 204 Receiver* receiver, |
203 ReceiverMethod method) { | 205 ReceiverMethod method) { |
204 Timer::Start(posted_from, delay, | 206 Timer::Start(posted_from, delay, |
205 base::Bind(method, base::Unretained(receiver))); | 207 base::Bind(method, base::Unretained(receiver))); |
206 } | 208 } |
207 }; | 209 }; |
208 | 210 |
209 //----------------------------------------------------------------------------- | 211 //----------------------------------------------------------------------------- |
210 // A simple, one-shot timer. See usage notes at the top of the file. | 212 // 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, | 241 : Timer(posted_from, delay, |
240 base::Bind(method, base::Unretained(receiver)), | 242 base::Bind(method, base::Unretained(receiver)), |
241 false) {} | 243 false) {} |
242 | 244 |
243 void Reset() { Timer::Reset(); } | 245 void Reset() { Timer::Reset(); } |
244 }; | 246 }; |
245 | 247 |
246 } // namespace base | 248 } // namespace base |
247 | 249 |
248 #endif // BASE_TIMER_TIMER_H_ | 250 #endif // BASE_TIMER_TIMER_H_ |
OLD | NEW |