Bug 1114935 - Part 6.8: Migration in MobileIdentityManager.jsm. r=ferjmoreno
authorBevis Tseng <btseng@mozilla.com>
Thu, 15 Jan 2015 18:46:08 +0800
changeset 265029 d76cc3361383c9217ffb9d7505b114f2ec365828
parent 265028 35c0866ffc481759d86b6219793764eba5d9bdd7
child 265030 a483c38d6f726be059403e242a8551549902bcf4
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersferjmoreno
bugs1114935
milestone39.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 1114935 - Part 6.8: Migration in MobileIdentityManager.jsm. r=ferjmoreno
services/mobileid/MobileIdentityManager.jsm
services/mobileid/tests/xpcshell/test_mobileid_manager.js
--- a/services/mobileid/MobileIdentityManager.jsm
+++ b/services/mobileid/MobileIdentityManager.jsm
@@ -51,19 +51,19 @@ XPCOMUtils.defineLazyServiceGetter(this,
                                    "@mozilla.org/AppsService;1",
                                    "nsIAppsService");
 
 #ifdef MOZ_B2G_RIL
 XPCOMUtils.defineLazyServiceGetter(this, "Ril",
                                    "@mozilla.org/ril;1",
                                    "nsIRadioInterfaceLayer");
 
-XPCOMUtils.defineLazyServiceGetter(this, "IccProvider",
-                                   "@mozilla.org/ril/content-helper;1",
-                                   "nsIIccProvider");
+XPCOMUtils.defineLazyServiceGetter(this, "IccService",
+                                   "@mozilla.org/icc/iccservice;1",
+                                   "nsIIccService");
 
 XPCOMUtils.defineLazyServiceGetter(this, "MobileConnectionService",
                                    "@mozilla.org/mobileconnection/mobileconnectionservice;1",
                                    "nsIMobileConnectionService");
 #endif
 
 
 this.MobileIdentityManager = {
@@ -111,21 +111,21 @@ this.MobileIdentityManager = {
   // We have these getters to allow mocking RIL stuff from the tests.
   get ril() {
     if (this._ril) {
       return this._ril;
     }
     return Ril;
   },
 
-  get iccProvider() {
-    if (this._iccProvider) {
-      return this._iccProvider;
+  get iccService() {
+    if (this._iccService) {
+      return this._iccService;
     }
-    return IccProvider;
+    return IccService;
   },
 
   get mobileConnectionService() {
     if (this._mobileConnectionService) {
       return this._mobileConnectionService;
     }
     return MobileConnectionService;
   },
@@ -148,18 +148,20 @@ this.MobileIdentityManager = {
         // If we receive a notification about an ICC info change, we clear
         // the ICC related caches so they can be rebuilt with the new changes.
 
         log.debug("ICC info changed observed. Clearing caches");
 
         // We don't need to keep listening for changes until we rebuild the
         // cache again.
         for (let i = 0; i < self._iccInfo.length; i++) {
-          self.iccProvider.unregisterIccMsg(self._iccInfo[i].clientId,
-                                            iccListener);
+          let icc = self.iccService.getIccByServiceId(i);
+          if (icc) {
+            icc.unregisterListener(iccListener);
+          }
         }
 
         self._iccInfo = null;
         self._iccIds = null;
       }
     };
 
     // _iccInfo is a local cache containing the information about the SIM cards
@@ -209,17 +211,20 @@ this.MobileIdentityManager = {
         // GSM SIMs may have MSISDN while CDMA SIMs may have MDN
         msisdn: info.msisdn || info.mdn || null,
         operator: operator,
         roaming: voice && voice.roaming
       });
 
       // We need to subscribe to ICC change notifications so we can refresh
       // the cache if any change is observed.
-      this.iccProvider.registerIccMsg(i, iccListener);
+      let icc = this.iccService.getIccByServiceId(i);
+      if (icc) {
+        icc.registerListener(iccListener);
+      }
     }
 
     return this._iccInfo;
 #endif
     return null;
   },
 
   get iccIds() {
--- a/services/mobileid/tests/xpcshell/test_mobileid_manager.js
+++ b/services/mobileid/tests/xpcshell/test_mobileid_manager.js
@@ -997,23 +997,29 @@ add_test(function() {
 
   MobileIdentityManager._mobileConnectionService = {
     _interfaces: [RADIO_INTERFACE, ANOTHER_RADIO_INTERFACE],
     getItemByServiceId: function(aIndex) {
       return this._interfaces[aIndex];
     }
   };
 
-  MobileIdentityManager._iccProvider = {
+  MobileIdentityManager._iccService = {
+    _iccs: [],
     _listeners: [],
-    registerIccMsg: function(aClientId, aIccListener) {
-      this._listeners.push(aIccListener);
-    },
-    unregisterIccMsg: function() {
-      this._listeners.pop();
+    getIccByServiceId: function(aClientId) {
+      let self = this;
+      this_iccs.push({
+        registerListener: function(aIccListener) {
+          self._listeners.push(aIccListener);
+        },
+        unregisterListener: function() {
+          self._listeners.pop();
+        }
+      });
     }
   };
 
   let ui = new MockUi();
   ui.startFlow = function() {
     // At this point we've already built the ICC cache.
     let interfaces = MobileIdentityManager._ril._interfaces;
     for (let i = 0; i < interfaces.length; i++) {
@@ -1022,27 +1028,27 @@ add_test(function() {
       do_check_eq(interfaceIccInfo.iccid, mIdIccInfo.iccId);
       do_check_eq(interfaceIccInfo.mcc, mIdIccInfo.mcc);
       do_check_eq(interfaceIccInfo.mnc, mIdIccInfo.mnc);
       do_check_eq(interfaceIccInfo.msisdn, mIdIccInfo.msisdn);
       do_check_eq(interfaceIccInfo.operator, mIdIccInfo.operator);
     }
 
     // We should have listeners for each valid icc.
-    do_check_eq(MobileIdentityManager._iccProvider._listeners.length, 2);
+    do_check_eq(MobileIdentityManager._iccService._listeners.length, 2);
 
     // We can mock an ICC change event at this point.
-    MobileIdentityManager._iccProvider._listeners[0].notifyIccInfoChanged();
+    MobileIdentityManager._iccService._listeners[0].notifyIccInfoChanged();
 
     // After the ICC change event the caches should be null.
     do_check_null(MobileIdentityManager._iccInfo);
     do_check_null(MobileIdentityManager._iccIds);
 
     // And we should have unregistered all listeners for ICC change events.
-    do_check_eq(MobileIdentityManager._iccProvider._listeners.length, 0);
+    do_check_eq(MobileIdentityManager._iccService._listeners.length, 0);
 
     do_test_finished();
     run_next_test();
   };
   MobileIdentityManager.ui = ui;
 
   let credStore = new MockCredStore();
   credStore.getByOrigin = function() {
@@ -1099,34 +1105,40 @@ add_test(function() {
 
   MobileIdentityManager._mobileConnectionService = {
     _interfaces: [INVALID_RADIO_INTERFACE],
     getItemByServiceId: function(aIndex) {
       return this._interfaces[aIndex];
     }
   };
 
-  MobileIdentityManager._iccProvider = {
+  MobileIdentityManager._iccService = {
+    _iccs: [],
     _listeners: [],
-    registerIccMsg: function(aClientId, aIccListener) {
-      this._listeners.push(aIccListener);
-    },
-    unregisterIccMsg: function() {
-      this._listeners.pop();
+    getIccByServiceId: function(aClientId) {
+      let self = this;
+      this_iccs.push({
+        registerListener: function(aIccListener) {
+          self._listeners.push(aIccListener);
+        },
+        unregisterListener: function() {
+          self._listeners.pop();
+        }
+      });
     }
   };
 
   let ui = new MockUi();
   ui.startFlow = function() {
     // At this point we've already built the ICC cache.
     do_check_eq(MobileIdentityManager._iccInfo.length, 0);
     do_check_eq(MobileIdentityManager._iccIds.length, 0);
 
     // We should have listeners for each valid icc.
-    do_check_eq(MobileIdentityManager._iccProvider._listeners.length, 0);
+    do_check_eq(MobileIdentityManager._iccService._listeners.length, 0);
 
     do_test_finished();
     run_next_test();
   };
   MobileIdentityManager.ui = ui;
 
   let credStore = new MockCredStore();
   credStore.getByOrigin = function() {