| 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 #include "ui/base/win/lock_state.h" |
| 11 |
| 10 namespace { | 12 namespace { |
| 11 | 13 |
| 12 DWORD CalculateIdleTimeInternal() { | 14 DWORD CalculateIdleTimeInternal() { |
| 13 LASTINPUTINFO last_input_info = {0}; | 15 LASTINPUTINFO last_input_info = {0}; |
| 14 last_input_info.cbSize = sizeof(LASTINPUTINFO); | 16 last_input_info.cbSize = sizeof(LASTINPUTINFO); |
| 15 DWORD current_idle_time = 0; | 17 DWORD current_idle_time = 0; |
| 16 if (::GetLastInputInfo(&last_input_info)) { | 18 if (::GetLastInputInfo(&last_input_info)) { |
| 17 DWORD now = ::GetTickCount(); | 19 DWORD now = ::GetTickCount(); |
| 18 if (now < last_input_info.dwTime) { | 20 if (now < last_input_info.dwTime) { |
| 19 // GetTickCount() wraps around every 49.7 days -- assume it wrapped just | 21 // GetTickCount() wraps around every 49.7 days -- assume it wrapped just |
| (...skipping 14 matching lines...) Expand all Loading... |
| 34 return current_idle_time; | 36 return current_idle_time; |
| 35 } | 37 } |
| 36 | 38 |
| 37 bool IsScreensaverRunning() { | 39 bool IsScreensaverRunning() { |
| 38 DWORD result = 0; | 40 DWORD result = 0; |
| 39 if (::SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &result, 0)) | 41 if (::SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &result, 0)) |
| 40 return result != FALSE; | 42 return result != FALSE; |
| 41 return false; | 43 return false; |
| 42 } | 44 } |
| 43 | 45 |
| 44 bool IsWorkstationLocked() { | |
| 45 bool is_locked = true; | |
| 46 HDESK input_desk = ::OpenInputDesktop(0, 0, GENERIC_READ); | |
| 47 if (input_desk) { | |
| 48 wchar_t name[256] = {0}; | |
| 49 DWORD needed = 0; | |
| 50 if (::GetUserObjectInformation(input_desk, | |
| 51 UOI_NAME, | |
| 52 name, | |
| 53 sizeof(name), | |
| 54 &needed)) { | |
| 55 is_locked = lstrcmpi(name, L"default") != 0; | |
| 56 } | |
| 57 ::CloseDesktop(input_desk); | |
| 58 } | |
| 59 return is_locked; | |
| 60 } | |
| 61 | |
| 62 } // namespace | 46 } // namespace |
| 63 | 47 |
| 64 void CalculateIdleTime(IdleTimeCallback notify) { | 48 void CalculateIdleTime(IdleTimeCallback notify) { |
| 65 notify.Run(static_cast<int>(CalculateIdleTimeInternal())); | 49 notify.Run(static_cast<int>(CalculateIdleTimeInternal())); |
| 66 } | 50 } |
| 67 | 51 |
| 68 bool CheckIdleStateIsLocked() { | 52 bool CheckIdleStateIsLocked() { |
| 69 return IsWorkstationLocked() || IsScreensaverRunning(); | 53 return ui::IsWorkstationLocked() || IsScreensaverRunning(); |
| 70 } | 54 } |
| OLD | NEW |