Bug 1114935 - Part 6.8: Migration in MobileIdentityManager.jsm. r=ferjmoreno

This commit is contained in:
Bevis Tseng 2015-01-15 18:46:08 +08:00
parent a7595bee88
commit 04d04c2c0e
2 changed files with 43 additions and 26 deletions

View File

@ -56,9 +56,9 @@ XPCOMUtils.defineLazyServiceGetter(this, "Ril",
"@mozilla.org/ril;1", "@mozilla.org/ril;1",
"nsIRadioInterfaceLayer"); "nsIRadioInterfaceLayer");
XPCOMUtils.defineLazyServiceGetter(this, "IccProvider", XPCOMUtils.defineLazyServiceGetter(this, "IccService",
"@mozilla.org/ril/content-helper;1", "@mozilla.org/icc/iccservice;1",
"nsIIccProvider"); "nsIIccService");
XPCOMUtils.defineLazyServiceGetter(this, "MobileConnectionService", XPCOMUtils.defineLazyServiceGetter(this, "MobileConnectionService",
"@mozilla.org/mobileconnection/mobileconnectionservice;1", "@mozilla.org/mobileconnection/mobileconnectionservice;1",
@ -116,11 +116,11 @@ this.MobileIdentityManager = {
return Ril; return Ril;
}, },
get iccProvider() { get iccService() {
if (this._iccProvider) { if (this._iccService) {
return this._iccProvider; return this._iccService;
} }
return IccProvider; return IccService;
}, },
get mobileConnectionService() { get mobileConnectionService() {
@ -153,8 +153,10 @@ this.MobileIdentityManager = {
// We don't need to keep listening for changes until we rebuild the // We don't need to keep listening for changes until we rebuild the
// cache again. // cache again.
for (let i = 0; i < self._iccInfo.length; i++) { for (let i = 0; i < self._iccInfo.length; i++) {
self.iccProvider.unregisterIccMsg(self._iccInfo[i].clientId, let icc = self.iccService.getIccByServiceId(i);
iccListener); if (icc) {
icc.unregisterListener(iccListener);
}
} }
self._iccInfo = null; self._iccInfo = null;
@ -214,7 +216,10 @@ this.MobileIdentityManager = {
// We need to subscribe to ICC change notifications so we can refresh // We need to subscribe to ICC change notifications so we can refresh
// the cache if any change is observed. // 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; return this._iccInfo;

View File

@ -1002,13 +1002,19 @@ add_test(function() {
} }
}; };
MobileIdentityManager._iccProvider = { MobileIdentityManager._iccService = {
_iccs: [],
_listeners: [], _listeners: [],
registerIccMsg: function(aClientId, aIccListener) { getIccByServiceId: function(aClientId) {
this._listeners.push(aIccListener); let self = this;
}, this_iccs.push({
unregisterIccMsg: function() { registerListener: function(aIccListener) {
this._listeners.pop(); self._listeners.push(aIccListener);
},
unregisterListener: function() {
self._listeners.pop();
}
});
} }
}; };
@ -1027,17 +1033,17 @@ add_test(function() {
} }
// We should have listeners for each valid icc. // 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. // 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. // After the ICC change event the caches should be null.
do_check_null(MobileIdentityManager._iccInfo); do_check_null(MobileIdentityManager._iccInfo);
do_check_null(MobileIdentityManager._iccIds); do_check_null(MobileIdentityManager._iccIds);
// And we should have unregistered all listeners for ICC change events. // 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(); do_test_finished();
run_next_test(); run_next_test();
@ -1104,13 +1110,19 @@ add_test(function() {
} }
}; };
MobileIdentityManager._iccProvider = { MobileIdentityManager._iccService = {
_iccs: [],
_listeners: [], _listeners: [],
registerIccMsg: function(aClientId, aIccListener) { getIccByServiceId: function(aClientId) {
this._listeners.push(aIccListener); let self = this;
}, this_iccs.push({
unregisterIccMsg: function() { registerListener: function(aIccListener) {
this._listeners.pop(); self._listeners.push(aIccListener);
},
unregisterListener: function() {
self._listeners.pop();
}
});
} }
}; };
@ -1121,7 +1133,7 @@ add_test(function() {
do_check_eq(MobileIdentityManager._iccIds.length, 0); do_check_eq(MobileIdentityManager._iccIds.length, 0);
// We should have listeners for each valid icc. // 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(); do_test_finished();
run_next_test(); run_next_test();