OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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. | |
4 | |
5 #include "content/browser/renderer_host/device_motion_browser_message_filter.h" | |
6 | |
7 #include "content/browser/device_orientation/device_motion_service.h" | |
8 #include "content/common/device_motion_messages.h" | |
9 | |
10 namespace content { | |
11 | |
12 DeviceMotionBrowserMessageFilter::DeviceMotionBrowserMessageFilter() | |
13 : is_started_(false) { | |
14 } | |
15 | |
16 DeviceMotionBrowserMessageFilter::~DeviceMotionBrowserMessageFilter() { | |
17 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
18 if (is_started_) | |
19 DeviceMotionService::GetInstance()->RemoveConsumer(); | |
20 } | |
21 | |
22 bool DeviceMotionBrowserMessageFilter::OnMessageReceived( | |
23 const IPC::Message& message, | |
24 bool* message_was_ok) { | |
25 bool handled = true; | |
26 IPC_BEGIN_MESSAGE_MAP_EX(DeviceMotionBrowserMessageFilter, | |
27 message, | |
28 *message_was_ok) | |
29 IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StartPolling, | |
30 OnDeviceMotionStartPolling) | |
31 IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StopPolling, | |
32 OnDeviceMotionStopPolling) | |
33 IPC_MESSAGE_UNHANDLED(handled = false) | |
34 IPC_END_MESSAGE_MAP_EX() | |
35 return handled; | |
36 } | |
37 | |
38 void DeviceMotionBrowserMessageFilter::OnDeviceMotionStartPolling() { | |
39 if (!is_started_) { | |
darin (slow to review)
2013/06/24 23:40:34
nit: Consider returning early when is_started_ is
timvolodine
2013/06/25 03:36:07
Done.
| |
40 is_started_ = true; | |
41 DeviceMotionService::GetInstance()->AddConsumer(); | |
42 DidStartDeviceMotionPolling(); | |
43 } else { | |
44 // Currently we only expect the renderer to tell us once to start. | |
45 NOTREACHED(); | |
darin (slow to review)
2013/06/24 23:40:34
Note that in release builds, this NOTREACHED will
timvolodine
2013/06/25 03:36:07
Ack.
Added a DCHECK to catch those messages in deb
| |
46 } | |
47 } | |
48 | |
49 void DeviceMotionBrowserMessageFilter::OnDeviceMotionStopPolling() { | |
50 if (is_started_) { | |
51 is_started_ = false; | |
52 DeviceMotionService::GetInstance()->RemoveConsumer(); | |
53 } else { | |
54 NOTREACHED(); | |
55 } | |
56 } | |
57 | |
58 void DeviceMotionBrowserMessageFilter::DidStartDeviceMotionPolling() { | |
59 Send(new DeviceMotionMsg_DidStartPolling( | |
60 DeviceMotionService::GetInstance()->GetSharedMemoryHandleForProcess( | |
61 peer_handle()))); | |
62 } | |
63 | |
64 } // namespace content | |
OLD | NEW |