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

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: Call AllocateSystemIOPorts before PowerMonitor's ctor 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 76%
rename from base/system_monitor/system_monitor_mac.mm
rename to base/power_monitor/power_monitor_mac.mm
index d0dbaabcd4417864b21166e81c068e20c769cbe6..aa949db21e0f869e14c64c64e476b2c80bc85cbb 100644
--- a/base/system_monitor/system_monitor_mac.mm
+++ b/base/power_monitor/power_monitor_mac.mm
@@ -5,13 +5,19 @@
// 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>
namespace base {
+// A helper function as a friend function of PowerMonitor.
+void ProcessPowerEventHelper(PowerMonitor::PowerEvent power_event) {
+ PowerMonitor* power_monitor = PowerMonitor::GetInstance();
+ power_monitor->ProcessPowerEvent(power_event);
+}
+
namespace {
io_connect_t g_system_power_io_port = 0;
@@ -22,17 +28,15 @@ void SystemPowerEventCallback(void*,
io_service_t service,
natural_t message_type,
void* message_argument) {
- SystemMonitor* sys_monitor = SystemMonitor::Get();
- DCHECK(sys_monitor);
switch (message_type) {
case kIOMessageSystemWillSleep:
- sys_monitor->ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT);
+ ProcessPowerEventHelper(PowerMonitor::SUSPEND_EVENT);
IOAllowPowerChange(g_system_power_io_port,
reinterpret_cast<intptr_t>(message_argument));
break;
case kIOMessageSystemWillPowerOn:
- sys_monitor->ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
+ ProcessPowerEventHelper(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);
+void PowerMonitor::AllocateSystemIOPorts() {
+ if (g_system_power_io_port != 0u)
Hongbo Min 2012/10/16 14:14:40 base/power_monitor/power_monitor_mac.mm:53: if (g_
vandebo (ex-Chrome) 2012/10/16 18:50:16 Hmm, this is a consequence of changing it to a Sin
willchan no longer on Chromium 2012/10/16 20:32:37 I'm confused. Why is this better than before? Let
vandebo (ex-Chrome) 2012/10/16 23:55:09 Maybe this and the other issue is why it wasn't a
+ 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(

Powered by Google App Engine
This is Rietveld 408576698