| 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 "device_motion_event_pump.h" | 5 #include "device_motion_event_pump.h" |
| 6 | 6 |
| 7 #include "content/common/device_sensors/device_motion_messages.h" | |
| 8 #include "content/public/renderer/render_thread.h" | 7 #include "content/public/renderer/render_thread.h" |
| 9 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic
eMotionListener.h" | 8 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic
eMotionListener.h" |
| 10 | 9 |
| 11 namespace content { | 10 namespace content { |
| 12 | 11 |
| 13 DeviceMotionEventPump::DeviceMotionEventPump(RenderThread* thread) | 12 DeviceMotionEventPump::DeviceMotionEventPump(RenderThread* thread) |
| 14 : DeviceSensorEventPump<blink::WebDeviceMotionListener>(thread) { | 13 : DeviceSensorMojoClientMixin< |
| 15 } | 14 DeviceSensorEventPump<blink::WebDeviceMotionListener>, |
| 15 device::mojom::MotionSensor>(thread) {} |
| 16 | 16 |
| 17 DeviceMotionEventPump::~DeviceMotionEventPump() { | 17 DeviceMotionEventPump::~DeviceMotionEventPump() { |
| 18 } | 18 } |
| 19 | 19 |
| 20 bool DeviceMotionEventPump::OnControlMessageReceived( | |
| 21 const IPC::Message& message) { | |
| 22 bool handled = true; | |
| 23 IPC_BEGIN_MESSAGE_MAP(DeviceMotionEventPump, message) | |
| 24 IPC_MESSAGE_HANDLER(DeviceMotionMsg_DidStartPolling, OnDidStart) | |
| 25 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 26 IPC_END_MESSAGE_MAP() | |
| 27 return handled; | |
| 28 } | |
| 29 | |
| 30 void DeviceMotionEventPump::FireEvent() { | 20 void DeviceMotionEventPump::FireEvent() { |
| 31 DCHECK(listener()); | 21 DCHECK(listener()); |
| 32 blink::WebDeviceMotionData data; | 22 blink::WebDeviceMotionData data; |
| 33 if (reader_->GetLatestData(&data) && data.allAvailableSensorsAreActive) | 23 if (reader_->GetLatestData(&data) && data.allAvailableSensorsAreActive) |
| 34 listener()->didChangeDeviceMotion(data); | 24 listener()->didChangeDeviceMotion(data); |
| 35 } | 25 } |
| 36 | 26 |
| 37 bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle) { | 27 bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle) { |
| 38 if (!reader_) | 28 if (!reader_) |
| 39 reader_.reset(new DeviceMotionSharedMemoryReader()); | 29 reader_.reset(new DeviceMotionSharedMemoryReader()); |
| 40 return reader_->Initialize(handle); | 30 return reader_->Initialize(handle); |
| 41 } | 31 } |
| 42 | 32 |
| 43 void DeviceMotionEventPump::SendStartMessage() { | |
| 44 RenderThread::Get()->Send(new DeviceMotionHostMsg_StartPolling()); | |
| 45 } | |
| 46 | |
| 47 void DeviceMotionEventPump::SendStopMessage() { | |
| 48 RenderThread::Get()->Send(new DeviceMotionHostMsg_StopPolling()); | |
| 49 } | |
| 50 | |
| 51 void DeviceMotionEventPump::SendFakeDataForTesting(void* fake_data) { | 33 void DeviceMotionEventPump::SendFakeDataForTesting(void* fake_data) { |
| 52 blink::WebDeviceMotionData data = | 34 blink::WebDeviceMotionData data = |
| 53 *static_cast<blink::WebDeviceMotionData*>(fake_data); | 35 *static_cast<blink::WebDeviceMotionData*>(fake_data); |
| 54 | 36 |
| 55 listener()->didChangeDeviceMotion(data); | 37 listener()->didChangeDeviceMotion(data); |
| 56 } | 38 } |
| 57 | 39 |
| 58 } // namespace content | 40 } // namespace content |
| OLD | NEW |