Chromium Code Reviews| Index: base/power_monitor/power_monitor_mac.mm |
| diff --git a/base/system_monitor/system_monitor_mac.mm b/base/power_monitor/power_monitor_mac.mm |
| similarity index 76% |
| rename from base/system_monitor/system_monitor_mac.mm |
| rename to base/power_monitor/power_monitor_mac.mm |
| index d0dbaabcd4417864b21166e81c068e20c769cbe6..27e8456e4bea0f0a6f6bc21ecfdf529a8150bec5 100644 |
| --- a/base/system_monitor/system_monitor_mac.mm |
| +++ b/base/power_monitor/power_monitor_mac.mm |
| @@ -5,7 +5,7 @@ |
| // Implementation based on sample code from |
| // http://developer.apple.com/library/mac/#qa/qa1340/_index.html. |
| -#include "base/system_monitor/system_monitor.h" |
| +#include "base/power_monitor/power_monitor.h" |
| #include <IOKit/pwr_mgt/IOPMLib.h> |
| #include <IOKit/IOMessage.h> |
| @@ -17,22 +17,26 @@ namespace { |
| io_connect_t g_system_power_io_port = 0; |
| IONotificationPortRef g_notification_port_ref = 0; |
| io_object_t g_notifier_object = 0; |
| +PowerMonitor::Notifier* g_power_notifier = NULL; |
| void SystemPowerEventCallback(void*, |
| io_service_t service, |
| natural_t message_type, |
| void* message_argument) { |
| - SystemMonitor* sys_monitor = SystemMonitor::Get(); |
| - DCHECK(sys_monitor); |
| + if (g_power_notifier == NULL) |
| + g_power_notifier = PowerMonitor::GetInstance()->GetNotifierOnce(); |
|
vandebo (ex-Chrome)
2012/10/23 01:27:57
Set this in PlatformInit and assert that we get it
|
| + |
| switch (message_type) { |
| case kIOMessageSystemWillSleep: |
| - sys_monitor->ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT); |
| + if (g_power_notifier) |
| + g_power_notifier->ProcessPowerEvent(base::PowerMonitor::SUSPEND_EVENT); |
| IOAllowPowerChange(g_system_power_io_port, |
| reinterpret_cast<intptr_t>(message_argument)); |
| break; |
| case kIOMessageSystemWillPowerOn: |
| - sys_monitor->ProcessPowerMessage(SystemMonitor::RESUME_EVENT); |
| + if (g_power_notifier) |
| + g_power_notifier->ProcessPowerEvent(PowerMonitor::RESUME_EVENT); |
| break; |
| } |
| } |
| @@ -45,8 +49,9 @@ void SystemPowerEventCallback(void*, |
| // See crbug.com/83783 . |
| // static |
| -void SystemMonitor::AllocateSystemIOPorts() { |
| - DCHECK_EQ(g_system_power_io_port, 0u); |
|
Hongbo Min
2012/10/21 09:56:03
If I keep the original DCHECK_EQ stmt, lots of tes
vandebo (ex-Chrome)
2012/10/23 01:27:57
DCHECKs are used on the bots even in release mode.
|
| +void PowerMonitor::AllocateSystemIOPorts() { |
| + if (g_system_power_io_port != 0u) |
| + return; |
| // Notification port allocated by IORegisterForSystemPower. |
| @@ -57,12 +62,10 @@ void SystemMonitor::AllocateSystemIOPorts() { |
| DCHECK_NE(g_system_power_io_port, 0u); |
| } |
| -void SystemMonitor::PlatformInit() { |
| - // Need to call AllocateSystemIOPorts() before constructing a SystemMonitor |
| +void PowerMonitor::PlatformInit() { |
| + // Need to call AllocateSystemIOPorts() before creating a PowerMonitor |
| // object. |
| - DCHECK_NE(g_system_power_io_port, 0u); |
| - if (g_system_power_io_port == 0) |
| - return; |
| + CHECK_NE(g_system_power_io_port, 0u); |
| // Add the notification port to the application runloop |
| CFRunLoopAddSource( |
| @@ -71,10 +74,9 @@ void SystemMonitor::PlatformInit() { |
| kCFRunLoopCommonModes); |
| } |
| -void SystemMonitor::PlatformDestroy() { |
| - DCHECK_NE(g_system_power_io_port, 0u); |
| - if (g_system_power_io_port == 0) |
| - return; |
| + |
| +void PowerMonitor::PlatformDestroy() { |
| + CHECK_NE(g_system_power_io_port, 0u); |
| // Remove the sleep notification port from the application runloop |
| CFRunLoopRemoveSource( |