Bug 1368567 - Remove support for importing localstore.rdf at startup; r=florian
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 02 Jun 2017 23:18:50 -0400
changeset 363258 95ca02ed62c40dc248bebda7c637211d757e3b63
parent 363257 ae536496bc6d565a03bfcafa96cbe55c704596a0
child 363259 6c35cc91b1bb156e43c59ed028b5edef290763da
push id32000
push userkwierso@gmail.com
push dateFri, 09 Jun 2017 22:28:18 +0000
treeherdermozilla-central@f0c05f5e4dda [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1368567
milestone55.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 1368567 - Remove support for importing localstore.rdf at startup; r=florian This removes some useless main-thread IO from the startup path.
toolkit/components/xulstore/XULStore.js
toolkit/components/xulstore/tests/xpcshell/test_XULStore.js
--- a/toolkit/components/xulstore/XULStore.js
+++ b/toolkit/components/xulstore/XULStore.js
@@ -16,17 +16,16 @@ const WRITE_DELAY_MS = (debugMode ? 3 : 
 
 const XULSTORE_CONTRACTID = "@mozilla.org/xul/xulstore;1";
 const XULSTORE_CID = Components.ID("{6f46b6f4-c8b1-4bd4-a4fa-9ebbed0753ea}");
 const STOREDB_FILENAME = "xulstore.json";
 
 Cu.import("resource://gre/modules/Services.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() {
   if (!Services.appinfo.inSafeMode)
     this.load();
 }
 
 XULStore.prototype = {
@@ -60,21 +59,17 @@ XULStore.prototype = {
   _writeTimer: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer),
 
   load() {
     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();
-    }
+    this.readFile();
   },
 
   observe(subject, topic, data) {
     this.writeFile();
     if (topic == "profile-before-change") {
       this._saveAllowed = false;
     }
   },
@@ -84,81 +79,30 @@ XULStore.prototype = {
    */
   log(message) {
     if (!debugMode)
       return;
     dump("XULStore: " + message + "\n");
     Services.console.logStringMessage("XULStore: " + message);
   },
 
-  import() {
-    let localStoreFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
-
-    localStoreFile.append("localstore.rdf");
-    if (!localStoreFile.exists()) {
-      return;
-    }
-
-    const RDF = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
-    const persistKey = RDF.GetResource("http://home.netscape.com/NC-rdf#persist");
-
-    this.log("Import localstore from " + localStoreFile.path);
-
-    let localStoreURI = Services.io.newFileURI(localStoreFile).spec;
-    let localStore = RDF.GetDataSourceBlocking(localStoreURI);
-    let resources = localStore.GetAllResources();
-
-    while (resources.hasMoreElements()) {
-      let resource = resources.getNext().QueryInterface(Ci.nsIRDFResource);
-      let uri;
-
-      try {
-        uri = NetUtil.newURI(resource.ValueUTF8);
-      } catch (ex) {
-        continue; // skip invalid uris
-      }
-
-      // If this has a ref, then this is an attribute reference. Otherwise,
-      // this is a document reference.
-      if (!uri.hasRef)
-          continue;
-
-      // Verify that there the persist key is connected up.
-      let docURI = uri.specIgnoringRef;
-
-      if (!localStore.HasAssertion(RDF.GetResource(docURI), persistKey, resource, true))
-          continue;
-
-      let id = uri.ref;
-      let attrs = localStore.ArcLabelsOut(resource);
-
-      while (attrs.hasMoreElements()) {
-        let attr = attrs.getNext().QueryInterface(Ci.nsIRDFResource);
-        let value = localStore.GetTarget(resource, attr, true);
-
-        if (value instanceof Ci.nsIRDFLiteral) {
-          this.setValue(docURI, id, attr.ValueUTF8, value.Value);
-        }
-      }
-    }
-  },
-
   readFile() {
     const MODE_RDONLY = 0x01;
     const FILE_PERMS  = 0o600;
 
     let stream = Cc["@mozilla.org/network/file-input-stream;1"].
                  createInstance(Ci.nsIFileInputStream);
     let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
     try {
       stream.init(this._storeFile, MODE_RDONLY, FILE_PERMS, 0);
       this._data = json.decodeFromStream(stream, stream.available());
     } catch (e) {
       this.log("Error reading JSON: " + e);
-      // Ignore problem, we'll just continue on with an empty dataset.
+      // This exception could mean that the file didn't exist.
+      // We'll just ignore the error and start with a blank slate.
     } finally {
       stream.close();
     }
   },
 
   async writeFile() {
     if (!this._needsSaving)
       return;
--- a/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js
+++ b/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js
@@ -17,17 +17,17 @@ var aboutURI = "about:config";
 
 function run_test() {
   do_get_profile();
   run_next_test();
 }
 
 function checkValue(uri, id, attr, reference) {
   let value = XULStore.getValue(uri, id, attr);
-  do_check_true(value === reference);
+  do_check_eq(value, reference);
 }
 
 function checkValueExists(uri, id, attr, exists) {
   do_check_eq(XULStore.hasValue(uri, id, attr), exists);
 }
 
 function getIDs(uri) {
   let it = XULStore.getIDsEnumerator(uri);
@@ -54,52 +54,55 @@ function getAttributes(uri, id) {
 
   result.sort();
   return result;
 }
 
 function checkArrays(a, b) {
   a.sort();
   b.sort();
-  do_check_true(a.toString() == b.toString());
+  do_check_eq(a.toString(), b.toString());
 }
 
 function checkOldStore() {
-  checkArrays(["addon-bar", "main-window", "sidebar-title"], getIDs(browserURI));
-  checkArrays(["collapsed"], getAttributes(browserURI, "addon-bar"));
-  checkArrays(["height", "screenX", "screenY", "sizemode", "width"],
+  checkArrays([], getIDs(browserURI));
+  checkArrays([], getAttributes(browserURI, "addon-bar"));
+  checkArrays([],
               getAttributes(browserURI, "main-window"));
-  checkArrays(["value"], getAttributes(browserURI, "sidebar-title"));
+  checkArrays([], getAttributes(browserURI, "sidebar-title"));
 
-  checkValue(browserURI, "addon-bar", "collapsed", "true");
-  checkValue(browserURI, "main-window", "width", "994");
-  checkValue(browserURI, "main-window", "height", "768");
-  checkValue(browserURI, "main-window", "screenX", "4");
-  checkValue(browserURI, "main-window", "screenY", "22");
-  checkValue(browserURI, "main-window", "sizemode", "normal");
+  checkValue(browserURI, "addon-bar", "collapsed", "");
+  checkValue(browserURI, "main-window", "width", "");
+  checkValue(browserURI, "main-window", "height", "");
+  checkValue(browserURI, "main-window", "screenX", "");
+  checkValue(browserURI, "main-window", "screenY", "");
+  checkValue(browserURI, "main-window", "sizemode", "");
   checkValue(browserURI, "sidebar-title", "value", "");
 
-  checkArrays(["lockCol", "prefCol"], getIDs(aboutURI));
-  checkArrays(["ordinal"], getAttributes(aboutURI, "lockCol"));
-  checkArrays(["ordinal", "sortDirection"], getAttributes(aboutURI, "prefCol"));
+  checkArrays([], getIDs(aboutURI));
+  checkArrays([], getAttributes(aboutURI, "lockCol"));
+  checkArrays([], getAttributes(aboutURI, "prefCol"));
 
-  checkValue(aboutURI, "prefCol", "ordinal", "1");
-  checkValue(aboutURI, "prefCol", "sortDirection", "ascending");
-  checkValue(aboutURI, "lockCol", "ordinal", "3");
+  checkValue(aboutURI, "prefCol", "ordinal", "");
+  checkValue(aboutURI, "prefCol", "sortDirection", "");
+  checkValue(aboutURI, "lockCol", "ordinal", "");
 }
 
 add_task(async function testImport() {
   let src = "localstore.rdf";
   let dst = OS.Path.join(OS.Constants.Path.profileDir, src);
 
   await OS.File.copy(src, dst);
 
-  // Importing relies on XULStore not yet being loaded before this point.
+  // Test to make sure that localstore.rdf isn't imported any more.
   XULStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
   checkOldStore();
+
+  // Set a value that a future test depends on manually
+  XULStore.setValue(browserURI, "main-window", "width", "994");
 });
 
 add_task(async function testTruncation() {
   let dos = Array(8192).join("~");
   // Long id names should trigger an exception
   Assert.throws(() => XULStore.setValue(browserURI, dos, "foo", "foo"), /NS_ERROR_ILLEGAL_VALUE/);
 
   // Long attr names should trigger an exception
@@ -128,48 +131,48 @@ add_task(async function testHasValue() {
   checkValueExists(browserURI, "main-window", "width", true);
 });
 
 add_task(async function testSetValue() {
   // Set new attribute
   checkValue(browserURI, "side-bar", "width", "");
   XULStore.setValue(browserURI, "side-bar", "width", "1000");
   checkValue(browserURI, "side-bar", "width", "1000");
-  checkArrays(["addon-bar", "main-window", "side-bar", "sidebar-title"], getIDs(browserURI));
+  checkArrays(["main-window", "side-bar"], getIDs(browserURI));
   checkArrays(["width"], getAttributes(browserURI, "side-bar"));
 
   // Modify existing property
   checkValue(browserURI, "side-bar", "width", "1000");
   XULStore.setValue(browserURI, "side-bar", "width", "1024");
   checkValue(browserURI, "side-bar", "width", "1024");
-  checkArrays(["addon-bar", "main-window", "side-bar", "sidebar-title"], getIDs(browserURI));
+  checkArrays(["main-window", "side-bar"], getIDs(browserURI));
   checkArrays(["width"], getAttributes(browserURI, "side-bar"));
 
   // Add another attribute
   checkValue(browserURI, "side-bar", "height", "");
   XULStore.setValue(browserURI, "side-bar", "height", "1000");
   checkValue(browserURI, "side-bar", "height", "1000");
-  checkArrays(["addon-bar", "main-window", "side-bar", "sidebar-title"], getIDs(browserURI));
+  checkArrays(["main-window", "side-bar"], getIDs(browserURI));
   checkArrays(["width", "height"], getAttributes(browserURI, "side-bar"));
 });
 
 add_task(async function testRemoveValue() {
   // Remove first attribute
   checkValue(browserURI, "side-bar", "width", "1024");
   XULStore.removeValue(browserURI, "side-bar", "width");
   checkValue(browserURI, "side-bar", "width", "");
   checkValueExists(browserURI, "side-bar", "width", false);
-  checkArrays(["addon-bar", "main-window", "side-bar", "sidebar-title"], getIDs(browserURI));
+  checkArrays(["main-window", "side-bar"], getIDs(browserURI));
   checkArrays(["height"], getAttributes(browserURI, "side-bar"));
 
   // Remove second attribute
   checkValue(browserURI, "side-bar", "height", "1000");
   XULStore.removeValue(browserURI, "side-bar", "height");
   checkValue(browserURI, "side-bar", "height", "");
-  checkArrays(["addon-bar", "main-window", "sidebar-title"], getIDs(browserURI));
+  checkArrays(["main-window"], getIDs(browserURI));
 
   // Removing an attribute that doesn't exists shouldn't fail
   XULStore.removeValue(browserURI, "main-window", "bar");
 
   // Removing from an id that doesn't exists shouldn't fail
   XULStore.removeValue(browserURI, "foo", "bar");
 
   // Removing from a document that doesn't exists shouldn't fail