| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "content/renderer/battery_status/battery_status_dispatcher.h" | |
| 6 | |
| 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" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 BatteryStatusDispatcher::BatteryStatusDispatcher( | |
| 14 blink::WebBatteryStatusListener* listener) | |
| 15 : listener_(listener) { | |
| 16 DCHECK(listener_); | |
| 17 | |
| 18 if (ServiceRegistry* registry = RenderThread::Get()->GetServiceRegistry()) { | |
| 19 // registry can be null during testing. | |
| 20 registry->ConnectToRemoteService(mojo::GetProxy(&monitor_)); | |
| 21 QueryNextStatus(); | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 BatteryStatusDispatcher::~BatteryStatusDispatcher() { | |
| 26 } | |
| 27 | |
| 28 void BatteryStatusDispatcher::QueryNextStatus() { | |
| 29 monitor_->QueryNextStatus( | |
| 30 base::Bind(&BatteryStatusDispatcher::DidChange, base::Unretained(this))); | |
| 31 } | |
| 32 | |
| 33 void BatteryStatusDispatcher::DidChange( | |
| 34 device::BatteryStatusPtr battery_status) { | |
| 35 // monitor_ can be null during testing. | |
| 36 if (monitor_) | |
| 37 QueryNextStatus(); | |
| 38 | |
| 39 DCHECK(battery_status); | |
| 40 | |
| 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); | |
| 47 } | |
| 48 | |
| 49 } // namespace content | |
| OLD | NEW |