Bug 1167132 - Part 15: [NetworkManager] Move network information into a separate interface (NetworkInterfaceList). r=echen
authorJessica Jong <jjong@mozilla.com>
Wed, 29 Jul 2015 02:16:00 -0400
changeset 286957 e684f5746f2fa8973755d0de8d92d5df62312163
parent 286956 efa5238b30d6f5a408931eb3cd994ff63bce241c
child 286958 48c08708614a7fe9ae431af6cf81282ffad4e215
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechen
bugs1167132
milestone42.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 1167132 - Part 15: [NetworkManager] Move network information into a separate interface (NetworkInterfaceList). r=echen
dom/media/tests/mochitest/network.js
dom/system/gonk/NetworkInterfaceListService.js
dom/system/gonk/NetworkManager.js
dom/system/gonk/nsINetworkInterfaceListService.idl
dom/system/gonk/tests/marionette/test_network_interface_list_service.js
media/mtransport/gonk_addrs.cpp
--- a/dom/media/tests/mochitest/network.js
+++ b/dom/media/tests/mochitest/network.js
@@ -20,17 +20,17 @@ function isNetworkReady() {
           SpecialPowers.Ci.nsINetworkInterfaceListService.LIST_NOT_INCLUDE_SUPL_INTERFACES |
           SpecialPowers.Ci.nsINetworkInterfaceListService.LIST_NOT_INCLUDE_IMS_INTERFACES |
           SpecialPowers.Ci.nsINetworkInterfaceListService.LIST_NOT_INCLUDE_DUN_INTERFACES |
           SpecialPowers.Ci.nsINetworkInterfaceListService.LIST_NOT_INCLUDE_FOTA_INTERFACES);
     var num = itfList.getNumberOfInterface();
     for (var i = 0; i < num; i++) {
       var ips = {};
       var prefixLengths = {};
-      var length = itfList.getInterface(i).getAddresses(ips, prefixLengths);
+      var length = itfList.getInterfaceInfo(i).getAddresses(ips, prefixLengths);
 
       for (var j = 0; j < length; j++) {
         var ip = ips.value[j];
         // skip IPv6 address until bug 797262 is implemented
         if (ip.indexOf(":") < 0) {
           info("Network interface is ready with address: " + ip);
           return true;
         }
--- a/dom/system/gonk/NetworkInterfaceListService.js
+++ b/dom/system/gonk/NetworkInterfaceListService.js
@@ -45,29 +45,27 @@ NetworkInterfaceListService.prototype = 
           excludeFota: (aConditions &
                         Ci.nsINetworkInterfaceListService.
                         LIST_NOT_INCLUDE_FOTA_INTERFACES) != 0
         }
       )[0]);
   }
 };
 
-function FakeNetworkInterface(aAttributes) {
+function FakeNetworkInfo(aAttributes) {
   this.state = aAttributes.state;
   this.type = aAttributes.type;
   this.name = aAttributes.name;
   this.ips = aAttributes.ips;
   this.prefixLengths = aAttributes.prefixLengths;
   this.gateways = aAttributes.gateways;
   this.dnses = aAttributes.dnses;
-  this.httpProxyHost = aAttributes.httpProxyHost;
-  this.httpProxyPort = aAttributes.httpProxyPort;
 }
-FakeNetworkInterface.prototype = {
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterface]),
+FakeNetworkInfo.prototype = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInfo]),
 
   getAddresses: function (ips, prefixLengths) {
     ips.value = this.ips.slice();
     prefixLengths.value = this.prefixLengths.slice();
 
     return this.ips.length;
   },
 
@@ -84,28 +82,28 @@ FakeNetworkInterface.prototype = {
     }
     return this.dnses.slice();
   }
 };
 
 function NetworkInterfaceList (aInterfaceLiterals) {
   this._interfaces = [];
   for (let entry of aInterfaceLiterals) {
-    this._interfaces.push(new FakeNetworkInterface(entry));
+    this._interfaces.push(new FakeNetworkInfo(entry));
   }
 }
 
 NetworkInterfaceList.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterfaceList]),
 
   getNumberOfInterface: function() {
     return this._interfaces.length;
   },
 
-  getInterface: function(index) {
+  getInterfaceInfo: function(index) {
     if (!this._interfaces) {
       return null;
     }
     return this._interfaces[index];
   }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkInterfaceListService]);
--- a/dom/system/gonk/NetworkManager.js
+++ b/dom/system/gonk/NetworkManager.js
@@ -226,17 +226,18 @@ NetworkManager.prototype = {
       case "NetworkInterfaceList:ListInterface": {
         let excludeMms = aMsg.json.excludeMms;
         let excludeSupl = aMsg.json.excludeSupl;
         let excludeIms = aMsg.json.excludeIms;
         let excludeDun = aMsg.json.excludeDun;
         let excludeFota = aMsg.json.excludeFota;
         let interfaces = [];
 
-        for each (let i in this.networkInterfaces) {
+        for each (let network in this.networkInterfaces) {
+          let i = network.info;
           if ((i.type == Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE_MMS && excludeMms) ||
               (i.type == Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE_SUPL && excludeSupl) ||
               (i.type == Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE_IMS && excludeIms) ||
               (i.type == Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE_DUN && excludeDun) ||
               (i.type == Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE_FOTA && excludeFota)) {
             continue;
           }
 
@@ -246,19 +247,17 @@ NetworkManager.prototype = {
 
           interfaces.push({
             state: i.state,
             type: i.type,
             name: i.name,
             ips: ips.value,
             prefixLengths: prefixLengths.value,
             gateways: i.getGateways(),
-            dnses: i.getDnses(),
-            httpProxyHost: i.httpProxyHost,
-            httpProxyPort: i.httpProxyPort
+            dnses: i.getDnses()
           });
         }
         return interfaces;
       }
     }
   },
 
   getNetworkId: function(aNetworkInfo) {
--- a/dom/system/gonk/nsINetworkInterfaceListService.idl
+++ b/dom/system/gonk/nsINetworkInterfaceListService.idl
@@ -1,28 +1,29 @@
 /* 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/. */
 
-#include "nsINetworkManager.idl"
 #include "nsISupports.idl"
 
-[scriptable, uuid(b44d74db-c9d6-41dd-98ae-a56918d6e6ad)]
+interface nsINetworkInfo;
+
+[scriptable, uuid(55779d32-1e28-4f43-af87-09d04bc3cce9)]
 interface nsINetworkInterfaceList : nsISupports
 {
   /**
    * Number of the network interfaces that is available.
    */
   long getNumberOfInterface();
 
   /**
-   * Get the i-th interface from the list.
+   * Get the i-th interface info info from the list.
    * @param interfaceIndex index of interface, from 0 to number of interface - 1.
    */
-  nsINetworkInterface getInterface(in long interfaceIndex);
+  nsINetworkInfo getInterfaceInfo(in long interfaceIndex);
 };
 
 [scriptable, uuid(21d7fc8b-28c4-4a4f-a15e-1f9defbc2cec)]
 interface nsINetworkInterfaceListService : nsISupports
 {
   const long LIST_NOT_INCLUDE_MMS_INTERFACES  = (1 << 0);
   const long LIST_NOT_INCLUDE_SUPL_INTERFACES = (1 << 1);
   const long LIST_NOT_INCLUDE_IMS_INTERFACES  = (1 << 2);
--- a/dom/system/gonk/tests/marionette/test_network_interface_list_service.js
+++ b/dom/system/gonk/tests/marionette/test_network_interface_list_service.js
@@ -1,71 +1,71 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
 MARIONETTE_HEAD_JS = "head.js";
 
-function getNetworkInterface(aType) {
+function getNetworkInfo(aType) {
   let networkListService =
     Cc["@mozilla.org/network/interface-list-service;1"].
       getService(Ci.nsINetworkInterfaceListService);
   // Get all available interfaces
   let networkList = networkListService.getDataInterfaceList(0);
 
   // Try to get nsINetworkInterface for aType.
   let numberOfInterface = networkList.getNumberOfInterface();
   for (let i = 0; i < numberOfInterface; i++) {
-    let iface = networkList.getInterface(i);
-    if (iface.type === aType) {
-      return iface;
+    let info = networkList.getInterfaceInfo(i);
+    if (info.type === aType) {
+      return info;
     }
   }
 
   return null;
 }
 
 // Test getDataInterfaceList by enabling/disabling mobile data.
 function testGetDataInterfaceList(aMobileDataEnabled) {
   log("Test getDataInterfaceList with mobile data " +
       aMobileDataEnabled ? "enabled" : "disabled");
 
   return setDataEnabledAndWait(aMobileDataEnabled)
-    .then(() => getNetworkInterface(NETWORK_TYPE_MOBILE))
-    .then((networkInterface) => {
-      if (!networkInterface) {
-        ok(false, "Should get an valid nsINetworkInterface for mobile");
+    .then(() => getNetworkInfo(NETWORK_TYPE_MOBILE))
+    .then((networkInfo) => {
+      if (!networkInfo) {
+        ok(false, "Should get an valid nsINetworkInfo for mobile");
         return;
       }
 
-      ok(networkInterface instanceof Ci.nsINetworkInterface,
-         "networkInterface should be an instance of nsINetworkInterface");
+      ok(networkInfo instanceof Ci.nsINetworkInfo,
+         "networkInfo should be an instance of nsINetworkInfo");
 
       let ipAddresses = {};
       let prefixs = {};
       let numOfGateways = {};
       let numOfDnses = {};
-      let numOfIpAddresses = networkInterface.getAddresses(ipAddresses, prefixs);
-      let gateways = networkInterface.getGateways(numOfGateways);
-      let dnses = networkInterface.getDnses(numOfDnses);
+      let numOfIpAddresses = networkInfo.getAddresses(ipAddresses, prefixs);
+      let gateways = networkInfo.getGateways(numOfGateways);
+      let dnses = networkInfo.getDnses(numOfDnses);
 
       if (aMobileDataEnabled) {
         // Mobile data is enabled.
-        is(networkInterface.state, NETWORK_STATE_CONNECTED, "check state");
+        is(networkInfo.state, NETWORK_STATE_CONNECTED, "check state");
         ok(numOfIpAddresses > 0, "check number of ipAddresses");
         ok(ipAddresses.value.length > 0, "check ipAddresses.length");
         ok(prefixs.value.length > 0, "check prefixs.length");
         ok(numOfGateways.value > 0, "check number of gateways");
         ok(prefixs.value.length > 0, "check prefixs.length");
         ok(gateways.length > 0, "check gateways.length");
         ok(numOfDnses.value > 0, "check number of dnses");
         ok(dnses.length > 0, "check dnses.length");
       } else {
         // Mobile data is disabled.
-        is(networkInterface.state, NETWORK_STATE_DISCONNECTED, "check state");
+        is(networkInfo.state, NETWORK_STATE_DISCONNECTED, "check state");
         is(numOfIpAddresses, 0, "check number of ipAddresses");
         is(ipAddresses.value.length, 0, "check ipAddresses.length");
         is(prefixs.value.length, 0, "check prefixs.length");
         is(numOfGateways.value, 0, "check number of gateways");
         is(prefixs.value.length, 0, "check prefixs.length");
         is(gateways.length, 0, "check gateways.length");
         is(numOfDnses.value, 0, "check number of dnses");
         is(dnses.length, 0, "check dnses.length");
--- a/media/mtransport/gonk_addrs.cpp
+++ b/media/mtransport/gonk_addrs.cpp
@@ -7,17 +7,17 @@ extern "C" {
 #include <arpa/inet.h>
 #include "r_types.h"
 #include "stun.h"
 #include "addrs.h"
 }
 
 #include <vector>
 #include <string>
-#include "nsINetworkManager.h"
+#include "nsINetworkInterface.h"
 #include "nsINetworkInterfaceListService.h"
 #include "runnable_utils.h"
 #include "nsCOMPtr.h"
 #include "nsMemory.h"
 #include "nsThreadUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "mozilla/SyncRunnable.h"
 
@@ -53,30 +53,30 @@ GetInterfaces(std::vector<NetworkInterfa
 
   // Translate nsINetworkInterfaceList to NetworkInterface.
   int32_t listLength;
   NS_ENSURE_SUCCESS(networkList->GetNumberOfInterface(&listLength),
                     NS_ERROR_FAILURE);
   aInterfaces->clear();
 
   for (int32_t i = 0; i < listLength; i++) {
-    nsCOMPtr<nsINetworkInterface> iface;
-    if (NS_FAILED(networkList->GetInterface(i, getter_AddRefs(iface)))) {
+    nsCOMPtr<nsINetworkInfo> info;
+    if (NS_FAILED(networkList->GetInterfaceInfo(i, getter_AddRefs(info)))) {
       continue;
     }
 
     char16_t **ips = nullptr;
     uint32_t *prefixs = nullptr;
     uint32_t count = 0;
     bool isAddressGot = false;
     NetworkInterface interface;
     memset(&(interface.addr), 0, sizeof(interface.addr));
     interface.addr.sin_family = AF_INET;
 
-    if (NS_FAILED(iface->GetAddresses(&ips, &prefixs, &count))) {
+    if (NS_FAILED(info->GetAddresses(&ips, &prefixs, &count))) {
       continue;
     }
 
     for (uint32_t j = 0; j < count; j++) {
       nsAutoString ip;
 
       ip.Assign(ips[j]);
       if (inet_pton(AF_INET, NS_ConvertUTF16toUTF8(ip).get(),
@@ -89,30 +89,30 @@ GetInterfaces(std::vector<NetworkInterfa
     free(prefixs);
     NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, ips);
 
     if (!isAddressGot) {
       continue;
     }
 
     nsAutoString ifaceName;
-    if (NS_FAILED(iface->GetName(ifaceName))) {
+    if (NS_FAILED(info->GetName(ifaceName))) {
       continue;
     }
     interface.name = NS_ConvertUTF16toUTF8(ifaceName).get();
 
     int32_t type;
-    if (NS_FAILED(iface->GetType(&type))) {
+    if (NS_FAILED(info->GetType(&type))) {
       continue;
     }
     switch (type) {
-      case nsINetworkInterface::NETWORK_TYPE_WIFI:
+      case nsINetworkInfo::NETWORK_TYPE_WIFI:
         interface.type = NR_INTERFACE_TYPE_WIFI;
         break;
-      case nsINetworkInterface::NETWORK_TYPE_MOBILE:
+      case nsINetworkInfo::NETWORK_TYPE_MOBILE:
         interface.type = NR_INTERFACE_TYPE_MOBILE;
         break;
     }
 
     aInterfaces->push_back(interface);
   }
   return NS_OK;
 }