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

Side by Side Diff: base/test/simple_test_tick_clock.cc

Issue 1132753008: Replaced TestNowSource with SimpleTestTickClock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing and additional code changes. Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/test/simple_test_tick_clock.h" 5 #include "base/test/simple_test_tick_clock.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace base { 9 namespace base {
10 10
11 SimpleTestTickClock::SimpleTestTickClock() {} 11 SimpleTestTickClock::SimpleTestTickClock() {}
12 12
13 SimpleTestTickClock::SimpleTestTickClock(int64_t initial) : now_ticks_() {
14 now_ticks_ = TimeTicks::FromInternalValue(initial);
15 }
16
17 SimpleTestTickClock::SimpleTestTickClock(TimeTicks initial) : now_ticks_() {
18 now_ticks_ = initial;
19 }
20
13 SimpleTestTickClock::~SimpleTestTickClock() {} 21 SimpleTestTickClock::~SimpleTestTickClock() {}
14 22
15 TimeTicks SimpleTestTickClock::NowTicks() { 23 TimeTicks SimpleTestTickClock::NowTicks() {
16 AutoLock lock(lock_); 24 AutoLock lock(lock_);
17 return now_ticks_; 25 return now_ticks_;
18 } 26 }
19 27
28 void SimpleTestTickClock::Set(TimeTicks time) {
29 AutoLock lock(lock_);
30 DCHECK(time >= now_ticks_); // Time should always go forward.
31 now_ticks_ = time;
32 }
33
20 void SimpleTestTickClock::Advance(TimeDelta delta) { 34 void SimpleTestTickClock::Advance(TimeDelta delta) {
21 AutoLock lock(lock_); 35 AutoLock lock(lock_);
22 DCHECK(delta >= TimeDelta()); 36 DCHECK(delta >= TimeDelta());
23 now_ticks_ += delta; 37 now_ticks_ += delta;
24 } 38 }
25 39
40 // SimpleTestTickClock::Convenience functions
41 void SimpleTestTickClock::AdvanceMicroseconds(int64_t period_in_microseconds) {
42 Advance(TimeDelta::FromMicroseconds(period_in_microseconds));
43 }
44
45 void SimpleTestTickClock::SetMicroseconds(int64_t time_in_microseconds) {
46 Set(TimeTicks::FromInternalValue(time_in_microseconds));
47 }
48
26 } // namespace base 49 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698