Bug 1388208: Stop using FileUtils.getFile. r=zombie

This performs main thread IO to make sure that directories exist, which is not
something we should be doing on the startup path.

MozReview-Commit-ID: 2NrgRgY5ua6
This commit is contained in:
Kris Maglione
2017-08-07 17:42:13 -07:00
parent 3ca5f7f59a
commit 04604d9ff9
3 changed files with 14 additions and 11 deletions

View File

@@ -22,8 +22,8 @@ XPCOMUtils.defineLazyModuleGetters(this, {
AppConstants: "resource://gre/modules/AppConstants.jsm",
DeferredSave: "resource://gre/modules/DeferredSave.jsm",
E10SUtils: "resource:///modules/E10SUtils.jsm",
FileUtils: "resource://gre/modules/FileUtils.jsm",
MessageChannel: "resource://gre/modules/MessageChannel.jsm",
OS: "resource://gre/modules/osfile.jsm",
NativeApp: "resource://gre/modules/NativeMessaging.jsm",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
Schemas: "resource://gre/modules/Schemas.jsm",
@@ -1373,13 +1373,16 @@ StartupCache = {
STORE_NAMES: Object.freeze(["general", "locales", "manifests", "other", "permissions", "schemas"]),
get file() {
return FileUtils.getFile("ProfLD", ["startupCache", "webext.sc.lz4"]);
},
file: OS.Path.join(OS.Constants.Path.localProfileDir, "startupCache", "webext.sc.lz4"),
get saver() {
if (!this._saver) {
this._saver = new DeferredSave(this.file.path,
OS.File.makeDir(OS.Path.dirname(this.file), {
ignoreExisting: true,
from: OS.Constants.Path.localProfileDir,
});
this._saver = new DeferredSave(this.file,
() => this.getBlob(),
{delay: 5000});
}

View File

@@ -7,8 +7,8 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
ExtensionParent: "resource://gre/modules/ExtensionParent.jsm",
ExtensionUtils: "resource://gre/modules/ExtensionUtils.jsm",
FileUtils: "resource://gre/modules/FileUtils.jsm",
JSONFile: "resource://gre/modules/JSONFile.jsm",
OS: "resource://gre/modules/osfile.jsm",
});
XPCOMUtils.defineLazyGetter(this, "StartupCache", () => ExtensionParent.StartupCache);
@@ -21,13 +21,13 @@ let prefs;
let _initPromise;
async function _lazyInit() {
let file = FileUtils.getFile("ProfD", [FILE_NAME]);
let path = OS.Path.join(OS.Constants.Path.profileDir, FILE_NAME);
prefs = new JSONFile({path: file.path});
prefs = new JSONFile({path});
prefs.data = {};
try {
let blob = await ExtensionUtils.promiseFileContents(file);
let blob = await ExtensionUtils.promiseFileContents(path);
prefs.data = JSON.parse(new TextDecoder().decode(blob));
} catch (e) {
if (!e.becauseNoSuchFile) {

View File

@@ -37,8 +37,8 @@ function getUniqueId() {
return `${nextId++}-${uniqueProcessID}`;
}
async function promiseFileContents(file) {
let res = await OS.File.read(file.path);
async function promiseFileContents(path) {
let res = await OS.File.read(path);
return res.buffer;
}