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

Side by Side Diff: content/child/power_monitor_broadcast_source.cc

Issue 17074009: Created multi-process-friendly PowerMonitor interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Wired up to all child processes, as requested by @jam Created 7 years, 4 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) 2013 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/child/power_monitor_broadcast_source.h"
6
7 #include "content/common/power_monitor_messages.h"
8
9 namespace content {
10
11 PowerMonitorBroadcastSource::PowerMonitorBroadcastSource(
12 scoped_refptr<base::MessageLoopProxy> message_loop)
13 : last_reported_battery_power_state_(false),
14 weak_factory_(this) {
15 message_filter_ = new PowerMessageFilter(weak_factory_.GetWeakPtr(),
16 message_loop);
17 }
18
19 PowerMonitorBroadcastSource::~PowerMonitorBroadcastSource() {
20 }
21
22 // MessageFilters are owned by the Channel they are added to, so this class does
23 // not need to retain a reference.
piman 2013/07/29 21:18:18 nit: ... but it does anyway, making this comment m
24 IPC::ChannelProxy::MessageFilter*
25 PowerMonitorBroadcastSource::MessageFilter() {
26 return message_filter_.get();
27 }
28
29 bool PowerMonitorBroadcastSource::IsOnBatteryPowerImpl() {
30 return last_reported_battery_power_state_;
31 }
32
33 void PowerMonitorBroadcastSource::OnPowerStateChange(bool on_battery_power) {
34 last_reported_battery_power_state_ = on_battery_power;
35 ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT);
36 }
37
38 void PowerMonitorBroadcastSource::OnSuspend() {
39 ProcessPowerEvent(PowerMonitorSource::SUSPEND_EVENT);
40 }
41
42 void PowerMonitorBroadcastSource::OnResume() {
43 ProcessPowerEvent(PowerMonitorSource::RESUME_EVENT);
44 }
45
46 PowerMonitorBroadcastSource::PowerMessageFilter::PowerMessageFilter(
47 base::WeakPtr<PowerMonitorBroadcastSource> source,
48 scoped_refptr<base::MessageLoopProxy> message_loop)
49 : source_(source),
50 message_loop_(message_loop) {
51 }
52
53 PowerMonitorBroadcastSource::PowerMessageFilter::~PowerMessageFilter() {
54 }
55
56 bool PowerMonitorBroadcastSource::PowerMessageFilter::OnMessageReceived(
57 const IPC::Message& message) {
58 bool msg_is_ok = false;
59 bool handled = true;
60 IPC_BEGIN_MESSAGE_MAP_EX(PowerMessageFilter, message, msg_is_ok)
61 IPC_MESSAGE_HANDLER(PowerMonitorMsg_PowerStateChange, OnPowerStateChange)
62 IPC_MESSAGE_HANDLER(PowerMonitorMsg_Suspend, OnSuspend)
63 IPC_MESSAGE_HANDLER(PowerMonitorMsg_Resume, OnResume)
64 IPC_MESSAGE_UNHANDLED(handled = false)
65 IPC_END_MESSAGE_MAP_EX()
66 return handled && msg_is_ok;
67 }
68
69 void PowerMonitorBroadcastSource::PowerMessageFilter::OnPowerStateChange(
70 bool on_battery_power) {
71 message_loop_->PostTask(FROM_HERE,
72 base::Bind(&PowerMonitorBroadcastSource::OnPowerStateChange, source_,
73 on_battery_power));
74 }
75
76 void PowerMonitorBroadcastSource::PowerMessageFilter::OnSuspend() {
77 message_loop_->PostTask(FROM_HERE,
78 base::Bind(&PowerMonitorBroadcastSource::OnSuspend, source_));
79 }
80
81 void PowerMonitorBroadcastSource::PowerMessageFilter::OnResume() {
82 message_loop_->PostTask(FROM_HERE,
83 base::Bind(&PowerMonitorBroadcastSource::OnResume, source_));
84 }
85
86 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698