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 "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 | |
OLD | NEW |