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

Side by Side Diff: third_party/WebKit/Source/platform/battery/battery_status_dispatcher.cc

Issue 1538803002: Migrates battery_status from content/renderer/ to WebKit/platform/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ready for code review Created 4 years, 10 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 "platform/battery/battery_status_dispatcher.h"
6 6
7 #include "content/public/common/service_registry.h" 7 #include "platform/base/Bind.h"
8 #include "content/public/renderer/render_thread.h" 8 #include "platform/battery/battery_status.h"
9 #include "third_party/WebKit/public/platform/WebBatteryStatusListener.h" 9 #include "platform/battery/battery_status_listener.h"
10 #include "public/platform/Platform.h"
11 #include "wtf/Assertions.h"
10 12
11 namespace content { 13 namespace blink {
12 14
13 BatteryStatusDispatcher::BatteryStatusDispatcher( 15 BatteryStatusDispatcher::BatteryStatusDispatcher(BatteryStatusListener* listener )
haraken 2016/02/09 12:01:21 Honestly speaking, I want to let modules/ directly
Yuki 2016/02/12 12:36:14 OK
haraken 2016/02/12 12:48:45 Ah, got it. Then how about passing a function poin
14 blink::WebBatteryStatusListener* listener) 16 : listener_(listener)
15 : listener_(listener) { 17 {
16 DCHECK(listener_); 18 ASSERT(listener_);
17 19
18 if (ServiceRegistry* registry = RenderThread::Get()->GetServiceRegistry()) { 20 Platform::current()->connectToRemoteService(mojo::GetProxy(&monitor_));
19 // registry can be null during testing. 21 // monitor_ can be null during testing.
20 registry->ConnectToRemoteService(mojo::GetProxy(&monitor_)); 22 if (monitor_)
21 QueryNextStatus(); 23 QueryNextStatus();
22 }
23 } 24 }
24 25
25 BatteryStatusDispatcher::~BatteryStatusDispatcher() { 26 BatteryStatusDispatcher::~BatteryStatusDispatcher() {}
27
28 void BatteryStatusDispatcher::QueryNextStatus()
29 {
30 monitor_->QueryNextStatus(
31 bindInstanceToMethodForMojo(&BatteryStatusDispatcher::OnDidChange, this));
26 } 32 }
27 33
28 void BatteryStatusDispatcher::QueryNextStatus() { 34 void BatteryStatusDispatcher::OnDidChange(device::BatteryStatusPtr battery_statu s)
29 monitor_->QueryNextStatus( 35 {
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 // monitor_ can be null during testing.
36 if (monitor_) 37 if (monitor_)
37 QueryNextStatus(); 38 QueryNextStatus();
38 39
39 DCHECK(battery_status); 40 DCHECK(battery_status);
40 41
41 blink::WebBatteryStatus web_battery_status; 42 BatteryStatus status(battery_status->charging,
42 web_battery_status.charging = battery_status->charging; 43 battery_status->charging_time,
43 web_battery_status.chargingTime = battery_status->charging_time; 44 battery_status->discharging_time,
44 web_battery_status.dischargingTime = battery_status->discharging_time; 45 battery_status->level);
45 web_battery_status.level = battery_status->level; 46 listener_->OnUpdateBatteryStatus(status);
46 listener_->updateBatteryStatus(web_battery_status);
47 } 47 }
48 48
49 } // namespace content 49 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698