Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: base/timer/mock_timer.cc

Issue 197243003: base: add MockTimer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Fix uninitialized variables. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/timer/mock_timer.h ('k') | base/timer/mock_timer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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(retain_user_task, is_repeating),
11 is_running_(false) {
12 }
13
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) {
21 }
22
23 MockTimer::~MockTimer() {
24 }
25
26 bool MockTimer::IsRunning() const {
27 return is_running_;
28 }
29
30 base::TimeDelta MockTimer::GetCurrentDelay() const {
31 return delay_;
32 }
33
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();
40 }
41
42 void MockTimer::Stop() {
43 is_running_ = false;
44 if (!retain_user_task())
45 user_task_.Reset();
46 }
47
48 void MockTimer::Reset() {
49 DCHECK(!user_task_.is_null());
50 is_running_ = true;
51 }
52
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();
61 }
62
63 } // namespace base
OLDNEW
« no previous file with comments | « base/timer/mock_timer.h ('k') | base/timer/mock_timer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698