Bug 1232910 - Use channel.asyncOpen2 within dom/push/PushServiceHttp2.jsm. r=sicking r=dragana
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Tue, 19 Jan 2016 20:00:18 -0800
changeset 280743 39f56e62c694ea209ab0013a4c357084e7ed67ce
parent 280742 5f8e691470d7b1cd1108c5d7e1d820fc728c4cb1
child 280744 edc2c8151935dbe465b0e9c4a486024498ad7e37
push id29922
push usercbook@mozilla.com
push dateThu, 21 Jan 2016 10:51:00 +0000
treeherdermozilla-central@977d78a8dd78 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking, dragana
bugs1232910
milestone46.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 1232910 - Use channel.asyncOpen2 within dom/push/PushServiceHttp2.jsm. r=sicking r=dragana
dom/push/PushServiceHttp2.jsm
--- a/dom/push/PushServiceHttp2.jsm
+++ b/dom/push/PushServiceHttp2.jsm
@@ -9,16 +9,17 @@ const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 const Cr = Components.results;
 
 const {PushDB} = Cu.import("resource://gre/modules/PushDB.jsm");
 const {PushRecord} = Cu.import("resource://gre/modules/PushRecord.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/NetUtil.jsm");
 Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
 Cu.import("resource://gre/modules/Timer.jsm");
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Promise.jsm");
 
 const {
   PushCrypto,
   concatArray,
@@ -98,17 +99,17 @@ PushSubscriptionListener.prototype = {
     this._pushService.connOnStop(aRequest,
                                  Components.isSuccessCode(aStatusCode),
                                  this.uri);
   },
 
   onPush: function(associatedChannel, pushChannel) {
     console.debug("PushSubscriptionListener: onPush()");
     var pushChannelListener = new PushChannelListener(this);
-    pushChannel.asyncOpen(pushChannelListener, pushChannel);
+    pushChannel.asyncOpen2(pushChannelListener);
   },
 
   disconnect: function() {
     this._pushService = null;
   }
 };
 
 /**
@@ -429,29 +430,18 @@ this.PushServiceHttp2 = {
     return this._mainPushService != null;
   },
 
   disconnect: function() {
     this._shutdownConnections(false);
   },
 
   _makeChannel: function(aUri) {
-
-    var ios = Cc["@mozilla.org/network/io-service;1"]
-                .getService(Ci.nsIIOService);
-
-    var chan = ios.newChannel2(aUri,
-                               null,
-                               null,
-                               null,      // aLoadingNode
-                               Services.scriptSecurityManager.getSystemPrincipal(),
-                               null,      // aTriggeringPrincipal
-                               Ci.nsILoadInfo.SEC_NORMAL,
-                               Ci.nsIContentPolicy.TYPE_OTHER)
-                 .QueryInterface(Ci.nsIHttpChannel);
+    var chan = NetUtil.newChannel({uri: aUri, loadUsingSystemPrincipal: true})
+                      .QueryInterface(Ci.nsIHttpChannel);
 
     var loadGroup = Cc["@mozilla.org/network/load-group;1"]
                       .createInstance(Ci.nsILoadGroup);
     chan.loadGroup = loadGroup;
     return chan;
   },
 
   /**
@@ -490,33 +480,33 @@ this.PushServiceHttp2 = {
       var listener = new SubscriptionListener(aSubInfo,
                                               resolve,
                                               reject,
                                               this._serverURI,
                                               this);
 
       var chan = this._makeChannel(this._serverURI.spec);
       chan.requestMethod = "POST";
-      chan.asyncOpen(listener, null);
+      chan.asyncOpen2(listener);
     })
     .catch(err => {
       if ("retry" in err) {
         return this._subscribeResourceInternal(err.subInfo);
       } else {
         throw err;
       }
     })
   },
 
   _deleteResource: function(aUri) {
 
     return new Promise((resolve,reject) => {
       var chan = this._makeChannel(aUri);
       chan.requestMethod = "DELETE";
-      chan.asyncOpen(new PushServiceDelete(resolve, reject), null);
+      chan.asyncOpen2(new PushServiceDelete(resolve, reject));
     });
   },
 
   /**
    * Unsubscribe the resource with a subscription uri aSubscriptionUri.
    * We can't do anything about it if it fails, so we don't listen for response.
    */
   _unsubscribeResource: function(aSubscriptionUri) {
@@ -540,20 +530,20 @@ this.PushServiceHttp2 = {
     var conn = {};
     conn.channel = chan;
     var listener = new PushSubscriptionListener(this, aSubscriptionUri);
     conn.listener = listener;
 
     chan.notificationCallbacks = listener;
 
     try {
-      chan.asyncOpen(listener, chan);
+      chan.asyncOpen2(listener);
     } catch (e) {
       console.error("listenForMsgs: Error connecting to push server.",
-        "asyncOpen failed", e);
+        "asyncOpen2 failed", e);
       conn.listener.disconnect();
       chan.cancel(Cr.NS_ERROR_ABORT);
       this._retryAfterBackoff(aSubscriptionUri, -1);
       return;
     }
 
     this._conns[aSubscriptionUri].lastStartListening = Date.now();
     this._conns[aSubscriptionUri].channel = conn.channel;