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 "base/memory/weak_ptr.h"
9 #include "cc/base/cc_export.h"
10 #include "cc/scheduler/time_source.h"
16 // This timer implements a time source that achieves the specified interval
17 // in face of millisecond-precision delayed callbacks and random queueing
19 class CC_EXPORT DelayBasedTimeSource
: public TimeSource
{
21 static scoped_refptr
<DelayBasedTimeSource
> Create(base::TimeDelta interval
,
24 virtual void SetClient(TimeSourceClient
* client
) OVERRIDE
;
26 // TimeSource implementation
27 virtual void SetTimebaseAndInterval(base::TimeTicks timebase
,
28 base::TimeDelta interval
) OVERRIDE
;
30 virtual void SetActive(bool active
) OVERRIDE
;
31 virtual bool Active() const OVERRIDE
;
33 // Get the last and next tick times. nextTimeTime() returns null when
35 virtual base::TimeTicks
LastTickTime() OVERRIDE
;
36 virtual base::TimeTicks
NextTickTime() OVERRIDE
;
38 // Virtual for testing.
39 virtual base::TimeTicks
Now() const;
42 DelayBasedTimeSource(base::TimeDelta interval
, Thread
* thread
);
43 virtual ~DelayBasedTimeSource();
45 base::TimeTicks
NextTickTarget(base::TimeTicks now
);
46 void PostNextTickTask(base::TimeTicks now
);
56 Parameters(base::TimeDelta interval
, base::TimeTicks tick_target
)
57 : interval(interval
), tick_target(tick_target
) {}
58 base::TimeDelta interval
;
59 base::TimeTicks tick_target
;
62 TimeSourceClient
* client_
;
63 bool has_tick_target_
;
64 base::TimeTicks last_tick_time_
;
66 // current_parameters_ should only be written by PostNextTickTask.
67 // next_parameters_ will take effect on the next call to PostNextTickTask.
68 // Maintaining a pending set of parameters allows NextTickTime() to always
69 // reflect the actual time we expect OnTimerFired to be called.
70 Parameters current_parameters_
;
71 Parameters next_parameters_
;
76 base::WeakPtrFactory
<DelayBasedTimeSource
> weak_factory_
;
77 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource
);
82 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_