Backed out changeset 453811f08638 (bug 1649599) for causing performance regressions seen in Bug 1683885.

CLOSED TREE
This commit is contained in:
Mihai Alexandru Michis 2020-12-22 19:15:23 +02:00
parent a35c5c45f9
commit 5ccd8dacb5

View File

@ -22,12 +22,14 @@ var EXPORTED_SYMBOLS = ["SessionFile"];
* e.g. if a request attempts to write sessionstore.js while
* another attempts to copy that file.
*
* This implementation uses OS.File, which guarantees property 1.
*/
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
const { AsyncShutdown } = ChromeUtils.import(
"resource://gre/modules/AsyncShutdown.jsm"
);
@ -94,35 +96,32 @@ var SessionFile = {
Object.freeze(SessionFile);
var profileDir = Services.dirsvc.get("ProfD", Ci.nsIFile).path;
var Path = OS.Path;
var profileDir = OS.Constants.Path.profileDir;
var SessionFileInternal = {
Paths: Object.freeze({
// The path to the latest version of sessionstore written during a clean
// shutdown. After startup, it is renamed `cleanBackup`.
clean: PathUtils.join(profileDir, "sessionstore.jsonlz4"),
clean: Path.join(profileDir, "sessionstore.jsonlz4"),
// The path at which we store the previous version of `clean`. Updated
// whenever we successfully load from `clean`.
cleanBackup: PathUtils.join(
cleanBackup: Path.join(
profileDir,
"sessionstore-backups",
"previous.jsonlz4"
),
// The directory containing all sessionstore backups.
backups: PathUtils.join(profileDir, "sessionstore-backups"),
backups: Path.join(profileDir, "sessionstore-backups"),
// The path to the latest version of the sessionstore written
// during runtime. Generally, this file contains more
// privacy-sensitive information than |clean|, and this file is
// therefore removed during clean shutdown. This file is designed to protect
// against crashes / sudden shutdown.
recovery: PathUtils.join(
profileDir,
"sessionstore-backups",
"recovery.jsonlz4"
),
recovery: Path.join(profileDir, "sessionstore-backups", "recovery.jsonlz4"),
// The path to the previous version of the sessionstore written
// during runtime (e.g. 15 seconds before recovery). In case of a
@ -131,7 +130,7 @@ var SessionFileInternal = {
// this file is therefore removed during clean shutdown. This
// file is designed to protect against crashes that are nasty
// enough to corrupt |recovery|.
recoveryBackup: PathUtils.join(
recoveryBackup: Path.join(
profileDir,
"sessionstore-backups",
"recovery.baklz4"
@ -141,7 +140,7 @@ var SessionFileInternal = {
// Having this backup protects the user essentially from bugs in
// Firefox or add-ons, especially for users of Nightly. This file
// does not contain any information more sensitive than |clean|.
upgradeBackupPrefix: PathUtils.join(
upgradeBackupPrefix: Path.join(
profileDir,
"sessionstore-backups",
"upgrade.jsonlz4-"
@ -244,16 +243,16 @@ var SessionFileInternal = {
let path;
let startMs = Date.now();
let options = {};
let options = { encoding: "utf-8" };
if (useOldExtension) {
path = this.Paths[key]
.replace("jsonlz4", "js")
.replace("baklz4", "bak");
} else {
path = this.Paths[key];
options.decompress = true;
options.compression = "lz4";
}
let source = await IOUtils.readUTF8(path, options);
let source = await OS.File.read(path, options);
let parsed = JSON.parse(source);
if (
@ -288,12 +287,12 @@ var SessionFileInternal = {
);
break;
} catch (ex) {
if (ex instanceof DOMException && ex.name == "NotFoundError") {
if (ex instanceof OS.File.Error && ex.becauseNoSuchFile) {
exists = false;
} else if (ex instanceof DOMException && ex.name == "NotAllowedError") {
} else if (ex instanceof OS.File.Error) {
// The file might be inaccessible due to wrong permissions
// or similar failures. We'll just count it as "corrupted".
console.error("Could not read session file ", ex);
console.error("Could not read session file ", ex, ex.stack);
corrupted = true;
} else if (ex instanceof SyntaxError) {
console.error(