Bug 1065128 - Fix SettingsRequestManager storage of MessageManager Principals; r=bent
authorKyle Machulis <kyle@nonpolynomial.com>
Mon, 15 Sep 2014 13:39:20 -0700
changeset 228695 d4b6ecaee33ceae44c190c8baf0b59679fb9e1f4
parent 228694 b72e89edbcc135ff218976190c07c5f719cd1a11
child 228696 1e0f892f3046057461b0b02b2ade18159ab673e0
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs1065128
milestone35.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 1065128 - Fix SettingsRequestManager storage of MessageManager Principals; r=bent
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,42 +669,46 @@ 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) debug("Principal/MessageManager pairs left: " + this.mmPrincipals.size);
   },
 
   removeLock: function(aLockID) {
     if (DEBUG) debug("Removing lock " + aLockID);
     let transaction = this.lockInfo[aLockID]._transaction;
     if (transaction) {
       try {
         transaction.abort();
@@ -724,17 +729,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]);
       }