Chromium Code Reviews| Index: chrome/browser/idle_win.cc |
| diff --git a/chrome/browser/idle_win.cc b/chrome/browser/idle_win.cc |
| index 01afca083998508b41f15277970d008063ec1383..474a8305eea2c797641fb06e8f246d33390bd173 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_after_wrap + time_after_wrap; |
|
brettw
2011/05/21 20:25:53
I think you mean time_before_wrap + time_after_wra
Nico
2011/05/21 21:17:58
!! Done.
|
| + } else { |
| + current_idle_time = now - last_input_info.dwTime; |
| + } |
| + |
| // Convert from ms to seconds. |
| current_idle_time /= 1000; |
| } |