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

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

Issue 685703002: Reland "Replace Chrome IPC with Mojo IPC for querying BatteryStatus service" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Tim's comments. Created 6 years, 1 month 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 "battery_status_dispatcher.h" 5 #include "content/renderer/battery_status/battery_status_dispatcher.h"
6 6
7 #include "content/common/battery_status_messages.h" 7 #include "content/public/common/service_registry.h"
8 #include "content/renderer/render_thread_impl.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(RenderThread* thread) 13 BatteryStatusDispatcher::BatteryStatusDispatcher(
14 : PlatformEventObserver<blink::WebBatteryStatusListener>(thread) { 14 blink::WebBatteryStatusListener* listener)
15 : listener_(listener) {
16 DCHECK(listener_);
17
18 RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService(&monitor_);
19 monitor_.set_client(this);
15 } 20 }
16 21
17 BatteryStatusDispatcher::~BatteryStatusDispatcher() { 22 BatteryStatusDispatcher::~BatteryStatusDispatcher() {
18 StopIfObserving();
19 } 23 }
20 24
21 bool BatteryStatusDispatcher::OnControlMessageReceived( 25 void BatteryStatusDispatcher::DidChange(
22 const IPC::Message& message) { 26 device::BatteryStatusPtr battery_status) {
23 bool handled = true; 27 DCHECK(battery_status);
24 IPC_BEGIN_MESSAGE_MAP(BatteryStatusDispatcher, message) 28 blink::WebBatteryStatus web_battery_status;
25 IPC_MESSAGE_HANDLER(BatteryStatusMsg_DidChange, OnDidChange) 29 web_battery_status.charging = battery_status->charging;
26 IPC_MESSAGE_UNHANDLED(handled = false) 30 web_battery_status.chargingTime = battery_status->charging_time;
27 IPC_END_MESSAGE_MAP() 31 web_battery_status.dischargingTime = battery_status->discharging_time;
28 return handled; 32 web_battery_status.level = battery_status->level;
29 } 33 listener_->updateBatteryStatus(web_battery_status);
30
31 void BatteryStatusDispatcher::SendStartMessage() {
32 RenderThread::Get()->Send(new BatteryStatusHostMsg_Start());
33 }
34
35 void BatteryStatusDispatcher::SendStopMessage() {
36 RenderThread::Get()->Send(new BatteryStatusHostMsg_Stop());
37 }
38
39 void BatteryStatusDispatcher::OnDidChange(
40 const blink::WebBatteryStatus& status) {
41 if (listener())
42 listener()->updateBatteryStatus(status);
43 }
44
45 void BatteryStatusDispatcher::SendFakeDataForTesting(void* fake_data) {
46 OnDidChange(*static_cast<blink::WebBatteryStatus*>(fake_data));
47 } 34 }
48 35
49 } // namespace content 36 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/battery_status/battery_status_dispatcher.h ('k') | content/renderer/renderer_blink_platform_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698