| 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 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h" | |
| 6 | |
| 7 #include <gestures/gestures.h> | |
| 8 | |
| 9 #include "base/timer/timer.h" | |
| 10 | |
| 11 // libgestures requires that this be in the top level namespace. | |
| 12 class GesturesTimer { | |
| 13 public: | |
| 14 GesturesTimer() : callback_(NULL), callback_data_(NULL) {} | |
| 15 ~GesturesTimer() {} | |
| 16 | |
| 17 void Set(stime_t delay, GesturesTimerCallback callback, void* callback_data) { | |
| 18 callback_ = callback; | |
| 19 callback_data_ = callback_data; | |
| 20 timer_.Start(FROM_HERE, | |
| 21 base::TimeDelta::FromMicroseconds( | |
| 22 delay * base::Time::kMicrosecondsPerSecond), | |
| 23 this, | |
| 24 &GesturesTimer::OnTimerExpired); | |
| 25 } | |
| 26 | |
| 27 void Cancel() { timer_.Stop(); } | |
| 28 | |
| 29 private: | |
| 30 void OnTimerExpired() { | |
| 31 struct timespec ts; | |
| 32 DCHECK(!clock_gettime(CLOCK_MONOTONIC, &ts)); | |
| 33 stime_t next_delay = callback_(StimeFromTimespec(&ts), callback_data_); | |
| 34 if (next_delay >= 0) { | |
| 35 timer_.Start(FROM_HERE, | |
| 36 base::TimeDelta::FromMicroseconds( | |
| 37 next_delay * base::Time::kMicrosecondsPerSecond), | |
| 38 this, | |
| 39 &GesturesTimer::OnTimerExpired); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 GesturesTimerCallback callback_; | |
| 44 void* callback_data_; | |
| 45 base::OneShotTimer<GesturesTimer> timer_; | |
| 46 }; | |
| 47 | |
| 48 namespace ui { | |
| 49 | |
| 50 namespace { | |
| 51 | |
| 52 GesturesTimer* GesturesTimerCreate(void* data) { return new GesturesTimer; } | |
| 53 | |
| 54 void GesturesTimerSet(void* data, | |
| 55 GesturesTimer* timer, | |
| 56 stime_t delay, | |
| 57 GesturesTimerCallback callback, | |
| 58 void* callback_data) { | |
| 59 timer->Set(delay, callback, callback_data); | |
| 60 } | |
| 61 | |
| 62 void GesturesTimerCancel(void* data, GesturesTimer* timer) { timer->Cancel(); } | |
| 63 | |
| 64 void GesturesTimerFree(void* data, GesturesTimer* timer) { delete timer; } | |
| 65 | |
| 66 } // namespace | |
| 67 | |
| 68 const GesturesTimerProvider kGestureTimerProvider = { | |
| 69 GesturesTimerCreate, GesturesTimerSet, GesturesTimerCancel, | |
| 70 GesturesTimerFree}; | |
| 71 | |
| 72 } // namespace ui | |
| OLD | NEW |