Bug 1317450 Remove duplicate implementation of AddonInstall.postpone() r?rhelmer draft
authorAndrew Swan <aswan@mozilla.com>
Mon, 14 Nov 2016 13:24:02 -0800
changeset 438606 ba9c4deb4ff20745403318cd4e6cea22602c0d35
parent 438550 71fd23fa0803a548b6e571aa25d0533a06cd0421
child 438855 eddb0118a647432a2067b2e290313ff0325b005a
child 438856 f70534dc90c7c8042a351a1354c35e57fbd47b70
child 439799 37040b7e06c5feb9915db0c6e802e6fe68bfdb6b
push id35778
push useraswan@mozilla.com
push dateMon, 14 Nov 2016 21:24:52 +0000
reviewersrhelmer
bugs1317450
milestone53.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)