Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1143)

Unified Diff: Source/core/page/DOMTimer.cpp

Issue 19494002: Distinguish actions registered with setTimeout() and setInterval(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix test, and add a new test. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/page/DOMTimer.cpp
diff --git a/Source/core/page/DOMTimer.cpp b/Source/core/page/DOMTimer.cpp
index 08a9ba99912a79b687581192168a7210dba4b0fd..908dade80a61f4909cff299329835e2ce2b918e6 100644
--- a/Source/core/page/DOMTimer.cpp
+++ b/Source/core/page/DOMTimer.cpp
@@ -69,21 +69,22 @@ double DOMTimer::visiblePageAlignmentInterval()
return 0;
}
-int DOMTimer::install(ScriptExecutionContext* context, PassOwnPtr<ScheduledAction> action, int timeout, bool singleShot)
+int DOMTimer::install(ScriptExecutionContext* context, TimerType timerType, PassOwnPtr<ScheduledAction> action, int timeout)
{
- int timeoutID = context->installNewTimeout(action, timeout, singleShot);
- InspectorInstrumentation::didInstallTimer(context, timeoutID, timeout, singleShot);
+ int timeoutID = context->installNewTimeout(timerType, action, timeout);
+ InspectorInstrumentation::didInstallTimer(context, timeoutID, timeout, timerType == TimerTypeTimeout); // FIXME: Fix inspector so it can accept a TimerType value.
return timeoutID;
}
-void DOMTimer::removeByID(ScriptExecutionContext* context, int timeoutID)
+void DOMTimer::removeByIDIfTypeMatches(ScriptExecutionContext* context, TimerType timerType, int timeoutID)
{
- context->removeTimeoutByID(timeoutID);
- InspectorInstrumentation::didRemoveTimer(context, timeoutID);
+ context->removeTimeoutByIDIfTypeMatches(timerType, timeoutID);
+ InspectorInstrumentation::didRemoveTimer(context, timeoutID == TimerTypeTimeout); // FIXME: Ditto.
Ken Russell (switch to Gerrit) 2013/07/18 19:05:13 Shouldn't didRemoveTimer only be called if ScriptE
Yuta Kitamura 2013/07/19 05:14:08 Sounds like a good idea, but when I tried locally,
Ken Russell (switch to Gerrit) 2013/07/19 20:28:36 Yes, thanks for trying to make the change. Sounds
}
-DOMTimer::DOMTimer(ScriptExecutionContext* context, PassOwnPtr<ScheduledAction> action, int interval, bool singleShot, int timeoutID)
+DOMTimer::DOMTimer(ScriptExecutionContext* context, TimerType timerType, PassOwnPtr<ScheduledAction> action, int interval, int timeoutID)
: SuspendableTimer(context)
+ , m_timerType(timerType)
, m_timeoutID(timeoutID)
, m_nestingLevel(timerNestingLevel + 1)
, m_action(action)
@@ -95,10 +96,14 @@ DOMTimer::DOMTimer(ScriptExecutionContext* context, PassOwnPtr<ScheduledAction>
double intervalMilliseconds = max(oneMillisecond, interval * oneMillisecond);
if (intervalMilliseconds < minimumInterval && m_nestingLevel >= maxTimerNestingLevel)
intervalMilliseconds = minimumInterval;
- if (singleShot)
+ switch (timerType) {
+ case TimerTypeTimeout:
startOneShot(intervalMilliseconds);
- else
+ break;
+ case TimerTypeInterval:
startRepeating(intervalMilliseconds);
+ break;
+ }
}
DOMTimer::~DOMTimer()
@@ -110,6 +115,11 @@ int DOMTimer::timeoutID() const
return m_timeoutID;
}
+DOMTimer::TimerType DOMTimer::timerType() const
+{
+ return m_timerType;
+}
+
void DOMTimer::fired()
{
ScriptExecutionContext* context = scriptExecutionContext();
@@ -140,7 +150,7 @@ void DOMTimer::fired()
OwnPtr<ScheduledAction> action = m_action.release();
// This timer is being deleted; no access to member variables allowed after this point.
- context->removeTimeoutByID(m_timeoutID);
+ context->removeTimeoutByIDIfTypeMatches(m_timerType, m_timeoutID);
action->execute(context);

Powered by Google App Engine
This is Rietveld 408576698