Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: content/renderer/battery_status/battery_status_dispatcher.cc

Issue 833983002: Stop using [Client=...] feature of Mojom for BatteryMonitor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixup per review feedback Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/battery_status/battery_status_dispatcher.h" 5 #include "content/renderer/battery_status/battery_status_dispatcher.h"
6 6
7 #include "content/public/common/service_registry.h" 7 #include "content/public/common/service_registry.h"
8 #include "content/public/renderer/render_thread.h" 8 #include "content/public/renderer/render_thread.h"
9 #include "third_party/WebKit/public/platform/WebBatteryStatusListener.h" 9 #include "third_party/WebKit/public/platform/WebBatteryStatusListener.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 BatteryStatusDispatcher::BatteryStatusDispatcher( 13 BatteryStatusDispatcher::BatteryStatusDispatcher(
14 blink::WebBatteryStatusListener* listener) 14 blink::WebBatteryStatusListener* listener)
15 : listener_(listener) { 15 : listener_(listener) {
16 DCHECK(listener_); 16 DCHECK(listener_);
17 17
18 if (ServiceRegistry* registry = RenderThread::Get()->GetServiceRegistry()) { 18 if (ServiceRegistry* registry = RenderThread::Get()->GetServiceRegistry()) {
19 // registry can be null during testing. 19 // registry can be null during testing.
20 registry->ConnectToRemoteService(&monitor_); 20 registry->ConnectToRemoteService(&monitor_);
21 monitor_.set_client(this); 21 QueryNextStatus();
22 } 22 }
23 } 23 }
24 24
25 BatteryStatusDispatcher::~BatteryStatusDispatcher() { 25 BatteryStatusDispatcher::~BatteryStatusDispatcher() {
26 } 26 }
27 27
28 void BatteryStatusDispatcher::QueryNextStatus() {
29 monitor_->QueryNextStatus(
30 base::Bind(&BatteryStatusDispatcher::DidChange, base::Unretained(this)));
31 }
32
28 void BatteryStatusDispatcher::DidChange( 33 void BatteryStatusDispatcher::DidChange(
29 device::BatteryStatusPtr battery_status) { 34 device::BatteryStatusPtr battery_status) {
35 // monitor_ can be null during testing.
36 if (monitor_)
37 QueryNextStatus();
38
30 DCHECK(battery_status); 39 DCHECK(battery_status);
40
31 blink::WebBatteryStatus web_battery_status; 41 blink::WebBatteryStatus web_battery_status;
32 web_battery_status.charging = battery_status->charging; 42 web_battery_status.charging = battery_status->charging;
33 web_battery_status.chargingTime = battery_status->charging_time; 43 web_battery_status.chargingTime = battery_status->charging_time;
34 web_battery_status.dischargingTime = battery_status->discharging_time; 44 web_battery_status.dischargingTime = battery_status->discharging_time;
35 web_battery_status.level = battery_status->level; 45 web_battery_status.level = battery_status->level;
36 listener_->updateBatteryStatus(web_battery_status); 46 listener_->updateBatteryStatus(web_battery_status);
37 } 47 }
38 48
39 } // namespace content 49 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698