OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/system_monitor/system_monitor.h" | 5 #include "base/system_monitor/system_monitor.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 | 12 |
13 static SystemMonitor* g_system_monitor = NULL; | 13 static SystemMonitor* g_system_monitor = NULL; |
14 | 14 |
15 #if defined(ENABLE_BATTERY_MONITORING) | 15 #if defined(ENABLE_BATTERY_MONITORING) |
16 // The amount of time (in ms) to wait before running the initial | 16 // The amount of time (in ms) to wait before running the initial |
17 // battery check. | 17 // battery check. |
18 static int kDelayedBatteryCheckMs = 10 * 1000; | 18 static int kDelayedBatteryCheckMs = 10 * 1000; |
19 #endif // defined(ENABLE_BATTERY_MONITORING) | 19 #endif // defined(ENABLE_BATTERY_MONITORING) |
20 | 20 |
21 SystemMonitor::SystemMonitor() | 21 SystemMonitor::SystemMonitor() |
22 : observer_list_(new ObserverListThreadSafe<PowerObserver>()), | 22 : observer_list_(new ObserverListThreadSafe<PowerObserver>()), |
23 battery_in_use_(false), | 23 battery_in_use_(false), |
24 suspended_(false) { | 24 suspended_(false) { |
25 DCHECK(!g_system_monitor); | 25 DCHECK(!g_system_monitor); |
26 g_system_monitor = this; | 26 g_system_monitor = this; |
27 | 27 |
28 DCHECK(MessageLoop::current()); | 28 DCHECK(MessageLoop::current()); |
29 #if defined(ENABLE_BATTERY_MONITORING) | 29 #if defined(ENABLE_BATTERY_MONITORING) |
30 delayed_battery_check_.Start(FROM_HERE, | 30 delayed_battery_check_.Start( |
31 base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this, | 31 base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this, |
32 &SystemMonitor::BatteryCheck); | 32 &SystemMonitor::BatteryCheck); |
33 #endif // defined(ENABLE_BATTERY_MONITORING) | 33 #endif // defined(ENABLE_BATTERY_MONITORING) |
34 #if defined(OS_MACOSX) | 34 #if defined(OS_MACOSX) |
35 PlatformInit(); | 35 PlatformInit(); |
36 #endif | 36 #endif |
37 } | 37 } |
38 | 38 |
39 SystemMonitor::~SystemMonitor() { | 39 SystemMonitor::~SystemMonitor() { |
40 #if defined(OS_MACOSX) | 40 #if defined(OS_MACOSX) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 void SystemMonitor::NotifyResume() { | 99 void SystemMonitor::NotifyResume() { |
100 VLOG(1) << "Power Resuming"; | 100 VLOG(1) << "Power Resuming"; |
101 observer_list_->Notify(&PowerObserver::OnResume); | 101 observer_list_->Notify(&PowerObserver::OnResume); |
102 } | 102 } |
103 | 103 |
104 void SystemMonitor::BatteryCheck() { | 104 void SystemMonitor::BatteryCheck() { |
105 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); | 105 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); |
106 } | 106 } |
107 | 107 |
108 } // namespace base | 108 } // namespace base |
OLD | NEW |