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

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

Issue 446603002: Refactor code listening to platform events in content/renderer/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webkitplatform_impl_start_stop
Patch Set: rebase Created 6 years, 4 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" 7 #include "content/common/device_sensors/device_motion_messages.h"
8 #include "content/public/renderer/render_thread.h" 8 #include "content/public/renderer/render_thread.h"
9 #include "third_party/WebKit/public/platform/WebDeviceMotionListener.h" 9 #include "third_party/WebKit/public/platform/WebDeviceMotionListener.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 DeviceMotionEventPump::DeviceMotionEventPump() 13 DeviceMotionEventPump::DeviceMotionEventPump(RenderThread* thread)
14 : DeviceSensorEventPump(), listener_(0) { 14 : DeviceSensorEventPump<blink::WebDeviceMotionListener>(thread) {
15 }
16
17 DeviceMotionEventPump::DeviceMotionEventPump(int pump_delay_millis)
18 : DeviceSensorEventPump(pump_delay_millis), listener_(0) {
19 } 15 }
20 16
21 DeviceMotionEventPump::~DeviceMotionEventPump() { 17 DeviceMotionEventPump::~DeviceMotionEventPump() {
22 } 18 }
23 19
24 bool DeviceMotionEventPump::SetListener(
25 blink::WebDeviceMotionListener* listener) {
26 listener_ = listener;
27 return listener_ ? RequestStart() : Stop();
28 }
29
30 bool DeviceMotionEventPump::OnControlMessageReceived( 20 bool DeviceMotionEventPump::OnControlMessageReceived(
31 const IPC::Message& message) { 21 const IPC::Message& message) {
32 bool handled = true; 22 bool handled = true;
33 IPC_BEGIN_MESSAGE_MAP(DeviceMotionEventPump, message) 23 IPC_BEGIN_MESSAGE_MAP(DeviceMotionEventPump, message)
34 IPC_MESSAGE_HANDLER(DeviceMotionMsg_DidStartPolling, OnDidStart) 24 IPC_MESSAGE_HANDLER(DeviceMotionMsg_DidStartPolling, OnDidStart)
35 IPC_MESSAGE_UNHANDLED(handled = false) 25 IPC_MESSAGE_UNHANDLED(handled = false)
36 IPC_END_MESSAGE_MAP() 26 IPC_END_MESSAGE_MAP()
37 return handled; 27 return handled;
38 } 28 }
39 29
40 void DeviceMotionEventPump::FireEvent() { 30 void DeviceMotionEventPump::FireEvent() {
41 DCHECK(listener_); 31 DCHECK(listener());
42 blink::WebDeviceMotionData data; 32 blink::WebDeviceMotionData data;
43 if (reader_->GetLatestData(&data) && data.allAvailableSensorsAreActive) 33 if (reader_->GetLatestData(&data) && data.allAvailableSensorsAreActive)
44 listener_->didChangeDeviceMotion(data); 34 listener()->didChangeDeviceMotion(data);
45 } 35 }
46 36
47 bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle) { 37 bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle) {
48 if (!reader_) 38 if (!reader_)
49 reader_.reset(new DeviceMotionSharedMemoryReader()); 39 reader_.reset(new DeviceMotionSharedMemoryReader());
50 return reader_->Initialize(handle); 40 return reader_->Initialize(handle);
51 } 41 }
52 42
53 bool DeviceMotionEventPump::SendStartMessage() { 43 void DeviceMotionEventPump::SendStartMessage() {
54 return RenderThread::Get()->Send(new DeviceMotionHostMsg_StartPolling()); 44 RenderThread::Get()->Send(new DeviceMotionHostMsg_StartPolling());
55 } 45 }
56 46
47 void DeviceMotionEventPump::SendStopMessage() {
48 RenderThread::Get()->Send(new DeviceMotionHostMsg_StopPolling());
49 }
57 50
58 bool DeviceMotionEventPump::SendStopMessage() { 51 void DeviceMotionEventPump::SendFakeDataForTesting(void* fake_data) {
59 return RenderThread::Get()->Send(new DeviceMotionHostMsg_StopPolling()); 52 blink::WebDeviceMotionData data =
53 *static_cast<blink::WebDeviceMotionData*>(fake_data);
54
55 listener()->didChangeDeviceMotion(data);
60 } 56 }
61 57
62 } // namespace content 58 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698