Fix IsRenderFrameLive and use it in RenderFrameHostManager.
[chromium-blink-merge.git] / cc / scheduler / delay_based_time_source.h
blobe503bdf920fef14e1d413e12cb6a814f8e9c40a4
1 // Copyright 2011 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_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_
6 #define CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_
8 #include <string>
10 #include "base/memory/weak_ptr.h"
11 #include "base/values.h"
12 #include "cc/base/cc_export.h"
14 namespace base {
15 namespace debug {
16 class TracedValue;
18 class SingleThreadTaskRunner;
21 namespace cc {
23 class CC_EXPORT TimeSourceClient {
24 public:
25 virtual void OnTimerTick() = 0;
27 protected:
28 virtual ~TimeSourceClient() {}
31 // This timer implements a time source that achieves the specified interval
32 // in face of millisecond-precision delayed callbacks and random queueing
33 // delays. DelayBasedTimeSource uses base::TimeTicks::Now as its timebase.
34 class CC_EXPORT DelayBasedTimeSource
35 : public base::RefCounted<DelayBasedTimeSource> {
36 public:
37 static scoped_refptr<DelayBasedTimeSource> Create(
38 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner);
40 virtual void SetClient(TimeSourceClient* client);
42 // TimeSource implementation
43 virtual void SetTimebaseAndInterval(base::TimeTicks timebase,
44 base::TimeDelta interval);
46 virtual base::TimeTicks SetActive(bool active);
47 virtual bool Active() const;
49 // Get the last and next tick times. NextTickTime() returns null when
50 // inactive.
51 virtual base::TimeTicks LastTickTime() const;
52 virtual base::TimeTicks NextTickTime() const;
54 // Virtual for testing.
55 virtual base::TimeTicks Now() const;
57 virtual void AsValueInto(base::debug::TracedValue* dict) const;
59 protected:
60 DelayBasedTimeSource(base::TimeDelta interval,
61 base::SingleThreadTaskRunner* task_runner);
62 virtual ~DelayBasedTimeSource();
64 virtual std::string TypeString() const;
66 base::TimeTicks NextTickTarget(base::TimeTicks now);
67 void PostNextTickTask(base::TimeTicks now);
68 void OnTimerFired();
70 struct Parameters {
71 Parameters(base::TimeDelta interval, base::TimeTicks tick_target)
72 : interval(interval), tick_target(tick_target) {}
73 base::TimeDelta interval;
74 base::TimeTicks tick_target;
77 TimeSourceClient* client_;
78 base::TimeTicks last_tick_time_;
80 // current_parameters_ should only be written by PostNextTickTask.
81 // next_parameters_ will take effect on the next call to PostNextTickTask.
82 // Maintaining a pending set of parameters allows NextTickTime() to always
83 // reflect the actual time we expect OnTimerFired to be called.
84 Parameters current_parameters_;
85 Parameters next_parameters_;
87 bool active_;
89 base::SingleThreadTaskRunner* task_runner_;
90 base::WeakPtrFactory<DelayBasedTimeSource> weak_factory_;
92 private:
93 friend class base::RefCounted<DelayBasedTimeSource>;
94 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource);
97 // DelayBasedTimeSource uses base::TimeTicks::HighResNow as its timebase.
98 class DelayBasedTimeSourceHighRes : public DelayBasedTimeSource {
99 public:
100 static scoped_refptr<DelayBasedTimeSourceHighRes> Create(
101 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner);
103 virtual base::TimeTicks Now() const OVERRIDE;
105 protected:
106 DelayBasedTimeSourceHighRes(base::TimeDelta interval,
107 base::SingleThreadTaskRunner* task_runner);
108 virtual ~DelayBasedTimeSourceHighRes();
110 virtual std::string TypeString() const OVERRIDE;
112 private:
113 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSourceHighRes);
116 } // namespace cc
118 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_