Bug 1065128 - Fix SettingsRequestManager storage of MessageManager Principals; r=bent a=bbajaj
authorKyle Machulis <kyle@nonpolynomial.com>
Fri, 19 Sep 2014 10:25:36 -0700
changeset 224952 6484b4d22e3340b19fede9426ebcad8b62da44ed
parent 224951 bfb75367ae2490e75f282bb51623a8c49e606534
child 224953 1889babe666ca000ccb929e67ffb10e8bb6d4691
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent, bbajaj
bugs1065128
milestone34.0a2
Bug 1065128 - Fix SettingsRequestManager storage of MessageManager Principals; r=bent a=bbajaj
dom/settings/SettingsRequestManager.jsm
--- a/dom/settings/SettingsRequestManager.jsm
+++ b/dom/settings/SettingsRequestManager.jsm
@@ -157,17 +157,18 @@ let SettingsRequestManager = {
              "Settings:CreateLock", "Settings:RegisterForMessages"],
   // Map of LockID to SettingsLockInfo objects
   lockInfo: {},
   // Queue of LockIDs. The LockID on the front of the queue is the only lock
   // that will have requests processed, all other locks will queue requests
   // until they hit the front of the queue.
   settingsLockQueue: [],
   children: [],
-  mmPrincipals: {},
+  mmPrincipals: new Map(),
+
   init: function() {
     if (DEBUG) debug("init");
     this.settingsDB.init();
     this.messages.forEach((function(msgName) {
       ppmm.addMessageListener(msgName, this);
     }).bind(this));
     Services.obs.addObserver(this, kXpcomShutdownObserverTopic, false);
   },
@@ -668,41 +669,53 @@ let SettingsRequestManager = {
         value: aValue,
         isInternalChange: aIsServiceLock
       }));
   },
 
   broadcastMessage: function broadcastMessage(aMsgName, aContent) {
     if (DEBUG) debug("Broadcast");
     this.children.forEach(function(msgMgr) {
-      let principal = this.mmPrincipals[msgMgr];
+      let principal = this.mmPrincipals.get(msgMgr);
       if (!principal) {
         if (DEBUG) debug("Cannot find principal for message manager to check permissions");
       }
       else if (SettingsPermissions.hasReadPermission(principal, aContent.key)) {
         msgMgr.sendAsyncMessage(aMsgName, aContent);
       }
     }.bind(this));
     if (DEBUG) debug("Finished Broadcasting");
   },
 
   addObserver: function(aMsgMgr, aPrincipal) {
-    if (DEBUG) debug("Add observer for" + aMsgMgr);
+    if (DEBUG) debug("Add observer for " + aPrincipal.origin);
     if (this.children.indexOf(aMsgMgr) == -1) {
       this.children.push(aMsgMgr);
-      this.mmPrincipals[aMsgMgr] = aPrincipal;
+      this.mmPrincipals.set(aMsgMgr, aPrincipal);
     }
   },
 
   removeObserver: function(aMsgMgr) {
-    if (DEBUG) debug("Remove observer for" + aMsgMgr);
+    if (DEBUG) {
+      let principal = this.mmPrincipals.get(aMsgMgr);
+      debug("Remove observer for " + principal.origin);
+    }
     let index = this.children.indexOf(aMsgMgr);
     if (index != -1) {
       this.children.splice(index, 1);
-      delete this.mmPrincipals[aMsgMgr];
+      this.mmPrincipals.delete(aMsgMgr);
+    }
+    if (DEBUG) {
+      // Make sure we're not leaking since Map requires management by
+      // hand.
+      let i = 0;
+      for (let it of this.mmPrincipals.keys()) {
+        i = i + 1;
+      }
+      debug("Principal/MessageManager pairs left: " + i);
     }
   },
 
   removeLock: function(aLockID) {
     if (DEBUG) debug("Removing lock " + aLockID);
     let transaction = this.lockInfo[aLockID]._transaction;
     if (transaction) {
       try {
@@ -724,17 +737,17 @@ let SettingsRequestManager = {
     // the queue, so possibly queue the next lock if it's
     // consumable.
     if (index == 0) {
       this.queueConsume();
     }
   },
 
   removeMessageManager: function(aMsgMgr){
-    if (DEBUG) debug("Removing message manager " + aMsgMgr);
+    if (DEBUG) debug("Removing message manager");
     this.removeObserver(aMsgMgr);
     let closedLockIDs = [];
     let lockIDs = Object.keys(this.lockInfo);
     for (let i in lockIDs) {
       if (this.lockInfo[lockIDs[i]]._mm == aMsgMgr) {
       	if (DEBUG) debug("Removing lock " + lockIDs[i] + " due to process close/crash");
         closedLockIDs.push(lockIDs[i]);
       }