mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Backout ed6074493479 Bug 803039
This commit is contained in:
parent
5cf9bf0408
commit
9ae506acc4
@ -381,10 +381,10 @@ nsIdleService::GetInstance()
|
|||||||
return instance.forget();
|
return instance.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsIdleService::nsIdleService() : mCurrentlySetToTimeoutAt(TimeStamp()),
|
nsIdleService::nsIdleService() : mCurrentlySetToTimeoutAtInPR(0),
|
||||||
mAnyObserverIdle(false),
|
mAnyObserverIdle(false),
|
||||||
mDeltaToNextIdleSwitchInS(UINT32_MAX),
|
mDeltaToNextIdleSwitchInS(UINT32_MAX),
|
||||||
mLastUserInteraction(TimeStamp::Now())
|
mLastUserInteractionInPR(PR_Now())
|
||||||
{
|
{
|
||||||
#ifdef PR_LOGGING
|
#ifdef PR_LOGGING
|
||||||
if (sLog == NULL)
|
if (sLog == NULL)
|
||||||
@ -507,8 +507,7 @@ nsIdleService::ResetIdleTimeOut(uint32_t idleDeltaInMS)
|
|||||||
idleDeltaInMS));
|
idleDeltaInMS));
|
||||||
|
|
||||||
// Store the time
|
// Store the time
|
||||||
mLastUserInteraction = TimeStamp::Now() -
|
mLastUserInteractionInPR = PR_Now() - (idleDeltaInMS * PR_USEC_PER_MSEC);
|
||||||
TimeDuration::FromMilliseconds(idleDeltaInMS);
|
|
||||||
|
|
||||||
// If no one is idle, then we are done, any existing timers can keep running.
|
// If no one is idle, then we are done, any existing timers can keep running.
|
||||||
if (!mAnyObserverIdle) {
|
if (!mAnyObserverIdle) {
|
||||||
@ -595,8 +594,8 @@ nsIdleService::GetIdleTime(uint32_t* idleTime)
|
|||||||
polledIdleTimeMS, polledIdleTimeIsValid));
|
polledIdleTimeMS, polledIdleTimeIsValid));
|
||||||
|
|
||||||
// timeSinceReset is in milliseconds.
|
// timeSinceReset is in milliseconds.
|
||||||
TimeDuration timeSinceReset = TimeStamp::Now() - mLastUserInteraction;
|
uint32_t timeSinceResetInMS = (PR_Now() - mLastUserInteractionInPR) /
|
||||||
uint32_t timeSinceResetInMS = timeSinceReset.ToMilliseconds();
|
PR_USEC_PER_MSEC;
|
||||||
|
|
||||||
PR_LOG(sLog, PR_LOG_DEBUG,
|
PR_LOG(sLog, PR_LOG_DEBUG,
|
||||||
("idleService: Get idle time: time since reset %u msec",
|
("idleService: Get idle time: time since reset %u msec",
|
||||||
@ -645,7 +644,7 @@ void
|
|||||||
nsIdleService::IdleTimerCallback(void)
|
nsIdleService::IdleTimerCallback(void)
|
||||||
{
|
{
|
||||||
// Remember that we no longer have a timer running.
|
// Remember that we no longer have a timer running.
|
||||||
mCurrentlySetToTimeoutAt = TimeStamp();
|
mCurrentlySetToTimeoutAtInPR = 0;
|
||||||
|
|
||||||
// Get the current idle time.
|
// Get the current idle time.
|
||||||
uint32_t currentIdleTimeInMS;
|
uint32_t currentIdleTimeInMS;
|
||||||
@ -673,8 +672,8 @@ nsIdleService::IdleTimerCallback(void)
|
|||||||
// we do the calculation in ms to lessen the chance for rounding errors to
|
// 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
|
// trigger wrong results, it is also very important that we call PR_Now AFTER
|
||||||
// the call to GetIdleTime().
|
// the call to GetIdleTime().
|
||||||
TimeDuration aIdleTime = TimeStamp::Now() - mLastUserInteraction;
|
if (((PR_Now() - mLastUserInteractionInPR) / PR_USEC_PER_MSEC) >
|
||||||
if (aIdleTime.ToMilliseconds() > currentIdleTimeInMS)
|
currentIdleTimeInMS)
|
||||||
{
|
{
|
||||||
// We had user activity, so handle that part first (to ensure the listeners
|
// 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.
|
// don't risk getting an non-idle after they get a new idle indication.
|
||||||
@ -760,16 +759,15 @@ nsIdleService::IdleTimerCallback(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsIdleService::SetTimerExpiryIfBefore(TimeStamp aNextTimeout)
|
nsIdleService::SetTimerExpiryIfBefore(PRTime aNextTimeoutInPR)
|
||||||
{
|
{
|
||||||
TimeDuration nextTimeoutDuration = aNextTimeout - TimeStamp::Now();
|
|
||||||
PR_LOG(sLog, PR_LOG_DEBUG,
|
PR_LOG(sLog, PR_LOG_DEBUG,
|
||||||
("idleService: SetTimerExpiryIfBefore: next timeout %0.f msec from now",
|
("idleService: SetTimerExpiryIfBefore: next timeout %lld usec",
|
||||||
nextTimeoutDuration.ToMilliseconds()));
|
aNextTimeoutInPR));
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
__android_log_print(ANDROID_LOG_INFO, "IdleService",
|
__android_log_print(ANDROID_LOG_INFO, "IdleService",
|
||||||
"SetTimerExpiryIfBefore: next timeout %0.f msec from now",
|
"SetTimerExpiryIfBefore: next timeout %lld usec",
|
||||||
nextTimeoutDuration.ToMilliseconds());
|
aNextTimeoutInPR);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Bail if we don't have a timer service.
|
// Bail if we don't have a timer service.
|
||||||
@ -779,37 +777,41 @@ nsIdleService::SetTimerExpiryIfBefore(TimeStamp aNextTimeout)
|
|||||||
|
|
||||||
// If the new timeout is before the old one or we don't have a timer running,
|
// If the new timeout is before the old one or we don't have a timer running,
|
||||||
// then restart the timer.
|
// then restart the timer.
|
||||||
if (mCurrentlySetToTimeoutAt.IsNull() ||
|
if (mCurrentlySetToTimeoutAtInPR > aNextTimeoutInPR ||
|
||||||
mCurrentlySetToTimeoutAt > aNextTimeout) {
|
!mCurrentlySetToTimeoutAtInPR) {
|
||||||
|
|
||||||
mCurrentlySetToTimeoutAt = aNextTimeout;
|
#if defined(PR_LOGGING) || defined(ANDROID)
|
||||||
|
PRTime oldTimeout = mCurrentlySetToTimeoutAtInPR;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mCurrentlySetToTimeoutAtInPR = aNextTimeoutInPR ;
|
||||||
|
|
||||||
// Stop the current timer (it's ok to try'n stop it, even it isn't running).
|
// Stop the current timer (it's ok to try'n stop it, even it isn't running).
|
||||||
mTimer->Cancel();
|
mTimer->Cancel();
|
||||||
|
|
||||||
// Check that the timeout is actually in the future, otherwise make it so.
|
// Check that the timeout is actually in the future, otherwise make it so.
|
||||||
TimeStamp currentTime = TimeStamp::Now();
|
PRTime currentTimeInPR = PR_Now();
|
||||||
if (currentTime > mCurrentlySetToTimeoutAt) {
|
if (currentTimeInPR > mCurrentlySetToTimeoutAtInPR) {
|
||||||
mCurrentlySetToTimeoutAt = currentTime;
|
mCurrentlySetToTimeoutAtInPR = currentTimeInPR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add 10 ms to ensure we don't undershoot, and never get a "0" timer.
|
// Add 10 ms to ensure we don't undershoot, and never get a "0" timer.
|
||||||
mCurrentlySetToTimeoutAt += TimeDuration::FromMilliseconds(10);
|
mCurrentlySetToTimeoutAtInPR += 10 * PR_USEC_PER_MSEC;
|
||||||
|
|
||||||
TimeDuration deltaTime = mCurrentlySetToTimeoutAt - currentTime;
|
|
||||||
PR_LOG(sLog, PR_LOG_DEBUG,
|
PR_LOG(sLog, PR_LOG_DEBUG,
|
||||||
("idleService: IdleService", "reset timer expiry to %0.f msec from now",
|
("idleService: reset timer expiry from %lld usec to %lld usec",
|
||||||
deltaTime.ToMilliseconds()));
|
oldTimeout, mCurrentlySetToTimeoutAtInPR));
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
__android_log_print(ANDROID_LOG_INFO, "IdleService",
|
__android_log_print(ANDROID_LOG_INFO, "IdleService",
|
||||||
"reset timer expiry to %0.f msec from now",
|
"reset timer expiry from %lld usec to %lld usec",
|
||||||
deltaTime.ToMilliseconds());
|
oldTimeout, mCurrentlySetToTimeoutAtInPR);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Start the timer
|
// Start the timer
|
||||||
mTimer->InitWithFuncCallback(StaticIdleTimerCallback,
|
mTimer->InitWithFuncCallback(StaticIdleTimerCallback,
|
||||||
this,
|
this,
|
||||||
deltaTime.ToMilliseconds(),
|
(mCurrentlySetToTimeoutAtInPR -
|
||||||
|
currentTimeInPR) / PR_USEC_PER_MSEC,
|
||||||
nsITimer::TYPE_ONE_SHOT);
|
nsITimer::TYPE_ONE_SHOT);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -836,26 +838,28 @@ nsIdleService::ReconfigureTimer(void)
|
|||||||
|
|
||||||
// We need to store the current time, so we don't get artifacts from the time
|
// We need to store the current time, so we don't get artifacts from the time
|
||||||
// ticking while we are processing.
|
// ticking while we are processing.
|
||||||
TimeStamp curTime = TimeStamp::Now();
|
PRTime curTimeInPR = PR_Now();
|
||||||
|
|
||||||
TimeStamp nextTimeoutAt = mLastUserInteraction +
|
PRTime nextTimeoutAtInPR = mLastUserInteractionInPR +
|
||||||
TimeDuration::FromSeconds(mDeltaToNextIdleSwitchInS);
|
(((PRTime)mDeltaToNextIdleSwitchInS) *
|
||||||
|
PR_USEC_PER_SEC);
|
||||||
|
|
||||||
TimeDuration nextTimeoutDuration = nextTimeoutAt - curTime;
|
|
||||||
PR_LOG(sLog, PR_LOG_DEBUG,
|
PR_LOG(sLog, PR_LOG_DEBUG,
|
||||||
("idleService: next timeout %0.f msec from now",
|
("idleService: next timeout %lld usec (%u msec from now)",
|
||||||
nextTimeoutDuration.ToMilliseconds()));
|
nextTimeoutAtInPR,
|
||||||
|
(uint32_t)((nextTimeoutAtInPR - curTimeInPR) / PR_USEC_PER_MSEC)));
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
__android_log_print(ANDROID_LOG_INFO, "IdleService",
|
__android_log_print(ANDROID_LOG_INFO, "IdleService",
|
||||||
"next timeout %0.f msec from now",
|
"next timeout %lld usec (%lld msec from now)",
|
||||||
nextTimeoutDuration.ToMilliseconds());
|
nextTimeoutAtInPR,
|
||||||
|
((nextTimeoutAtInPR - curTimeInPR) / PR_USEC_PER_MSEC));
|
||||||
#endif
|
#endif
|
||||||
// Check if we should correct the timeout time because we should poll before.
|
// Check if we should correct the timeout time because we should poll before.
|
||||||
if (mAnyObserverIdle && UsePollMode()) {
|
if (mAnyObserverIdle && UsePollMode()) {
|
||||||
TimeStamp pollTimeout =
|
PRTime pollTimeout = curTimeInPR +
|
||||||
curTime + TimeDuration::FromMilliseconds(MIN_IDLE_POLL_INTERVAL_MSEC);
|
MIN_IDLE_POLL_INTERVAL_MSEC * PR_USEC_PER_MSEC;
|
||||||
|
|
||||||
if (nextTimeoutAt > pollTimeout) {
|
if (nextTimeoutAtInPR > pollTimeout) {
|
||||||
PR_LOG(sLog, PR_LOG_DEBUG,
|
PR_LOG(sLog, PR_LOG_DEBUG,
|
||||||
("idleService: idle observers, reducing timeout to %u msec from now",
|
("idleService: idle observers, reducing timeout to %u msec from now",
|
||||||
MIN_IDLE_POLL_INTERVAL_MSEC));
|
MIN_IDLE_POLL_INTERVAL_MSEC));
|
||||||
@ -864,10 +868,10 @@ nsIdleService::ReconfigureTimer(void)
|
|||||||
"idle observers, reducing timeout to %u msec from now",
|
"idle observers, reducing timeout to %u msec from now",
|
||||||
MIN_IDLE_POLL_INTERVAL_MSEC);
|
MIN_IDLE_POLL_INTERVAL_MSEC);
|
||||||
#endif
|
#endif
|
||||||
nextTimeoutAt = pollTimeout;
|
nextTimeoutAtInPR = pollTimeout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetTimerExpiryIfBefore(nextTimeoutAt);
|
SetTimerExpiryIfBefore(nextTimeoutAtInPR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "nsIIdleService.h"
|
#include "nsIIdleService.h"
|
||||||
#include "nsCategoryCache.h"
|
#include "nsCategoryCache.h"
|
||||||
#include "nsWeakReference.h"
|
#include "nsWeakReference.h"
|
||||||
#include "mozilla/TimeStamp.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class we can use to store an observer with its associated idle time
|
* Class we can use to store an observer with its associated idle time
|
||||||
@ -156,15 +155,15 @@ private:
|
|||||||
*
|
*
|
||||||
* The function might not restart the timer if there is one running currently
|
* The function might not restart the timer if there is one running currently
|
||||||
*
|
*
|
||||||
* @param aNextTimeout
|
* @param aNextTimeoutInPR
|
||||||
* The last absolute time the timer should expire
|
* The last absolute time the timer should expire
|
||||||
*/
|
*/
|
||||||
void SetTimerExpiryIfBefore(mozilla::TimeStamp aNextTimeout);
|
void SetTimerExpiryIfBefore(PRTime aNextTimeoutInPR);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the next timeout time, 0 means timer not running
|
* Stores the next timeout time, 0 means timer not running
|
||||||
*/
|
*/
|
||||||
mozilla::TimeStamp mCurrentlySetToTimeoutAt;
|
PRTime mCurrentlySetToTimeoutAtInPR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mTimer holds the internal timer used by this class to detect when to poll
|
* mTimer holds the internal timer used by this class to detect when to poll
|
||||||
@ -200,7 +199,7 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Absolute value for when the last user interaction took place.
|
* Absolute value for when the last user interaction took place.
|
||||||
*/
|
*/
|
||||||
mozilla::TimeStamp mLastUserInteraction;
|
PRTime mLastUserInteractionInPR;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user