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

Unified Diff: content/renderer/renderer_webkitplatformsupport_impl.cc

Issue 421293010: Update RendererWebPlatformSupportImpl to use {start,stop}Listening(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/renderer_webkitplatformsupport_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/renderer_webkitplatformsupport_impl.cc
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc
index 3c9197ad638f50af92a85dbb0109b21a81d60483..2ba96b743acf2ba39b1d61794c8849d551158e9f 100644
--- a/content/renderer/renderer_webkitplatformsupport_impl.cc
+++ b/content/renderer/renderer_webkitplatformsupport_impl.cc
@@ -888,12 +888,6 @@ void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) {
gamepad_provider_->SampleGamepads(gamepads);
}
-void RendererWebKitPlatformSupportImpl::setGamepadListener(
- blink::WebGamepadListener* listener) {
- DCHECK(gamepad_provider_);
- gamepad_provider_->SetGamepadListener(listener);
-}
-
//------------------------------------------------------------------------------
WebRTCPeerConnectionHandler*
@@ -1021,24 +1015,6 @@ blink::WebString RendererWebKitPlatformSupportImpl::convertIDNToUnicode(
//------------------------------------------------------------------------------
-void RendererWebKitPlatformSupportImpl::setDeviceLightListener(
- blink::WebDeviceLightListener* listener) {
- if (g_test_device_light_data < 0) {
- if (!device_light_event_pump_) {
- device_light_event_pump_.reset(new DeviceLightEventPump);
- device_light_event_pump_->Attach(RenderThreadImpl::current());
- }
- device_light_event_pump_->SetListener(listener);
- } else if (listener) {
- // Testing mode: just echo the test data to the listener.
- base::MessageLoopProxy::current()->PostTask(
- FROM_HERE,
- base::Bind(&blink::WebDeviceLightListener::didChangeDeviceLight,
- base::Unretained(listener),
- g_test_device_light_data));
- }
-}
-
// static
void RendererWebKitPlatformSupportImpl::SetMockDeviceLightDataForTesting(
double data) {
@@ -1047,7 +1023,92 @@ void RendererWebKitPlatformSupportImpl::SetMockDeviceLightDataForTesting(
//------------------------------------------------------------------------------
-void RendererWebKitPlatformSupportImpl::setDeviceMotionListener(
+// static
+void RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting(
+ const blink::WebDeviceMotionData& data) {
+ g_test_device_motion_data.Get() = data;
+}
+
+//------------------------------------------------------------------------------
+
+// static
+void RendererWebKitPlatformSupportImpl::SetMockDeviceOrientationDataForTesting(
+ const blink::WebDeviceOrientationData& data) {
+ g_test_device_orientation_data.Get() = data;
+}
+
+//------------------------------------------------------------------------------
+
+void RendererWebKitPlatformSupportImpl::vibrate(unsigned int milliseconds) {
+ RenderThread::Get()->Send(
+ new ViewHostMsg_Vibrate(base::checked_cast<int64>(milliseconds)));
+}
+
+void RendererWebKitPlatformSupportImpl::cancelVibration() {
+ RenderThread::Get()->Send(new ViewHostMsg_CancelVibration());
+}
+
+//------------------------------------------------------------------------------
+
+void RendererWebKitPlatformSupportImpl::startListening(
+ blink::WebPlatformEventType type,
+ blink::WebPlatformEventListener* listener) {
+ switch (type) {
+ case blink::WebPlatformEventDeviceMotion:
+ SetDeviceMotionListener(
+ static_cast<blink::WebDeviceMotionListener*>(listener));
+ break;
+ case blink::WebPlatformEventDeviceOrientation:
+ SetDeviceOrientationListener(
+ static_cast<blink::WebDeviceOrientationListener*>(listener));
+ break;
+ case blink::WebPlatformEventDeviceLight:
+ SetDeviceLightListener(
+ static_cast<blink::WebDeviceLightListener*>(listener));
+ break;
+ case blink::WebPlatformEventBattery:
+ SetBatteryStatusListener(
+ static_cast<blink::WebBatteryStatusListener*>(listener));
+ break;
+ case blink::WebPlatformEventGamepad:
+ SetGamepadListener(
+ static_cast<blink::WebGamepadListener*>(listener));
+ break;
+ default:
+ // A default statement is required to prevent compilation errors when Blink
+ // adds a new type.
+ LOG(ERROR) << "RendererWebKitPlatformSupportImpl::startListening() with "
+ "unknown type.";
+ }
+}
+
+void RendererWebKitPlatformSupportImpl::stopListening(
+ blink::WebPlatformEventType type) {
+ switch (type) {
+ case blink::WebPlatformEventDeviceMotion:
+ SetDeviceMotionListener(0);
+ break;
+ case blink::WebPlatformEventDeviceOrientation:
+ SetDeviceOrientationListener(0);
+ break;
+ case blink::WebPlatformEventDeviceLight:
+ SetDeviceLightListener(0);
+ break;
+ case blink::WebPlatformEventBattery:
+ SetBatteryStatusListener(0);
+ break;
+ case blink::WebPlatformEventGamepad:
+ SetGamepadListener(0);
+ break;
+ default:
+ // A default statement is required to prevent compilation errors when Blink
+ // adds a new type.
+ LOG(ERROR) << "RendererWebKitPlatformSupportImpl::stopListening() with "
jochen (gone - plz use gerrit) 2014/08/04 12:44:20 VLOG(1) ?
mlamouri (slow - plz ping) 2014/08/04 14:28:44 Done. For startListening() too.
+ "unknown type.";
+ }
+}
+
+void RendererWebKitPlatformSupportImpl::SetDeviceMotionListener(
blink::WebDeviceMotionListener* listener) {
if (g_test_device_motion_data == 0) {
if (!device_motion_event_pump_) {
@@ -1065,15 +1126,7 @@ void RendererWebKitPlatformSupportImpl::setDeviceMotionListener(
}
}
-// static
-void RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting(
- const blink::WebDeviceMotionData& data) {
- g_test_device_motion_data.Get() = data;
-}
-
-//------------------------------------------------------------------------------
-
-void RendererWebKitPlatformSupportImpl::setDeviceOrientationListener(
+void RendererWebKitPlatformSupportImpl::SetDeviceOrientationListener(
blink::WebDeviceOrientationListener* listener) {
if (g_test_device_orientation_data == 0) {
if (!device_orientation_event_pump_) {
@@ -1092,21 +1145,46 @@ void RendererWebKitPlatformSupportImpl::setDeviceOrientationListener(
}
}
-// static
-void RendererWebKitPlatformSupportImpl::SetMockDeviceOrientationDataForTesting(
- const blink::WebDeviceOrientationData& data) {
- g_test_device_orientation_data.Get() = data;
+void RendererWebKitPlatformSupportImpl::SetDeviceLightListener(
+ blink::WebDeviceLightListener* listener) {
+ if (g_test_device_light_data < 0) {
+ if (!device_light_event_pump_) {
+ device_light_event_pump_.reset(new DeviceLightEventPump);
+ device_light_event_pump_->Attach(RenderThreadImpl::current());
+ }
+ device_light_event_pump_->SetListener(listener);
+ } else if (listener) {
+ // Testing mode: just echo the test data to the listener.
+ base::MessageLoopProxy::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&blink::WebDeviceLightListener::didChangeDeviceLight,
+ base::Unretained(listener),
+ g_test_device_light_data));
+ }
}
-//------------------------------------------------------------------------------
-
-void RendererWebKitPlatformSupportImpl::vibrate(unsigned int milliseconds) {
- RenderThread::Get()->Send(
- new ViewHostMsg_Vibrate(base::checked_cast<int64>(milliseconds)));
+void RendererWebKitPlatformSupportImpl::SetGamepadListener(
+ blink::WebGamepadListener* listener) {
+ DCHECK(gamepad_provider_);
+ gamepad_provider_->SetGamepadListener(listener);
}
-void RendererWebKitPlatformSupportImpl::cancelVibration() {
- RenderThread::Get()->Send(new ViewHostMsg_CancelVibration());
+void RendererWebKitPlatformSupportImpl::SetBatteryStatusListener(
+ blink::WebBatteryStatusListener* listener) {
+ if (RenderThreadImpl::current() &&
+ RenderThreadImpl::current()->layout_test_mode()) {
+ // If we are in test mode, we want to use a fake battery status dispatcher,
+ // which does not communicate with the browser process. Battery status
+ // changes are signalled by invoking MockBatteryStatusChangedForTesting().
+ g_test_battery_status_dispatcher.Get().SetListener(listener);
+ return;
+ }
+
+ if (!battery_status_dispatcher_) {
+ battery_status_dispatcher_.reset(
+ new BatteryStatusDispatcher(RenderThreadImpl::current()));
+ }
+ battery_status_dispatcher_->SetListener(listener);
}
//------------------------------------------------------------------------------
@@ -1127,24 +1205,6 @@ void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota(
//------------------------------------------------------------------------------
-void RendererWebKitPlatformSupportImpl::setBatteryStatusListener(
- blink::WebBatteryStatusListener* listener) {
- if (RenderThreadImpl::current() &&
- RenderThreadImpl::current()->layout_test_mode()) {
- // If we are in test mode, we want to use a fake battery status dispatcher,
- // which does not communicate with the browser process. Battery status
- // changes are signalled by invoking MockBatteryStatusChangedForTesting().
- g_test_battery_status_dispatcher.Get().SetListener(listener);
- return;
- }
-
- if (!battery_status_dispatcher_) {
- battery_status_dispatcher_.reset(
- new BatteryStatusDispatcher(RenderThreadImpl::current()));
- }
- battery_status_dispatcher_->SetListener(listener);
-}
-
// static
void RendererWebKitPlatformSupportImpl::MockBatteryStatusChangedForTesting(
const blink::WebBatteryStatus& status) {
« no previous file with comments | « content/renderer/renderer_webkitplatformsupport_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698