Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: content/renderer/battery_status_dispatcher.cc

Issue 10024013: chromeos: Add support for the battery status API on chromeos. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/battery_status_dispatcher.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « content/renderer/battery_status_dispatcher.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698