|
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 |
|
3 // found in the LICENSE file. |
|
4 |
|
5 #include "base/system_monitor.h" |
|
6 |
|
7 namespace base { |
|
8 |
|
9 void SystemMonitor::ProcessWmPowerBroadcastMessage(int event_id) { |
|
10 PowerEvent power_event; |
|
11 switch (event_id) { |
|
12 case PBT_APMPOWERSTATUSCHANGE: // The power status changed. |
|
13 power_event = POWER_STATE_EVENT; |
|
14 break; |
|
15 case PBT_APMRESUMEAUTOMATIC: // Non-user initiated resume from suspend. |
|
16 case PBT_APMRESUMESUSPEND: // User initiated resume from suspend. |
|
17 power_event = RESUME_EVENT; |
|
18 break; |
|
19 case PBT_APMSUSPEND: // System has been suspended. |
|
20 power_event = SUSPEND_EVENT; |
|
21 break; |
|
22 default: |
|
23 return; |
|
24 |
|
25 // Other Power Events: |
|
26 // PBT_APMBATTERYLOW - removed in Vista. |
|
27 // PBT_APMOEMEVENT - removed in Vista. |
|
28 // PBT_APMQUERYSUSPEND - removed in Vista. |
|
29 // PBT_APMQUERYSUSPENDFAILED - removed in Vista. |
|
30 // PBT_APMRESUMECRITICAL - removed in Vista. |
|
31 // PBT_POWERSETTINGCHANGE - user changed the power settings. |
|
32 } |
|
33 ProcessPowerMessage(power_event); |
|
34 } |
|
35 |
|
36 // Function to query the system to see if it is currently running on |
|
37 // battery power. Returns true if running on battery. |
|
38 bool SystemMonitor::IsBatteryPower() { |
|
39 SYSTEM_POWER_STATUS status; |
|
40 if (!GetSystemPowerStatus(&status)) { |
|
41 CHROMIUM_LOG(ERROR) << "GetSystemPowerStatus failed: " << GetLastError(); |
|
42 return false; |
|
43 } |
|
44 return (status.ACLineStatus == 0); |
|
45 } |
|
46 |
|
47 |
|
48 |
|
49 } // namespace base |