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/WebDeviceMotionListener.h"
13 DeviceMotionEventPump::DeviceMotionEventPump()
14 : DeviceSensorEventPump(), listener_(0) {
17 DeviceMotionEventPump::DeviceMotionEventPump(int pump_delay_millis
)
18 : DeviceSensorEventPump(pump_delay_millis
), listener_(0) {
21 DeviceMotionEventPump::~DeviceMotionEventPump() {
24 bool DeviceMotionEventPump::SetListener(
25 blink::WebDeviceMotionListener
* listener
) {
27 return listener_
? RequestStart() : Stop();
30 bool DeviceMotionEventPump::OnControlMessageReceived(
31 const IPC::Message
& message
) {
33 IPC_BEGIN_MESSAGE_MAP(DeviceMotionEventPump
, message
)
34 IPC_MESSAGE_HANDLER(DeviceMotionMsg_DidStartPolling
, OnDidStart
)
35 IPC_MESSAGE_UNHANDLED(handled
= false)
40 void DeviceMotionEventPump::FireEvent() {
42 blink::WebDeviceMotionData data
;
43 if (reader_
->GetLatestData(&data
) && data
.allAvailableSensorsAreActive
)
44 listener_
->didChangeDeviceMotion(data
);
47 bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle
) {
49 reader_
.reset(new DeviceMotionSharedMemoryReader());
50 return reader_
->Initialize(handle
);
53 bool DeviceMotionEventPump::SendStartMessage() {
54 return RenderThread::Get()->Send(new DeviceMotionHostMsg_StartPolling());
58 bool DeviceMotionEventPump::SendStopMessage() {
59 return RenderThread::Get()->Send(new DeviceMotionHostMsg_StopPolling());
62 } // namespace content