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.
5 #include "device_motion_event_pump.h"
7 #include "content/common/device_sensors/device_motion_messages.h"
8 #include "content/public/renderer/render_thread.h"
9 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceMotionListener.h"
13 DeviceMotionEventPump::DeviceMotionEventPump(RenderThread
* thread
)
14 : DeviceSensorEventPump
<blink::WebDeviceMotionListener
>(thread
) {
17 DeviceMotionEventPump::~DeviceMotionEventPump() {
20 bool DeviceMotionEventPump::OnControlMessageReceived(
21 const IPC::Message
& message
) {
23 IPC_BEGIN_MESSAGE_MAP(DeviceMotionEventPump
, message
)
24 IPC_MESSAGE_HANDLER(DeviceMotionMsg_DidStartPolling
, OnDidStart
)
25 IPC_MESSAGE_UNHANDLED(handled
= false)
30 void DeviceMotionEventPump::FireEvent() {
32 blink::WebDeviceMotionData data
;
33 if (reader_
->GetLatestData(&data
) && data
.allAvailableSensorsAreActive
)
34 listener()->didChangeDeviceMotion(data
);
37 bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle
) {
39 reader_
.reset(new DeviceMotionSharedMemoryReader());
40 return reader_
->Initialize(handle
);
43 void DeviceMotionEventPump::SendStartMessage() {
44 RenderThread::Get()->Send(new DeviceMotionHostMsg_StartPolling());
47 void DeviceMotionEventPump::SendStopMessage() {
48 RenderThread::Get()->Send(new DeviceMotionHostMsg_StopPolling());
51 void DeviceMotionEventPump::SendFakeDataForTesting(void* fake_data
) {
52 blink::WebDeviceMotionData data
=
53 *static_cast<blink::WebDeviceMotionData
*>(fake_data
);
55 listener()->didChangeDeviceMotion(data
);
58 } // namespace content