Chromium Code Reviews| Index: content/renderer/battery_status/battery_status_dispatcher.cc |
| diff --git a/content/renderer/battery_status/battery_status_dispatcher.cc b/content/renderer/battery_status/battery_status_dispatcher.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1aec04f61f09994dc75aa3d29aabbc1dc17bd6f5 |
| --- /dev/null |
| +++ b/content/renderer/battery_status/battery_status_dispatcher.cc |
| @@ -0,0 +1,55 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "battery_status_dispatcher.h" |
| + |
| +#include "base/logging.h" |
| +#include "content/common/battery_status_messages.h" |
| +#include "content/public/renderer/render_thread.h" |
|
jochen (gone - plz use gerrit)
2014/04/30 04:54:07
please use the content/renderer version inside con
timvolodine
2014/05/01 10:32:39
Done, if you mean "content/renderer/render_thread_
|
| +#include "third_party/WebKit/public/platform/WebBatteryStatusListener.h" |
| + |
| +namespace content { |
| + |
| +BatteryStatusDispatcher::BatteryStatusDispatcher() : listener_(0) { } |
| + |
| +BatteryStatusDispatcher::~BatteryStatusDispatcher() { } |
| + |
| +bool BatteryStatusDispatcher::SetListener( |
| + blink::WebBatteryStatusListener* listener) { |
| + listener_ = listener; |
| + return listener ? Start() : Stop(); |
| +} |
| + |
| +void BatteryStatusDispatcher::Attach(RenderThread* thread) { |
| + if (!thread) |
| + return; |
| + thread->AddObserver(this); |
|
jochen (gone - plz use gerrit)
2014/04/30 04:54:07
Why not RenderThread::Get()->AddObserver() in the
timvolodine
2014/05/01 10:32:39
Done.
|
| +} |
| + |
| +bool BatteryStatusDispatcher::OnControlMessageReceived( |
| + const IPC::Message& message) { |
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP(BatteryStatusDispatcher, message) |
| + IPC_MESSAGE_HANDLER(BatteryStatusMsg_DidChange, OnDidChange) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + return handled; |
| +} |
| + |
| +bool BatteryStatusDispatcher::Start() { |
| + return RenderThread::Get()->Send(new BatteryStatusHostMsg_Start()); |
| + |
| +} |
| + |
| +bool BatteryStatusDispatcher::Stop() { |
| + return RenderThread::Get()->Send(new BatteryStatusHostMsg_Stop()); |
| +} |
| + |
| +void BatteryStatusDispatcher::OnDidChange( |
| + const blink::WebBatteryStatus& status) { |
| + if (listener_) |
| + listener_->updateBatteryStatus(status); |
| +} |
| + |
| +} // namespace content |