michael@0: // Copyright (c) 2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "base/system_monitor.h" michael@0: michael@0: namespace base { michael@0: michael@0: void SystemMonitor::ProcessWmPowerBroadcastMessage(int event_id) { michael@0: PowerEvent power_event; michael@0: switch (event_id) { michael@0: case PBT_APMPOWERSTATUSCHANGE: // The power status changed. michael@0: power_event = POWER_STATE_EVENT; michael@0: break; michael@0: case PBT_APMRESUMEAUTOMATIC: // Non-user initiated resume from suspend. michael@0: case PBT_APMRESUMESUSPEND: // User initiated resume from suspend. michael@0: power_event = RESUME_EVENT; michael@0: break; michael@0: case PBT_APMSUSPEND: // System has been suspended. michael@0: power_event = SUSPEND_EVENT; michael@0: break; michael@0: default: michael@0: return; michael@0: michael@0: // Other Power Events: michael@0: // PBT_APMBATTERYLOW - removed in Vista. michael@0: // PBT_APMOEMEVENT - removed in Vista. michael@0: // PBT_APMQUERYSUSPEND - removed in Vista. michael@0: // PBT_APMQUERYSUSPENDFAILED - removed in Vista. michael@0: // PBT_APMRESUMECRITICAL - removed in Vista. michael@0: // PBT_POWERSETTINGCHANGE - user changed the power settings. michael@0: } michael@0: ProcessPowerMessage(power_event); michael@0: } michael@0: michael@0: // Function to query the system to see if it is currently running on michael@0: // battery power. Returns true if running on battery. michael@0: bool SystemMonitor::IsBatteryPower() { michael@0: SYSTEM_POWER_STATUS status; michael@0: if (!GetSystemPowerStatus(&status)) { michael@0: CHROMIUM_LOG(ERROR) << "GetSystemPowerStatus failed: " << GetLastError(); michael@0: return false; michael@0: } michael@0: return (status.ACLineStatus == 0); michael@0: } michael@0: michael@0: michael@0: michael@0: } // namespace base