OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_MOTION_EVENT_PUMP_H_ | 5 #ifndef CONTENT_RENDERER_DEVICE_MOTION_EVENT_PUMP_H_ |
6 #define CONTENT_RENDERER_DEVICE_MOTION_EVENT_PUMP_H_ | 6 #define CONTENT_RENDERER_DEVICE_MOTION_EVENT_PUMP_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "content/renderer/device_orientation/device_sensor_event_pump.h" |
darin (slow to review)
2013/07/31 19:27:28
Hmm, so "device sensor" is the term we are using a
timvolodine
2013/08/01 15:31:36
On the Blink side we have DeviceSensorEventControl
| |
10 #include "base/timer/timer.h" | |
11 #include "content/public/renderer/render_process_observer.h" | |
12 #include "content/renderer/shared_memory_seqlock_reader.h" | 10 #include "content/renderer/shared_memory_seqlock_reader.h" |
13 #include "third_party/WebKit/public/platform/WebDeviceMotionData.h" | 11 #include "third_party/WebKit/public/platform/WebDeviceMotionData.h" |
14 | 12 |
15 namespace WebKit { | 13 namespace WebKit { |
16 class WebDeviceMotionListener; | 14 class WebDeviceMotionListener; |
17 } | 15 } |
18 | 16 |
19 namespace content { | 17 namespace content { |
20 class RenderThread; | |
21 | 18 |
22 typedef SharedMemorySeqLockReader<WebKit::WebDeviceMotionData> | 19 typedef SharedMemorySeqLockReader<WebKit::WebDeviceMotionData> |
23 DeviceMotionSharedMemoryReader; | 20 DeviceMotionSharedMemoryReader; |
24 | 21 |
25 class CONTENT_EXPORT DeviceMotionEventPump : public RenderProcessObserver { | 22 class CONTENT_EXPORT DeviceMotionEventPump : public DeviceSensorEventPump { |
26 public: | 23 public: |
27 DeviceMotionEventPump(); | 24 DeviceMotionEventPump(); |
25 explicit DeviceMotionEventPump(int pump_delay_millis); | |
28 virtual ~DeviceMotionEventPump(); | 26 virtual ~DeviceMotionEventPump(); |
29 | 27 |
30 static double GetDelayMillis(); | |
31 | |
32 // Sets the listener to receive updates for device motion data at | 28 // Sets the listener to receive updates for device motion data at |
33 // regular intervals. | 29 // regular intervals. Returns true if the registration was successful. |
34 // Returns true if the registration was successful. | 30 bool SetListener(WebKit::WebDeviceMotionListener* listener); |
35 bool SetListener(WebKit::WebDeviceMotionListener*); | |
36 | |
37 void SetDeviceMotionReader(scoped_ptr<DeviceMotionSharedMemoryReader>); | |
38 | |
39 void Attach(RenderThread* thread); | |
40 | 31 |
41 // RenderProcessObserver implementation. | 32 // RenderProcessObserver implementation. |
42 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; | 33 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; |
43 | 34 |
44 protected: | 35 protected: |
45 // Delay between subsequent firing of events. | 36 virtual void FireEvent() OVERRIDE; |
46 static const double kPumpDelayMillis; | 37 virtual bool InitializeReader(base::SharedMemoryHandle handle) OVERRIDE; |
47 | 38 virtual bool SendStartMessage() OVERRIDE; |
48 // The pump is a tri-state automaton with allowed transitions as follows: | 39 virtual bool SendStopMessage() OVERRIDE; |
49 // STOPPED -> PENDING_START | |
50 // PENDING_START -> RUNNING | |
51 // PENDING_START -> STOPPED | |
52 // RUNNING -> STOPPED | |
53 enum PumpState { | |
54 STOPPED, | |
55 RUNNING, | |
56 PENDING_START | |
57 }; | |
58 | |
59 bool StartFetchingDeviceMotion(); | |
60 bool StopFetchingDeviceMotion(); | |
61 void OnDidStartDeviceMotion(base::SharedMemoryHandle renderer_handle); | |
62 void FireEvent(); | |
63 | 40 |
64 WebKit::WebDeviceMotionListener* listener_; | 41 WebKit::WebDeviceMotionListener* listener_; |
65 scoped_ptr<DeviceMotionSharedMemoryReader> reader_; | 42 scoped_ptr<DeviceMotionSharedMemoryReader> reader_; |
66 base::RepeatingTimer<DeviceMotionEventPump> timer_; | |
67 PumpState state_; | |
68 }; | 43 }; |
69 | 44 |
70 } // namespace content | 45 } // namespace content |
71 | 46 |
72 #endif // CONTENT_RENDERER_DEVICE_MOTION_EVENT_PUMP_H_ | 47 #endif // CONTENT_RENDERER_DEVICE_MOTION_EVENT_PUMP_H_ |
OLD | NEW |