OLD | NEW |
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::AddObserver(this); | 16 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
| 17 if (power_monitor) |
| 18 power_monitor->AddObserver(this); |
17 } | 19 } |
18 | 20 |
19 PowerMonitorMessageBroadcaster::~PowerMonitorMessageBroadcaster() { | 21 PowerMonitorMessageBroadcaster::~PowerMonitorMessageBroadcaster() { |
20 base::PowerMonitor::RemoveObserver(this); | 22 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
| 23 if (power_monitor) |
| 24 power_monitor->RemoveObserver(this); |
21 } | 25 } |
22 | 26 |
23 void PowerMonitorMessageBroadcaster::OnPowerStateChange(bool on_battery_power) { | 27 void PowerMonitorMessageBroadcaster::OnPowerStateChange(bool on_battery_power) { |
24 sender_->Send(new PowerMonitorMsg_PowerStateChange(on_battery_power)); | 28 sender_->Send(new PowerMonitorMsg_PowerStateChange(on_battery_power)); |
25 } | 29 } |
26 | 30 |
27 void PowerMonitorMessageBroadcaster::OnSuspend() { | 31 void PowerMonitorMessageBroadcaster::OnSuspend() { |
28 sender_->Send(new PowerMonitorMsg_Suspend()); | 32 sender_->Send(new PowerMonitorMsg_Suspend()); |
29 } | 33 } |
30 | 34 |
31 void PowerMonitorMessageBroadcaster::OnResume() { | 35 void PowerMonitorMessageBroadcaster::OnResume() { |
32 sender_->Send(new PowerMonitorMsg_Resume()); | 36 sender_->Send(new PowerMonitorMsg_Resume()); |
33 } | 37 } |
34 | 38 |
35 } // namespace content | 39 } // namespace content |
OLD | NEW |