Bug 1058436 Don't access xulstore.json in safe mode r=Enn
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Thu, 28 Aug 2014 00:19:57 +0100
changeset 223714 7ed7216d3d8b6bf815ce139ed09745cd7a8beee1
parent 223713 2976adaf32789e87f20ce8cde587a39d64964db9
child 223715 a531fd3f3ab772098a0dd8ff8f906461fa20edf6
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEnn
bugs1058436
milestone34.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 1058436 Don't access xulstore.json in safe mode r=Enn
toolkit/components/xulstore/XULStore.js
--- a/toolkit/components/xulstore/XULStore.js
+++ b/toolkit/components/xulstore/XULStore.js
@@ -21,17 +21,18 @@ const STOREDB_FILENAME = "xulstore.json"
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import('resource://gre/modules/XPCOMUtils.jsm');
 
 XPCOMUtils.defineLazyModuleGetter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
 
 function XULStore() {
-  this.init();
+  if (!Services.appinfo.inSafeMode)
+    this.load();
 }
 
 XULStore.prototype = {
   classID: XULSTORE_CID,
   classInfo: XPCOMUtils.generateCI({classID: XULSTORE_CID,
                                     contractID: XULSTORE_CONTRACTID,
                                     classDescription: "XULStore",
                                     interfaces: [Ci.nsIXULStore]}),
@@ -53,34 +54,33 @@ XULStore.prototype = {
    *      ...
    *  }
    */
   _data: {},
   _storeFile: null,
   _needsSaving: false,
   _saveAllowed: true,
   _writeTimer: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer),
-  _writeTimerInitialized: false,
 
-  init: function () {
+  load: function () {
     Services.obs.addObserver(this, "profile-before-change", true);
 
     this._storeFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
     this._storeFile.append(STOREDB_FILENAME);
 
     if (!this._storeFile.exists()) {
       this.import();
     } else {
       this.readFile();
     }
   },
 
   observe: function(subject, topic, data) {
+    this.writeFile();
     if (topic == "profile-before-change") {
-      this.writeFile();
       this._saveAllowed = false;
     }
   },
 
   /*
    * Internal function for logging debug messages to the Error Console window
    */
   log: function (message) {
@@ -177,28 +177,22 @@ XULStore.prototype = {
                               { tmpPath: this._storeFile.path + ".tmp" });
     } catch (e) {
       this.log("Failed to write xulstore.json: " + e);
       throw e;
     }
   }),
 
   markAsChanged: function() {
-    this._needsSaving = true;
-    if (this._writeTimerInitialized)
+    if (this._needsSaving || !this._storeFile)
       return;
 
-    let callback = () => {
-      this._writeTimerInitialized = false;
-      this.writeFile();
-    };
-
     // Don't write the file more than once every 30 seconds.
-    this._writeTimerInitialized = true;
-    this._writeTimer.initWithCallback(callback, WRITE_DELAY_MS, Ci.nsITimer.TYPE_ONE_SHOT);
+    this._needsSaving = true;
+    this._writeTimer.init(this, WRITE_DELAY_MS, Ci.nsITimer.TYPE_ONE_SHOT);
   },
 
   /* ---------- interface implementation ---------- */
 
   setValue: function (docURI, id, attr, value) {
     this.log("Saving " + attr + "=" + value + " for id=" + id + ", doc=" + docURI);
 
     if (!this._saveAllowed) {