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/public/renderer/render_thread.h" |
| 9 #include "content/common/battery_status_messages.h" |
| 10 #include "third_party/WebKit/public/platform/WebBatteryListener.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 BatteryStatusDispatcher::BatteryStatusDispatcher() : listener_(0) { } |
| 15 |
| 16 BatteryStatusDispatcher::~BatteryStatusDispatcher() { } |
| 17 |
| 18 bool BatteryStatusDispatcher::SetListener(blink::WebBatteryListener* listener) { |
| 19 listener_ = listener; |
| 20 return listener ? Start() : Stop(); |
| 21 } |
| 22 |
| 23 void BatteryStatusDispatcher::Attach(RenderThread* thread) { |
| 24 if (!thread) |
| 25 return; |
| 26 thread->AddObserver(this); |
| 27 } |
| 28 |
| 29 bool BatteryStatusDispatcher::OnControlMessageReceived( |
| 30 const IPC::Message& message) { |
| 31 bool handled = true; |
| 32 IPC_BEGIN_MESSAGE_MAP(BatteryStatusDispatcher, message) |
| 33 IPC_MESSAGE_HANDLER(BatteryStatusMsg_DidChange, OnDidChange) |
| 34 IPC_MESSAGE_UNHANDLED(handled = false) |
| 35 IPC_END_MESSAGE_MAP() |
| 36 return handled; |
| 37 } |
| 38 |
| 39 bool BatteryStatusDispatcher::Start() { |
| 40 LOG(INFO)<<"BLA: BatteryStatusDispatcher::Start"; |
| 41 return RenderThread::Get()->Send(new BatteryStatusHostMsg_Start()); |
| 42 |
| 43 } |
| 44 |
| 45 bool BatteryStatusDispatcher::Stop() { |
| 46 LOG(INFO)<<"BLA: BatteryStatusDispatcher::Stop"; |
| 47 return RenderThread::Get()->Send(new BatteryStatusHostMsg_Stop()); |
| 48 } |
| 49 |
| 50 void BatteryStatusDispatcher::OnDidChange(const blink::WebBatteryStatus& status)
{ |
| 51 LOG(INFO) << "BLA: BatteryStatusDispatcher::OnDidChange level="<<status.level; |
| 52 if (listener_) |
| 53 listener_->updateBatteryStatus(status); |
| 54 } |
| 55 |
| 56 } // namespace content |
OLD | NEW |