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

Unified Diff: base/power_monitor/power_monitor_device_source_mac.mm

Issue 2351593004: Implement base::PowerMonitor::IsOnBatteryPower() for OSX. (Closed)
Patch Set: Fix logic. Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« base/BUILD.gn ('K') | « base/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« base/BUILD.gn ('K') | « base/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698