| 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 "content/browser/device_sensors/device_motion_message_filter.h" | 5 #include "content/browser/device_sensors/device_motion_message_filter.h" |
| 6 | 6 |
| 7 #include "content/browser/device_sensors/device_inertial_sensor_service.h" | 7 #include "content/browser/device_sensors/device_inertial_sensor_service.h" |
| 8 #include "content/common/device_sensors/device_motion_messages.h" | 8 #include "content/common/device_sensors/device_motion_messages.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| 11 | 11 |
| 12 DeviceMotionMessageFilter::DeviceMotionMessageFilter() | 12 DeviceMotionMessageFilter::DeviceMotionMessageFilter() |
| 13 : BrowserMessageFilter(DeviceMotionMsgStart), | 13 : BrowserMessageFilter(DeviceMotionMsgStart), |
| 14 is_started_(false) { | 14 is_started_(false) { |
| 15 } | 15 } |
| 16 | 16 |
| 17 DeviceMotionMessageFilter::~DeviceMotionMessageFilter() { | 17 DeviceMotionMessageFilter::~DeviceMotionMessageFilter() { |
| 18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 19 if (is_started_) | 19 if (is_started_) |
| 20 DeviceInertialSensorService::GetInstance()->RemoveConsumer( | 20 DeviceInertialSensorService::GetInstance()->RemoveConsumer( |
| 21 CONSUMER_TYPE_MOTION); | 21 CONSUMER_TYPE_MOTION); |
| 22 } | 22 } |
| 23 | 23 |
| 24 bool DeviceMotionMessageFilter::OnMessageReceived( | 24 bool DeviceMotionMessageFilter::OnMessageReceived(const IPC::Message& message) { |
| 25 const IPC::Message& message, | |
| 26 bool* message_was_ok) { | |
| 27 bool handled = true; | 25 bool handled = true; |
| 28 IPC_BEGIN_MESSAGE_MAP_EX(DeviceMotionMessageFilter, | 26 IPC_BEGIN_MESSAGE_MAP(DeviceMotionMessageFilter, message) |
| 29 message, | |
| 30 *message_was_ok) | |
| 31 IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StartPolling, | 27 IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StartPolling, |
| 32 OnDeviceMotionStartPolling) | 28 OnDeviceMotionStartPolling) |
| 33 IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StopPolling, | 29 IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StopPolling, |
| 34 OnDeviceMotionStopPolling) | 30 OnDeviceMotionStopPolling) |
| 35 IPC_MESSAGE_UNHANDLED(handled = false) | 31 IPC_MESSAGE_UNHANDLED(handled = false) |
| 36 IPC_END_MESSAGE_MAP_EX() | 32 IPC_END_MESSAGE_MAP() |
| 37 return handled; | 33 return handled; |
| 38 } | 34 } |
| 39 | 35 |
| 40 void DeviceMotionMessageFilter::OnDeviceMotionStartPolling() { | 36 void DeviceMotionMessageFilter::OnDeviceMotionStartPolling() { |
| 41 DCHECK(!is_started_); | 37 DCHECK(!is_started_); |
| 42 if (is_started_) | 38 if (is_started_) |
| 43 return; | 39 return; |
| 44 is_started_ = true; | 40 is_started_ = true; |
| 45 DeviceInertialSensorService::GetInstance()->AddConsumer( | 41 DeviceInertialSensorService::GetInstance()->AddConsumer( |
| 46 CONSUMER_TYPE_MOTION); | 42 CONSUMER_TYPE_MOTION); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 57 } | 53 } |
| 58 | 54 |
| 59 void DeviceMotionMessageFilter::DidStartDeviceMotionPolling() { | 55 void DeviceMotionMessageFilter::DidStartDeviceMotionPolling() { |
| 60 Send(new DeviceMotionMsg_DidStartPolling( | 56 Send(new DeviceMotionMsg_DidStartPolling( |
| 61 DeviceInertialSensorService::GetInstance()-> | 57 DeviceInertialSensorService::GetInstance()-> |
| 62 GetSharedMemoryHandleForProcess( | 58 GetSharedMemoryHandleForProcess( |
| 63 CONSUMER_TYPE_MOTION, PeerHandle()))); | 59 CONSUMER_TYPE_MOTION, PeerHandle()))); |
| 64 } | 60 } |
| 65 | 61 |
| 66 } // namespace content | 62 } // namespace content |
| OLD | NEW |