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

Side by Side Diff: chrome/browser/idle_win.cc

Issue 7038042: win: Let CalculateIdleState() deal better with GetTickCount() wrapping around. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 7 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 IdleState CalculateIdleState(unsigned int idle_threshold) { 13 IdleState CalculateIdleState(unsigned int idle_threshold) {
14 if (IsScreensaverRunning() || IsWorkstationLocked()) 14 if (IsScreensaverRunning() || IsWorkstationLocked())
15 return IDLE_STATE_LOCKED; 15 return IDLE_STATE_LOCKED;
16 16
17 LASTINPUTINFO last_input_info = {0}; 17 LASTINPUTINFO last_input_info = {0};
18 last_input_info.cbSize = sizeof(LASTINPUTINFO); 18 last_input_info.cbSize = sizeof(LASTINPUTINFO);
19 DWORD current_idle_time = 0; 19 DWORD current_idle_time = 0;
20 if (::GetLastInputInfo(&last_input_info)) { 20 if (::GetLastInputInfo(&last_input_info)) {
21 current_idle_time = ::GetTickCount() - last_input_info.dwTime; 21 DWORD now = ::GetTickCount();
22 // Will go -ve if we have been idle for a long time (2gb seconds). 22 if (now < last_input_info.dwTime) {
23 if (current_idle_time < 0) 23 // GetTickCount() wraps around every 49.7 days -- assume it wrapped just
24 current_idle_time = INT_MAX; 24 // once.
25 const DWORD kMaxDWORD = static_cast<DWORD>(-1);
26 DWORD time_before_wrap = kMaxDWORD - last_input_info.dwTime;
27 DWORD time_after_wrap = now;
28 // The sum is always smaller than kMaxDWORD.
29 current_idle_time = time_before_wrap + time_after_wrap;
30 } else {
31 current_idle_time = now - last_input_info.dwTime;
32 }
33
25 // Convert from ms to seconds. 34 // Convert from ms to seconds.
26 current_idle_time /= 1000; 35 current_idle_time /= 1000;
27 } 36 }
28 37
29 if (current_idle_time >= idle_threshold) 38 if (current_idle_time >= idle_threshold)
30 return IDLE_STATE_IDLE; 39 return IDLE_STATE_IDLE;
31 return IDLE_STATE_ACTIVE; 40 return IDLE_STATE_ACTIVE;
32 } 41 }
33 42
34 bool IsScreensaverRunning() { 43 bool IsScreensaverRunning() {
(...skipping 13 matching lines...) Expand all
48 UOI_NAME, 57 UOI_NAME,
49 name, 58 name,
50 sizeof(name), 59 sizeof(name),
51 &needed)) { 60 &needed)) {
52 is_locked = lstrcmpi(name, L"default") != 0; 61 is_locked = lstrcmpi(name, L"default") != 0;
53 } 62 }
54 ::CloseDesktop(input_desk); 63 ::CloseDesktop(input_desk);
55 } 64 }
56 return is_locked; 65 return is_locked;
57 } 66 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698