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

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

Issue 252113006: Add Battery Status API support in content/renderer and IPC messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed Jochen's comments Created 6 years, 7 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
(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 "battery_status_dispatcher.h"
6
7 #include "base/logging.h"
8 #include "content/common/battery_status_messages.h"
9 #include "content/renderer/render_thread_impl.h"
10 #include "third_party/WebKit/public/platform/WebBatteryStatusListener.h"
11
12 namespace content {
13
14 BatteryStatusDispatcher::BatteryStatusDispatcher(RenderThread* thread)
15 : listener_(0) {
16 if (thread)
17 thread->AddObserver(this);
18 }
19
20 BatteryStatusDispatcher::~BatteryStatusDispatcher() { }
jochen (gone - plz use gerrit) 2014/05/02 14:08:53 should this invoke Stop() if listener_ is non-NULL
timvolodine 2014/05/02 15:03:55 Done.
21
22 bool BatteryStatusDispatcher::SetListener(
23 blink::WebBatteryStatusListener* listener) {
24 listener_ = listener;
25 return listener ? Start() : Stop();
26 }
27
28 bool BatteryStatusDispatcher::OnControlMessageReceived(
29 const IPC::Message& message) {
30 bool handled = true;
31 IPC_BEGIN_MESSAGE_MAP(BatteryStatusDispatcher, message)
32 IPC_MESSAGE_HANDLER(BatteryStatusMsg_DidChange, OnDidChange)
33 IPC_MESSAGE_UNHANDLED(handled = false)
34 IPC_END_MESSAGE_MAP()
35 return handled;
36 }
37
38 bool BatteryStatusDispatcher::Start() {
39 return RenderThread::Get()->Send(new BatteryStatusHostMsg_Start());
40 }
41
42 bool BatteryStatusDispatcher::Stop() {
43 return RenderThread::Get()->Send(new BatteryStatusHostMsg_Stop());
44 }
45
46 void BatteryStatusDispatcher::OnDidChange(
47 const blink::WebBatteryStatus& status) {
48 if (listener_)
49 listener_->updateBatteryStatus(status);
50 }
51
52 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698