OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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.h" | 5 #include "base/system_monitor.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/singleton.h" |
8 | 9 |
9 namespace base { | 10 namespace base { |
10 | 11 |
11 #if defined(ENABLE_BATTERY_MONITORING) | 12 #if defined(ENABLE_BATTERY_MONITORING) |
12 // The amount of time (in ms) to wait before running the initial | 13 // The amount of time (in ms) to wait before running the initial |
13 // battery check. | 14 // battery check. |
14 static int kDelayedBatteryCheckMs = 10 * 1000; | 15 static int kDelayedBatteryCheckMs = 10 * 1000; |
15 #endif // defined(ENABLE_BATTERY_MONITORING) | 16 #endif // defined(ENABLE_BATTERY_MONITORING) |
16 | 17 |
17 SystemMonitor::SystemMonitor() | 18 SystemMonitor::SystemMonitor() |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 void SystemMonitor::NotifySuspend() { | 66 void SystemMonitor::NotifySuspend() { |
66 LOG(INFO) << L"Power Suspending"; | 67 LOG(INFO) << L"Power Suspending"; |
67 observer_list_->Notify(&PowerObserver::OnSuspend, this); | 68 observer_list_->Notify(&PowerObserver::OnSuspend, this); |
68 } | 69 } |
69 | 70 |
70 void SystemMonitor::NotifyResume() { | 71 void SystemMonitor::NotifyResume() { |
71 LOG(INFO) << L"Power Resuming"; | 72 LOG(INFO) << L"Power Resuming"; |
72 observer_list_->Notify(&PowerObserver::OnResume, this); | 73 observer_list_->Notify(&PowerObserver::OnResume, this); |
73 } | 74 } |
74 | 75 |
| 76 // static |
| 77 SystemMonitor* SystemMonitor::Get() { |
| 78 // Uses the LeakySingletonTrait because cleanup is optional. |
| 79 return |
| 80 Singleton<SystemMonitor, LeakySingletonTraits<SystemMonitor> >::get(); |
| 81 } |
| 82 |
| 83 // static |
75 void SystemMonitor::Start() { | 84 void SystemMonitor::Start() { |
76 #if defined(ENABLE_BATTERY_MONITORING) | 85 #if defined(ENABLE_BATTERY_MONITORING) |
77 DCHECK(MessageLoop::current()); // Can't call start too early. | 86 DCHECK(MessageLoop::current()); // Can't call start too early. |
78 SystemMonitor* monitor = Get(); | 87 SystemMonitor* monitor = Get(); |
79 monitor->delayed_battery_check_.Start( | 88 monitor->delayed_battery_check_.Start( |
80 TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), monitor, | 89 TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), monitor, |
81 &SystemMonitor::BatteryCheck); | 90 &SystemMonitor::BatteryCheck); |
82 #endif // defined(ENABLE_BATTERY_MONITORING) | 91 #endif // defined(ENABLE_BATTERY_MONITORING) |
83 } | 92 } |
84 | 93 |
85 void SystemMonitor::BatteryCheck() { | 94 void SystemMonitor::BatteryCheck() { |
86 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); | 95 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); |
87 } | 96 } |
88 | 97 |
89 } // namespace base | 98 } // namespace base |
OLD | NEW |