Bug 803039 - Correct the logic of finding user activity in IdleTimerCallback (fixes bug 811459). r=jlebar
authorShelly Lin <slin@mozilla.com>
Mon, 03 Dec 2012 10:21:00 +0800
changeset 115145 f3ef58ba9e55d4ce808150ea8d469861c3067cf0
parent 115144 4998bde6d220408a28a65e767ef0f68939afa9e1
child 115146 20e8cde489bae20822b1ded0b64fedac1d3f8fd3
push id23973
push useremorley@mozilla.com
push dateThu, 06 Dec 2012 10:04:18 +0000
treeherdermozilla-central@ddda5400c826 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlebar
bugs803039, 811459
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 803039 - Correct the logic of finding user activity in IdleTimerCallback (fixes bug 811459). r=jlebar
widget/xpwidgets/nsIdleService.cpp
--- a/widget/xpwidgets/nsIdleService.cpp
+++ b/widget/xpwidgets/nsIdleService.cpp
@@ -642,16 +642,19 @@ nsIdleService::StaticIdleTimerCallback(n
 }
 
 void
 nsIdleService::IdleTimerCallback(void)
 {
   // Remember that we no longer have a timer running.
   mCurrentlySetToTimeoutAt = TimeStamp();
 
+  // Find the last detected idle time.
+  uint32_t lastIdleTimeInMS = static_cast<uint32_t>((TimeStamp::Now() -
+                              mLastUserInteraction).ToMilliseconds());
   // Get the current idle time.
   uint32_t currentIdleTimeInMS;
 
   if (NS_FAILED(GetIdleTime(&currentIdleTimeInMS))) {
     PR_LOG(sLog, PR_LOG_ALWAYS,
            ("idleService: Idle timer callback: failed to get idle time"));
 #ifdef ANDROID
     __android_log_print(ANDROID_LOG_INFO, "IdleService",
@@ -666,20 +669,18 @@ nsIdleService::IdleTimerCallback(void)
 #ifdef ANDROID
   __android_log_print(ANDROID_LOG_INFO, "IdleService",
                       "Idle timer callback: current idle time %u msec",
                       currentIdleTimeInMS);
 #endif
 
   // Check if we have had some user interaction we didn't handle previously
   // we do the calculation in ms to lessen the chance for rounding errors to
-  // trigger wrong results, it is also very important that we call PR_Now AFTER
-  // the call to GetIdleTime().
-  TimeDuration aIdleTime = TimeStamp::Now() - mLastUserInteraction;
-  if (aIdleTime.ToMilliseconds() > currentIdleTimeInMS)
+  // trigger wrong results.
+  if (lastIdleTimeInMS > currentIdleTimeInMS)
   {
     // We had user activity, so handle that part first (to ensure the listeners
     // don't risk getting an non-idle after they get a new idle indication.
     ResetIdleTimeOut(currentIdleTimeInMS);
 
     // NOTE: We can't bail here, as we might have something already timed out.
   }
 
@@ -793,17 +794,17 @@ nsIdleService::SetTimerExpiryIfBefore(Ti
       mCurrentlySetToTimeoutAt = currentTime;
     }
 
     // Add 10 ms to ensure we don't undershoot, and never get a "0" timer.
     mCurrentlySetToTimeoutAt += TimeDuration::FromMilliseconds(10);
 
     TimeDuration deltaTime = mCurrentlySetToTimeoutAt - currentTime;
     PR_LOG(sLog, PR_LOG_DEBUG,
-           ("idleService: IdleService", "reset timer expiry to %0.f msec from now",
+           ("idleService: IdleService reset timer expiry to %0.f msec from now",
             deltaTime.ToMilliseconds()));
 #ifdef ANDROID
     __android_log_print(ANDROID_LOG_INFO, "IdleService",
                         "reset timer expiry to %0.f msec from now",
                         deltaTime.ToMilliseconds());
 #endif
 
     // Start the timer