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

Side by Side Diff: content/renderer/device_sensors/device_motion_event_pump.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
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 "base/process/process_handle.h"
8 #include "content/public/common/service_registry.h"
8 #include "content/public/renderer/render_thread.h" 9 #include "content/public/renderer/render_thread.h"
9 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic eMotionListener.h" 10 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic eMotionListener.h"
10 11
11 namespace content { 12 namespace content {
12 13
13 DeviceMotionEventPump::DeviceMotionEventPump(RenderThread* thread) 14 DeviceMotionEventPump::DeviceMotionEventPump(
14 : DeviceSensorEventPump<blink::WebDeviceMotionListener>(thread) { 15 blink::WebDeviceMotionListener* listener)
16 : listener_(listener) {
17 DCHECK(listener_);
18
19 if (ServiceRegistry* registry = RenderThread::Get()->GetServiceRegistry()) {
20 // registry can be null during testing.
21 registry->ConnectToRemoteService(&service_);
22 service_->StartPolling(
23 static_cast<int32>(base::GetCurrentProcId()),
24 base::Bind(&DeviceMotionEventPump::OnDidStart, base::Unretained(this)));
25 }
15 } 26 }
16 27
17 DeviceMotionEventPump::~DeviceMotionEventPump() { 28 DeviceMotionEventPump::~DeviceMotionEventPump() {
18 } 29 }
19 30
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() { 31 void DeviceMotionEventPump::FireEvent() {
31 DCHECK(listener()); 32 LOG(WARNING) << "DeviceMotionEventPump::FireEvent";
33 DCHECK(listener_);
32 blink::WebDeviceMotionData data; 34 blink::WebDeviceMotionData data;
33 if (reader_->GetLatestData(&data) && data.allAvailableSensorsAreActive) 35 if (reader_->GetLatestData(&data)) {
34 listener()->didChangeDeviceMotion(data); 36 LOG(WARNING) << "DeviceMotionEventPump::FireEvent, "
37 "data.allAvailableSensorsAreActive: "
38 << data.allAvailableSensorsAreActive;
39 if (data.allAvailableSensorsAreActive)
40 listener_->didChangeDeviceMotion(data);
41 }
35 } 42 }
36 43
37 bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle) { 44 bool DeviceMotionEventPump::InitializeReader(base::SharedMemoryHandle handle) {
38 if (!reader_) 45 if (!reader_)
39 reader_.reset(new DeviceMotionSharedMemoryReader()); 46 reader_.reset(new DeviceMotionSharedMemoryReader());
40 return reader_->Initialize(handle); 47 return reader_->Initialize(handle);
41 } 48 }
42 49
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) { 50 void DeviceMotionEventPump::SendFakeDataForTesting(void* fake_data) {
52 blink::WebDeviceMotionData data = 51 blink::WebDeviceMotionData data =
53 *static_cast<blink::WebDeviceMotionData*>(fake_data); 52 *static_cast<blink::WebDeviceMotionData*>(fake_data);
54 53
55 listener()->didChangeDeviceMotion(data); 54 listener_->didChangeDeviceMotion(data);
56 } 55 }
57 56
58 } // namespace content 57 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698