Bug 514415 - Expose NetUtil's reference to nsIIOService. r=sdwilsh, sr=bzbarsky
authorRyan Flint <rflint@ryanflint.com>
Sat, 03 Oct 2009 01:11:20 -0400
changeset 33414 f2f941b8bff83d657bde5343ee3aba58a4968712
parent 33413 0ff8f0469f37754c34151cbfb8027b40d14aa6d4
child 33415 6078ebef6e2d4ab538a20ffb8166eaa8698208db
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssdwilsh, bzbarsky
bugs514415
milestone1.9.3a1pre
Bug 514415 - Expose NetUtil's reference to nsIIOService. r=sdwilsh, sr=bzbarsky
netwerk/base/src/NetUtil.jsm
netwerk/test/unit/test_NetUtil.js
toolkit/components/search/nsSearchService.js
--- a/netwerk/base/src/NetUtil.jsm
+++ b/netwerk/base/src/NetUtil.jsm
@@ -143,23 +143,32 @@ const NetUtil = {
             let exception = new Components.Exception(
                 "Must have a non-null spec",
                 Cr.NS_ERROR_INVALID_ARG,
                 Components.stack.caller
             );
             throw exception;
         }
 
-        return ioService.newURI(aSpec, aOriginCharset, aBaseURI);
+        return this.ioService.newURI(aSpec, aOriginCharset, aBaseURI);
+    },
+
+    /**
+     * Returns a reference to nsIIOService.
+     *
+     * @return a reference to nsIIOService.
+     */
+    get ioService()
+    {
+        delete this.ioService;
+        return this.ioService = Cc["@mozilla.org/network/io-service;1"].
+                                getService(Ci.nsIIOService);
     },
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Initialization
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 // Define our lazy getters.
 XPCOMUtils.defineLazyServiceGetter(this, "ioUtil", "@mozilla.org/io-util;1",
                                    "nsIIOUtil");
-XPCOMUtils.defineLazyServiceGetter(this, "ioService",
-                                   "@mozilla.org/network/io-service;1",
-                                   "nsIIOService");
--- a/netwerk/test/unit/test_NetUtil.js
+++ b/netwerk/test/unit/test_NetUtil.js
@@ -168,24 +168,31 @@ function test_newURI()
   const TEST_URI = "http://mozilla.org";
   let iosURI = ios.newURI(TEST_URI, null, null);
   let NetUtilURI = NetUtil.newURI(TEST_URI);
   do_check_true(iosURI.equals(NetUtilURI));
 
   run_next_test();
 }
 
+function test_ioService()
+{
+  do_check_true(NetUtil.ioService instanceof Ci.nsIIOService);
+  run_next_test();
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 //// Test Runner
 
 let tests = [
   test_async_write_file,
   test_async_write_file_nsISafeOutputStream,
   test_newURI_no_spec_throws,
   test_newURI,
+  test_ioService,
 ];
 let index = 0;
 
 function run_next_test()
 {
   if (index < tests.length) {
     do_test_pending();
     print("Running the next test: " + tests[index].name);
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -204,22 +204,16 @@ function isUsefulLine(aLine) {
 }
 
 __defineGetter__("gObsSvc", function() {
   delete this.gObsSvc;
   return this.gObsSvc = Cc["@mozilla.org/observer-service;1"].
                         getService(Ci.nsIObserverService);
 });
 
-__defineGetter__("gIoSvc", function() {
-  delete this.gIoSvc;
-  return this.gIoSvc = Cc["@mozilla.org/network/io-service;1"].
-                       getService(Ci.nsIIOService);
-});
-
 __defineGetter__("gPrefSvc", function() {
   delete this.gPrefSvc;
   return this.gPrefSvc = Cc["@mozilla.org/preferences-service;1"].
                          getService(Ci.nsIPrefBranch);
 });
 
 __defineGetter__("NetUtil", function() {
   delete this.NetUtil;
@@ -1136,17 +1130,17 @@ Engine.prototype = {
    */
   _initFromURI: function SRCH_ENG_initFromURI() {
     ENSURE_WARN(this._uri instanceof Ci.nsIURI,
                 "Must have URI when calling _initFromURI!",
                 Cr.NS_ERROR_UNEXPECTED);
 
     LOG("_initFromURI: Downloading engine from: \"" + this._uri.spec + "\".");
 
-    var chan = gIoSvc.newChannelFromURI(this._uri);
+    var chan = NetUtil.ioService.newChannelFromURI(this._uri);
 
     if (this._engineToUpdate && (chan instanceof Ci.nsIHttpChannel)) {
       var lastModified = engineMetadataService.getAttr(this._engineToUpdate,
                                                        "updatelastmodified");
       if (lastModified)
         chan.setRequestHeader("If-Modified-Since", lastModified, false);
     }
     var listener = new loadListener(chan, this, this._onLoad);
@@ -1396,17 +1390,17 @@ Engine.prototype = {
         break;
       case "http":
       case "https":
       case "ftp":
         // No use downloading the icon if the engine file is read-only
         if (!this._readOnly) {
           LOG("_setIcon: Downloading icon: \"" + uri.spec +
               "\" for engine: \"" + this.name + "\"");
-          var chan = gIoSvc.newChannelFromURI(uri);
+          var chan = NetUtil.ioService.newChannelFromURI(uri);
 
           function iconLoadCallback(aByteArray, aEngine) {
             // This callback may run after we've already set a preferred icon,
             // so check again.
             if (aEngine._hasPreferredIcon && !aIsPreferred)
               return;
 
             if (!aByteArray || aByteArray.length > MAX_ICON_SIZE) {
@@ -2656,17 +2650,17 @@ SearchService.prototype = {
     var addedEngines = [];
     while (files.hasMoreElements()) {
       var file = files.nextFile;
 
       // Ignore hidden and empty files, and directories
       if (!file.isFile() || file.fileSize == 0 || file.isHidden())
         continue;
 
-      var fileURL = gIoSvc.newFileURI(file).QueryInterface(Ci.nsIURL);
+      var fileURL = NetUtil.ioService.newFileURI(file).QueryInterface(Ci.nsIURL);
       var fileExtension = fileURL.fileExtension.toLowerCase();
       var isWritable = isInProfile && file.isWritable();
 
       var dataType;
       switch (fileExtension) {
         case XML_FILE_EXT:
           dataType = SEARCH_DATA_XML;
           break;
@@ -2699,17 +2693,17 @@ SearchService.prototype = {
             addedEngine._readOnly = true;
           }
         }
 
         // If the engine still doesn't have an icon, see if we can find one
         if (!addedEngine._iconURI) {
           var icon = this._findSherlockIcon(file, fileURL.fileBaseName);
           if (icon)
-            addedEngine._iconURI = gIoSvc.newFileURI(icon);
+            addedEngine._iconURI = NetUtil.ioService.newFileURI(icon);
         }
       }
 
       this._addEngineToStore(addedEngine);
       addedEngines.push(addedEngine);
     }
     return addedEngines;
   },