Chromium Code Reviews| Index: base/power_monitor/power_monitor_device_source_mac.mm |
| diff --git a/base/power_monitor/power_monitor_device_source_mac.mm b/base/power_monitor/power_monitor_device_source_mac.mm |
| index 8c48117e22007f522e6d4433ff3e1ed621fb3f31..aa7274574d51ab39a1b8c741c872651d796d8e9d 100644 |
| --- a/base/power_monitor/power_monitor_device_source_mac.mm |
| +++ b/base/power_monitor/power_monitor_device_source_mac.mm |
| @@ -11,6 +11,8 @@ |
| #include "base/power_monitor/power_monitor_source.h" |
| #include <IOKit/IOMessage.h> |
| +#include <IOKit/ps/IOPSKeys.h> |
| +#include <IOKit/ps/IOPowerSources.h> |
| #include <IOKit/pwr_mgt/IOPMLib.h> |
| namespace base { |
| @@ -19,6 +21,29 @@ void ProcessPowerEventHelper(PowerMonitorSource::PowerEvent event) { |
| PowerMonitorSource::ProcessPowerEvent(event); |
| } |
| +bool PowerMonitorDeviceSource::IsOnBatteryPowerImpl() { |
|
Nico
2016/09/20 00:05:08
how often do we poll this? there's a "this changed
DaleCurtis
2016/09/20 00:15:13
Doesn't look like it's called very much anywhere.
Robert Sesek
2016/09/20 18:19:56
I do think we should use the IOPSNotificationCreat
DaleCurtis
2016/09/21 22:49:39
Done.
|
| + base::ScopedCFTypeRef<CFTypeRef> info(IOPSCopyPowerSourcesInfo()); |
| + base::ScopedCFTypeRef<CFArrayRef> power_sources_list( |
| + IOPSCopyPowerSourcesList(info)); |
| + |
| + const CFIndex count = CFArrayGetCount(power_sources_list); |
| + for (CFIndex i = 0; i < count; ++i) { |
| + const CFDictionaryRef description = IOPSGetPowerSourceDescription( |
| + info, CFArrayGetValueAtIndex(power_sources_list, i)); |
| + if (!description) |
| + continue; |
| + |
| + CFStringRef current_state = base::mac::GetValueFromDictionary<CFStringRef>( |
| + description, CFSTR(kIOPSPowerSourceStateKey)); |
| + |
| + // We only report "on battery power" if no source is on AC power. |
| + if (!CFStringsAreEqual(current_state, CFSTR(kIOPSBatteryPowerValue))) |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| namespace { |
| io_connect_t g_system_power_io_port = 0; |