| 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 namespace base { | 7 namespace base { |
| 8 | 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: // Resume from suspend. | |
| 16 //case PBT_APMRESUMESUSPEND: // User-initiated resume from suspend. | |
| 17 // We don't notify for this latter event | |
| 18 // because if it occurs it is always sent as a | |
| 19 // second event after PBT_APMRESUMEAUTOMATIC. | |
| 20 power_event = RESUME_EVENT; | |
| 21 break; | |
| 22 case PBT_APMSUSPEND: // System has been suspended. | |
| 23 power_event = SUSPEND_EVENT; | |
| 24 break; | |
| 25 default: | |
| 26 return; | |
| 27 | |
| 28 // Other Power Events: | |
| 29 // PBT_APMBATTERYLOW - removed in Vista. | |
| 30 // PBT_APMOEMEVENT - removed in Vista. | |
| 31 // PBT_APMQUERYSUSPEND - removed in Vista. | |
| 32 // PBT_APMQUERYSUSPENDFAILED - removed in Vista. | |
| 33 // PBT_APMRESUMECRITICAL - removed in Vista. | |
| 34 // PBT_POWERSETTINGCHANGE - user changed the power settings. | |
| 35 } | |
| 36 ProcessPowerMessage(power_event); | |
| 37 } | |
| 38 | |
| 39 // Function to query the system to see if it is currently running on | 9 // Function to query the system to see if it is currently running on |
| 40 // battery power. Returns true if running on battery. | 10 // battery power. Returns true if running on battery. |
| 41 bool SystemMonitor::IsBatteryPower() { | 11 bool SystemMonitor::IsBatteryPower() { |
| 42 SYSTEM_POWER_STATUS status; | 12 SYSTEM_POWER_STATUS status; |
| 43 if (!GetSystemPowerStatus(&status)) { | 13 if (!GetSystemPowerStatus(&status)) { |
| 44 DLOG_GETLASTERROR(ERROR) << "GetSystemPowerStatus failed"; | 14 DLOG_GETLASTERROR(ERROR) << "GetSystemPowerStatus failed"; |
| 45 return false; | 15 return false; |
| 46 } | 16 } |
| 47 return (status.ACLineStatus == 0); | 17 return (status.ACLineStatus == 0); |
| 48 } | 18 } |
| 49 | 19 |
| 50 } // namespace base | 20 } // namespace base |
| OLD | NEW |