| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h" | 5 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h" |
| 6 | 6 |
| 7 #include <gestures/gestures.h> | 7 #include <gestures/gestures.h> |
| 8 | 8 |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 base::TimeDelta::FromMicroseconds( | 21 base::TimeDelta::FromMicroseconds( |
| 22 delay * base::Time::kMicrosecondsPerSecond), | 22 delay * base::Time::kMicrosecondsPerSecond), |
| 23 this, | 23 this, |
| 24 &GesturesTimer::OnTimerExpired); | 24 &GesturesTimer::OnTimerExpired); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void Cancel() { timer_.Stop(); } | 27 void Cancel() { timer_.Stop(); } |
| 28 | 28 |
| 29 private: | 29 private: |
| 30 void OnTimerExpired() { | 30 void OnTimerExpired() { |
| 31 struct timespec ts; | |
| 32 int fail = clock_gettime(CLOCK_MONOTONIC, &ts); | |
| 33 DCHECK(!fail); | |
| 34 | |
| 35 // Run the callback and reschedule the next run if requested. | 31 // Run the callback and reschedule the next run if requested. |
| 36 stime_t next_delay = callback_(StimeFromTimespec(&ts), callback_data_); | 32 stime_t next_delay = callback_(ui::StimeNow(), callback_data_); |
| 37 if (next_delay >= 0) { | 33 if (next_delay >= 0) { |
| 38 timer_.Start(FROM_HERE, | 34 timer_.Start(FROM_HERE, |
| 39 base::TimeDelta::FromMicroseconds( | 35 base::TimeDelta::FromMicroseconds( |
| 40 next_delay * base::Time::kMicrosecondsPerSecond), | 36 next_delay * base::Time::kMicrosecondsPerSecond), |
| 41 this, | 37 this, |
| 42 &GesturesTimer::OnTimerExpired); | 38 &GesturesTimer::OnTimerExpired); |
| 43 } | 39 } |
| 44 } | 40 } |
| 45 | 41 |
| 46 GesturesTimerCallback callback_; | 42 GesturesTimerCallback callback_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 61 void* callback_data) { | 57 void* callback_data) { |
| 62 timer->Set(delay, callback, callback_data); | 58 timer->Set(delay, callback, callback_data); |
| 63 } | 59 } |
| 64 | 60 |
| 65 void GesturesTimerCancel(void* data, GesturesTimer* timer) { timer->Cancel(); } | 61 void GesturesTimerCancel(void* data, GesturesTimer* timer) { timer->Cancel(); } |
| 66 | 62 |
| 67 void GesturesTimerFree(void* data, GesturesTimer* timer) { delete timer; } | 63 void GesturesTimerFree(void* data, GesturesTimer* timer) { delete timer; } |
| 68 | 64 |
| 69 } // namespace | 65 } // namespace |
| 70 | 66 |
| 67 stime_t StimeNow() { |
| 68 struct timespec ts; |
| 69 |
| 70 if (clock_gettime(CLOCK_MONOTONIC, &ts)) |
| 71 PLOG(FATAL) << "clock_gettime"; |
| 72 |
| 73 return StimeFromTimespec(&ts); |
| 74 } |
| 75 |
| 71 const GesturesTimerProvider kGestureTimerProvider = { | 76 const GesturesTimerProvider kGestureTimerProvider = { |
| 72 GesturesTimerCreate, GesturesTimerSet, GesturesTimerCancel, | 77 GesturesTimerCreate, GesturesTimerSet, GesturesTimerCancel, |
| 73 GesturesTimerFree}; | 78 GesturesTimerFree}; |
| 74 | 79 |
| 75 } // namespace ui | 80 } // namespace ui |
| OLD | NEW |