OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "content/renderer/battery_status_dispatcher.h" |
| 6 |
| 7 #include "base/pickle.h" |
| 8 #include "content/common/battery_status_messages.h" |
| 9 #include "content/renderer/render_thread_impl.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBatteryStatus.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 BatteryStatusDispatcher::BatteryStatusDispatcher() { |
| 15 } |
| 16 |
| 17 BatteryStatusDispatcher::~BatteryStatusDispatcher() { |
| 18 if (client_list_.size() > 0) |
| 19 StopUpdates(); |
| 20 } |
| 21 |
| 22 void BatteryStatusDispatcher::OnBatteryStatusUpdated( |
| 23 const WebKit::WebBatteryStatus& battery_status) { |
| 24 for (WebBatteryMonitorClientList::iterator iter = client_list_.begin(); |
| 25 iter != client_list_.end(); |
| 26 ++iter) |
| 27 (*iter)->updateBatteryStatus(battery_status); |
| 28 } |
| 29 |
| 30 void BatteryStatusDispatcher::StopUpdates() { |
| 31 RenderThreadImpl* thread = RenderThreadImpl::current(); |
| 32 thread->Send(new |
| 33 BatteryStatusHostMsg_StopUpdating()); |
| 34 } |
| 35 |
| 36 bool BatteryStatusDispatcher::OnControlMessageReceived( |
| 37 const IPC::Message& msg) { |
| 38 bool handled = true; |
| 39 IPC_BEGIN_MESSAGE_MAP(BatteryStatusDispatcher, msg) |
| 40 IPC_MESSAGE_HANDLER(BatteryStatusMsg_Updated, OnBatteryStatusUpdated) |
| 41 IPC_MESSAGE_UNHANDLED(handled = false) |
| 42 IPC_END_MESSAGE_MAP() |
| 43 return handled; |
| 44 } |
| 45 |
| 46 void BatteryStatusDispatcher::start(WebKit::WebBatteryMonitorClient* client) { |
| 47 client_list_.push_back(client); |
| 48 if (client_list_.size() == 1) { |
| 49 RenderThreadImpl* thread = RenderThreadImpl::current(); |
| 50 thread->Send(new |
| 51 BatteryStatusHostMsg_StartUpdating()); |
| 52 } |
| 53 } |
| 54 |
| 55 void BatteryStatusDispatcher::stop(WebKit::WebBatteryMonitorClient* client) { |
| 56 WebBatteryMonitorClientList::iterator find = std::find(client_list_.begin(), |
| 57 client_list_.end(), client); |
| 58 if (find == client_list_.end()) |
| 59 return; |
| 60 |
| 61 client_list_.erase(find); |
| 62 if (client_list_.size() == 0) |
| 63 StopUpdates(); |
| 64 } |
| 65 |
| 66 } // namespace content |
OLD | NEW |