Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / battery_status / battery_status_dispatcher.cc
blob3e27c129439a54b8bfd651cb029ba8aaf641b263
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 "battery_status_dispatcher.h"
7 #include "content/common/battery_status_messages.h"
8 #include "content/renderer/render_thread_impl.h"
9 #include "third_party/WebKit/public/platform/WebBatteryStatusListener.h"
11 namespace content {
13 BatteryStatusDispatcher::BatteryStatusDispatcher(RenderThread* thread)
14 : PlatformEventObserver<blink::WebBatteryStatusListener>(thread) {
17 BatteryStatusDispatcher::~BatteryStatusDispatcher() {
20 bool BatteryStatusDispatcher::OnControlMessageReceived(
21 const IPC::Message& message) {
22 bool handled = true;
23 IPC_BEGIN_MESSAGE_MAP(BatteryStatusDispatcher, message)
24 IPC_MESSAGE_HANDLER(BatteryStatusMsg_DidChange, OnDidChange)
25 IPC_MESSAGE_UNHANDLED(handled = false)
26 IPC_END_MESSAGE_MAP()
27 return handled;
30 void BatteryStatusDispatcher::SendStartMessage() {
31 RenderThread::Get()->Send(new BatteryStatusHostMsg_Start());
34 void BatteryStatusDispatcher::SendStopMessage() {
35 RenderThread::Get()->Send(new BatteryStatusHostMsg_Stop());
38 void BatteryStatusDispatcher::OnDidChange(
39 const blink::WebBatteryStatus& status) {
40 if (listener())
41 listener()->updateBatteryStatus(status);
44 void BatteryStatusDispatcher::SendFakeDataForTesting(void* fake_data) {
45 OnDidChange(*static_cast<blink::WebBatteryStatus*>(fake_data));
48 } // namespace content