| OLD | NEW |
| 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 "content/renderer/device_sensors/device_light_event_pump.h" | 5 #include "content/renderer/device_sensors/device_light_event_pump.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/time/time.h" |
| 7 #include "content/common/device_sensors/device_light_messages.h" | 9 #include "content/common/device_sensors/device_light_messages.h" |
| 8 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
| 9 #include "third_party/WebKit/public/platform/WebDeviceLightListener.h" | 11 #include "third_party/WebKit/public/platform/WebDeviceLightListener.h" |
| 10 | 12 |
| 11 namespace { | 13 namespace { |
| 12 // Default delay between subsequent firing of DeviceLight events. | 14 // Default rate for firing of DeviceLight events. |
| 13 const int kDefaultLightPumpDelayMillis = 200; | 15 const int kDefaultLightPumpFrequencyHz = 5; |
| 16 const int kDefaultLightPumpDelayMicroseconds = |
| 17 base::Time::kMicrosecondsPerSecond / kDefaultLightPumpFrequencyHz; |
| 14 } // namespace | 18 } // namespace |
| 15 | 19 |
| 16 namespace content { | 20 namespace content { |
| 17 | 21 |
| 18 DeviceLightEventPump::DeviceLightEventPump(RenderThread* thread) | 22 DeviceLightEventPump::DeviceLightEventPump(RenderThread* thread) |
| 19 : DeviceSensorEventPump<blink::WebDeviceLightListener>(thread), | 23 : DeviceSensorEventPump<blink::WebDeviceLightListener>(thread), |
| 20 last_seen_data_(-1) { | 24 last_seen_data_(-1) { |
| 21 pump_delay_millis_ = kDefaultLightPumpDelayMillis; | 25 pump_delay_microseconds_ = kDefaultLightPumpDelayMicroseconds; |
| 22 } | 26 } |
| 23 | 27 |
| 24 DeviceLightEventPump::~DeviceLightEventPump() { | 28 DeviceLightEventPump::~DeviceLightEventPump() { |
| 25 } | 29 } |
| 26 | 30 |
| 27 bool DeviceLightEventPump::OnControlMessageReceived( | 31 bool DeviceLightEventPump::OnControlMessageReceived( |
| 28 const IPC::Message& message) { | 32 const IPC::Message& message) { |
| 29 bool handled = true; | 33 bool handled = true; |
| 30 IPC_BEGIN_MESSAGE_MAP(DeviceLightEventPump, message) | 34 IPC_BEGIN_MESSAGE_MAP(DeviceLightEventPump, message) |
| 31 IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling, OnDidStart) | 35 IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling, OnDidStart) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling()); | 74 RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling()); |
| 71 } | 75 } |
| 72 | 76 |
| 73 void DeviceLightEventPump::SendFakeDataForTesting(void* fake_data) { | 77 void DeviceLightEventPump::SendFakeDataForTesting(void* fake_data) { |
| 74 double data = *static_cast<double*>(fake_data); | 78 double data = *static_cast<double*>(fake_data); |
| 75 | 79 |
| 76 listener()->didChangeDeviceLight(data); | 80 listener()->didChangeDeviceLight(data); |
| 77 } | 81 } |
| 78 | 82 |
| 79 } // namespace content | 83 } // namespace content |
| OLD | NEW |