OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/timer/mock_timer.h" |
| 6 |
| 7 namespace base { |
| 8 |
| 9 MockTimer::MockTimer(bool retain_user_task, bool is_repeating) |
| 10 : Timer(false, false), |
| 11 retain_user_task_(retain_user_task), |
| 12 is_repeating_(is_repeating), |
| 13 is_running_(false) { |
| 14 |
| 15 } |
| 16 |
| 17 MockTimer::MockTimer(const tracked_objects::Location& posted_from, |
| 18 TimeDelta delay, |
| 19 const base::Closure& user_task, |
| 20 bool is_repeating) |
| 21 : Timer(false, false), |
| 22 retain_user_task_(true), |
| 23 delay_(delay), |
| 24 is_repeating_(is_repeating), |
| 25 is_running_(false) { |
| 26 } |
| 27 |
| 28 MockTimer::~MockTimer() { |
| 29 } |
| 30 |
| 31 bool MockTimer::IsRunning() const { |
| 32 return is_running_; |
| 33 } |
| 34 |
| 35 base::TimeDelta MockTimer::GetCurrentDelay() const { |
| 36 return delay_; |
| 37 } |
| 38 |
| 39 void MockTimer::Start(const tracked_objects::Location& posted_from, |
| 40 TimeDelta delay, |
| 41 const base::Closure& user_task) { |
| 42 delay_ = delay; |
| 43 user_task_ = user_task; |
| 44 Reset(); |
| 45 } |
| 46 |
| 47 void MockTimer::Stop() { |
| 48 is_running_ = false; |
| 49 if (!retain_user_task_) |
| 50 user_task_.Reset(); |
| 51 } |
| 52 |
| 53 void MockTimer::Reset() { |
| 54 DCHECK(!user_task_.is_null()); |
| 55 is_running_ = true; |
| 56 } |
| 57 |
| 58 void MockTimer::Fire() { |
| 59 DCHECK(is_running_); |
| 60 base::Closure old_task = user_task_; |
| 61 if (is_repeating_) |
| 62 Reset(); |
| 63 else |
| 64 Stop(); |
| 65 old_task.Run(); |
| 66 } |
| 67 |
| 68 } // namespace base |
OLD | NEW |