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

Side by Side Diff: content/browser/renderer_host/device_motion_browser_message_filter.cc

Issue 14678012: Implement the content/renderer and content/browser part of the Device Motion API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compilation: peer_handle -> PeerHandle() Created 7 years, 5 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 (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 DCHECK(!is_started_);
40 if (is_started_)
41 return;
42 is_started_ = true;
43 DeviceMotionService::GetInstance()->AddConsumer();
44 DidStartDeviceMotionPolling();
45 }
46
47 void DeviceMotionBrowserMessageFilter::OnDeviceMotionStopPolling() {
48 DCHECK(is_started_);
49 if (!is_started_)
50 return;
51 is_started_ = false;
52 DeviceMotionService::GetInstance()->RemoveConsumer();
53 }
54
55 void DeviceMotionBrowserMessageFilter::DidStartDeviceMotionPolling() {
56 Send(new DeviceMotionMsg_DidStartPolling(
57 DeviceMotionService::GetInstance()->GetSharedMemoryHandleForProcess(
58 PeerHandle())));
59 }
60
61 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698