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
3 // found in the LICENSE file.
5 #include "content/browser/device_orientation/device_motion_message_filter.h"
7 #include "content/browser/device_orientation/device_inertial_sensor_service.h"
8 #include "content/common/device_orientation/device_motion_messages.h"
12 DeviceMotionMessageFilter::DeviceMotionMessageFilter()
13 : is_started_(false) {
16 DeviceMotionMessageFilter::~DeviceMotionMessageFilter() {
17 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
19 DeviceInertialSensorService::GetInstance()->RemoveConsumer(
20 CONSUMER_TYPE_MOTION);
23 bool DeviceMotionMessageFilter::OnMessageReceived(
24 const IPC::Message& message,
25 bool* message_was_ok) {
27 IPC_BEGIN_MESSAGE_MAP_EX(DeviceMotionMessageFilter,
30 IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StartPolling,
31 OnDeviceMotionStartPolling)
32 IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StopPolling,
33 OnDeviceMotionStopPolling)
34 IPC_MESSAGE_UNHANDLED(handled = false)
35 IPC_END_MESSAGE_MAP_EX()
39 void DeviceMotionMessageFilter::OnDeviceMotionStartPolling() {
44 DeviceInertialSensorService::GetInstance()->AddConsumer(
45 CONSUMER_TYPE_MOTION);
46 DidStartDeviceMotionPolling();
49 void DeviceMotionMessageFilter::OnDeviceMotionStopPolling() {
54 DeviceInertialSensorService::GetInstance()->RemoveConsumer(
55 CONSUMER_TYPE_MOTION);
58 void DeviceMotionMessageFilter::DidStartDeviceMotionPolling() {
59 Send(new DeviceMotionMsg_DidStartPolling(
60 DeviceInertialSensorService::GetInstance()->
61 GetSharedMemoryHandleForProcess(
62 CONSUMER_TYPE_MOTION, PeerHandle())));
65 } // namespace content