Chromium Code Reviews| Index: base/timer.h |
| =================================================================== |
| --- base/timer.h (revision 6138) |
| +++ base/timer.h (working copy) |
| @@ -135,21 +135,42 @@ |
| receiver_(receiver), |
| method_(method) { |
| } |
| + |
| + virtual ~TimerTask() { |
|
darin (slow to review)
2008/12/02 01:37:22
It is nice that delayed Tasks have the guarantee o
|
| + ClearBaseTimer(); |
| + } |
| + |
| virtual void Run() { |
| if (!timer_) // timer_ is null if we were orphaned. |
| return; |
| - SelfType* self = static_cast<SelfType*>(timer_); |
| - if (kIsRepeating) { |
| - self->Reset(); |
| - } else { |
| - self->delayed_task_ = NULL; |
| - } |
| + if (kIsRepeating) |
| + ResetBaseTimer(); |
| + else |
| + ClearBaseTimer(); |
| DispatchToMethod(receiver_, method_, Tuple0()); |
| } |
| + |
| TimerTask* Clone() const { |
| return new TimerTask(delay_, receiver_, method_); |
| } |
| + |
| private: |
| + // Inform the Base that the timer is no longer active. |
| + void ClearBaseTimer() { |
| + if (timer_) { |
| + SelfType* self = static_cast<SelfType*>(timer_); |
| + self->delayed_task_ = NULL; |
| + } |
| + } |
| + |
| + // Inform the Base that we're resetting the timer. |
| + void ResetBaseTimer() { |
| + DCHECK(timer_); |
| + DCHECK(kIsRepeating); |
| + SelfType* self = static_cast<SelfType*>(timer_); |
| + self->Reset(); |
| + } |
| + |
| Receiver* receiver_; |
| ReceiverMethod method_; |
| }; |