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"
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
{
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
30 virtual base::TimeTicks
lastTickTime() OVERRIDE
;
31 virtual base::TimeTicks
nextTickTime() OVERRIDE
;
34 // Virtual for testing.
35 virtual base::TimeTicks
now() const;
38 DelayBasedTimeSource(base::TimeDelta interval
, Thread
* thread
);
39 virtual ~DelayBasedTimeSource();
41 base::TimeTicks
nextTickTarget(base::TimeTicks now
);
42 void postNextTickTask(base::TimeTicks now
);
52 Parameters(base::TimeDelta interval
, base::TimeTicks tickTarget
)
53 : interval(interval
), tickTarget(tickTarget
)
55 base::TimeDelta interval
;
56 base::TimeTicks tickTarget
;
59 TimeSourceClient
* m_client
;
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
;
73 base::WeakPtrFactory
<DelayBasedTimeSource
> m_weakFactory
;
74 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource
);
79 #endif // CC_DELAY_BASED_TIME_SOURCE_H_