Bug 1346716 - Remove the entry for "mimeTypes.rdf" in the directory service. r=mak draft
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Thu, 30 Mar 2017 15:51:18 +0100
changeset 553723 d32861416d72e0a055f36c92c0b0cc7d3277b0a5
parent 553722 4fb510c3e05be398aa7876b952b8f60376fc2371
child 553753 c54406d30580476fbfd353cd2d5665de4fe85025
push id51737
push userpaolo.mozmail@amadzone.org
push dateThu, 30 Mar 2017 14:53:35 +0000
reviewersmak
bugs1346716
milestone55.0a1
Bug 1346716 - Remove the entry for "mimeTypes.rdf" in the directory service. r=mak This improves performance because we won't try to fix the permissions of the file every time the nsIHandlerService implementation wants to open it, and makes it easier to access the file path from xpcshell tests. MozReview-Commit-ID: DZmLa92qUnZ
toolkit/xre/nsXREDirProvider.cpp
uriloader/exthandler/nsHandlerService.js
uriloader/exthandler/tests/unit/common_test_handlerService.js
uriloader/exthandler/tests/unit/head.js
uriloader/exthandler/tests/unit/head_handlerService.js
uriloader/exthandler/tests/unit/test_handlerService.js
uriloader/exthandler/tests/unit/test_handlerService_json.js
uriloader/exthandler/tests/unit/test_handlerService_rdf.js
uriloader/exthandler/tests/unit/test_punycodeURIs.js
uriloader/exthandler/tests/unit/xpcshell.ini
xpcom/io/nsAppDirectoryServiceDefs.h
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -534,20 +534,16 @@ nsXREDirProvider::GetFile(const char* aP
         rv = file->AppendNative(NS_LITERAL_CSTRING("localstore-safe.rdf"));
         file->Remove(false);
       }
       else {
         rv = file->AppendNative(NS_LITERAL_CSTRING("localstore.rdf"));
         ensureFilePermissions = true;
       }
     }
-    else if (!strcmp(aProperty, NS_APP_USER_MIMETYPES_50_FILE)) {
-      rv = file->AppendNative(NS_LITERAL_CSTRING("mimeTypes.rdf"));
-      ensureFilePermissions = true;
-    }
     else if (!strcmp(aProperty, NS_APP_DOWNLOADS_50_FILE)) {
       rv = file->AppendNative(NS_LITERAL_CSTRING("downloads.rdf"));
     }
     else if (!strcmp(aProperty, NS_APP_PREFS_OVERRIDE_DIR)) {
       rv = mProfileDir->Clone(getter_AddRefs(file));
       nsresult tmp = file->AppendNative(NS_LITERAL_CSTRING(PREF_OVERRIDE_DIRNAME));
       if (NS_FAILED(tmp)) {
         rv = tmp;
--- a/uriloader/exthandler/nsHandlerService.js
+++ b/uriloader/exthandler/nsHandlerService.js
@@ -923,17 +923,18 @@ HandlerService.prototype = {
                               getService(Ci.nsIRDFContainerUtils);
     return this.__containerUtils;
   },
 
   // RDF datasource containing content handling config (i.e. mimeTypes.rdf)
   __ds: null,
   get _ds() {
     if (!this.__ds) {
-      var file = this._dirSvc.get("UMimTyp", Ci.nsIFile);
+      var file = this._dirSvc.get("ProfD", Ci.nsIFile);
+      file.append("mimeTypes.rdf");
       // FIXME: make this a memoizing getter if we use it anywhere else.
       var ioService = Cc["@mozilla.org/network/io-service;1"].
                       getService(Ci.nsIIOService);
       var fileHandler = ioService.getProtocolHandler("file").
                         QueryInterface(Ci.nsIFileProtocolHandler);
       this.__ds =
         this._rdf.GetDataSourceBlocking(fileHandler.getURLSpecFromFile(file));
       // do any necessary updating of the datastore
--- a/uriloader/exthandler/tests/unit/common_test_handlerService.js
+++ b/uriloader/exthandler/tests/unit/common_test_handlerService.js
@@ -4,34 +4,32 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * This script is loaded by "test_handlerService_json.js" and "test_handlerService_rdf.js"
  * to make sure there is the same behavior when using two different implementations
  * of handlerService (JSON backend and RDF backend).
  */
 
-"use strict"
-
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://testing-common/TestUtils.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gMIMEService",
                                    "@mozilla.org/mime;1",
                                    "nsIMIMEService");
 XPCOMUtils.defineLazyServiceGetter(this, "gExternalProtocolService",
                                    "@mozilla.org/uriloader/external-protocol-service;1",
                                    "nsIExternalProtocolService");
 
 const pdfHandlerInfo = gMIMEService.getFromTypeAndExtension("application/pdf", null);
 const gzipHandlerInfo = gMIMEService.getFromTypeAndExtension("application/x-gzip", null);
 const ircHandlerInfo = gExternalProtocolService.getProtocolHandlerInfo("irc");
 
-let executable = HandlerServiceTest._dirSvc.get("TmpD", Ci.nsIFile);
+let executable = Services.dirsvc.get("TmpD", Ci.nsIFile);
 let localHandler = {
   name: "Local Handler",
   executable: executable,
   interfaces: [Ci.nsIHandlerApp, Ci.nsILocalHandlerApp, Ci.nsISupports],
   QueryInterface: function(iid) {
     if (!this.interfaces.some( function(v) { return iid.equals(v) } ))
       throw Cr.NS_ERROR_NO_INTERFACE;
     return this;
new file mode 100644
--- /dev/null
+++ b/uriloader/exthandler/tests/unit/head.js
@@ -0,0 +1,30 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * Initialization for tests related to invoking external handler applications.
+ */
+
+"use strict";
+
+const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+do_get_profile();
+
+let rdfFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
+rdfFile.append("mimeTypes.rdf")
+
+function deleteDatasourceFile() {
+  if (rdfFile.exists()) {
+    rdfFile.remove(false);
+  }
+}
+
+// Delete the existing datasource file, if any, so we start from scratch.
+// We also do this after finishing the tests, so there shouldn't be an old
+// file lying around, but just in case we delete it here as well.
+deleteDatasourceFile();
+do_register_cleanup(deleteDatasourceFile);
deleted file mode 100644
--- a/uriloader/exthandler/tests/unit/head_handlerService.js
+++ /dev/null
@@ -1,168 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-// Inspired by the Places infrastructure in head_bookmarks.js
-
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cr = Components.results;
-var Cu = Components.utils;
-
-var HandlerServiceTest = {
-  //**************************************************************************//
-  // Convenience Getters
-
-  __dirSvc: null,
-  get _dirSvc() {
-    if (!this.__dirSvc)
-      this.__dirSvc = Cc["@mozilla.org/file/directory_service;1"].
-                      getService(Ci.nsIProperties).
-                      QueryInterface(Ci.nsIDirectoryService);
-    return this.__dirSvc;
-  },
-
-  __consoleSvc: null,
-  get _consoleSvc() {
-    if (!this.__consoleSvc)
-      this.__consoleSvc = Cc["@mozilla.org/consoleservice;1"].
-                          getService(Ci.nsIConsoleService);
-    return this.__consoleSvc;
-  },
-
-
-  //**************************************************************************//
-  // nsISupports
-
-  interfaces: [Ci.nsIDirectoryServiceProvider, Ci.nsISupports],
-
-  QueryInterface: function HandlerServiceTest_QueryInterface(iid) {
-    if (!this.interfaces.some( function(v) { return iid.equals(v) } ))
-      throw Cr.NS_ERROR_NO_INTERFACE;
-    return this;
-  },
-
-
-  //**************************************************************************//
-  // Initialization & Destruction
-
-  init: function HandlerServiceTest_init() {
-    // Register ourselves as a directory provider for the datasource file
-    // if there isn't one registered already.
-    try {
-      this._dirSvc.get("UMimTyp", Ci.nsIFile);
-    } catch (ex) {
-      do_get_profile();
-      this._dirSvc.registerProvider(this);
-      this._providerRegistered = true;
-    }
-
-    // Delete the existing datasource file, if any, so we start from scratch.
-    // We also do this after finishing the tests, so there shouldn't be an old
-    // file lying around, but just in case we delete it here as well.
-    this._deleteDatasourceFile();
-
-    // Turn on logging so we can troubleshoot problems with the tests.
-    var prefBranch = Cc["@mozilla.org/preferences-service;1"].
-                     getService(Ci.nsIPrefBranch);
-    prefBranch.setBoolPref("browser.contentHandling.log", true);
-  },
-
-  destroy: function HandlerServiceTest_destroy() {
-    // Delete the existing datasource file, if any, so we don't leave test files
-    // lying around and we start from scratch the next time.
-    this._deleteDatasourceFile();
-    // Unregister the directory service provider
-    if (this._providerRegistered)
-      this._dirSvc.unregisterProvider(this);
-  },
-
-
-  //**************************************************************************//
-  // nsIDirectoryServiceProvider
-
-  getFile: function HandlerServiceTest_getFile(property, persistent) {
-    this.log("getFile: requesting " + property);
-
-    persistent.value = true;
-
-    if (property == "UMimTyp") {
-      var datasourceFile = this._dirSvc.get("ProfD", Ci.nsIFile);
-      datasourceFile.append("mimeTypes.rdf");
-      return datasourceFile;
-    }
-
-    // This causes extraneous errors to show up in the log when the directory
-    // service asks us first for CurProcD and MozBinD.  I wish there was a way
-    // to suppress those errors.
-    this.log("the following NS_ERROR_FAILURE exception in " +
-             "nsIDirectoryServiceProvider::getFile is expected, " +
-             "as we don't provide the '" + property + "' file");
-    throw Cr.NS_ERROR_FAILURE;
-  },
-
-
-  //**************************************************************************//
-  // Utilities
-
-  /**
-   * Delete the datasource file.
-   */
-  _deleteDatasourceFile: function HandlerServiceTest__deleteDatasourceFile() {
-    var file = this._dirSvc.get("UMimTyp", Ci.nsIFile);
-    if (file.exists())
-      file.remove(false);
-  },
-
-  /**
-   * Get the contents of the datasource as a serialized string.  Useful for
-   * debugging problems with test failures, i.e.:
-   *
-   * HandlerServiceTest.log(HandlerServiceTest.getDatasourceContents());
-   *
-   * @returns {string} the serialized datasource
-   */
-  getDatasourceContents: function HandlerServiceTest_getDatasourceContents() {
-    var rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
-
-    var ioService = Cc["@mozilla.org/network/io-service;1"].
-                    getService(Ci.nsIIOService);
-    var fileHandler = ioService.getProtocolHandler("file").
-                      QueryInterface(Ci.nsIFileProtocolHandler);
-    var fileURL = fileHandler.getURLSpecFromFile(this.getDatasourceFile());
-    var ds = rdf.GetDataSourceBlocking(fileURL);
-
-    var outputStream = {
-      data: "",
-      close: function() {},
-      flush: function() {},
-      write: function (buffer,count) {
-        this.data += buffer;
-        return count;
-      },
-      writeFrom: function (stream,count) {},
-      isNonBlocking: false
-    };
-
-    ds.QueryInterface(Components.interfaces.nsIRDFXMLSource);
-    ds.Serialize(outputStream);
-
-    return outputStream.data;
-  },
-
-  /**
-   * Log a message to the console and the test log.
-   */
-  log: function HandlerServiceTest_log(message) {
-    message = "*** HandlerServiceTest: " + message;
-    this._consoleSvc.logStringMessage(message);
-    print(message);
-  }
-
-};
-
-HandlerServiceTest.init();
-
-do_register_cleanup(function() {
-  HandlerServiceTest.destroy();
-});
--- a/uriloader/exthandler/tests/unit/test_handlerService.js
+++ b/uriloader/exthandler/tests/unit/test_handlerService.js
@@ -59,17 +59,17 @@ function run_test() {
   //**************************************************************************//
   // Sample Data
 
   // It doesn't matter whether or not this nsIFile is actually executable,
   // only that it has a path and exists.  Since we don't know any executable
   // that exists on all platforms (except possibly the application being
   // tested, but there doesn't seem to be a way to get a reference to that
   // from the directory service), we use the temporary directory itself.
-  var executable = HandlerServiceTest._dirSvc.get("TmpD", Ci.nsIFile);
+  var executable = Services.dirsvc.get("TmpD", Ci.nsIFile);
   // XXX We could, of course, create an actual executable in the directory:
   //executable.append("localhandler");
   //if (!executable.exists())
   //  executable.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o755);
 
   var localHandler = {
     name: "Local Handler",
     executable: executable,
@@ -433,17 +433,16 @@ function run_test() {
   lolHandler.alwaysAskBeforeHandling = false;
 
   // store the handler
   do_check_false(handlerSvc.exists(lolHandler));
   handlerSvc.store(lolHandler);
   do_check_true(handlerSvc.exists(lolHandler));
 
   // Get a file:// string pointing to mimeTypes.rdf
-  var rdfFile = HandlerServiceTest._dirSvc.get("UMimTyp", Ci.nsIFile);
   var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Ci.nsIFileProtocolHandler);
   var rdfFileURI = fileHandler.getURLSpecFromFile(rdfFile);
 
   // Assign a file extenstion to the handler. handlerSvc.store() doesn't
   // actually store any file extensions added with setFileExtensions(), you
   // have to wade into RDF muck to do so.
 
   // Based on toolkit/mozapps/downloads/content/helperApps.js :: addExtension()
--- a/uriloader/exthandler/tests/unit/test_handlerService_json.js
+++ b/uriloader/exthandler/tests/unit/test_handlerService_json.js
@@ -2,19 +2,16 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests the handlerService interfaces using JSON backend.
  */
 
-"use strict"
-
-
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/NetUtil.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gHandlerService",
                                    "@mozilla.org/uriloader/handler-service-json;1",
                                    "nsIHandlerService");
 
--- a/uriloader/exthandler/tests/unit/test_handlerService_rdf.js
+++ b/uriloader/exthandler/tests/unit/test_handlerService_rdf.js
@@ -2,42 +2,37 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests the handlerService interfaces using RDF backend.
  */
 
-"use strict"
-
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/NetUtil.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gHandlerService",
                                    "@mozilla.org/uriloader/handler-service;1",
                                    "nsIHandlerService");
 
 var scriptFile = do_get_file("common_test_handlerService.js");
 Services.scriptloader.loadSubScript(NetUtil.newURI(scriptFile).spec);
 
 var prepareImportDB = Task.async(function* () {
   yield reloadData();
 
-  let dst = HandlerServiceTest._dirSvc.get("UMimTyp", Ci.nsIFile);
-  yield OS.File.copy(do_get_file("mimeTypes.rdf").path, dst.path);
-  Assert.ok((yield OS.File.exists(dst.path)), "should have a DB now");
+  yield OS.File.copy(do_get_file("mimeTypes.rdf").path, rdfFile.path);
 });
 
 var removeImportDB = Task.async(function* () {
   yield reloadData();
-  HandlerServiceTest._deleteDatasourceFile();
-  let dst = HandlerServiceTest._dirSvc.get("UMimTyp", Ci.nsIFile);
-  Assert.ok(!(yield OS.File.exists(dst.path)), "should not have a DB now");
+
+  yield OS.File.remove(rdfFile.path, { ignoreAbsent: true });
 });
 
 var reloadData = Task.async(function* () {
   // Force the initialization of handlerService to prevent observer is not initialized yet.
   let svc = gHandlerService;
   let promise = TestUtils.topicObserved("handlersvc-rdf-replace-complete");
   Services.obs.notifyObservers(null, "handlersvc-rdf-replace", null);
   yield promise;
--- a/uriloader/exthandler/tests/unit/test_punycodeURIs.js
+++ b/uriloader/exthandler/tests/unit/test_punycodeURIs.js
@@ -97,17 +97,17 @@ function run_test() {
   // Set an environment variable for WriteArgument to pick up
   var envSvc =
     Components.classes["@mozilla.org/process/environment;1"]
               .getService(Components.interfaces.nsIEnvironment);
 
   // The Write Argument file needs to know where its libraries are, so
   // just force the path variable
   // For mac
-  var greDir = HandlerServiceTest._dirSvc.get("GreD", Components.interfaces.nsIFile);
+  var greDir = Services.dirsvc.get("GreD", Components.interfaces.nsIFile);
 
   envSvc.set("DYLD_LIBRARY_PATH", greDir.path);
   // For Linux
   envSvc.set("LD_LIBRARY_PATH", greDir.path);
   //XXX: handle windows
 
   // Now tell it where we want the file.
   envSvc.set("WRITE_ARGUMENT_FILE", outFile.path);
--- a/uriloader/exthandler/tests/unit/xpcshell.ini
+++ b/uriloader/exthandler/tests/unit/xpcshell.ini
@@ -1,10 +1,10 @@
 [DEFAULT]
-head = head_handlerService.js
+head = head.js
 run-sequentially = Bug 912235 - Intermittent failures
 firefox-appdir = browser
 support-files = common_test_handlerService.js
 
 [test_getTypeFromExtension_ext_to_type_mapping.js]
 [test_getTypeFromExtension_with_empty_Content_Type.js]
 [test_badMIMEType.js]
 [test_handlerService.js]
--- a/xpcom/io/nsAppDirectoryServiceDefs.h
+++ b/xpcom/io/nsAppDirectoryServiceDefs.h
@@ -66,17 +66,16 @@
 #define NS_APP_USER_PROFILE_50_DIR              "ProfD"
 #define NS_APP_USER_PROFILE_LOCAL_50_DIR        "ProfLD"
 
 #define NS_APP_USER_CHROME_DIR                  "UChrm"
 #define NS_APP_USER_SEARCH_DIR                  "UsrSrchPlugns"
 
 #define NS_APP_LOCALSTORE_50_FILE               "LclSt"
 #define NS_APP_USER_PANELS_50_FILE              "UPnls"
-#define NS_APP_USER_MIMETYPES_50_FILE           "UMimTyp"
 #define NS_APP_CACHE_PARENT_DIR                 "cachePDir"
 
 #define NS_APP_DOWNLOADS_50_FILE                "DLoads"
 
 #define NS_APP_SEARCH_50_FILE                   "SrchF"
 
 #define NS_APP_INSTALL_CLEANUP_DIR              "XPIClnupD"  //location of xpicleanup.dat xpicleanup.exe