Bug 1204426 - Unregister message listeners of settings service locks. r=khuey
authorAlexandre Lissy <lissyx@lissyx.dyndns.org>
Mon, 14 Sep 2015 02:43:00 +0200
changeset 295150 2ee63977ebaaa5455371c9fee18b93c7b91bf7a4
parent 295149 c817e82939c6eb3c2bc5700b28fc3c1ed5ef7916
child 295151 7c530c7851cb648d4d44deb7454a45bf9c5d1223
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1204426
milestone43.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 1204426 - Unregister message listeners of settings service locks. r=khuey
dom/settings/SettingsService.js
--- a/dom/settings/SettingsService.js
+++ b/dom/settings/SettingsService.js
@@ -46,37 +46,35 @@ const nsISettingsServiceLock         = C
 function makeSettingsServiceRequest(aCallback, aName, aValue) {
   return {
     callback: aCallback,
     name: aName,
     value: aValue
   };
 };
 
+const kLockListeners = ["Settings:Get:OK", "Settings:Get:KO",
+                        "Settings:Clear:OK", "Settings:Clear:KO",
+                        "Settings:Set:OK", "Settings:Set:KO",
+                        "Settings:Finalize:OK", "Settings:Finalize:KO"];
+
 function SettingsServiceLock(aSettingsService, aTransactionCallback) {
   if (VERBOSE) debug("settingsServiceLock constr!");
   this._open = true;
   this._settingsService = aSettingsService;
   this._id = uuidgen.generateUUID().toString();
   this._transactionCallback = aTransactionCallback;
   this._requests = {};
   let closeHelper = function() {
     if (VERBOSE) debug("closing lock " + this._id);
     this._open = false;
     this.runOrFinalizeQueries();
   }.bind(this);
 
-  let msgs =   ["Settings:Get:OK", "Settings:Get:KO",
-                "Settings:Clear:OK", "Settings:Clear:KO",
-                "Settings:Set:OK", "Settings:Set:KO",
-                "Settings:Finalize:OK", "Settings:Finalize:KO"];
-
-  for (let msg in msgs) {
-    cpmm.addMessageListener(msgs[msg], this);
-  }
+  this.addListeners();
 
   let createLockPayload = {
     lockID: this._id,
     isServiceLock: true,
     windowID: undefined,
     lockStack: (new Error).stack
   };
 
@@ -84,16 +82,28 @@ function SettingsServiceLock(aSettingsSe
   Services.tm.currentThread.dispatch(closeHelper, Ci.nsIThread.DISPATCH_NORMAL);
 }
 
 SettingsServiceLock.prototype = {
   get closed() {
     return !this._open;
   },
 
+  addListeners: function() {
+    for (let msg of kLockListeners) {
+      cpmm.addMessageListener(msg, this);
+    }
+  },
+
+  removeListeners: function() {
+    for (let msg of kLockListeners) {
+      cpmm.removeMessageListener(msg, this);
+    }
+  },
+
   returnMessage: function(aMessage, aData) {
     SettingsRequestManager.receiveMessage({
       name: aMessage,
       data: aData,
       target: undefined,
       principal: Services.scriptSecurityManager.getSystemPrincipal()
     });
   },
@@ -301,16 +311,17 @@ SettingsService.prototype = {
     this._createdLocks++;
   },
 
   unregisterLock: function(aLockID) {
     let lock_index = this._locks.indexOf(aLockID);
     if (lock_index != -1) {
       if (VERBOSE) debug("Unregistering lock " + aLockID);
       this._locks.splice(lock_index, 1);
+      this._serviceLocks[aLockID].removeListeners();
       this._serviceLocks[aLockID] = null;
       delete this._serviceLocks[aLockID];
       this._unregisteredLocks++;
     }
   },
 
   collectReports: function(aCallback, aData, aAnonymize) {
     aCallback.callback("",