| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 virtual ~Timer(); | 83 virtual ~Timer(); |
| 84 | 84 |
| 85 // Returns true if the timer is running (i.e., not stopped). | 85 // Returns true if the timer is running (i.e., not stopped). |
| 86 virtual bool IsRunning() const; | 86 virtual bool IsRunning() const; |
| 87 | 87 |
| 88 // Returns the current delay for this timer. | 88 // Returns the current delay for this timer. |
| 89 virtual TimeDelta GetCurrentDelay() const; | 89 virtual TimeDelta GetCurrentDelay() const; |
| 90 | 90 |
| 91 // Set the task runner on which the task should be scheduled. This method can | 91 // Set the task runner on which the task should be scheduled. This method can |
| 92 // only be called before any tasks have been scheduled. | 92 // only be called before any tasks have been scheduled. The task runner must |
| 93 // run tasks on the same thread the timer is used on. |
| 93 virtual void SetTaskRunner(scoped_refptr<SingleThreadTaskRunner> task_runner); | 94 virtual void SetTaskRunner(scoped_refptr<SingleThreadTaskRunner> task_runner); |
| 94 | 95 |
| 95 // Start the timer to run at the given |delay| from now. If the timer is | 96 // Start the timer to run at the given |delay| from now. If the timer is |
| 96 // already running, it will be replaced to call the given |user_task|. | 97 // already running, it will be replaced to call the given |user_task|. |
| 97 virtual void Start(const tracked_objects::Location& posted_from, | 98 virtual void Start(const tracked_objects::Location& posted_from, |
| 98 TimeDelta delay, | 99 TimeDelta delay, |
| 99 const base::Closure& user_task); | 100 const base::Closure& user_task); |
| 100 | 101 |
| 101 // Call this method to stop and cancel the timer. It is a no-op if the timer | 102 // Call this method to stop and cancel the timer. It is a no-op if the timer |
| 102 // is not running. | 103 // is not running. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 : Timer(posted_from, delay, | 259 : Timer(posted_from, delay, |
| 259 base::Bind(method, base::Unretained(receiver)), | 260 base::Bind(method, base::Unretained(receiver)), |
| 260 false) {} | 261 false) {} |
| 261 | 262 |
| 262 void Reset() override { Timer::Reset(); } | 263 void Reset() override { Timer::Reset(); } |
| 263 }; | 264 }; |
| 264 | 265 |
| 265 } // namespace base | 266 } // namespace base |
| 266 | 267 |
| 267 #endif // BASE_TIMER_TIMER_H_ | 268 #endif // BASE_TIMER_TIMER_H_ |
| OLD | NEW |