Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: base/power_monitor/power_monitor_win.cc

Issue 10959020: SystemMonitor refactoring: move power state monitor into a separate class called PowerMonitor (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add PlatformInit/Destory for all platforms Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/power_monitor/power_monitor.h"
6 6
7 namespace base { 7 namespace base {
8 8
9 void SystemMonitor::ProcessWmPowerBroadcastMessage(int event_id) { 9 void PowerMonitor::ProcessWmPowerBroadcastMessage(int event_id) {
10 PowerEvent power_event; 10 PowerEvent power_event;
11 switch (event_id) { 11 switch (event_id) {
12 case PBT_APMPOWERSTATUSCHANGE: // The power status changed. 12 case PBT_APMPOWERSTATUSCHANGE: // The power status changed.
13 power_event = POWER_STATE_EVENT; 13 power_event = POWER_STATE_EVENT;
14 break; 14 break;
15 case PBT_APMRESUMEAUTOMATIC: // Resume from suspend. 15 case PBT_APMRESUMEAUTOMATIC: // Resume from suspend.
16 //case PBT_APMRESUMESUSPEND: // User-initiated resume from suspend. 16 //case PBT_APMRESUMESUSPEND: // User-initiated resume from suspend.
17 // We don't notify for this latter event 17 // We don't notify for this latter event
18 // because if it occurs it is always sent as a 18 // because if it occurs it is always sent as a
19 // second event after PBT_APMRESUMEAUTOMATIC. 19 // second event after PBT_APMRESUMEAUTOMATIC.
20 power_event = RESUME_EVENT; 20 power_event = RESUME_EVENT;
21 break; 21 break;
22 case PBT_APMSUSPEND: // System has been suspended. 22 case PBT_APMSUSPEND: // System has been suspended.
23 power_event = SUSPEND_EVENT; 23 power_event = SUSPEND_EVENT;
24 break; 24 break;
25 default: 25 default:
26 return; 26 return;
27 27
28 // Other Power Events: 28 // Other Power Events:
29 // PBT_APMBATTERYLOW - removed in Vista. 29 // PBT_APMBATTERYLOW - removed in Vista.
30 // PBT_APMOEMEVENT - removed in Vista. 30 // PBT_APMOEMEVENT - removed in Vista.
31 // PBT_APMQUERYSUSPEND - removed in Vista. 31 // PBT_APMQUERYSUSPEND - removed in Vista.
32 // PBT_APMQUERYSUSPENDFAILED - removed in Vista. 32 // PBT_APMQUERYSUSPENDFAILED - removed in Vista.
33 // PBT_APMRESUMECRITICAL - removed in Vista. 33 // PBT_APMRESUMECRITICAL - removed in Vista.
34 // PBT_POWERSETTINGCHANGE - user changed the power settings. 34 // PBT_POWERSETTINGCHANGE - user changed the power settings.
35 } 35 }
36 ProcessPowerMessage(power_event); 36 ProcessPowerEvent(power_event);
37 }
38
39 void PowerMonitor::PlatformInit() {
40 }
41
42 void PowerMonitor::PlatformDestroy() {
37 } 43 }
38 44
39 // Function to query the system to see if it is currently running on 45 // Function to query the system to see if it is currently running on
40 // battery power. Returns true if running on battery. 46 // battery power. Returns true if running on battery.
41 bool SystemMonitor::IsBatteryPower() { 47 bool PowerMonitor::IsBatteryPower() {
42 SYSTEM_POWER_STATUS status; 48 SYSTEM_POWER_STATUS status;
43 if (!GetSystemPowerStatus(&status)) { 49 if (!GetSystemPowerStatus(&status)) {
44 DLOG(ERROR) << "GetSystemPowerStatus failed: " << GetLastError(); 50 DLOG(ERROR) << "GetSystemPowerStatus failed: " << GetLastError();
45 return false; 51 return false;
46 } 52 }
47 return (status.ACLineStatus == 0); 53 return (status.ACLineStatus == 0);
48 } 54 }
49 55
50 } // namespace base 56 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698