| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/idle.h" | 5 #import "chrome/browser/idle.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #import <CoreGraphics/CGEventSource.h> | 8 #import <CoreGraphics/CGEventSource.h> |
| 9 | 9 |
| 10 @interface MacScreenMonitor : NSObject { | 10 @interface MacScreenMonitor : NSObject { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 if (!g_screenMonitor) | 78 if (!g_screenMonitor) |
| 79 g_screenMonitor = [[MacScreenMonitor alloc] init]; | 79 g_screenMonitor = [[MacScreenMonitor alloc] init]; |
| 80 } | 80 } |
| 81 | 81 |
| 82 void StopIdleMonitor() { | 82 void StopIdleMonitor() { |
| 83 [g_screenMonitor release]; | 83 [g_screenMonitor release]; |
| 84 g_screenMonitor = nil; | 84 g_screenMonitor = nil; |
| 85 } | 85 } |
| 86 | 86 |
| 87 void CalculateIdleState(unsigned int idle_threshold, IdleCallback notify) { | 87 void CalculateIdleState(unsigned int idle_threshold, IdleCallback notify) { |
| 88 if ([g_screenMonitor isScreensaverRunning] || | 88 if (CheckIdleStateIsLocked()) { |
| 89 [g_screenMonitor isScreenLocked]) { | |
| 90 notify.Run(IDLE_STATE_LOCKED); | 89 notify.Run(IDLE_STATE_LOCKED); |
| 91 return; | 90 return; |
| 92 } | 91 } |
| 93 | 92 |
| 94 CFTimeInterval idle_time = CGEventSourceSecondsSinceLastEventType( | 93 CFTimeInterval idle_time = CGEventSourceSecondsSinceLastEventType( |
| 95 kCGEventSourceStateCombinedSessionState, | 94 kCGEventSourceStateCombinedSessionState, |
| 96 kCGAnyInputEventType); | 95 kCGAnyInputEventType); |
| 97 if (idle_time >= idle_threshold) | 96 if (idle_time >= idle_threshold) |
| 98 notify.Run(IDLE_STATE_IDLE); | 97 notify.Run(IDLE_STATE_IDLE); |
| 99 else | 98 else |
| 100 notify.Run(IDLE_STATE_ACTIVE); | 99 notify.Run(IDLE_STATE_ACTIVE); |
| 101 } | 100 } |
| 101 |
| 102 bool CheckIdleStateIsLocked() { |
| 103 return [g_screenMonitor isScreensaverRunning] || |
| 104 [g_screenMonitor isScreenLocked]; |
| 105 } |
| OLD | NEW |