Mechanical rename of tracing includes for /chrome
[chromium-blink-merge.git] / base / timer / mock_timer.cc
blob296071e8e37224e76c5995a646c5bb0868e8e52c
1 // Copyright 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.
5 #include "base/timer/mock_timer.h"
7 namespace base {
9 MockTimer::MockTimer(bool retain_user_task, bool is_repeating)
10 : Timer(retain_user_task, is_repeating),
11 is_running_(false) {
14 MockTimer::MockTimer(const tracked_objects::Location& posted_from,
15 TimeDelta delay,
16 const base::Closure& user_task,
17 bool is_repeating)
18 : Timer(true, is_repeating),
19 delay_(delay),
20 is_running_(false) {
23 MockTimer::~MockTimer() {
26 bool MockTimer::IsRunning() const {
27 return is_running_;
30 base::TimeDelta MockTimer::GetCurrentDelay() const {
31 return delay_;
34 void MockTimer::Start(const tracked_objects::Location& posted_from,
35 TimeDelta delay,
36 const base::Closure& user_task) {
37 delay_ = delay;
38 user_task_ = user_task;
39 Reset();
42 void MockTimer::Stop() {
43 is_running_ = false;
44 if (!retain_user_task())
45 user_task_.Reset();
48 void MockTimer::Reset() {
49 DCHECK(!user_task_.is_null());
50 is_running_ = true;
53 void MockTimer::Fire() {
54 DCHECK(is_running_);
55 base::Closure old_task = user_task_;
56 if (is_repeating())
57 Reset();
58 else
59 Stop();
60 old_task.Run();
63 } // namespace base