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..79b0c7439c9e0f4b3207036557e3c673fc2f3e5c 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 MAX_DWORD = static_cast<DWORD>(-1); |
|
Evan Martin
2011/05/20 21:25:46
kMaxDWORD ?
Nico
2011/05/20 21:31:34
Done.
|
| + DWORD time_before_wrap = MAX_DWORD - last_input_info.dwTime; |
| + DWORD time_after_wrap = now; |
| + // The sum is always smaller than MAX_DWORD. |
| + current_idle_time = time_after_wrap + time_after_wrap; |
| + } else { |
| + current_idle_time = now - last_input_info.dwTime; |
| + } |
| + |
| // Convert from ms to seconds. |
| current_idle_time /= 1000; |
| } |