| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "app/system_monitor.h" | |
| 6 | |
| 7 #import <AppKit/AppKit.h> | |
| 8 | |
| 9 @interface SystemMonitorBridge : NSObject { | |
| 10 @private | |
| 11 SystemMonitor* systemMonitor_; // weak | |
| 12 } | |
| 13 | |
| 14 - (id)initWithSystemMonitor:(SystemMonitor*)monitor; | |
| 15 - (void)computerDidSleep:(NSNotification*)notification; | |
| 16 - (void)computerDidWake:(NSNotification*)notification; | |
| 17 | |
| 18 @end | |
| 19 | |
| 20 @implementation SystemMonitorBridge | |
| 21 | |
| 22 - (id)initWithSystemMonitor:(SystemMonitor*)monitor { | |
| 23 self = [super init]; | |
| 24 if (self) { | |
| 25 systemMonitor_ = monitor; | |
| 26 | |
| 27 // See QA1340 | |
| 28 // <http://developer.apple.com/library/mac/#qa/qa2004/qa1340.html> for more | |
| 29 // details. | |
| 30 [[[NSWorkspace sharedWorkspace] notificationCenter] | |
| 31 addObserver:self | |
| 32 selector:@selector(computerDidSleep:) | |
| 33 name:NSWorkspaceWillSleepNotification | |
| 34 object:nil]; | |
| 35 [[[NSWorkspace sharedWorkspace] notificationCenter] | |
| 36 addObserver:self | |
| 37 selector:@selector(computerDidWake:) | |
| 38 name:NSWorkspaceDidWakeNotification | |
| 39 object:nil]; | |
| 40 } | |
| 41 return self; | |
| 42 } | |
| 43 | |
| 44 - (void)dealloc { | |
| 45 [[[NSWorkspace sharedWorkspace] notificationCenter] | |
| 46 removeObserver:self]; | |
| 47 [super dealloc]; | |
| 48 } | |
| 49 | |
| 50 - (void)computerDidSleep:(NSNotification*)notification { | |
| 51 systemMonitor_->ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT); | |
| 52 } | |
| 53 | |
| 54 - (void)computerDidWake:(NSNotification*)notification { | |
| 55 systemMonitor_->ProcessPowerMessage(SystemMonitor::RESUME_EVENT); | |
| 56 } | |
| 57 | |
| 58 @end | |
| 59 | |
| 60 void SystemMonitor::PlatformInit() { | |
| 61 system_monitor_bridge_ = | |
| 62 [[SystemMonitorBridge alloc] initWithSystemMonitor:this]; | |
| 63 } | |
| 64 | |
| 65 void SystemMonitor::PlatformDestroy() { | |
| 66 [system_monitor_bridge_ release]; | |
| 67 } | |
| OLD | NEW |