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

Side by Side Diff: content/common/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: Windows fixes, Power messages posted to main GPU thread now Created 7 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 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/common/power_monitor_broadcast_source.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "content/common/power_monitor_messages.h"
10
11 namespace content {
12
13 PowerMonitorBroadcastSource::PowerMonitorBroadcastSource(
14 scoped_refptr<base::MessageLoopProxy> message_loop)
15 : on_battery_power_(false),
16 message_filter_(new PowerMessageFilter(this)),
17 message_loop_(message_loop),
18 weak_factory_(this) {
19 }
20
21 PowerMonitorBroadcastSource::~PowerMonitorBroadcastSource() {
22 }
23
24 // MessageFilters are owned by the Channel they are added to, so this class does
25 // not need to retain a reference.
26 IPC::ChannelProxy::MessageFilter*
27 PowerMonitorBroadcastSource::MessageFilter() {
28 return message_filter_.get();
29 }
30
31 bool PowerMonitorBroadcastSource::IsBatteryPower() {
32 return on_battery_power_;
33 }
34
35 void PowerMonitorBroadcastSource::OnPowerStateChange(bool on_battery_power) {
36 on_battery_power_ = on_battery_power;
Ken Russell (switch to Gerrit) 2013/07/03 09:49:43 Is synchronization needed around this variable? It
37 message_loop_->PostTask(FROM_HERE,
38 base::Bind(&PowerMonitorBroadcastSource::ProcessPowerEvent,
39 weak_factory_.GetWeakPtr(), PowerMonitorSource::POWER_STATE_EVENT));
40 //ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT);
Ken Russell (switch to Gerrit) 2013/07/03 09:49:43 Here and below: remove commented out code.
41 }
42
43 void PowerMonitorBroadcastSource::OnSuspend() {
44 message_loop_->PostTask(FROM_HERE,
45 base::Bind(&PowerMonitorBroadcastSource::ProcessPowerEvent,
46 weak_factory_.GetWeakPtr(), PowerMonitorSource::SUSPEND_EVENT));
47 //ProcessPowerEvent(PowerMonitorSource::SUSPEND_EVENT);
48 }
49
50 void PowerMonitorBroadcastSource::OnResume() {
51 message_loop_->PostTask(FROM_HERE,
52 base::Bind(&PowerMonitorBroadcastSource::ProcessPowerEvent,
53 weak_factory_.GetWeakPtr(), PowerMonitorSource::RESUME_EVENT));
54 //ProcessPowerEvent(PowerMonitorSource::RESUME_EVENT);
55 }
56
57 PowerMonitorBroadcastSource::PowerMessageFilter::PowerMessageFilter(
58 PowerMonitorBroadcastSource* source) : source_(source) {
59 }
60
61 PowerMonitorBroadcastSource::PowerMessageFilter::~PowerMessageFilter() {
62 }
63
64 bool PowerMonitorBroadcastSource::PowerMessageFilter::OnMessageReceived(
65 const IPC::Message& message) {
66 bool msg_is_ok = true;
67 bool handled = true;
68 IPC_BEGIN_MESSAGE_MAP_EX(PowerMessageFilter, message, msg_is_ok)
69 IPC_MESSAGE_HANDLER(PowerMonitorMsg_PowerStateChange, OnPowerStateChange)
70 IPC_MESSAGE_HANDLER(PowerMonitorMsg_Suspend, OnSuspend)
71 IPC_MESSAGE_HANDLER(PowerMonitorMsg_Resume, OnResume)
72 IPC_MESSAGE_UNHANDLED(handled = false)
73 IPC_END_MESSAGE_MAP_EX()
74 return handled;
75 }
76
77 void PowerMonitorBroadcastSource::PowerMessageFilter::OnPowerStateChange(
78 bool on_battery_power) {
79 source_->OnPowerStateChange(on_battery_power);
80 }
81
82 void PowerMonitorBroadcastSource::PowerMessageFilter::OnSuspend() {
83 source_->OnSuspend();
84 }
85
86 void PowerMonitorBroadcastSource::PowerMessageFilter::OnResume() {
87 source_->OnResume();
88 }
89
90 } // namespace content
OLDNEW
« no previous file with comments | « content/common/power_monitor_broadcast_source.h ('k') | content/common/power_monitor_message_broadcaster.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698