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

Side by Side Diff: content/browser/power_monitor_message_broadcaster.cc

Issue 401083002: Initialize PowerMonitor on_power_battery intitial value for newly created processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Typo Created 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/power_monitor_message_broadcaster.h" 5 #include "content/browser/power_monitor_message_broadcaster.h"
6 6
7 #include "base/power_monitor/power_monitor.h" 7 #include "base/power_monitor/power_monitor.h"
8 #include "content/common/power_monitor_messages.h" 8 #include "content/common/power_monitor_messages.h"
9 #include "ipc/ipc_sender.h" 9 #include "ipc/ipc_sender.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 PowerMonitorMessageBroadcaster::PowerMonitorMessageBroadcaster( 13 PowerMonitorMessageBroadcaster::PowerMonitorMessageBroadcaster(
14 IPC::Sender* sender) 14 IPC::Sender* sender)
15 : sender_(sender) { 15 : sender_(sender) {
16 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); 16 base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
17 if (power_monitor) 17 if (power_monitor)
18 power_monitor->AddObserver(this); 18 power_monitor->AddObserver(this);
19 } 19 }
20 20
21 PowerMonitorMessageBroadcaster::~PowerMonitorMessageBroadcaster() { 21 PowerMonitorMessageBroadcaster::~PowerMonitorMessageBroadcaster() {
22 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); 22 base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
23 if (power_monitor) 23 if (power_monitor)
24 power_monitor->RemoveObserver(this); 24 power_monitor->RemoveObserver(this);
25 } 25 }
26 26
27 void PowerMonitorMessageBroadcaster::Init() {
28 base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
29 // Unit tests does not initialize the PowerMonitor.
30 if (power_monitor)
31 OnPowerStateChange(power_monitor->IsOnBatteryPower());
32 }
33
27 void PowerMonitorMessageBroadcaster::OnPowerStateChange(bool on_battery_power) { 34 void PowerMonitorMessageBroadcaster::OnPowerStateChange(bool on_battery_power) {
28 sender_->Send(new PowerMonitorMsg_PowerStateChange(on_battery_power)); 35 sender_->Send(new PowerMonitorMsg_PowerStateChange(on_battery_power));
29 } 36 }
30 37
31 void PowerMonitorMessageBroadcaster::OnSuspend() { 38 void PowerMonitorMessageBroadcaster::OnSuspend() {
32 sender_->Send(new PowerMonitorMsg_Suspend()); 39 sender_->Send(new PowerMonitorMsg_Suspend());
33 } 40 }
34 41
35 void PowerMonitorMessageBroadcaster::OnResume() { 42 void PowerMonitorMessageBroadcaster::OnResume() {
36 sender_->Send(new PowerMonitorMsg_Resume()); 43 sender_->Send(new PowerMonitorMsg_Resume());
37 } 44 }
38 45
39 } // namespace content 46 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/power_monitor_message_broadcaster.h ('k') | content/browser/power_monitor_message_broadcaster_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698