Bug 1218266 - Harden against AsyncShutdown timeouts in Experiments.jsm. r=mossop a=sylvestre
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Tue, 03 Nov 2015 14:26:13 +0100
changeset 310605 fc1c8094f8d43d53084f766645c1df57275f15e5
parent 310604 6f10c503b63f21523df03ddefa09c7f98221c371
child 310606 9421bb0715d231e8cda03cb4fb0455a1f5858759
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop, sylvestre
bugs1218266
milestone45.0a2
Bug 1218266 - Harden against AsyncShutdown timeouts in Experiments.jsm. r=mossop a=sylvestre
browser/experiments/Experiments.jsm
--- a/browser/experiments/Experiments.jsm
+++ b/browser/experiments/Experiments.jsm
@@ -1935,37 +1935,58 @@ Experiments.ExperimentEntry.prototype = 
                       "enabled.");
     }
 
     // If we have the add-on and it is enabled, we are done.
     if (!addon.userDisabled) {
       return changes;
     }
 
+    // Check permissions to see if we can enable the addon.
+    if (!(addon.permissions & AddonManager.PERM_CAN_ENABLE)) {
+      throw new Error("Don't have permission to enable addon " + addon.id + ", perm=" + addon.permission);
+    }
+
+    // Experiment addons should not require a restart.
+    if (!!(addon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_ENABLE)) {
+      throw new Error("Experiment addon requires a restart: " + addon.id);
+    }
+
     let deferred = Promise.defer();
 
     // Else we need to enable it.
     let listener = {
       onEnabled: enabledAddon => {
         if (enabledAddon.id != addon.id) {
           return;
         }
 
         AddonManager.removeAddonListener(listener);
         deferred.resolve();
       },
     };
 
-    this._log.info("Activating add-on: " + addon.id);
+    for (let handler of ["onDisabled", "onOperationCancelled", "onUninstalled"]) {
+      listener[handler] = (evtAddon) => {
+        if (evtAddon.id != addon.id) {
+          return;
+        }
+
+        AddonManager.removeAddonListener(listener);
+        deferred.reject("Failed to enable addon " + addon.id + " due to: " + handler);
+      };
+    }
+
+    this._log.info("reconcileAddonState() - Activating add-on: " + addon.id);
     AddonManager.addAddonListener(listener);
     addon.userDisabled = false;
     yield deferred.promise;
     changes |= this.ADDON_CHANGE_ENABLE;
 
-    this._log.info("Add-on has been enabled: " + addon.id);
+    this._log.info("reconcileAddonState() - Add-on has been enabled: " + addon.id);
     return changes;
    }),
 
   /**
    * Obtain the underlying Addon from the Addon Manager.
    *
    * @return Promise<Addon|null>
    */