зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1072814 - Fix SessionFile.jsm to use new Promise() API r=yoric
This commit is contained in:
Родитель
3bde457253
Коммит
ac9a92b4bf
|
@ -265,7 +265,6 @@ let SessionFileInternal = {
|
||||||
if (this._isClosed) {
|
if (this._isClosed) {
|
||||||
return Promise.reject(new Error("SessionFile is closed"));
|
return Promise.reject(new Error("SessionFile is closed"));
|
||||||
}
|
}
|
||||||
let refObj = {};
|
|
||||||
|
|
||||||
let isFinalWrite = false;
|
let isFinalWrite = false;
|
||||||
if (Services.startup.shuttingDown) {
|
if (Services.startup.shuttingDown) {
|
||||||
|
@ -274,50 +273,62 @@ let SessionFileInternal = {
|
||||||
isFinalWrite = this._isClosed = true;
|
isFinalWrite = this._isClosed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let deferredWritten = Promise.defer();
|
let refObj = {};
|
||||||
return Task.spawn(function* task() {
|
let name = "FX_SESSION_RESTORE_WRITE_FILE_LONGEST_OP_MS";
|
||||||
TelemetryStopwatch.start("FX_SESSION_RESTORE_WRITE_FILE_LONGEST_OP_MS", refObj);
|
|
||||||
|
|
||||||
// Ensure that we can write sessionstore.js cleanly before the profile
|
let promise = new Promise(resolve => {
|
||||||
// becomes unaccessible.
|
// Start measuring main thread impact.
|
||||||
AsyncShutdown.profileBeforeChange.addBlocker(
|
TelemetryStopwatch.start(name, refObj);
|
||||||
"SessionFile: Finish writing Session Restore data",
|
|
||||||
deferredWritten.promise
|
let performShutdownCleanup = isFinalWrite &&
|
||||||
);
|
!sessionStartup.isAutomaticRestoreEnabled();
|
||||||
|
|
||||||
|
let options = {isFinalWrite, performShutdownCleanup};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let performShutdownCleanup = isFinalWrite &&
|
resolve(SessionWorker.post("write", [aData, options]));
|
||||||
!sessionStartup.isAutomaticRestoreEnabled();
|
|
||||||
let options = {
|
|
||||||
isFinalWrite: isFinalWrite,
|
|
||||||
performShutdownCleanup: performShutdownCleanup
|
|
||||||
};
|
|
||||||
let promise = SessionWorker.post("write", [aData, options]);
|
|
||||||
// At this point, we measure how long we stop the main thread
|
|
||||||
TelemetryStopwatch.finish("FX_SESSION_RESTORE_WRITE_FILE_LONGEST_OP_MS", refObj);
|
|
||||||
|
|
||||||
// Now wait for the result and record how long the write took
|
|
||||||
let msg = yield promise;
|
|
||||||
this._recordTelemetry(msg.telemetry);
|
|
||||||
|
|
||||||
if (msg.result.upgradeBackup) {
|
|
||||||
// We have just completed a backup-on-upgrade, store the information
|
|
||||||
// in preferences.
|
|
||||||
Services.prefs.setCharPref(PREF_UPGRADE_BACKUP, Services.appinfo.platformBuildID);
|
|
||||||
}
|
|
||||||
deferredWritten.resolve();
|
|
||||||
} catch (ex) {
|
|
||||||
TelemetryStopwatch.cancel("FX_SESSION_RESTORE_WRITE_FILE_LONGEST_OP_MS", refObj);
|
|
||||||
console.error("Could not write session state file ", ex, ex.stack);
|
|
||||||
deferredWritten.reject(ex);
|
|
||||||
} finally {
|
} finally {
|
||||||
AsyncShutdown.profileBeforeChange.removeBlocker(deferredWritten.promise);
|
// Record how long we stopped the main thread.
|
||||||
|
TelemetryStopwatch.finish(name, refObj);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait until the write is done.
|
||||||
|
promise = promise.then(msg => {
|
||||||
|
// Record how long the write took.
|
||||||
|
this._recordTelemetry(msg.telemetry);
|
||||||
|
|
||||||
|
if (msg.result.upgradeBackup) {
|
||||||
|
// We have just completed a backup-on-upgrade, store the information
|
||||||
|
// in preferences.
|
||||||
|
Services.prefs.setCharPref(PREF_UPGRADE_BACKUP,
|
||||||
|
Services.appinfo.platformBuildID);
|
||||||
|
}
|
||||||
|
}, err => {
|
||||||
|
// Catch and report any errors.
|
||||||
|
TelemetryStopwatch.cancel(name, refObj);
|
||||||
|
console.error("Could not write session state file ", err, err.stack);
|
||||||
|
// By not doing anything special here we ensure that |promise| cannot
|
||||||
|
// be rejected anymore. The shutdown/cleanup code at the end of the
|
||||||
|
// function will thus always be executed.
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure that we can write sessionstore.js cleanly before the profile
|
||||||
|
// becomes unaccessible.
|
||||||
|
AsyncShutdown.profileBeforeChange.addBlocker(
|
||||||
|
"SessionFile: Finish writing Session Restore data", promise);
|
||||||
|
|
||||||
|
// This code will always be executed because |promise| can't fail anymore.
|
||||||
|
// We ensured that by having a reject handler that reports the failure but
|
||||||
|
// doesn't forward the rejection.
|
||||||
|
return promise.then(() => {
|
||||||
|
// Remove the blocker, no matter if writing failed or not.
|
||||||
|
AsyncShutdown.profileBeforeChange.removeBlocker(promise);
|
||||||
|
|
||||||
if (isFinalWrite) {
|
if (isFinalWrite) {
|
||||||
Services.obs.notifyObservers(null, "sessionstore-final-state-write-complete", "");
|
Services.obs.notifyObservers(null, "sessionstore-final-state-write-complete", "");
|
||||||
}
|
}
|
||||||
}.bind(this));
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
wipe: function () {
|
wipe: function () {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче