| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 virtual bool IsRunning() const; | 85 virtual bool IsRunning() const; |
| 86 | 86 |
| 87 // Returns the current delay for this timer. | 87 // Returns the current delay for this timer. |
| 88 virtual TimeDelta GetCurrentDelay() const; | 88 virtual TimeDelta GetCurrentDelay() const; |
| 89 | 89 |
| 90 // Start the timer to run at the given |delay| from now. If the timer is | 90 // Start the timer to run at the given |delay| from now. If the timer is |
| 91 // already running, it will be replaced to call the given |user_task|. | 91 // already running, it will be replaced to call the given |user_task|. |
| 92 virtual void Start(const tracked_objects::Location& posted_from, | 92 virtual void Start(const tracked_objects::Location& posted_from, |
| 93 TimeDelta delay, | 93 TimeDelta delay, |
| 94 const base::Closure& user_task); | 94 const base::Closure& user_task); |
| 95 | 95 |
| 96 // Call this method to stop and cancel the timer. It is a no-op if the timer | 96 // Call this method to stop and cancel the timer. It is a no-op if the timer |
| 97 // is not running. | 97 // is not running. |
| 98 virtual void Stop(); | 98 virtual void Stop(); |
| 99 | 99 |
| 100 // Call this method to reset the timer delay. The user_task_ must be set. If | 100 // Call this method to reset the timer delay. The user_task_ must be set. If |
| 101 // the timer is not running, this will start it by posting a task. | 101 // the timer is not running, this will start it by posting a task. |
| 102 virtual void Reset(); | 102 virtual void Reset(); |
| 103 | 103 |
| 104 const base::Closure& user_task() const { return user_task_; } | 104 const base::Closure& user_task() const { return user_task_; } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // and convert callers to use the base::Closure version in Timer::Start, | 190 // and convert callers to use the base::Closure version in Timer::Start, |
| 191 // see bug 148832. | 191 // see bug 148832. |
| 192 using Timer::Start; | 192 using Timer::Start; |
| 193 | 193 |
| 194 BaseTimerMethodPointer() : Timer(kIsRepeating, kIsRepeating) {} | 194 BaseTimerMethodPointer() : Timer(kIsRepeating, kIsRepeating) {} |
| 195 | 195 |
| 196 // Start the timer to run at the given |delay| from now. If the timer is | 196 // Start the timer to run at the given |delay| from now. If the timer is |
| 197 // already running, it will be replaced to call a task formed from | 197 // already running, it will be replaced to call a task formed from |
| 198 // |reviewer->*method|. | 198 // |reviewer->*method|. |
| 199 virtual void Start(const tracked_objects::Location& posted_from, | 199 virtual void Start(const tracked_objects::Location& posted_from, |
| 200 TimeDelta delay, | 200 TimeDelta delay, |
| 201 Receiver* receiver, | 201 Receiver* receiver, |
| 202 ReceiverMethod method) { | 202 ReceiverMethod method) { |
| 203 Timer::Start(posted_from, delay, | 203 Timer::Start(posted_from, delay, |
| 204 base::Bind(method, base::Unretained(receiver))); | 204 base::Bind(method, base::Unretained(receiver))); |
| 205 } | 205 } |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 //----------------------------------------------------------------------------- | 208 //----------------------------------------------------------------------------- |
| 209 // A simple, one-shot timer. See usage notes at the top of the file. | 209 // A simple, one-shot timer. See usage notes at the top of the file. |
| 210 template <class Receiver> | 210 template <class Receiver> |
| 211 class OneShotTimer : public BaseTimerMethodPointer<Receiver, false> {}; | 211 class OneShotTimer : public BaseTimerMethodPointer<Receiver, false> {}; |
| 212 | 212 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 238 : Timer(posted_from, delay, | 238 : Timer(posted_from, delay, |
| 239 base::Bind(method, base::Unretained(receiver)), | 239 base::Bind(method, base::Unretained(receiver)), |
| 240 false) {} | 240 false) {} |
| 241 | 241 |
| 242 void Reset() { Timer::Reset(); } | 242 void Reset() { Timer::Reset(); } |
| 243 }; | 243 }; |
| 244 | 244 |
| 245 } // namespace base | 245 } // namespace base |
| 246 | 246 |
| 247 #endif // BASE_TIMER_TIMER_H_ | 247 #endif // BASE_TIMER_TIMER_H_ |
| OLD | NEW |