Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: content/browser/device_sensors/device_motion_message_filter.cc

Issue 1164563003: Extract device_sensors to /device via Mojofication (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_motion_message_filter.h"
6
7 #include "content/browser/device_sensors/device_inertial_sensor_service.h"
8 #include "content/common/device_sensors/device_motion_messages.h"
9
10 namespace content {
11
12 DeviceMotionMessageFilter::DeviceMotionMessageFilter()
13 : BrowserMessageFilter(DeviceMotionMsgStart),
14 is_started_(false) {
15 }
16
17 DeviceMotionMessageFilter::~DeviceMotionMessageFilter() {
18 DCHECK_CURRENTLY_ON(BrowserThread::IO);
19 if (is_started_)
20 DeviceInertialSensorService::GetInstance()->RemoveConsumer(
21 CONSUMER_TYPE_MOTION);
22 }
23
24 bool DeviceMotionMessageFilter::OnMessageReceived(const IPC::Message& message) {
25 bool handled = true;
26 IPC_BEGIN_MESSAGE_MAP(DeviceMotionMessageFilter, message)
27 IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StartPolling,
28 OnDeviceMotionStartPolling)
29 IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StopPolling,
30 OnDeviceMotionStopPolling)
31 IPC_MESSAGE_UNHANDLED(handled = false)
32 IPC_END_MESSAGE_MAP()
33 return handled;
34 }
35
36 void DeviceMotionMessageFilter::OnDeviceMotionStartPolling() {
37 DCHECK(!is_started_);
38 if (is_started_)
39 return;
40 is_started_ = true;
41 DeviceInertialSensorService::GetInstance()->AddConsumer(
42 CONSUMER_TYPE_MOTION);
43 DidStartDeviceMotionPolling();
44 }
45
46 void DeviceMotionMessageFilter::OnDeviceMotionStopPolling() {
47 DCHECK(is_started_);
48 if (!is_started_)
49 return;
50 is_started_ = false;
51 DeviceInertialSensorService::GetInstance()->RemoveConsumer(
52 CONSUMER_TYPE_MOTION);
53 }
54
55 void DeviceMotionMessageFilter::DidStartDeviceMotionPolling() {
56 Send(new DeviceMotionMsg_DidStartPolling(
57 DeviceInertialSensorService::GetInstance()->
58 GetSharedMemoryHandleForProcess(
59 CONSUMER_TYPE_MOTION, PeerHandle())));
60 }
61
62 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698