Bug 472258 - Reinitializing one-shot timers by resetting delay (->SetDelay) doesn't work anymore - fix callers; r+sr=bzbarsky

This commit is contained in:
Nickolay_Ponomarev 2009-02-03 15:42:21 +01:00
parent c0f2dadc80
commit e729d0aede
4 changed files with 23 additions and 12 deletions

View File

@ -986,6 +986,8 @@ mozJSComponentLoader::StartFastLoad(nsIFastLoadService *flSvc)
kFastLoadWriteDelay,
nsITimer::TYPE_ONE_SHOT);
} else {
// Note, that since CloseFastLoad nulls out mFastLoadTimer,
// SetDelay() will only be called on a timer that hasn't fired.
rv = mFastLoadTimer->SetDelay(kFastLoadWriteDelay);
}

View File

@ -79,9 +79,9 @@ interface nsITimerCallback : nsISupports
/**
* nsITimer instances must be initialized by calling one of the "init" methods
* documented below. You may also re-initialize an existing instance with new
* delay to avoid the overhead of destroying and creating a timer. It is not
* necessary to cancel the timer in that case.
* documented below. You may also re-initialize (using one of the init()
* methods) an existing instance to avoid the overhead of destroying and
* creating a timer. It is not necessary to cancel the timer in that case.
*/
[scriptable, uuid(193fc37a-8aa4-4d29-aa57-1acd87c26b66)]
interface nsITimer : nsISupports
@ -170,12 +170,16 @@ interface nsITimer : nsISupports
void cancel();
/**
* The millisecond delay of the timeout
* The millisecond delay of the timeout.
*
* NOTE: Re-setting the delay on a one-shot timer that has already fired
* doesn't restart the timer. Call one of the init() methods to restart
* a one-shot timer.
*/
attribute unsigned long delay;
/**
* The timer type : one shot or repeating
* The timer type - one of the above TYPE_* constants.
*/
attribute unsigned long type;

View File

@ -292,6 +292,14 @@ NS_IMETHODIMP nsTimerImpl::Cancel()
NS_IMETHODIMP nsTimerImpl::SetDelay(PRUint32 aDelay)
{
if (mCallbackType == CALLBACK_TYPE_UNKNOWN && mType == TYPE_ONE_SHOT) {
// This may happen if someone tries to re-use a one-shot timer
// by re-setting delay instead of reinitializing the timer.
NS_ERROR("nsITimer->SetDelay() called when the "
"one-shot timer is not set up.");
return NS_ERROR_NOT_INITIALIZED;
}
// If we're already repeating precisely, update mTimeout now so that the
// new delay takes effect in the future.
if (mTimeout != 0 && mType == TYPE_REPEATING_PRECISE)

View File

@ -572,19 +572,16 @@ nsWebShellWindow::SetPersistenceTimer(PRUint32 aDirtyFlags)
return;
PR_Lock(mSPTimerLock);
if (mSPTimer) {
mSPTimer->SetDelay(SIZE_PERSISTENCE_TIMEOUT);
PersistentAttributesDirty(aDirtyFlags);
} else {
if (!mSPTimer) {
nsresult rv;
mSPTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
if (NS_SUCCEEDED(rv)) {
NS_ADDREF_THIS(); // for the timer, which holds a reference to this window
mSPTimer->InitWithFuncCallback(FirePersistenceTimer, this,
SIZE_PERSISTENCE_TIMEOUT, nsITimer::TYPE_ONE_SHOT);
PersistentAttributesDirty(aDirtyFlags);
}
}
mSPTimer->InitWithFuncCallback(FirePersistenceTimer, this,
SIZE_PERSISTENCE_TIMEOUT, nsITimer::TYPE_ONE_SHOT);
PersistentAttributesDirty(aDirtyFlags);
PR_Unlock(mSPTimerLock);
}