Index: content/renderer/battery_status_dispatcher.cc |
diff --git a/content/renderer/battery_status_dispatcher.cc b/content/renderer/battery_status_dispatcher.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..38f8e223d159281cbaf38b76d2a3e874fac1f012 |
--- /dev/null |
+++ b/content/renderer/battery_status_dispatcher.cc |
@@ -0,0 +1,66 @@ |
+// Copyright (c) 2012 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 "content/renderer/battery_status_dispatcher.h" |
+ |
+#include "base/pickle.h" |
+#include "content/common/battery_status_messages.h" |
+#include "content/renderer/render_thread_impl.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebBatteryStatus.h" |
+ |
+namespace content { |
+ |
+BatteryStatusDispatcher::BatteryStatusDispatcher() { |
+} |
+ |
+BatteryStatusDispatcher::~BatteryStatusDispatcher() { |
+ if (client_list_.size() > 0) |
+ StopUpdates(); |
+} |
+ |
+void BatteryStatusDispatcher::OnBatteryStatusUpdated( |
+ const WebKit::WebBatteryStatus& battery_status) { |
+ for (WebBatteryMonitorClientList::iterator iter = client_list_.begin(); |
+ iter != client_list_.end(); |
+ ++iter) |
+ (*iter)->updateBatteryStatus(battery_status); |
+} |
+ |
+void BatteryStatusDispatcher::StopUpdates() { |
+ RenderThreadImpl* thread = RenderThreadImpl::current(); |
+ thread->Send(new |
+ BatteryStatusHostMsg_StopUpdating()); |
+} |
+ |
+bool BatteryStatusDispatcher::OnControlMessageReceived( |
+ const IPC::Message& msg) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(BatteryStatusDispatcher, msg) |
+ IPC_MESSAGE_HANDLER(BatteryStatusMsg_Updated, OnBatteryStatusUpdated) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void BatteryStatusDispatcher::start(WebKit::WebBatteryMonitorClient* client) { |
+ client_list_.push_back(client); |
+ if (client_list_.size() == 1) { |
+ RenderThreadImpl* thread = RenderThreadImpl::current(); |
+ thread->Send(new |
+ BatteryStatusHostMsg_StartUpdating()); |
+ } |
+} |
+ |
+void BatteryStatusDispatcher::stop(WebKit::WebBatteryMonitorClient* client) { |
+ WebBatteryMonitorClientList::iterator find = std::find(client_list_.begin(), |
+ client_list_.end(), client); |
+ if (find == client_list_.end()) |
+ return; |
+ |
+ client_list_.erase(find); |
+ if (client_list_.size() == 0) |
+ StopUpdates(); |
+} |
+ |
+} // namespace content |