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/battery_status/battery_status_dispatcher.h"
7 #include "content/public/common/service_registry.h"
8 #include "content/public/renderer/render_thread.h"
9 #include "third_party/WebKit/public/platform/WebBatteryStatusListener.h"
13 BatteryStatusDispatcher::BatteryStatusDispatcher(
14 blink::WebBatteryStatusListener
* listener
)
15 : listener_(listener
) {
18 if (ServiceRegistry
* registry
= RenderThread::Get()->GetServiceRegistry()) {
19 // registry can be null during testing.
20 registry
->ConnectToRemoteService(mojo::GetProxy(&monitor_
));
25 BatteryStatusDispatcher::~BatteryStatusDispatcher() {
28 void BatteryStatusDispatcher::QueryNextStatus() {
29 monitor_
->QueryNextStatus(
30 base::Bind(&BatteryStatusDispatcher::DidChange
, base::Unretained(this)));
33 void BatteryStatusDispatcher::DidChange(
34 device::BatteryStatusPtr battery_status
) {
35 // monitor_ can be null during testing.
39 DCHECK(battery_status
);
41 blink::WebBatteryStatus web_battery_status
;
42 web_battery_status
.charging
= battery_status
->charging
;
43 web_battery_status
.chargingTime
= battery_status
->charging_time
;
44 web_battery_status
.dischargingTime
= battery_status
->discharging_time
;
45 web_battery_status
.level
= battery_status
->level
;
46 listener_
->updateBatteryStatus(web_battery_status
);
49 } // namespace content