| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // Stops the timer. | 59 // Stops the timer. |
| 60 ~BaseTimer_Helper() { | 60 ~BaseTimer_Helper() { |
| 61 OrphanDelayedTask(); | 61 OrphanDelayedTask(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Returns true if the timer is running (i.e., not stopped). | 64 // Returns true if the timer is running (i.e., not stopped). |
| 65 bool IsRunning() const { | 65 bool IsRunning() const { |
| 66 return delayed_task_ != NULL; | 66 return delayed_task_ != NULL; |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Returns the current delay for this timer. May only call this method when |
| 70 // the timer is running! |
| 71 TimeDelta GetCurrentDelay() const { |
| 72 DCHECK(IsRunning()); |
| 73 return delayed_task_->delay_; |
| 74 } |
| 75 |
| 69 protected: | 76 protected: |
| 70 BaseTimer_Helper() : delayed_task_(NULL) {} | 77 BaseTimer_Helper() : delayed_task_(NULL) {} |
| 71 | 78 |
| 72 // We have access to the timer_ member so we can orphan this task. | 79 // We have access to the timer_ member so we can orphan this task. |
| 73 class TimerTask : public Task { | 80 class TimerTask : public Task { |
| 74 public: | 81 public: |
| 75 TimerTask(TimeDelta delay) : delay_(delay) { | 82 TimerTask(TimeDelta delay) : delay_(delay) { |
| 76 // timer_ is set in InitiateDelayedTask. | 83 // timer_ is set in InitiateDelayedTask. |
| 77 } | 84 } |
| 78 BaseTimer_Helper* timer_; | 85 BaseTimer_Helper* timer_; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 class OneShotTimer : public BaseTimer<Receiver, false> {}; | 161 class OneShotTimer : public BaseTimer<Receiver, false> {}; |
| 155 | 162 |
| 156 //----------------------------------------------------------------------------- | 163 //----------------------------------------------------------------------------- |
| 157 // A simple, repeating timer. See usage notes at the top of the file. | 164 // A simple, repeating timer. See usage notes at the top of the file. |
| 158 template <class Receiver> | 165 template <class Receiver> |
| 159 class RepeatingTimer : public BaseTimer<Receiver, true> {}; | 166 class RepeatingTimer : public BaseTimer<Receiver, true> {}; |
| 160 | 167 |
| 161 } // namespace base | 168 } // namespace base |
| 162 | 169 |
| 163 #endif // BASE_TIMER_H_ | 170 #endif // BASE_TIMER_H_ |
| OLD | NEW |