зеркало из https://github.com/mozilla/gecko-dev.git
Bug 564118 - Waking up every second due to IdleService. r=MikeK a=blocking-fennec
This commit is contained in:
Родитель
984b79bca9
Коммит
1686e61067
|
@ -55,6 +55,10 @@ interface nsIIdleService : nsISupports
|
|||
/**
|
||||
* The amount of time in milliseconds that has passed
|
||||
* since the last user activity.
|
||||
*
|
||||
* If we do not have a valid idle time to report, 0 is returned
|
||||
* (this can happen if the user never interacted with the browser
|
||||
* at all, and if we are also unable to poll for idle time manually).
|
||||
*/
|
||||
readonly attribute unsigned long idleTime;
|
||||
|
||||
|
|
|
@ -179,7 +179,9 @@ nsIdleServiceDaily::DailyCallback(nsITimer* aTimer, void* aClosure)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// nsIdleService
|
||||
|
||||
nsIdleService::nsIdleService() : mLastIdleReset(0), mLastHandledActivity(0)
|
||||
nsIdleService::nsIdleService() : mLastIdleReset(0)
|
||||
, mLastHandledActivity(0)
|
||||
, mPolledIdleTimeIsValid(false)
|
||||
{
|
||||
mDailyIdle = new nsIdleServiceDaily(this);
|
||||
}
|
||||
|
@ -239,13 +241,18 @@ nsIdleService::RemoveIdleObserver(nsIObserver* aObserver, PRUint32 aTime)
|
|||
void
|
||||
nsIdleService::ResetIdleTimeOut()
|
||||
{
|
||||
mLastIdleReset = PR_IntervalToSeconds(PR_IntervalNow());
|
||||
// A zero in mLastIdleReset indicates that this function has never been
|
||||
// called.
|
||||
bool calledBefore = mLastIdleReset != 0;
|
||||
mLastIdleReset = PR_IntervalToSeconds(PR_IntervalNow());
|
||||
if (!mLastIdleReset) mLastIdleReset = 1;
|
||||
|
||||
// Now check if this changes anything
|
||||
CheckAwayState(true);
|
||||
// Note that if we have never been called before, we cannot do the
|
||||
// optimization of passing true to CheckAwayState, which avoids
|
||||
// calculating the timer (because if we have never been called before,
|
||||
// we need to recalculate the timer and start it there).
|
||||
CheckAwayState(calledBefore);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -258,12 +265,11 @@ nsIdleService::GetIdleTime(PRUint32* idleTime)
|
|||
|
||||
// Polled idle time in ms
|
||||
PRUint32 polledIdleTimeMS;
|
||||
bool polledIdleTimeIsValid;
|
||||
|
||||
polledIdleTimeIsValid = PollIdleTime(&polledIdleTimeMS);
|
||||
mPolledIdleTimeIsValid = PollIdleTime(&polledIdleTimeMS);
|
||||
|
||||
// If we don't have any valid data, then we are not in idle - pr. definition.
|
||||
if (!polledIdleTimeIsValid && 0 == mLastIdleReset) {
|
||||
if (!mPolledIdleTimeIsValid && 0 == mLastIdleReset) {
|
||||
*idleTime = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -279,7 +285,7 @@ nsIdleService::GetIdleTime(PRUint32* idleTime)
|
|||
PR_IntervalToSeconds(PR_IntervalNow()) - mLastIdleReset;
|
||||
|
||||
// If we did't get pulled data, return the time since last idle reset.
|
||||
if (!polledIdleTimeIsValid) {
|
||||
if (!mPolledIdleTimeIsValid) {
|
||||
// We need to convert to ms before returning the time.
|
||||
*idleTime = timeSinceReset * 1000;
|
||||
return NS_OK;
|
||||
|
@ -329,6 +335,11 @@ nsIdleService::CheckAwayState(bool aNoTimeReset)
|
|||
return;
|
||||
}
|
||||
|
||||
// If we have no valid data about the idle time, stop
|
||||
if (!mPolledIdleTimeIsValid && 0 == mLastIdleReset) {
|
||||
return;
|
||||
}
|
||||
|
||||
// GetIdleTime returns the time in ms, internally we only calculate in s.
|
||||
idleTime /= 1000;
|
||||
|
||||
|
|
|
@ -215,6 +215,12 @@ private:
|
|||
* Callback function that is called when the internal timer expires.
|
||||
*/
|
||||
static void IdleTimerCallback(nsITimer* aTimer, void* aClosure);
|
||||
|
||||
/**
|
||||
* Whether the idle time calculated in the last call to GetIdleTime is
|
||||
* actually valid (see nsIdleService.idl - we return 0 when it isn't).
|
||||
*/
|
||||
bool mPolledIdleTimeIsValid;
|
||||
};
|
||||
|
||||
#endif // nsIdleService_h__
|
||||
|
|
Загрузка…
Ссылка в новой задаче