| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/idle.h" | 5 #include "chrome/browser/idle.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 static bool IsScreensaverRunning(); | 10 static bool IsScreensaverRunning(); |
| 11 static bool IsWorkstationLocked(); | 11 static bool IsWorkstationLocked(); |
| 12 | 12 |
| 13 void CalculateIdleState(unsigned int idle_threshold, IdleCallback notify) { | 13 void CalculateIdleState(unsigned int idle_threshold, IdleCallback notify) { |
| 14 if (IsScreensaverRunning() || IsWorkstationLocked()) { | 14 if (CheckIdleStateIsLocked()) { |
| 15 notify.Run(IDLE_STATE_LOCKED); | 15 notify.Run(IDLE_STATE_LOCKED); |
| 16 return; | 16 return; |
| 17 } | 17 } |
| 18 | 18 |
| 19 LASTINPUTINFO last_input_info = {0}; | 19 LASTINPUTINFO last_input_info = {0}; |
| 20 last_input_info.cbSize = sizeof(LASTINPUTINFO); | 20 last_input_info.cbSize = sizeof(LASTINPUTINFO); |
| 21 DWORD current_idle_time = 0; | 21 DWORD current_idle_time = 0; |
| 22 if (::GetLastInputInfo(&last_input_info)) { | 22 if (::GetLastInputInfo(&last_input_info)) { |
| 23 DWORD now = ::GetTickCount(); | 23 DWORD now = ::GetTickCount(); |
| 24 if (now < last_input_info.dwTime) { | 24 if (now < last_input_info.dwTime) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 UOI_NAME, | 60 UOI_NAME, |
| 61 name, | 61 name, |
| 62 sizeof(name), | 62 sizeof(name), |
| 63 &needed)) { | 63 &needed)) { |
| 64 is_locked = lstrcmpi(name, L"default") != 0; | 64 is_locked = lstrcmpi(name, L"default") != 0; |
| 65 } | 65 } |
| 66 ::CloseDesktop(input_desk); | 66 ::CloseDesktop(input_desk); |
| 67 } | 67 } |
| 68 return is_locked; | 68 return is_locked; |
| 69 } | 69 } |
| 70 |
| 71 bool CheckIdleStateIsLocked() { |
| 72 return IsWorkstationLocked() || IsScreensaverRunning(); |
| 73 } |
| OLD | NEW |