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.
8 #include "cc/test/test_now_source.h"
12 // TestNowSource::Constructors
13 scoped_refptr
<TestNowSource
> TestNowSource::Create() {
14 return make_scoped_refptr(new TestNowSource());
17 scoped_refptr
<TestNowSource
> TestNowSource::Create(base::TimeTicks initial
) {
18 return make_scoped_refptr(new TestNowSource(initial
));
21 scoped_refptr
<TestNowSource
> TestNowSource::Create(int64_t initial
) {
22 return make_scoped_refptr(new TestNowSource(initial
));
25 TestNowSource::TestNowSource()
26 : initial_(base::TimeTicks::FromInternalValue(10000)), now_() {
30 TestNowSource::TestNowSource(base::TimeTicks initial
)
31 : initial_(initial
), now_() {
35 TestNowSource::TestNowSource(int64_t initial
)
36 : initial_(base::TimeTicks::FromInternalValue(initial
)), now_() {
40 TestNowSource::~TestNowSource() {
43 // TestNowSource actual functionality
44 void TestNowSource::Reset() {
45 TRACE_EVENT_INSTANT2("cc",
46 "TestNowSource::Reset",
47 TRACE_EVENT_SCOPE_THREAD
,
55 base::TimeTicks
TestNowSource::Now() const {
59 void TestNowSource::SetNow(base::TimeTicks time
) {
60 TRACE_EVENT_INSTANT2("cc",
61 "TestNowSource::SetNow",
62 TRACE_EVENT_SCOPE_THREAD
,
67 DCHECK(time
>= now_
); // Time should always go forward.
71 void TestNowSource::AdvanceNow(base::TimeDelta period
) {
72 TRACE_EVENT_INSTANT2("cc",
73 "TestNowSource::AdvanceNow",
74 TRACE_EVENT_SCOPE_THREAD
,
78 period
.ToInternalValue());
79 DCHECK(now_
!= kAbsoluteMaxNow
);
80 DCHECK(period
>= base::TimeDelta()); // Time should always go forward.
84 const base::TimeTicks
TestNowSource::kAbsoluteMaxNow
=
85 base::TimeTicks::FromInternalValue(std::numeric_limits
<int64_t>::max());
87 // TestNowSource::Convenience functions
88 void TestNowSource::AdvanceNowMicroseconds(int64_t period_in_microseconds
) {
89 AdvanceNow(base::TimeDelta::FromMicroseconds(period_in_microseconds
));
91 void TestNowSource::SetNowMicroseconds(int64_t time_in_microseconds
) {
92 SetNow(base::TimeTicks::FromInternalValue(time_in_microseconds
));
95 // TestNowSource::Tracing functions
96 void TestNowSource::AsValueInto(base::debug::TracedValue
* state
) const {
97 state
->SetInteger("now_in_microseconds", now_
.ToInternalValue());
100 scoped_refptr
<base::debug::ConvertableToTraceFormat
> TestNowSource::AsValue()
102 scoped_refptr
<base::debug::TracedValue
> state
=
103 new base::debug::TracedValue();
104 AsValueInto(state
.get());
108 // TestNowSource::Pretty printing functions
109 std::string
TestNowSource::ToString() const {
110 std::string
output("TestNowSource(");
111 AsValue()->AppendAsTraceFormat(&output
);
116 ::std::ostream
& operator<<(::std::ostream
& os
,
117 const scoped_refptr
<TestNowSource
>& src
) {
118 os
<< src
->ToString();
121 void PrintTo(const scoped_refptr
<TestNowSource
>& src
, ::std::ostream
* os
) {