Bug 842890 - Fix logic error which made applying updates Later fail. r=marshall_law
authorDave Hylands <dhylands@mozilla.com>
Fri, 22 Feb 2013 16:57:10 -0600
changeset 122715 f6f8457d343608bc986adca400b4e70fba97a2e3
parent 122714 cb7a7827a9a6f19baaf508e86b8c48e37d47765a
child 122716 257c5fd48f5ac91587650c02abb5aa8d0bbcd8cf
push id24356
push usergszorc@mozilla.com
push dateSun, 24 Feb 2013 01:00:12 +0000
treeherdermozilla-central@195e706140d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarshall_law
bugs842890
milestone22.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 842890 - Fix logic error which made applying updates Later fail. r=marshall_law
b2g/components/UpdatePrompt.js
--- a/b2g/components/UpdatePrompt.js
+++ b/b2g/components/UpdatePrompt.js
@@ -172,25 +172,16 @@ UpdatePrompt.prototype = {
 
     this._update = aUpdate;
     this.waitForIdle();
   },
 
   showUpdateError: function UP_showUpdateError(aUpdate) {
     log("Update error, state: " + aUpdate.state + ", errorCode: " +
         aUpdate.errorCode);
-    if (aUpdate.state == "applied" && aUpdate.errorCode == 0) {
-      // The user chose to apply the update later and then tried to download
-      // it again. If there isn't a new update to download, then the updater
-      // code will detect that there is an update waiting to be installed and
-      // fail. So reprompt the user to apply the update.
-      this.showApplyPrompt(aUpdate);
-      return;
-    }
-
     this.sendUpdateEvent("update-error", aUpdate);
     this.setUpdateStatus(aUpdate.statusText);
   },
 
   showUpdateHistory: function UP_showUpdateHistory(aParent) { },
   showUpdateInstalled: function UP_showUpdateInstalled() {
     let lock = Services.settings.createLock();
     lock.set("deviceinfo.last_updated", Date.now(), null, null);
@@ -309,16 +300,24 @@ UpdatePrompt.prototype = {
     }
 
     let status = Services.aus.downloadUpdate(aUpdate, true);
     if (status == STATE_DOWNLOADING) {
       Services.aus.addDownloadListener(this);
       return;
     }
 
+    // If the update has already been downloaded and applied, then
+    // Services.aus.downloadUpdate will return immediately and not
+    // call showUpdateDownloaded, so we detect this.
+    if (aUpdate.state == "applied" && aUpdate.errorCode == 0) {
+      this.showUpdateDownloaded(aUpdate, true);
+      return;
+    }
+
     log("Error downloading update " + aUpdate.name + ": " + aUpdate.errorCode);
     if (aUpdate.errorCode == FILE_ERROR_TOO_BIG) {
       aUpdate.statusText = "file-too-big";
     }
     this.showUpdateError(aUpdate);
   },
 
   handleDownloadCancel: function UP_handleDownloadCancel() {
@@ -407,17 +406,23 @@ UpdatePrompt.prototype = {
     }
 
     switch (detail.type) {
       case "force-update-check":
         this.forceUpdateCheck();
         break;
       case "update-available-result":
         this.handleAvailableResult(detail);
-        this._update = null;
+        // If we started the apply prompt timer, this means that we're waiting
+        // for the user to press Later or Install Now. In this situation we
+        // don't want to clear this._update, becuase handleApplyPromptResult
+        // needs it.
+        if (this._applyPromptTimer == null) {
+          this._update = null;
+        }
         break;
       case "update-download-cancel":
         this.handleDownloadCancel();
         break;
       case "update-prompt-apply-result":
         this.handleApplyPromptResult(detail);
         break;
     }
@@ -498,16 +503,17 @@ UpdatePrompt.prototype = {
 
   // nsITimerCallback
 
   notify: function UP_notify(aTimer) {
     if (aTimer == this._applyPromptTimer) {
       log("Timed out waiting for result, restarting");
       this._applyPromptTimer = null;
       this.finishUpdate();
+      this._update = null;
     }
   },
 
   createTimer: function UP_createTimer(aTimeoutMs) {
     let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     timer.initWithCallback(this, aTimeoutMs, timer.TYPE_ONE_SHOT);
     return timer;
   },