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