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

Unified Diff: third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.cpp

Issue 1989363005: Graceful idle callback cancellation with invalid IDs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.cpp
diff --git a/third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.cpp b/third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.cpp
index 9da877cfecfca81f708ff842bd0a5e3ef148fa06..db9a8ed88be87a9b173c5bf4f714649781878d0f 100644
--- a/third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.cpp
+++ b/third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.cpp
@@ -87,9 +87,22 @@ DEFINE_TRACE(ScriptedIdleTaskController)
ActiveDOMObject::trace(visitor);
}
+int ScriptedIdleTaskController::nextCallbackId()
+{
+ while (true) {
+ ++m_nextCallbackId;
+
+ if (!isValidCallbackId(m_nextCallbackId))
+ m_nextCallbackId = 1;
+
+ if (!m_callbacks.contains(m_nextCallbackId))
+ return m_nextCallbackId;
+ }
+}
+
ScriptedIdleTaskController::CallbackId ScriptedIdleTaskController::registerCallback(IdleRequestCallback* callback, const IdleRequestOptions& options)
{
- CallbackId id = ++m_nextCallbackId;
+ CallbackId id = nextCallbackId();
m_callbacks.set(id, callback);
long long timeoutMillis = options.timeout();
@@ -104,6 +117,9 @@ ScriptedIdleTaskController::CallbackId ScriptedIdleTaskController::registerCallb
void ScriptedIdleTaskController::cancelCallback(CallbackId id)
{
TRACE_EVENT_INSTANT1("devtools.timeline", "CancelIdleCallback", TRACE_EVENT_SCOPE_THREAD, "data", InspectorIdleCallbackCancelEvent::data(getExecutionContext(), id));
+ if (!isValidCallbackId(id))
+ return;
+
m_callbacks.remove(id);
}
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698