Bug 1706445 - Stop using "SessionStore:flush" for SHIP, r=nika

Differential Revision: https://phabricator.services.mozilla.com/D116144
This commit is contained in:
Kashav Madan 2021-06-01 20:06:46 +00:00
Родитель 555cddd8c9
Коммит 47ad1edf15
1 изменённых файлов: 34 добавлений и 19 удалений

Просмотреть файл

@ -6,6 +6,11 @@
var EXPORTED_SYMBOLS = ["TabStateFlusher"]; var EXPORTED_SYMBOLS = ["TabStateFlusher"];
ChromeUtils.defineModuleGetter(
this,
"Services",
"resource://gre/modules/Services.jsm"
);
ChromeUtils.defineModuleGetter( ChromeUtils.defineModuleGetter(
this, this,
"SessionStore", "SessionStore",
@ -110,21 +115,24 @@ var TabStateFlusherInternal = {
*/ */
nativePromise = browser.frameLoader.requestTabStateFlush(); nativePromise = browser.frameLoader.requestTabStateFlush();
} }
/*
In the event that we have to trigger a process switch and thus change
browser remoteness, session store needs to register and track the new
browser window loaded and to have message manager listener registered
** before ** TabStateFlusher send "SessionStore:flush" message. This fixes
the race where we send the message before the message listener is
registered for it.
*/
SessionStore.ensureInitialized(browser.ownerGlobal);
let mm = browser.messageManager; if (!Services.appinfo.sessionHistoryInParent) {
mm.sendAsyncMessage("SessionStore:flush", { /*
id, In the event that we have to trigger a process switch and thus change
epoch: SessionStore.getCurrentEpoch(browser), browser remoteness, session store needs to register and track the new
}); browser window loaded and to have message manager listener registered
** before ** TabStateFlusher send "SessionStore:flush" message. This fixes
the race where we send the message before the message listener is
registered for it.
*/
SessionStore.ensureInitialized(browser.ownerGlobal);
let mm = browser.messageManager;
mm.sendAsyncMessage("SessionStore:flush", {
id,
epoch: SessionStore.getCurrentEpoch(browser),
});
}
// Retrieve active requests for given browser. // Retrieve active requests for given browser.
let permanentKey = browser.permanentKey; let permanentKey = browser.permanentKey;
@ -136,13 +144,20 @@ var TabStateFlusherInternal = {
this._requests.set(permanentKey, request); this._requests.set(permanentKey, request);
} }
let promise = new Promise(resolve => { // Non-SHIP flushes resolve this after the "SessionStore:update" message. We
// Store resolve() so that we can resolve the promise later. // don't use that message for SHIP, so it's fine to resolve the request
request.perBrowserRequests.set(id, resolve); // immediately after the native promise resolves, since SessionStore will
}); // have processed all updates from this browser by that point.
let requestPromise = Promise.resolve();
if (!Services.appinfo.sessionHistoryInParent) {
requestPromise = new Promise(resolve => {
// Store resolve() so that we can resolve the promise later.
request.perBrowserRequests.set(id, resolve);
});
}
return Promise.race([ return Promise.race([
nativePromise.then(_ => promise), nativePromise.then(_ => requestPromise),
request.cancelPromise, request.cancelPromise,
]); ]);
}, },