Delete unused downloads page asset.
[chromium-blink-merge.git] / cc / scheduler / delay_based_time_source.h
blobcd474a5c807f3f66a182b55fea663e454a576001
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/cancelable_callback.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/values.h"
13 #include "cc/base/cc_export.h"
15 namespace base {
16 namespace trace_event {
17 class TracedValue;
19 class SingleThreadTaskRunner;
22 namespace cc {
23 class CC_EXPORT DelayBasedTimeSourceClient {
24 public:
25 virtual void OnTimerTick() = 0;
27 protected:
28 virtual ~DelayBasedTimeSourceClient() {}
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:
36 static scoped_ptr<DelayBasedTimeSource> Create(
37 base::TimeDelta interval,
38 base::SingleThreadTaskRunner* task_runner) {
39 return make_scoped_ptr(new DelayBasedTimeSource(interval, task_runner));
42 virtual ~DelayBasedTimeSource();
44 void SetClient(DelayBasedTimeSourceClient* client);
46 void SetTimebaseAndInterval(base::TimeTicks timebase,
47 base::TimeDelta interval);
49 base::TimeDelta Interval() const;
51 // Returns the time for the last missed tick.
52 base::TimeTicks SetActive(bool active);
53 bool Active() const;
55 // Get the last and next tick times. NextTickTime() returns null when
56 // inactive.
57 base::TimeTicks LastTickTime() const;
58 base::TimeTicks NextTickTime() const;
60 virtual void AsValueInto(base::trace_event::TracedValue* dict) const;
62 protected:
63 DelayBasedTimeSource(base::TimeDelta interval,
64 base::SingleThreadTaskRunner* task_runner);
66 // Virtual for testing.
67 virtual base::TimeTicks Now() const;
68 virtual std::string TypeString() const;
70 private:
71 base::TimeTicks NextTickTarget(base::TimeTicks now) const;
73 void PostNextTickTask(base::TimeTicks now);
74 void ResetTickTask(base::TimeTicks now);
76 void OnTimerTick();
78 DelayBasedTimeSourceClient* client_;
80 bool active_;
82 base::TimeTicks timebase_;
83 base::TimeDelta interval_;
85 base::TimeTicks last_tick_time_;
86 base::TimeTicks next_tick_time_;
88 base::CancelableClosure tick_closure_;
90 base::SingleThreadTaskRunner* task_runner_;
92 base::WeakPtrFactory<DelayBasedTimeSource> weak_factory_;
94 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource);
97 } // namespace cc
99 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_