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

Unified Diff: app/system_monitor_mac.mm

Issue 5310005: Monitor sleep/wake on Mac. Should fix some networking issues arising after sl... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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
« no previous file with comments | « app/system_monitor.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/system_monitor_mac.mm
===================================================================
--- app/system_monitor_mac.mm (revision 0)
+++ app/system_monitor_mac.mm (revision 0)
@@ -0,0 +1,67 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "app/system_monitor.h"
+
+#import <AppKit/AppKit.h>
+
+@interface SystemMonitorBridge : NSObject {
+ @private
+ SystemMonitor* systemMonitor_; // weak
+}
+
+- (id)initWithSystemMonitor:(SystemMonitor*)monitor;
+- (void)computerDidSleep:(NSNotification*)notification;
+- (void)computerDidWake:(NSNotification*)notification;
+
+@end
+
+@implementation SystemMonitorBridge
+
+- (id)initWithSystemMonitor:(SystemMonitor*)monitor {
+ self = [super init];
+ if (self) {
+ systemMonitor_ = monitor;
+
+ // See QA1340
+ // <http://developer.apple.com/library/mac/#qa/qa2004/qa1340.html> for more
+ // details.
+ [[[NSWorkspace sharedWorkspace] notificationCenter]
+ addObserver:self
+ selector:@selector(computerDidSleep:)
+ name:NSWorkspaceWillSleepNotification
+ object:nil];
+ [[[NSWorkspace sharedWorkspace] notificationCenter]
+ addObserver:self
+ selector:@selector(computerDidWake:)
+ name:NSWorkspaceDidWakeNotification
+ object:nil];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [[[NSWorkspace sharedWorkspace] notificationCenter]
+ removeObserver:self];
+ [super dealloc];
+}
+
+- (void)computerDidSleep:(NSNotification*)notification {
+ systemMonitor_->ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT);
+}
+
+- (void)computerDidWake:(NSNotification*)notification {
+ systemMonitor_->ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
+}
+
+@end
+
+void SystemMonitor::PlatformInit() {
+ system_monitor_bridge_ =
+ [[SystemMonitorBridge alloc] initWithSystemMonitor:this];
+}
+
+void SystemMonitor::PlatformDestroy() {
+ [system_monitor_bridge_ release];
+}
Property changes on: app/system_monitor_mac.mm
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « app/system_monitor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698