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

Unified Diff: content/renderer/device_sensors/device_light_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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/device_sensors/device_light_event_pump.cc
diff --git a/content/renderer/device_sensors/device_light_event_pump.cc b/content/renderer/device_sensors/device_light_event_pump.cc
index 31b0970d60bfbfe410f41e4df4cd2c9a6d89382c..a20919d968d9f3637afe8fb3e1435255d98890ce 100644
--- a/content/renderer/device_sensors/device_light_event_pump.cc
+++ b/content/renderer/device_sensors/device_light_event_pump.cc
@@ -15,44 +15,32 @@ const int kDefaultLightPumpDelayMillis = 200;
namespace content {
-DeviceLightEventPump::DeviceLightEventPump()
- : DeviceSensorEventPump(kDefaultLightPumpDelayMillis),
- listener_(NULL),
- last_seen_data_(-1) {
-}
-
-DeviceLightEventPump::DeviceLightEventPump(int pump_delay_millis)
- : DeviceSensorEventPump(pump_delay_millis),
- listener_(NULL),
+DeviceLightEventPump::DeviceLightEventPump(RenderThread* thread)
+ : DeviceSensorEventPump<blink::WebDeviceLightListener>(thread),
last_seen_data_(-1) {
+ pump_delay_millis_ = kDefaultLightPumpDelayMillis;
}
DeviceLightEventPump::~DeviceLightEventPump() {
}
-bool DeviceLightEventPump::SetListener(
- blink::WebDeviceLightListener* listener) {
- listener_ = listener;
- return listener_ ? RequestStart() : Stop();
-}
-
bool DeviceLightEventPump::OnControlMessageReceived(
const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(DeviceLightEventPump, message)
- IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling, OnDidStart)
- IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling, OnDidStart)
+ IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void DeviceLightEventPump::FireEvent() {
- DCHECK(listener_);
+ DCHECK(listener());
DeviceLightData data;
bool did_return_light_data = reader_->GetLatestData(&data);
if (did_return_light_data && data.value != last_seen_data_) {
last_seen_data_ = data.value;
- listener_->didChangeDeviceLight(data.value);
+ listener()->didChangeDeviceLight(data.value);
}
}
@@ -62,13 +50,19 @@ bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) {
return reader_->Initialize(handle);
}
-bool DeviceLightEventPump::SendStartMessage() {
- return RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling());
+void DeviceLightEventPump::SendStartMessage() {
+ RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling());
}
-bool DeviceLightEventPump::SendStopMessage() {
+void DeviceLightEventPump::SendStopMessage() {
last_seen_data_ = -1;
- return RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling());
+ RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling());
+}
+
+void DeviceLightEventPump::SendFakeDataForTesting(void* fake_data) {
+ double data = *static_cast<double*>(fake_data);
+
+ listener()->didChangeDeviceLight(data);
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698