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

Side by Side 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: file-move Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_view_impl.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBatteryStatus.h"
11
12 BatteryStatusDispatcher::BatteryStatusDispatcher(RenderViewImpl* render_view)
13 : content::RenderViewObserver(render_view),
14 started_(false) {
15 }
16
17 BatteryStatusDispatcher::~BatteryStatusDispatcher() {
18 if (started_)
19 stopUpdating();
20 }
21
22 bool BatteryStatusDispatcher::OnMessageReceived(const IPC::Message& msg) {
23 bool handled = true;
24 IPC_BEGIN_MESSAGE_MAP(BatteryStatusDispatcher, msg)
25 IPC_MESSAGE_HANDLER(BatteryStatusMsg_Updated, OnBatteryStatusUpdated)
26 IPC_MESSAGE_UNHANDLED(handled = false)
27 IPC_END_MESSAGE_MAP()
28 return handled;
29 }
30
31 void BatteryStatusDispatcher::startUpdating() {
32 Send(new BatteryStatusHostMsg_StartUpdating(routing_id()));
33 started_ = true;
34 }
35
36 void BatteryStatusDispatcher::stopUpdating() {
37 Send(new BatteryStatusHostMsg_StopUpdating(routing_id()));
38 started_ = false;
39 }
40
41 void BatteryStatusDispatcher::OnBatteryStatusUpdated(
42 const IPC::Message& message) {
43 const char* data;
44 int data_length;
45 PickleIterator iter(message);
46 if (message.ReadData(&iter, &data, &data_length)) {
47 const WebKit::WebBatteryStatus* web_status =
48 reinterpret_cast<const WebKit::WebBatteryStatus*>(data);
49 render_view()->GetWebView()->updateBatteryStatus(*web_status);
50 }
51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698