Setup a experiment to enable background tracing.
[chromium-blink-merge.git] / cc / test / test_now_source.h
blob9b46bbe70f1d42ef7be6a7bd3a30ca4093216056
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 #ifndef CC_TEST_TEST_NOW_SOURCE_H_
6 #define CC_TEST_TEST_NOW_SOURCE_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12 #include "base/trace_event/trace_event.h"
13 #include "base/trace_event/trace_event_argument.h"
15 namespace cc {
17 class TestNowSource : public base::RefCounted<TestNowSource> {
18 public:
19 static scoped_refptr<TestNowSource> Create();
20 static scoped_refptr<TestNowSource> Create(int64_t initial);
21 static scoped_refptr<TestNowSource> Create(base::TimeTicks initial);
23 virtual void Reset();
24 virtual base::TimeTicks Now() const;
25 virtual void SetNow(base::TimeTicks time);
26 virtual void AdvanceNow(base::TimeDelta period);
28 // Convenience functions to make it the now source easier to use in unit
29 // tests.
30 void AdvanceNowMicroseconds(int64_t period_in_microseconds);
31 void SetNowMicroseconds(int64_t time_in_microseconds);
33 static const base::TimeTicks kAbsoluteMaxNow;
35 // Tracing functions
36 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue() const;
37 void AsValueInto(base::trace_event::TracedValue* state) const;
38 std::string ToString() const;
40 int NumNowCalls() const { return num_now_calls_; }
42 protected:
43 TestNowSource();
44 explicit TestNowSource(int64_t initial);
45 explicit TestNowSource(base::TimeTicks initial);
47 base::TimeTicks initial_;
48 base::TimeTicks now_;
49 mutable int num_now_calls_;
51 private:
52 friend class base::RefCounted<TestNowSource>;
53 virtual ~TestNowSource();
56 // gtest pretty printing functions
57 void PrintTo(const scoped_refptr<TestNowSource>& src, ::std::ostream* os);
58 ::std::ostream& operator<<(::std::ostream& os,
59 const scoped_refptr<TestNowSource>& src);
61 } // namespace cc
63 #endif // CC_TEST_TEST_NOW_SOURCE_H_