| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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. | |
| 4 | |
| 5 #ifndef SKY_SCHEDULER_TIMER_H_ | |
| 6 #define SKY_SCHEDULER_TIMER_H_ | |
| 7 | |
| 8 #include "base/memory/weak_ptr.h" | |
| 9 #include "base/single_thread_task_runner.h" | |
| 10 #include "base/time/time.h" | |
| 11 #include "sky/scheduler/time_interval.h" | |
| 12 | |
| 13 namespace sky { | |
| 14 | |
| 15 class Timer { | |
| 16 public: | |
| 17 class Client { | |
| 18 public: | |
| 19 virtual void OnTimerTick(base::TimeTicks now) = 0; | |
| 20 | |
| 21 protected: | |
| 22 virtual ~Client(); | |
| 23 }; | |
| 24 | |
| 25 Timer(Client* client, | |
| 26 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 27 ~Timer(); | |
| 28 | |
| 29 void SetInterval(const TimeInterval& parameters); | |
| 30 void SetEnabled(bool enabled); | |
| 31 | |
| 32 private: | |
| 33 base::TimeTicks NextTickTarget(base::TimeTicks now); | |
| 34 void ScheduleNextTick(base::TimeTicks now); | |
| 35 void PostTickTask(base::TimeTicks now, base::TimeTicks target); | |
| 36 void OnTimerFired(); | |
| 37 | |
| 38 Client* client_; | |
| 39 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 40 | |
| 41 TimeInterval interval_; | |
| 42 base::TimeTicks last_tick_; | |
| 43 base::TimeTicks current_target_; | |
| 44 | |
| 45 bool enabled_; | |
| 46 | |
| 47 base::WeakPtrFactory<Timer> weak_factory_; | |
| 48 }; | |
| 49 | |
| 50 } | |
| 51 | |
| 52 #endif // SKY_SCHEDULER_TIMER_H_ | |
| OLD | NEW |