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

Unified Diff: content/renderer/renderer_blink_platform_impl.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, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/renderer_blink_platform_impl.cc
diff --git a/content/renderer/renderer_blink_platform_impl.cc b/content/renderer/renderer_blink_platform_impl.cc
index 0e9864fdc6feb887fb8e3637c9baea5be4aac70a..6883051523e7214ccd83e1cbe064960f11999a68 100644
--- a/content/renderer/renderer_blink_platform_impl.cc
+++ b/content/renderer/renderer_blink_platform_impl.cc
@@ -1093,12 +1093,6 @@ RendererBlinkPlatformImpl::CreatePlatformEventObserverFromType(
thread = NULL;
switch (type) {
- case blink::WebPlatformEventDeviceMotion:
- return new DeviceMotionEventPump(thread);
- case blink::WebPlatformEventDeviceOrientation:
- return new DeviceOrientationEventPump(thread);
- case blink::WebPlatformEventDeviceLight:
- return new DeviceLightEventPump(thread);
case blink::WebPlatformEventGamepad:
return new GamepadSharedMemoryReader(thread);
case blink::WebPlatformEventScreenOrientation:
@@ -1117,6 +1111,9 @@ void RendererBlinkPlatformImpl::SetPlatformEventObserverForTesting(
blink::WebPlatformEventType type,
scoped_ptr<PlatformEventObserverBase> observer) {
DCHECK(type != blink::WebPlatformEventBattery);
+ DCHECK(type != blink::WebPlatformEventDeviceMotion);
+ DCHECK(type != blink::WebPlatformEventDeviceOrientation);
+ DCHECK(type != blink::WebPlatformEventDeviceLight);
if (platform_event_observers_.Lookup(type))
platform_event_observers_.Remove(type);
@@ -1126,7 +1123,8 @@ void RendererBlinkPlatformImpl::SetPlatformEventObserverForTesting(
void RendererBlinkPlatformImpl::startListening(
blink::WebPlatformEventType type,
blink::WebPlatformEventListener* listener) {
- if (type == blink::WebPlatformEventBattery) {
+ switch (type) {
+ case blink::WebPlatformEventBattery:
if (RenderThreadImpl::current() &&
RenderThreadImpl::current()->layout_test_mode()) {
g_test_battery_status_listener =
@@ -1136,6 +1134,23 @@ void RendererBlinkPlatformImpl::startListening(
static_cast<blink::WebBatteryStatusListener*>(listener)));
}
return;
+ case blink::WebPlatformEventDeviceMotion:
+ device_motion_event_pump_.reset(new DeviceMotionEventPump(
+ static_cast<blink::WebDeviceMotionListener*>(listener)));
+ SendFakeDeviceEventDataForTesting(type);
+ return;
+ case blink::WebPlatformEventDeviceOrientation:
+ device_orientation_event_pump_.reset(new DeviceOrientationEventPump(
+ static_cast<blink::WebDeviceOrientationListener*>(listener)));
+ SendFakeDeviceEventDataForTesting(type);
+ return;
+ case blink::WebPlatformEventDeviceLight:
+ device_light_event_pump_.reset(new DeviceLightEventPump(
+ static_cast<blink::WebDeviceLightListener*>(listener)));
+ SendFakeDeviceEventDataForTesting(type);
+ return;
+ default:
+ break;
}
PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type);
@@ -1146,60 +1161,72 @@ void RendererBlinkPlatformImpl::startListening(
platform_event_observers_.AddWithID(observer, static_cast<int32>(type));
}
observer->Start(listener);
+}
+void RendererBlinkPlatformImpl::SendFakeDeviceEventDataForTesting(
+ blink::WebPlatformEventType type) {
// Device events (motion, orientation and light) expect to get an event fired
// as soon as a listener is registered if a fake data was passed before.
// TODO(mlamouri,timvolodine): make those send mock values directly instead of
// using this broken pattern.
- if (RenderThreadImpl::current() &&
- RenderThreadImpl::current()->layout_test_mode() &&
- (type == blink::WebPlatformEventDeviceMotion ||
- type == blink::WebPlatformEventDeviceOrientation ||
- type == blink::WebPlatformEventDeviceLight)) {
- SendFakeDeviceEventDataForTesting(type);
+ if (!RenderThreadImpl::current() ||
+ !RenderThreadImpl::current()->layout_test_mode()) {
+ return;
}
-}
-
-void RendererBlinkPlatformImpl::SendFakeDeviceEventDataForTesting(
- blink::WebPlatformEventType type) {
- PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type);
- CHECK(observer);
void* data = 0;
+ DeviceSensorEventPump* event_pump = nullptr;
switch (type) {
case blink::WebPlatformEventDeviceMotion:
if (!(g_test_device_motion_data == 0))
data = &g_test_device_motion_data.Get();
+ event_pump =
+ static_cast<DeviceSensorEventPump*>(device_motion_event_pump_.get());
break;
case blink::WebPlatformEventDeviceOrientation:
if (!(g_test_device_orientation_data == 0))
data = &g_test_device_orientation_data.Get();
+ event_pump = static_cast<DeviceSensorEventPump*>(
+ device_orientation_event_pump_.get());
break;
case blink::WebPlatformEventDeviceLight:
if (g_test_device_light_data >= 0)
data = &g_test_device_light_data;
+ event_pump =
+ static_cast<DeviceSensorEventPump*>(device_light_event_pump_.get());
break;
default:
NOTREACHED();
break;
}
- if (!data)
+ if (!data || !event_pump)
return;
base::MessageLoopProxy::current()->PostTask(
- FROM_HERE,
- base::Bind(&PlatformEventObserverBase::SendFakeDataForTesting,
- base::Unretained(observer), data));
+ FROM_HERE, base::Bind(&DeviceSensorEventPump::SendFakeDataForTesting,
+ base::Unretained(event_pump), data));
}
void RendererBlinkPlatformImpl::stopListening(
blink::WebPlatformEventType type) {
- if (type == blink::WebPlatformEventBattery) {
- g_test_battery_status_listener = nullptr;
- battery_status_dispatcher_.reset();
- return;
+ switch (type) {
+ case blink::WebPlatformEventBattery:
+ g_test_battery_status_listener = nullptr;
+ battery_status_dispatcher_.reset();
+ return;
+ case blink::WebPlatformEventDeviceMotion:
+ device_motion_event_pump_.reset();
+ return;
+ case blink::WebPlatformEventDeviceOrientation:
+ device_orientation_event_pump_.reset();
+ return;
+ case blink::WebPlatformEventDeviceLight:
+ device_light_event_pump_.reset();
+ return;
+ default:
+ break;
}
PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type);
« no previous file with comments | « content/renderer/device_sensors/device_sensor_event_pump.cc ('k') | content/renderer/shared_memory_seqlock_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698