Bug 1317450 Remove duplicate implementation of AddonInstall.postpone() r?rhelmer
MozReview-Commit-ID: F9mp8tJfdFx
--- 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)