Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ | 5 #ifndef CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ |
| 6 #define CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ | 6 #define CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/time/tick_clock.h" | |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "cc/base/cc_export.h" | 17 #include "cc/base/cc_export.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 namespace trace_event { | 20 namespace trace_event { |
| 20 class TracedValue; | 21 class TracedValue; |
| 21 } | 22 } |
| 22 class SingleThreadTaskRunner; | 23 class SingleThreadTaskRunner; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace cc { | 26 namespace cc { |
| 26 class CC_EXPORT DelayBasedTimeSourceClient { | 27 class CC_EXPORT DelayBasedTimeSourceClient { |
| 27 public: | 28 public: |
| 28 virtual void OnTimerTick() = 0; | 29 virtual void OnTimerTick() = 0; |
| 29 | 30 |
| 30 protected: | 31 protected: |
| 31 virtual ~DelayBasedTimeSourceClient() {} | 32 virtual ~DelayBasedTimeSourceClient() {} |
| 32 }; | 33 }; |
| 33 | 34 |
| 34 // This timer implements a time source that achieves the specified interval | 35 // Simple timer that keeps track of its last and next tick times can an use an |
| 35 // in face of millisecond-precision delayed callbacks and random queueing | 36 // optional clock for timing. |
| 36 // delays. DelayBasedTimeSource uses base::TimeTicks::Now as its timebase. | |
| 37 class CC_EXPORT DelayBasedTimeSource { | 37 class CC_EXPORT DelayBasedTimeSource { |
| 38 public: | 38 public: |
| 39 explicit DelayBasedTimeSource(base::SingleThreadTaskRunner* task_runner); | 39 DelayBasedTimeSource(base::SingleThreadTaskRunner* task_runner, |
| 40 virtual ~DelayBasedTimeSource(); | 40 base::TickClock* clock); |
| 41 ~DelayBasedTimeSource(); | |
| 41 | 42 |
| 42 void SetClient(DelayBasedTimeSourceClient* client); | 43 void SetClient(DelayBasedTimeSourceClient* client); |
| 43 | 44 |
| 44 void SetTimebaseAndInterval(base::TimeTicks timebase, | 45 void SetTimebaseAndInterval(base::TimeTicks timebase, |
| 45 base::TimeDelta interval); | 46 base::TimeDelta interval); |
| 46 | 47 |
| 47 base::TimeDelta Interval() const; | 48 base::TimeDelta Interval() const; |
| 48 | 49 |
| 49 void SetActive(bool active); | 50 void SetActive(bool active); |
| 50 bool Active() const; | 51 bool Active() const; |
| 51 | 52 |
| 52 // Get the last and next tick times. NextTickTime() returns null when | 53 // Get the last and next tick times. NextTickTime() returns null when |
| 53 // inactive. | 54 // inactive. |
| 54 base::TimeTicks LastTickTime() const; | 55 base::TimeTicks LastTickTime() const; |
| 55 base::TimeTicks NextTickTime() const; | 56 base::TimeTicks NextTickTime() const; |
| 56 | 57 |
| 57 virtual void AsValueInto(base::trace_event::TracedValue* dict) const; | 58 void AsValueInto(base::trace_event::TracedValue* dict) const; |
| 58 | |
| 59 protected: | |
| 60 // Virtual for testing. | |
| 61 virtual base::TimeTicks Now() const; | |
| 62 virtual std::string TypeString() const; | |
| 63 | 59 |
| 64 private: | 60 private: |
| 65 void PostNextTickTask(base::TimeTicks now); | 61 void PostNextTickTask(base::TimeTicks now); |
| 66 void ResetTickTask(base::TimeTicks now); | 62 void ResetTickTask(base::TimeTicks now); |
| 67 | 63 |
| 68 void OnTimerTick(); | 64 void OnTimerTick(); |
| 69 | 65 |
| 66 base::TimeTicks Now(); | |
|
brianderson
2016/07/13 21:14:49
Should this just go away now that there's a tick c
| |
| 67 | |
| 68 base::SingleThreadTaskRunner* task_runner_; | |
| 69 base::TickClock* clock_; | |
| 70 DelayBasedTimeSourceClient* client_; | 70 DelayBasedTimeSourceClient* client_; |
| 71 | 71 |
| 72 bool active_; | 72 bool active_; |
| 73 | 73 |
| 74 base::TimeTicks timebase_; | 74 base::TimeTicks timebase_; |
| 75 base::TimeDelta interval_; | 75 base::TimeDelta interval_; |
| 76 | 76 |
| 77 base::TimeTicks last_tick_time_; | 77 base::TimeTicks last_tick_time_; |
| 78 base::TimeTicks next_tick_time_; | 78 base::TimeTicks next_tick_time_; |
| 79 | 79 |
| 80 base::CancelableClosure tick_closure_; | 80 base::CancelableClosure tick_closure_; |
| 81 | |
| 82 base::SingleThreadTaskRunner* task_runner_; | |
| 83 | |
| 84 base::WeakPtrFactory<DelayBasedTimeSource> weak_factory_; | 81 base::WeakPtrFactory<DelayBasedTimeSource> weak_factory_; |
| 85 | 82 |
| 86 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource); | 83 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource); |
| 87 }; | 84 }; |
| 88 | 85 |
| 89 } // namespace cc | 86 } // namespace cc |
| 90 | 87 |
| 91 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ | 88 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ |
| OLD | NEW |