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_orientation_message_filter.h"
7 #include "content/browser/device_orientation/device_inertial_sensor_service.h"
8 #include "content/common/device_orientation/device_orientation_messages.h"
12 DeviceOrientationMessageFilter::DeviceOrientationMessageFilter()
13 : is_started_(false) {
16 DeviceOrientationMessageFilter::~DeviceOrientationMessageFilter() {
17 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
19 DeviceInertialSensorService::GetInstance()->RemoveConsumer(
20 CONSUMER_TYPE_ORIENTATION);
23 bool DeviceOrientationMessageFilter::OnMessageReceived(
24 const IPC::Message& message,
25 bool* message_was_ok) {
27 IPC_BEGIN_MESSAGE_MAP_EX(DeviceOrientationMessageFilter,
30 IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StartPolling,
31 OnDeviceOrientationStartPolling)
32 IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StopPolling,
33 OnDeviceOrientationStopPolling)
34 IPC_MESSAGE_UNHANDLED(handled = false)
35 IPC_END_MESSAGE_MAP_EX()
39 void DeviceOrientationMessageFilter::OnDeviceOrientationStartPolling() {
44 DeviceInertialSensorService::GetInstance()->AddConsumer(
45 CONSUMER_TYPE_ORIENTATION);
46 DidStartDeviceOrientationPolling();
49 void DeviceOrientationMessageFilter::OnDeviceOrientationStopPolling() {
54 DeviceInertialSensorService::GetInstance()->RemoveConsumer(
55 CONSUMER_TYPE_ORIENTATION);
58 void DeviceOrientationMessageFilter::DidStartDeviceOrientationPolling() {
59 Send(new DeviceOrientationMsg_DidStartPolling(
60 DeviceInertialSensorService::GetInstance()->
61 GetSharedMemoryHandleForProcess(
62 CONSUMER_TYPE_ORIENTATION,
66 } // namespace content