Add Sad Tab resources to the iOS build.
[chromium-blink-merge.git] / cc / delay_based_time_source.h
blobda8e0e7cd4eca236b6d3877c2d20d3dcbd2d744b
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_DELAY_BASED_TIME_SOURCE_H_
6 #define CC_DELAY_BASED_TIME_SOURCE_H_
8 #include "base/memory/weak_ptr.h"
9 #include "cc/cc_export.h"
10 #include "cc/time_source.h"
12 namespace cc {
14 // This timer implements a time source that achieves the specified interval
15 // in face of millisecond-precision delayed callbacks and random queueing delays.
16 class CC_EXPORT DelayBasedTimeSource : public TimeSource {
17 public:
18 static scoped_refptr<DelayBasedTimeSource> create(base::TimeDelta interval, Thread* thread);
20 virtual void setClient(TimeSourceClient* client) OVERRIDE;
22 // TimeSource implementation
23 virtual void setTimebaseAndInterval(base::TimeTicks timebase, base::TimeDelta interval) OVERRIDE;
25 virtual void setActive(bool) OVERRIDE;
26 virtual bool active() const OVERRIDE;
28 // Get the last and next tick times. nextTimeTime() returns null when
29 // inactive.
30 virtual base::TimeTicks lastTickTime() OVERRIDE;
31 virtual base::TimeTicks nextTickTime() OVERRIDE;
34 // Virtual for testing.
35 virtual base::TimeTicks now() const;
37 protected:
38 DelayBasedTimeSource(base::TimeDelta interval, Thread* thread);
39 virtual ~DelayBasedTimeSource();
41 base::TimeTicks nextTickTarget(base::TimeTicks now);
42 void postNextTickTask(base::TimeTicks now);
43 void onTimerFired();
45 enum State {
46 STATE_INACTIVE,
47 STATE_STARTING,
48 STATE_ACTIVE,
51 struct Parameters {
52 Parameters(base::TimeDelta interval, base::TimeTicks tickTarget)
53 : interval(interval), tickTarget(tickTarget)
54 { }
55 base::TimeDelta interval;
56 base::TimeTicks tickTarget;
59 TimeSourceClient* m_client;
60 bool m_hasTickTarget;
61 base::TimeTicks m_lastTickTime;
63 // m_currentParameters should only be written by postNextTickTask.
64 // m_nextParameters will take effect on the next call to postNextTickTask.
65 // Maintaining a pending set of parameters allows nextTickTime() to always
66 // reflect the actual time we expect onTimerFired to be called.
67 Parameters m_currentParameters;
68 Parameters m_nextParameters;
70 State m_state;
72 Thread* m_thread;
73 base::WeakPtrFactory<DelayBasedTimeSource> m_weakFactory;
74 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource);
77 } // namespace cc
79 #endif // CC_DELAY_BASED_TIME_SOURCE_H_