зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1371664 P4 Remove old TimeoutManager code that adjusted Timeout::When() while in background. r=ehsan
This commit is contained in:
Родитель
2771b377cb
Коммит
a3c8156b38
|
@ -54,7 +54,6 @@ Timeout::SetWhenOrTimeRemaining(const TimeStamp& aBaseTime,
|
|||
if (mWindow->IsFrozen()) {
|
||||
mWhen = TimeStamp();
|
||||
mTimeRemaining = aDelay;
|
||||
mScheduledDelay = TimeDuration(0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -63,7 +62,6 @@ Timeout::SetWhenOrTimeRemaining(const TimeStamp& aBaseTime,
|
|||
// that it appears time passes while suspended.
|
||||
mWhen = aBaseTime + aDelay;
|
||||
mTimeRemaining = TimeDuration(0);
|
||||
mScheduledDelay = aDelay;
|
||||
}
|
||||
|
||||
const TimeStamp&
|
||||
|
@ -84,12 +82,5 @@ Timeout::TimeRemaining() const
|
|||
return mTimeRemaining;
|
||||
}
|
||||
|
||||
const TimeDuration&
|
||||
Timeout::ScheduledDelay() const
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(!mWhen.IsNull());
|
||||
return mScheduledDelay;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -50,9 +50,6 @@ public:
|
|||
// Can only be called when frozen.
|
||||
const TimeDuration& TimeRemaining() const;
|
||||
|
||||
// Can only be called when not frozen.
|
||||
const TimeDuration& ScheduledDelay() const;
|
||||
|
||||
// Window for which this timeout fires
|
||||
RefPtr<nsGlobalWindow> mWindow;
|
||||
|
||||
|
@ -101,10 +98,6 @@ private:
|
|||
// Remaining time to wait. Used only when timeouts are frozen.
|
||||
TimeDuration mTimeRemaining;
|
||||
|
||||
// The actual interval in milliseconds. This may be throttled to
|
||||
// a longer delay than mInterval for a number of reasons.
|
||||
TimeDuration mScheduledDelay;
|
||||
|
||||
~Timeout() = default;
|
||||
};
|
||||
|
||||
|
|
|
@ -146,6 +146,9 @@ const uint32_t TimeoutManager::InvalidFiringId = 0;
|
|||
bool
|
||||
TimeoutManager::IsBackground() const
|
||||
{
|
||||
// Don't use the background timeout value when the tab is playing audio.
|
||||
// Until bug 1336484 we only used to do this for pages that use Web Audio.
|
||||
// The original behavior was implemented in bug 11811073.
|
||||
return !mWindow.AsInner()->IsPlayingAudio() && mWindow.IsBackgroundInternal();
|
||||
}
|
||||
|
||||
|
@ -227,15 +230,9 @@ TimeoutManager::IsInvalidFiringId(uint32_t aFiringId) const
|
|||
|
||||
int32_t
|
||||
TimeoutManager::DOMMinTimeoutValue(bool aIsTracking) const {
|
||||
// Don't use the background timeout value when the tab is playing audio.
|
||||
// Until bug 1336484 we only used to do this for pages that use Web Audio.
|
||||
// The original behavior was implemented in bug 11811073.
|
||||
bool isBackground = IsBackground();
|
||||
bool throttleTracking = aIsTracking && mThrottleTrackingTimeouts;
|
||||
auto minValue = throttleTracking ? (isBackground ? gMinTrackingBackgroundTimeoutValue
|
||||
: gMinTrackingTimeoutValue)
|
||||
: (isBackground ? gMinBackgroundTimeoutValue
|
||||
: gMinTimeoutValue);
|
||||
auto minValue = throttleTracking ? gMinTrackingTimeoutValue
|
||||
: gMinTimeoutValue;
|
||||
return minValue;
|
||||
}
|
||||
|
||||
|
@ -418,7 +415,6 @@ TimeoutManager::SetTimeout(nsITimeoutHandler* aHandler,
|
|||
uint32_t nestingLevel = sNestingLevel + 1;
|
||||
uint32_t realInterval = interval;
|
||||
if (aIsInterval || nestingLevel >= DOM_CLAMP_TIMEOUT_NESTING_LEVEL ||
|
||||
mWindow.IsBackgroundInternal() ||
|
||||
timeout->mIsTracking) {
|
||||
// Don't allow timeouts less than DOMMinTimeoutValue() from
|
||||
// now...
|
||||
|
@ -486,7 +482,7 @@ TimeoutManager::SetTimeout(nsITimeoutHandler* aHandler,
|
|||
mThrottleTrackingTimeouts ? "yes"
|
||||
: (mThrottleTrackingTimeoutsTimer ?
|
||||
"pending" : "no"),
|
||||
int(mWindow.IsBackgroundInternal()), realInterval,
|
||||
int(IsBackground()), realInterval,
|
||||
timeout->mIsTracking ? "" : "non-",
|
||||
timeout->mTimeoutId));
|
||||
|
||||
|
@ -838,126 +834,6 @@ TimeoutManager::RescheduleTimeout(Timeout* aTimeout, const TimeStamp& now)
|
|||
return true;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimeoutManager::ResetTimersForThrottleReduction()
|
||||
{
|
||||
return ResetTimersForThrottleReduction(gMinBackgroundTimeoutValue);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimeoutManager::ResetTimersForThrottleReduction(int32_t aPreviousThrottleDelayMS)
|
||||
{
|
||||
MOZ_ASSERT(aPreviousThrottleDelayMS > 0);
|
||||
|
||||
MOZ_ASSERT_IF(mWindow.IsFrozen(), mWindow.IsSuspended());
|
||||
if (mWindow.IsSuspended()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = mNormalTimeouts.ResetTimersForThrottleReduction(aPreviousThrottleDelayMS,
|
||||
*this,
|
||||
Timeouts::SortBy::TimeWhen);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = mTrackingTimeouts.ResetTimersForThrottleReduction(aPreviousThrottleDelayMS,
|
||||
*this,
|
||||
Timeouts::SortBy::TimeWhen);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
OrderedTimeoutIterator iter(mNormalTimeouts, mTrackingTimeouts);
|
||||
Timeout* firstTimeout = iter.Next();
|
||||
if (firstTimeout) {
|
||||
rv = mExecutor->MaybeSchedule(firstTimeout->When(), MinSchedulingDelay());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimeoutManager::Timeouts::ResetTimersForThrottleReduction(int32_t aPreviousThrottleDelayMS,
|
||||
const TimeoutManager& aTimeoutManager,
|
||||
SortBy aSortBy)
|
||||
{
|
||||
TimeStamp now = TimeStamp::Now();
|
||||
|
||||
for (RefPtr<Timeout> timeout = GetFirst(); timeout; ) {
|
||||
// Skip over any Timeout values with a valid FiringId. These are in the
|
||||
// middle of a RunTimeout and should not be modified. Also, skip any
|
||||
// timeouts in the past. It's important that this check be <= so that we
|
||||
// guarantee that taking std::max with |now| won't make a quantity equal to
|
||||
// timeout->When() below.
|
||||
if (mManager.IsValidFiringId(timeout->mFiringId) ||
|
||||
timeout->When() <= now) {
|
||||
timeout = timeout->getNext();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (timeout->When() - now >
|
||||
TimeDuration::FromMilliseconds(aPreviousThrottleDelayMS)) {
|
||||
// No need to loop further. Timeouts are sorted in When() order
|
||||
// and the ones after this point were all set up for at least
|
||||
// gMinBackgroundTimeoutValue ms and hence were not clamped.
|
||||
break;
|
||||
}
|
||||
|
||||
// We reduced our throttled delay. Re-init the timer appropriately.
|
||||
// Compute the interval the timer should have had if it had not been set in a
|
||||
// background window
|
||||
TimeDuration interval =
|
||||
TimeDuration::FromMilliseconds(
|
||||
std::max(timeout->mInterval,
|
||||
uint32_t(aTimeoutManager.
|
||||
DOMMinTimeoutValue(timeout->mIsTracking))));
|
||||
const TimeDuration& oldInterval = timeout->ScheduledDelay();
|
||||
if (oldInterval > interval) {
|
||||
// unclamp
|
||||
TimeStamp firingTime =
|
||||
std::max(timeout->When() - oldInterval + interval, now);
|
||||
|
||||
NS_ASSERTION(firingTime < timeout->When(),
|
||||
"Our firing time should strictly decrease!");
|
||||
|
||||
TimeDuration delay = firingTime - now;
|
||||
timeout->SetWhenOrTimeRemaining(now, delay);
|
||||
MOZ_DIAGNOSTIC_ASSERT(timeout->When() == firingTime);
|
||||
|
||||
// Since we reset When() we need to move |timeout| to the right
|
||||
// place in the list so that it remains sorted by When().
|
||||
|
||||
// Get the pointer to the next timeout now, before we move the
|
||||
// current timeout in the list.
|
||||
Timeout* nextTimeout = timeout->getNext();
|
||||
|
||||
// Since we are only reducing intervals in this method we can
|
||||
// make an optimization here. If the reduction does not cause us
|
||||
// to fall before our previous timeout then we do not have to
|
||||
// remove and re-insert the current timeout. This is important
|
||||
// because re-insertion makes this algorithm O(n^2). Since we
|
||||
// will typically be shifting a lot of timers at once this
|
||||
// optimization saves us a lot of work.
|
||||
Timeout* prevTimeout = timeout->getPrevious();
|
||||
if (prevTimeout && prevTimeout->When() > timeout->When()) {
|
||||
// It is safe to remove and re-insert because When() is now
|
||||
// strictly smaller than it used to be, so we know we'll insert
|
||||
// |timeout| before nextTimeout.
|
||||
NS_ASSERTION(!nextTimeout ||
|
||||
timeout->When() < nextTimeout->When(), "How did that happen?");
|
||||
timeout->remove();
|
||||
// Insert() will reset mFiringId. Make sure to undo that.
|
||||
uint32_t firingId = timeout->mFiringId;
|
||||
Insert(timeout, aSortBy);
|
||||
timeout->mFiringId = firingId;
|
||||
}
|
||||
|
||||
timeout = nextTimeout;
|
||||
} else {
|
||||
timeout = timeout->getNext();
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
TimeoutManager::ClearAllTimeouts()
|
||||
{
|
||||
|
@ -1170,10 +1046,6 @@ TimeoutManager::Thaw()
|
|||
void
|
||||
TimeoutManager::UpdateBackgroundState()
|
||||
{
|
||||
if (!IsBackground()) {
|
||||
ResetTimersForThrottleReduction();
|
||||
}
|
||||
|
||||
// When the window moves to the background or foreground we should
|
||||
// reschedule the TimeoutExecutor in case the MinSchedulingDelay()
|
||||
// changed. Only do this if the window is not suspended and we
|
||||
|
|
|
@ -55,11 +55,6 @@ public:
|
|||
void ClearAllTimeouts();
|
||||
uint32_t GetTimeoutId(mozilla::dom::Timeout::Reason aReason);
|
||||
|
||||
// When timers are being throttled and we reduce the thottle delay we must
|
||||
// reschedule. The amount of the old throttle delay must be provided in
|
||||
// order to bound how many timers must be examined.
|
||||
nsresult ResetTimersForThrottleReduction();
|
||||
|
||||
int32_t DOMMinTimeoutValue(bool aIsTracking) const;
|
||||
|
||||
// aTimeout is the timeout that we're about to start running. This function
|
||||
|
@ -120,7 +115,6 @@ public:
|
|||
static const uint32_t InvalidFiringId;
|
||||
|
||||
private:
|
||||
nsresult ResetTimersForThrottleReduction(int32_t aPreviousThrottleDelayMS);
|
||||
void MaybeStartThrottleTrackingTimout();
|
||||
|
||||
bool IsBackground() const;
|
||||
|
@ -156,9 +150,6 @@ private:
|
|||
TimeWhen
|
||||
};
|
||||
void Insert(mozilla::dom::Timeout* aTimeout, SortBy aSortBy);
|
||||
nsresult ResetTimersForThrottleReduction(int32_t aPreviousThrottleDelayMS,
|
||||
const TimeoutManager& aTimeoutManager,
|
||||
SortBy aSortBy);
|
||||
|
||||
const Timeout* GetFirst() const { return mTimeoutList.getFirst(); }
|
||||
Timeout* GetFirst() { return mTimeoutList.getFirst(); }
|
||||
|
|
Загрузка…
Ссылка в новой задаче