OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "content/browser/device_sensors/device_orientation_message_filter.h" | |
6 | |
7 #include "content/browser/device_sensors/device_inertial_sensor_service.h" | |
8 #include "content/common/device_sensors/device_orientation_messages.h" | |
9 | |
10 namespace content { | |
11 | |
12 DeviceOrientationMessageFilter::DeviceOrientationMessageFilter() | |
13 : BrowserMessageFilter(DeviceOrientationMsgStart), | |
14 is_started_(false) { | |
15 } | |
16 | |
17 DeviceOrientationMessageFilter::~DeviceOrientationMessageFilter() { | |
18 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
19 if (is_started_) | |
20 DeviceInertialSensorService::GetInstance()->RemoveConsumer( | |
21 CONSUMER_TYPE_ORIENTATION); | |
22 } | |
23 | |
24 bool DeviceOrientationMessageFilter::OnMessageReceived( | |
25 const IPC::Message& message) { | |
26 bool handled = true; | |
27 IPC_BEGIN_MESSAGE_MAP(DeviceOrientationMessageFilter, message) | |
28 IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StartPolling, | |
29 OnDeviceOrientationStartPolling) | |
30 IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StopPolling, | |
31 OnDeviceOrientationStopPolling) | |
32 IPC_MESSAGE_UNHANDLED(handled = false) | |
33 IPC_END_MESSAGE_MAP() | |
34 return handled; | |
35 } | |
36 | |
37 void DeviceOrientationMessageFilter::OnDeviceOrientationStartPolling() { | |
38 DCHECK(!is_started_); | |
39 if (is_started_) | |
40 return; | |
41 is_started_ = true; | |
42 DeviceInertialSensorService::GetInstance()->AddConsumer( | |
43 CONSUMER_TYPE_ORIENTATION); | |
44 DidStartDeviceOrientationPolling(); | |
45 } | |
46 | |
47 void DeviceOrientationMessageFilter::OnDeviceOrientationStopPolling() { | |
48 DCHECK(is_started_); | |
49 if (!is_started_) | |
50 return; | |
51 is_started_ = false; | |
52 DeviceInertialSensorService::GetInstance()->RemoveConsumer( | |
53 CONSUMER_TYPE_ORIENTATION); | |
54 } | |
55 | |
56 void DeviceOrientationMessageFilter::DidStartDeviceOrientationPolling() { | |
57 Send(new DeviceOrientationMsg_DidStartPolling( | |
58 DeviceInertialSensorService::GetInstance()-> | |
59 GetSharedMemoryHandleForProcess( | |
60 CONSUMER_TYPE_ORIENTATION, | |
61 PeerHandle()))); | |
62 } | |
63 | |
64 } // namespace content | |
OLD | NEW |