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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/idle_win.cc
diff --git a/chrome/browser/idle_win.cc b/chrome/browser/idle_win.cc
index 01afca083998508b41f15277970d008063ec1383..712211943e107a2d69e9265787d18a70a87b7900 100644
--- a/chrome/browser/idle_win.cc
+++ b/chrome/browser/idle_win.cc
@@ -18,10 +18,19 @@ IdleState CalculateIdleState(unsigned int idle_threshold) {
last_input_info.cbSize = sizeof(LASTINPUTINFO);
DWORD current_idle_time = 0;
if (::GetLastInputInfo(&last_input_info)) {
- current_idle_time = ::GetTickCount() - last_input_info.dwTime;
- // Will go -ve if we have been idle for a long time (2gb seconds).
- if (current_idle_time < 0)
- current_idle_time = INT_MAX;
+ DWORD now = ::GetTickCount();
+ if (now < last_input_info.dwTime) {
+ // GetTickCount() wraps around every 49.7 days -- assume it wrapped just
+ // once.
+ const DWORD kMaxDWORD = static_cast<DWORD>(-1);
+ DWORD time_before_wrap = kMaxDWORD - last_input_info.dwTime;
+ DWORD time_after_wrap = now;
+ // The sum is always smaller than kMaxDWORD.
+ current_idle_time = time_before_wrap + time_after_wrap;
+ } else {
+ current_idle_time = now - last_input_info.dwTime;
+ }
+
// Convert from ms to seconds.
current_idle_time /= 1000;
}
« 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