From 300eff47537fea5c389a3eff1a3421470ad47930 Mon Sep 17 00:00:00 2001 From: Adam Gashlin Date: Sun, 27 May 2018 11:21:49 -0700 Subject: [PATCH] Bug 1458119: Part 1: Use idleDispatch to be independent from a content window. r=mikedeboer When using content.requestIdleCallback(), the idle callback may not be run by the time the content goes away, resulting in a missed send. ChromeUtils.idleDispatch does not have this issue. MozReview-Commit-ID: DdGMr6j80sZ --HG-- extra : rebase_source : 8886a199416e5a526faf6a0895a71fdc9752d555 --- .../content/content-sessionStore.js | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/browser/components/sessionstore/content/content-sessionStore.js b/browser/components/sessionstore/content/content-sessionStore.js index 92c6fab46fae..7345536663ce 100644 --- a/browser/components/sessionstore/content/content-sessionStore.js +++ b/browser/components/sessionstore/content/content-sessionStore.js @@ -734,10 +734,10 @@ var MessageQueue = { _timeoutDisabled: false, /** - * The idle callback ID referencing an active idle callback. When no idle - * callback is pending, this is null. - * */ - _idleCallbackID: null, + * True if there is already a send pending idle dispatch, set to prevent + * scheduling more than one. If false there may or may not be one scheduled. + */ + _idleScheduled: false, /** * True if batched messages are not being fired on a timer. This should only @@ -782,10 +782,7 @@ var MessageQueue = { * Cleanup pending idle callback and timer. */ cleanupTimers() { - if (this._idleCallbackID) { - content.cancelIdleCallback(this._idleCallbackID); - this._idleCallbackID = null; - } + this._idleScheduled = false; if (this._timeout) { clearTimeout(this._timeout); this._timeout = null; @@ -837,7 +834,7 @@ var MessageQueue = { * given, this function is going to schedule the first request. * * @param deadline (object) - * An IdleDeadline object passed by requestIdleCallback(). + * An IdleDeadline object passed by idleDispatch(). */ sendWhenIdle(deadline) { if (!content) { @@ -850,13 +847,13 @@ var MessageQueue = { MessageQueue.send(); return; } - } else if (MessageQueue._idleCallbackID) { + } else if (MessageQueue._idleScheduled) { // Bail out if there's a pending run. return; } - MessageQueue._idleCallbackID = - content.requestIdleCallback(MessageQueue.sendWhenIdle, {timeout: MessageQueue._timeoutWaitIdlePeriodMs}); - }, + ChromeUtils.idleDispatch(MessageQueue.sendWhenIdle, {timeout: MessageQueue._timeoutWaitIdlePeriodMs}); + MessageQueue._idleScheduled = true; + }, /** * Sends queued data to the chrome process.