Bug 1230221 - Convert JS callsites to use asyncOpen2 within services/ (r=sicking)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Fri, 15 Jan 2016 11:39:12 -0800
changeset 322143 2f0efcc5f4f77da0735e284cee3e55e3b1d9af2a
parent 322142 66a7f0a6d71e5ca9d8ea3fd0dda3d22db0aacce3
child 322144 5026fb2da3f2d8eca6dae63f164d11e13813c8ee
push id9535
push userdmitchell@mozilla.com
push dateFri, 15 Jan 2016 20:33:33 +0000
reviewerssicking
bugs1230221
milestone46.0a1
Bug 1230221 - Convert JS callsites to use asyncOpen2 within services/ (r=sicking)
services/common/rest.js
services/sync/modules/resource.js
--- a/services/common/rest.js
+++ b/services/common/rest.js
@@ -11,16 +11,17 @@ this.EXPORTED_SYMBOLS = [
   "RESTResponse",
   "TokenAuthenticatedRESTRequest",
 ];
 
 #endif
 
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/NetUtil.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://services-common/utils.js");
 
 XPCOMUtils.defineLazyModuleGetter(this, "CryptoUtils",
                                   "resource://services-crypto/utils.js");
 
 const Prefs = new Preferences("services.common.rest.");
@@ -300,24 +301,19 @@ RESTRequest.prototype = {
     if (onComplete) {
       this.onComplete = onComplete;
     }
     if (onProgress) {
       this.onProgress = onProgress;
     }
 
     // Create and initialize HTTP channel.
-    let channel = Services.io.newChannelFromURI2(this.uri,
-                                                 null,      // aLoadingNode
-                                                 Services.scriptSecurityManager.getSystemPrincipal(),
-                                                 null,      // aTriggeringPrincipal
-                                                 Ci.nsILoadInfo.SEC_NORMAL,
-                                                 Ci.nsIContentPolicy.TYPE_OTHER)
-                          .QueryInterface(Ci.nsIRequest)
-                          .QueryInterface(Ci.nsIHttpChannel);
+    let channel = NetUtil.newChannel({uri: this.uri, loadUsingSystemPrincipal: true})
+                         .QueryInterface(Ci.nsIRequest)
+                         .QueryInterface(Ci.nsIHttpChannel);
     this.channel = channel;
     channel.loadFlags |= this.loadFlags;
     channel.notificationCallbacks = this;
 
     // Set request headers.
     let headers = this._headers;
     for (let key in headers) {
       if (key == 'authorization') {
@@ -353,17 +349,17 @@ RESTRequest.prototype = {
     channel.requestMethod = method;
 
     // Before opening the channel, set the charset that serves as a hint
     // as to what the response might be encoded as.
     channel.contentCharset = this.charset;
 
     // Blast off!
     try {
-      channel.asyncOpen(this, null);
+      channel.asyncOpen2(this);
     } catch (ex) {
       // asyncOpen can throw in a bunch of cases -- e.g., a forbidden port.
       this._log.warn("Caught an error in asyncOpen", ex);
       CommonUtils.nextTick(onComplete.bind(this, ex));
     }
     this.status = this.SENT;
     this.delayTimeout();
     return this;
--- a/services/sync/modules/resource.js
+++ b/services/sync/modules/resource.js
@@ -8,16 +8,17 @@ this.EXPORTED_SYMBOLS = [
 ];
 
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 var Cr = Components.results;
 var Cu = Components.utils;
 
 Cu.import("resource://gre/modules/Preferences.jsm");
+Cu.import("resource://gre/modules/NetUtil.jsm");
 Cu.import("resource://services-common/async.js");
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://services-common/observers.js");
 Cu.import("resource://services-common/utils.js");
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://services-sync/util.js");
 
 const DEFAULT_LOAD_FLAGS =
@@ -143,26 +144,19 @@ AsyncResource.prototype = {
 
   // ** {{{ AsyncResource._createRequest }}} **
   //
   // This method returns a new IO Channel for requests to be made
   // through. It is never called directly, only {{{_doRequest}}} uses it
   // to obtain a request channel.
   //
   _createRequest: function Res__createRequest(method) {
-    let channel = Services.io.newChannel2(this.spec,
-                                          null,
-                                          null,
-                                          null,      // aLoadingNode
-                                          Services.scriptSecurityManager.getSystemPrincipal(),
-                                          null,      // aTriggeringPrincipal
-                                          Ci.nsILoadInfo.SEC_NORMAL,
-                                          Ci.nsIContentPolicy.TYPE_OTHER)
-                          .QueryInterface(Ci.nsIRequest)
-                          .QueryInterface(Ci.nsIHttpChannel);
+    let channel = NetUtil.newChannel({uri: this.spec, loadUsingSystemPrincipal: true})
+                         .QueryInterface(Ci.nsIRequest)
+                         .QueryInterface(Ci.nsIHttpChannel);
 
     channel.loadFlags |= DEFAULT_LOAD_FLAGS;
 
     // Setup a callback to handle channel notifications.
     let listener = new ChannelNotificationListener(this.headerNames);
     channel.notificationCallbacks = listener;
 
     // Compose a UA string fragment from the various available identifiers.
@@ -225,20 +219,20 @@ AsyncResource.prototype = {
     }
 
     // Setup a channel listener so that the actual network operation
     // is performed asynchronously.
     let listener = new ChannelListener(this._onComplete, this._onProgress,
                                        this._log, this.ABORT_TIMEOUT);
     channel.requestMethod = action;
     try {
-      channel.asyncOpen(listener, null);
+      channel.asyncOpen2(listener);
     } catch (ex) {
-      // asyncOpen can throw in a bunch of cases -- e.g., a forbidden port.
-      this._log.warn("Caught an error in asyncOpen", ex);
+      // asyncOpen2 can throw in a bunch of cases -- e.g., a forbidden port.
+      this._log.warn("Caught an error in asyncOpen2", ex);
       CommonUtils.nextTick(callback.bind(this, ex));
     }
   },
 
   _onComplete: function _onComplete(error, data, channel) {
     this._log.trace("In _onComplete. Error is " + error + ".");
 
     if (error) {