Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / device_sensors / device_light_event_pump.cc
bloba20919d968d9f3637afe8fb3e1435255d98890ce
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
3 // found in the LICENSE file.
5 #include "content/renderer/device_sensors/device_light_event_pump.h"
7 #include "content/common/device_sensors/device_light_messages.h"
8 #include "content/public/renderer/render_thread.h"
9 #include "third_party/WebKit/public/platform/WebDeviceLightListener.h"
11 namespace {
12 // Default delay between subsequent firing of DeviceLight events.
13 const int kDefaultLightPumpDelayMillis = 200;
14 } // namespace
16 namespace content {
18 DeviceLightEventPump::DeviceLightEventPump(RenderThread* thread)
19 : DeviceSensorEventPump<blink::WebDeviceLightListener>(thread),
20 last_seen_data_(-1) {
21 pump_delay_millis_ = kDefaultLightPumpDelayMillis;
24 DeviceLightEventPump::~DeviceLightEventPump() {
27 bool DeviceLightEventPump::OnControlMessageReceived(
28 const IPC::Message& message) {
29 bool handled = true;
30 IPC_BEGIN_MESSAGE_MAP(DeviceLightEventPump, message)
31 IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling, OnDidStart)
32 IPC_MESSAGE_UNHANDLED(handled = false)
33 IPC_END_MESSAGE_MAP()
34 return handled;
37 void DeviceLightEventPump::FireEvent() {
38 DCHECK(listener());
39 DeviceLightData data;
40 bool did_return_light_data = reader_->GetLatestData(&data);
41 if (did_return_light_data && data.value != last_seen_data_) {
42 last_seen_data_ = data.value;
43 listener()->didChangeDeviceLight(data.value);
47 bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) {
48 if (!reader_)
49 reader_.reset(new DeviceLightSharedMemoryReader());
50 return reader_->Initialize(handle);
53 void DeviceLightEventPump::SendStartMessage() {
54 RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling());
57 void DeviceLightEventPump::SendStopMessage() {
58 last_seen_data_ = -1;
59 RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling());
62 void DeviceLightEventPump::SendFakeDataForTesting(void* fake_data) {
63 double data = *static_cast<double*>(fake_data);
65 listener()->didChangeDeviceLight(data);
68 } // namespace content