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

Side by Side Diff: content/renderer/device_sensors/device_motion_event_pump.cc

Issue 2037513002: Convert device_sensors to use mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@conversion--mime-registry
Patch Set: Created 4 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
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 "device_motion_event_pump.h" 5 #include "device_motion_event_pump.h"
6 6
7 #include "content/common/device_sensors/device_motion_messages.h"
8 #include "content/public/renderer/render_thread.h" 7 #include "content/public/renderer/render_thread.h"
9 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic eMotionListener.h" 8 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic eMotionListener.h"
10 9
11 namespace content { 10 namespace content {
12 11
13 DeviceMotionEventPump::DeviceMotionEventPump(RenderThread* thread) 12 DeviceMotionEventPump::DeviceMotionEventPump(RenderThread* thread)
14 : DeviceSensorEventPump<blink::WebDeviceMotionListener>(thread) { 13 : DeviceMojoClientMixin<
15 } 14 DeviceSensorEventPump<blink::WebDeviceMotionListener>,
15 device::mojom::MotionSensor>(thread) {}
16 16
17 DeviceMotionEventPump::~DeviceMotionEventPump() { 17 DeviceMotionEventPump::~DeviceMotionEventPump() {
18 } 18 }
19 19
20 bool DeviceMotionEventPump::OnControlMessageReceived(
21 const IPC::Message& message) {
22 bool handled = true;
23 IPC_BEGIN_MESSAGE_MAP(DeviceMotionEventPump, message)
24 IPC_MESSAGE_HANDLER(DeviceMotionMsg_DidStartPolling, OnDidStart)
25 IPC_MESSAGE_UNHANDLED(handled = false)
26 IPC_END_MESSAGE_MAP()
27 return handled;
28 }
29
30 void DeviceMotionEventPump::FireEvent() { 20 void DeviceMotionEventPump::FireEvent() {
31 DCHECK(listener()); 21 DCHECK(listener());
32 blink::WebDeviceMotionData data; 22 blink::WebDeviceMotionData data;
33 if (reader_->GetLatestData(&data) && data.allAvailableSensorsAreActive) 23 if (!using_fake_data_for_testing_ && reader_->GetLatestData(&data) &&
timvolodine 2016/06/09 17:43:47 don't think this should be called in testing mode
Sam McNally 2016/06/10 01:07:51 Done. Previously, I hadn't replicated the testing
24 data.allAvailableSensorsAreActive) {
34 listener()->didChangeDeviceMotion(data); 25 listener()->didChangeDeviceMotion(data);
26 }
35 } 27 }
36 28
37 bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle) { 29 bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle) {
38 if (!reader_) 30 if (!reader_)
39 reader_.reset(new DeviceMotionSharedMemoryReader()); 31 reader_.reset(new DeviceMotionSharedMemoryReader());
40 return reader_->Initialize(handle); 32 return reader_->Initialize(handle);
41 } 33 }
42 34
43 void DeviceMotionEventPump::SendStartMessage() {
44 RenderThread::Get()->Send(new DeviceMotionHostMsg_StartPolling());
45 }
46
47 void DeviceMotionEventPump::SendStopMessage() {
48 RenderThread::Get()->Send(new DeviceMotionHostMsg_StopPolling());
49 }
50
51 void DeviceMotionEventPump::SendFakeDataForTesting(void* fake_data) { 35 void DeviceMotionEventPump::SendFakeDataForTesting(void* fake_data) {
36 using_fake_data_for_testing_ = true;
52 blink::WebDeviceMotionData data = 37 blink::WebDeviceMotionData data =
53 *static_cast<blink::WebDeviceMotionData*>(fake_data); 38 *static_cast<blink::WebDeviceMotionData*>(fake_data);
54 39
55 listener()->didChangeDeviceMotion(data); 40 listener()->didChangeDeviceMotion(data);
56 } 41 }
57 42
58 } // namespace content 43 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698