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

Unified Diff: base/power_monitor/power_monitor_mac.mm

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: Revert using Singleton pattern for PowerMonitor Created 8 years, 2 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
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 74%
rename from base/system_monitor/system_monitor_mac.mm
rename to base/power_monitor/power_monitor_mac.mm
index d0dbaabcd4417864b21166e81c068e20c769cbe6..005fdb656eb0e89da677657ae6f885693bac98b3 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>
@@ -16,23 +16,24 @@ namespace {
io_connect_t g_system_power_io_port = 0;
IONotificationPortRef g_notification_port_ref = 0;
-io_object_t g_notifier_object = 0;
+io_object_t g_signaler_object = 0;
vandebo (ex-Chrome) 2012/10/29 18:04:38 no reason to change the name of this variable.
Hongbo Min 2012/10/30 14:33:47 It mainly arises from the grep and replace action
+PowerMonitor::Signaler* g_power_signaler = NULL;
void SystemPowerEventCallback(void*,
io_service_t service,
natural_t message_type,
void* message_argument) {
- SystemMonitor* sys_monitor = SystemMonitor::Get();
- DCHECK(sys_monitor);
+
+ CHECK(g_power_signaler);
switch (message_type) {
case kIOMessageSystemWillSleep:
- sys_monitor->ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT);
+ g_power_signaler->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);
+ g_power_signaler->ProcessPowerEvent(PowerMonitor::RESUME_EVENT);
break;
}
}
@@ -45,25 +46,25 @@ void SystemPowerEventCallback(void*,
// See crbug.com/83783 .
// static
-void SystemMonitor::AllocateSystemIOPorts() {
- DCHECK_EQ(g_system_power_io_port, 0u);
+void PowerMonitor::AllocateSystemIOPorts() {
+ if (g_system_power_io_port != 0u)
+ return;
// Notification port allocated by IORegisterForSystemPower.
g_system_power_io_port = IORegisterForSystemPower(
NULL, &g_notification_port_ref, SystemPowerEventCallback,
- &g_notifier_object);
+ &g_signaler_object);
vandebo (ex-Chrome) 2012/10/29 18:04:38 and here
Hongbo Min 2012/10/30 14:33:47 Done.
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(!g_power_signaler);
+ g_power_signaler = PowerMonitor::Get()->GetSignalerOnce();
+ CHECK_NE(g_system_power_io_port, 0u);
vandebo (ex-Chrome) 2012/10/29 18:04:38 Move this just under the comment online 64
Hongbo Min 2012/10/30 14:33:47 Done.
// Add the notification port to the application runloop
CFRunLoopAddSource(
CFRunLoopGetCurrent(),
@@ -71,10 +72,9 @@ void SystemMonitor::PlatformInit() {
kCFRunLoopCommonModes);
}
-void SystemMonitor::PlatformDestroy() {
- DCHECK_NE(g_system_power_io_port, 0u);
- if (g_system_power_io_port == 0)
vandebo (ex-Chrome) 2012/10/29 18:04:38 Leave these lines in.
Hongbo Min 2012/10/30 14:33:47 Done.
- return;
+
+void PowerMonitor::PlatformDestroy() {
vandebo (ex-Chrome) 2012/10/29 18:04:38 Maybe PlatformDestroy should clean up g_power_sign
Hongbo Min 2012/10/30 14:33:47 I don't clean it in PlatformDestroy. The reason is
vandebo (ex-Chrome) 2012/10/30 20:41:24 I'm ok having PlatformInit/PlatformDestroy on all
+ CHECK_NE(g_system_power_io_port, 0u);
vandebo (ex-Chrome) 2012/10/29 18:04:38 Levae this as a DCHECK
Hongbo Min 2012/10/30 14:33:47 Done.
// Remove the sleep notification port from the application runloop
CFRunLoopRemoveSource(
@@ -83,7 +83,7 @@ void SystemMonitor::PlatformDestroy() {
kCFRunLoopCommonModes);
// Deregister for system sleep notifications
- IODeregisterForSystemPower(&g_notifier_object);
+ IODeregisterForSystemPower(&g_signaler_object);
vandebo (ex-Chrome) 2012/10/29 18:04:38 and here
Hongbo Min 2012/10/30 14:33:47 Done.
// IORegisterForSystemPower implicitly opens the Root Power Domain IOService,
// so we close it here.

Powered by Google App Engine
This is Rietveld 408576698