Bug 1317450 Remove duplicate implementation of AddonInstall.postpone() r=rhelmer
authorAndrew Swan <aswan@mozilla.com>
Mon, 14 Nov 2016 13:24:02 -0800
changeset 322458 7ea8e42c983584ed6638f2a10aca9b0019f20025
parent 322457 fa0b586fa39d99daac1d1950ee8ad35cc901c091
child 322459 f45564cb091fb98a058f470de5e1f5857683870f
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersrhelmer
bugs1317450
milestone52.0a1
Bug 1317450 Remove duplicate implementation of AddonInstall.postpone() r=rhelmer MozReview-Commit-ID: F9mp8tJfdFx
toolkit/mozapps/extensions/internal/XPIProvider.jsm
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -6013,20 +6013,20 @@ class AddonInstall {
       removedAddon.leafName = this.addon.id + ".xpi";
       yield removeAsync(removedAddon);
     }).bind(this));
   }
 
   /**
     * Postone a pending update, until restart or until the add-on resumes.
     *
-    * @param {Function} resumeFunction - a function for the add-on to run
+    * @param {Function} resumeFn - a function for the add-on to run
     *                                    when resuming.
     */
-  postpone(resumeFunction) {
+  postpone(resumeFn) {
     return Task.spawn((function*() {
       this.state = AddonManager.STATE_POSTPONED;
 
       let stagingDir = this.installLocation.getStagingDir();
       let stagedAddon = stagingDir.clone();
 
       yield this.installLocation.requestStagingDir();
       yield this.unstageInstall(stagedAddon);
@@ -6036,34 +6036,37 @@ class AddonInstall {
 
       yield this.stageInstall(true, stagedAddon, true);
 
       AddonManagerPrivate.callInstallListeners("onInstallPostponed",
                                                this.listeners, this.wrapper)
 
       // upgrade has been staged for restart, provide a way for it to call the
       // resume function.
-      if (resumeFunction) {
-        let callback = AddonManagerPrivate.getUpgradeListener(this.addon.id);
-        if (callback) {
-          callback({
-            version: this.version,
-            install: () => {
-              switch (this.state) {
-              case AddonManager.STATE_POSTPONED:
-                resumeFunction();
-                break;
-              default:
-                logger.warn(`${this.addon.id} cannot resume postponed upgrade from state (${this.state})`);
-                break;
+      let callback = AddonManagerPrivate.getUpgradeListener(this.addon.id);
+      if (callback) {
+        callback({
+          version: this.version,
+          install: () => {
+            switch (this.state) {
+            case AddonManager.STATE_POSTPONED:
+              if (resumeFn) {
+                resumeFn();
               }
-            },
-          });
-        }
-      }
+              break;
+            default:
+              logger.warn(`${this.addon.id} cannot resume postponed upgrade from state (${this.state})`);
+              break;
+            }
+          },
+        });
+      }
+      // Release the staging directory lock, but since the staging dir is populated
+      // it will not be removed until resumed or installed by restart.
+      // See also cleanStagingDir()
       this.installLocation.releaseStagingDir();
     }).bind(this));
   }
 }
 
 class LocalAddonInstall extends AddonInstall {
   /**
    * Initialises this install to be an install from a local file.
@@ -6609,67 +6612,16 @@ class DownloadAddonInstall extends Addon
       return prompt;
     }
     else if (iid.equals(Ci.nsIChannelEventSink)) {
       return this;
     }
 
     return this.badCertHandler.getInterface(iid);
   }
-
-  /**
-    * Postone a pending update, until restart or until the add-on resumes.
-    *
-    * @param {Function} resumeFn - a function for the add-on to run
-    *                                    when resuming.
-    */
-  postpone(resumeFn) {
-    return Task.spawn((function*() {
-      this.state = AddonManager.STATE_POSTPONED;
-
-      let stagingDir = this.installLocation.getStagingDir();
-      let stagedAddon = stagingDir.clone();
-
-      yield this.installLocation.requestStagingDir();
-      yield this.unstageInstall(stagedAddon);
-
-      stagedAddon.append(this.addon.id);
-      stagedAddon.leafName = this.addon.id + ".xpi";
-
-      yield this.stageInstall(true, stagedAddon, true);
-
-      AddonManagerPrivate.callInstallListeners("onInstallPostponed",
-                                               this.listeners, this.wrapper)
-
-      // upgrade has been staged for restart, provide a way for it to call the
-      // resume function.
-      let callback = AddonManagerPrivate.getUpgradeListener(this.addon.id);
-      if (callback) {
-        callback({
-          version: this.version,
-          install: () => {
-            switch (this.state) {
-            case AddonManager.STATE_POSTPONED:
-              if (resumeFn) {
-                resumeFn();
-              }
-              break;
-            default:
-              logger.warn(`${this.addon.id} cannot resume postponed upgrade from state (${this.state})`);
-              break;
-            }
-          },
-        });
-      }
-      // Release the staging directory lock, but since the staging dir is populated
-      // it will not be removed until resumed or installed by restart.
-      // See also cleanStagingDir()
-      this.installLocation.releaseStagingDir();
-    }).bind(this));
-  }
 }
 
 /**
  * This class exists just for the specific case of staged add-ons that
  * fail to install at startup.  When that happens, the add-on remains
  * staged but we want to keep track of it like other installs so that we
  * can clean it up if the same add-on is installed again (see the comment
  * about "pending installs for the same add-on" in AddonInstall.startInstall)