Bug 1388208: Stop using FileUtils.getFile. r=zombie
authorKris Maglione <maglione.k@gmail.com>
Mon, 07 Aug 2017 17:42:13 -0700
changeset 373880 903db0ac80c6a27b61b68e7df699782acc7f8842
parent 373879 5c9b13e813391a433976999f59a5090e66311697
child 373881 6f7aa77d3ac9b57d1718a7d855d39c491a2ce35b
push id32311
push userkwierso@gmail.com
push dateFri, 11 Aug 2017 01:14:57 +0000
treeherdermozilla-central@253a8560dc34 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszombie
bugs1388208
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
toolkit/components/extensions/ExtensionParent.jsm
toolkit/components/extensions/ExtensionPermissions.jsm
toolkit/components/extensions/ExtensionUtils.jsm
--- a/toolkit/components/extensions/ExtensionParent.jsm
+++ b/toolkit/components/extensions/ExtensionParent.jsm
@@ -17,18 +17,18 @@ this.EXPORTED_SYMBOLS = ["ExtensionParen
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 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",
 });
 
 XPCOMUtils.defineLazyServiceGetters(this, {
   gAddonPolicyService: ["@mozilla.org/addons/policy-service;1", "nsIAddonPolicyService"],
   aomStartup: ["@mozilla.org/addons/addon-manager-startup;1", "amIAddonManagerStartup"],
@@ -1368,23 +1368,26 @@ let IconDetails = {
   },
 };
 
 StartupCache = {
   DB_NAME: "ExtensionStartupCache",
 
   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});
     }
     return this._saver;
   },
 
   async save() {
     return this.saver.saveChanges();
--- a/toolkit/components/extensions/ExtensionPermissions.jsm
+++ b/toolkit/components/extensions/ExtensionPermissions.jsm
@@ -2,37 +2,37 @@
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 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);
 
 this.EXPORTED_SYMBOLS = ["ExtensionPermissions"];
 
 const FILE_NAME = "extension-preferences.json";
 
 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) {
       Cu.reportError(e);
     }
   }
 }
 
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -32,18 +32,18 @@ const appinfo = Cc["@mozilla.org/xre/app
 
 let nextId = 0;
 XPCOMUtils.defineLazyGetter(this, "uniqueProcessID", () => appinfo.uniqueProcessID);
 
 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;
 }
 
 
 /**
  * An Error subclass for which complete error messages are always passed
  * to extensions, rather than being interpreted as an unknown error.
  */