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 #ifndef CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ | 5 #ifndef CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ |
6 #define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ | 6 #define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ |
7 | 7 |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
11 #include "content/public/renderer/platform_event_observer.h" | 11 #include "content/public/renderer/platform_event_observer.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 | 14 |
15 template <typename ListenerType> | 15 template <typename ListenerType> |
16 class CONTENT_EXPORT DeviceSensorEventPump | 16 class CONTENT_EXPORT DeviceSensorEventPump |
17 : NON_EXPORTED_BASE(public PlatformEventObserver<ListenerType>) { | 17 : NON_EXPORTED_BASE(public PlatformEventObserver<ListenerType>) { |
18 public: | 18 public: |
19 // Default rate for firing events. | 19 // Default rate for firing events. |
20 static const int kDefaultPumpFrequencyHz = 60; | 20 static const int kDefaultPumpFrequencyHz = 60; |
21 static const int kDefaultPumpDelayMicroseconds = | 21 static const int kDefaultPumpDelayMicroseconds = |
22 base::Time::kMicrosecondsPerSecond / kDefaultPumpFrequencyHz; | 22 base::Time::kMicrosecondsPerSecond / kDefaultPumpFrequencyHz; |
23 | 23 |
24 // PlatformEventObserver | 24 // PlatformEventObserver |
25 virtual void Start(blink::WebPlatformEventListener* listener) OVERRIDE { | 25 virtual void Start(blink::WebPlatformEventListener* listener) override { |
26 DVLOG(2) << "requested start"; | 26 DVLOG(2) << "requested start"; |
27 | 27 |
28 if (state_ != STOPPED) | 28 if (state_ != STOPPED) |
29 return; | 29 return; |
30 | 30 |
31 DCHECK(!timer_.IsRunning()); | 31 DCHECK(!timer_.IsRunning()); |
32 | 32 |
33 PlatformEventObserver<ListenerType>::Start(listener); | 33 PlatformEventObserver<ListenerType>::Start(listener); |
34 state_ = PENDING_START; | 34 state_ = PENDING_START; |
35 } | 35 } |
36 | 36 |
37 virtual void Stop() OVERRIDE { | 37 virtual void Stop() override { |
38 DVLOG(2) << "stop"; | 38 DVLOG(2) << "stop"; |
39 | 39 |
40 if (state_ == STOPPED) | 40 if (state_ == STOPPED) |
41 return; | 41 return; |
42 | 42 |
43 DCHECK((state_ == PENDING_START && !timer_.IsRunning()) || | 43 DCHECK((state_ == PENDING_START && !timer_.IsRunning()) || |
44 (state_ == RUNNING && timer_.IsRunning())); | 44 (state_ == RUNNING && timer_.IsRunning())); |
45 | 45 |
46 if (timer_.IsRunning()) | 46 if (timer_.IsRunning()) |
47 timer_.Stop(); | 47 timer_.Stop(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 int pump_delay_microseconds_; | 93 int pump_delay_microseconds_; |
94 PumpState state_; | 94 PumpState state_; |
95 base::RepeatingTimer<DeviceSensorEventPump> timer_; | 95 base::RepeatingTimer<DeviceSensorEventPump> timer_; |
96 | 96 |
97 DISALLOW_COPY_AND_ASSIGN(DeviceSensorEventPump); | 97 DISALLOW_COPY_AND_ASSIGN(DeviceSensorEventPump); |
98 }; | 98 }; |
99 | 99 |
100 } // namespace content | 100 } // namespace content |
101 | 101 |
102 #endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ | 102 #endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_SENSOR_EVENT_PUMP_H_ |
OLD | NEW |