Bug 800838 - remove unnecessary delay when unscheduling plugin timers r=blassey

This commit is contained in:
James Willcox
2012-12-17 10:05:49 -05:00
parent 44e25027c4
commit 98a6bb545f
2 changed files with 6 additions and 28 deletions

View File

@@ -1379,35 +1379,13 @@ nsNPAPIPluginInstance::PrivateModeStateChanged(bool enabled)
return NS_ERROR_FAILURE;
PluginDestructionGuard guard(this);
NPError error;
NPBool value = static_cast<NPBool>(enabled);
NS_TRY_SAFE_CALL_RETURN(error, (*pluginFunctions->setvalue)(&mNPP, NPNVprivateModeBool, &value), this);
return (error == NPERR_NO_ERROR) ? NS_OK : NS_ERROR_FAILURE;
}
class DelayUnscheduleEvent : public nsRunnable {
public:
nsRefPtr<nsNPAPIPluginInstance> mInstance;
uint32_t mTimerID;
DelayUnscheduleEvent(nsNPAPIPluginInstance* aInstance, uint32_t aTimerId)
: mInstance(aInstance)
, mTimerID(aTimerId)
{}
~DelayUnscheduleEvent() {}
NS_IMETHOD Run();
};
NS_IMETHODIMP
DelayUnscheduleEvent::Run()
{
mInstance->UnscheduleTimer(mTimerID);
return NS_OK;
}
static void
PluginTimerCallback(nsITimer *aTimer, void *aClosure)
{
@@ -1433,8 +1411,8 @@ PluginTimerCallback(nsITimer *aTimer, void *aClosure)
// use UnscheduleTimer to clean up if this is a one-shot timer
uint32_t timerType;
t->timer->GetType(&timerType);
if (timerType == nsITimer::TYPE_ONE_SHOT)
inst->UnscheduleTimer(id);
if (t->needUnschedule || timerType == nsITimer::TYPE_ONE_SHOT)
inst->UnscheduleTimer(id);
}
nsNPAPITimer*
@@ -1459,7 +1437,7 @@ nsNPAPIPluginInstance::ScheduleTimer(uint32_t interval, NPBool repeat, void (*ti
nsNPAPITimer *newTimer = new nsNPAPITimer();
newTimer->inCallback = false;
newTimer->inCallback = newTimer->needUnschedule = false;
newTimer->npp = &mNPP;
// generate ID that is unique to this instance
@@ -1498,8 +1476,7 @@ nsNPAPIPluginInstance::UnscheduleTimer(uint32_t timerID)
return;
if (t->inCallback) {
nsCOMPtr<nsIRunnable> e = new DelayUnscheduleEvent(this, timerID);
NS_DispatchToCurrentThread(e);
t->needUnschedule = true;
return;
}