Bug 871428 - Fix AlarmService shutdown leaks. r=gene

--HG--
extra : amend_source : 43f24156a4b6c124b712094ae81d750e16e6a0b5
This commit is contained in:
Nikhil Marathe 2013-05-12 22:40:00 +05:30
parent 09593e64ab
commit 2df824df8e

View File

@ -48,6 +48,7 @@ let myGlobal = this;
this.AlarmService = {
init: function init() {
debug("init()");
Services.obs.addObserver(this, "profile-change-teardown", false);
this._currentTimezoneOffset = (new Date()).getTimezoneOffset();
@ -59,11 +60,11 @@ this.AlarmService = {
alarmHalService.setTimezoneChangedCb(this._onTimezoneChanged.bind(this));
// Add the messages to be listened to.
const messages = ["AlarmsManager:GetAll",
this._messages = ["AlarmsManager:GetAll",
"AlarmsManager:Add",
"AlarmsManager:Remove"];
messages.forEach(function addMessage(msgName) {
ppmm.addMessageListener(msgName, this);
this._messages.forEach(function addMessage(msgName) {
ppmm.addMessageListener(msgName, this);
}.bind(this));
// Set the indexeddb database.
@ -99,8 +100,7 @@ this.AlarmService = {
// To prevent the hacked child process from sending commands to parent
// to schedule alarms, we need to check its permission and manifest URL.
if (["AlarmsManager:GetAll", "AlarmsManager:Add", "AlarmsManager:Remove"]
.indexOf(aMessage.name) != -1) {
if (this._messages.indexOf(aMessage.name) != -1) {
if (!aMessage.target.assertPermission("alarms")) {
debug("Got message from a child process with no 'alarms' permission.");
return null;
@ -490,6 +490,30 @@ this.AlarmService = {
this._debugCurrentAlarm();
}.bind(this)
);
},
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case "profile-change-teardown":
this.uninit();
}
},
uninit: function uninit() {
debug("uninit()");
Services.obs.removeObserver(this, "profile-change-teardown");
this._messages.forEach(function(aMsgName) {
ppmm.removeMessageListener(aMsgName, this);
}.bind(this));
ppmm = null;
if (this._db) {
this._db.close();
}
this._db = null;
this._alarmHalService = null;
}
}