Main patch for Bug 774618 - Partner builds don't download complete update if partial fails, or show workaround information if complete fails. r=bbondy
authorRobert Strong <robert.bugzilla@gmail.com>
Fri, 19 Oct 2012 12:42:55 -0700
changeset 110888 6eb49c920cd466b841a32dc9970a519d2d607a69
parent 110887 ca6044e25cd24ef7616979ff3e30d320597d3300
child 110889 42df37484d371984935b1a4edd1feaf50d8f4c3f
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersbbondy
bugs774618
milestone19.0a1
Main patch for Bug 774618 - Partner builds don't download complete update if partial fails, or show workaround information if complete fails. r=bbondy
toolkit/mozapps/update/nsUpdateService.js
--- a/toolkit/mozapps/update/nsUpdateService.js
+++ b/toolkit/mozapps/update/nsUpdateService.js
@@ -1028,17 +1028,17 @@ function handleFallbackToCompleteUpdate(
   cleanupActiveUpdate();
 
   update.statusText = gUpdateBundle.GetStringFromName("patchApplyFailure");
   var oldType = update.selectedPatch ? update.selectedPatch.type
                                      : "complete";
   if (update.selectedPatch && oldType == "partial" && update.patchCount == 2) {
     // Partial patch application failed, try downloading the complete
     // update in the background instead.
-    LOG("UpdateService:_postUpdateProcessing - install of partial patch " +
+    LOG("handleFallbackToCompleteUpdate - install of partial patch " +
         "failed, downloading complete patch");
     var status = Cc["@mozilla.org/updates/update-service;1"].
                  getService(Ci.nsIApplicationUpdateService).
                  downloadUpdate(update, !postStaging);
     if (status == STATE_NONE)
       cleanupActiveUpdate();
   }
   else {
@@ -1623,18 +1623,25 @@ UpdateService.prototype = {
         case Ci.nsIRecoveryService.FOTA_UPDATE_UNKNOWN:
         default:
           status = STATE_FAILED + ": " + FOTA_UNKNOWN_ERROR;
           break;
       }
     }
 #endif
 
-    if (!update)
+    if (!update) {
+      if (status != STATE_SUCCEEDED) {
+        LOG("UpdateService:_postUpdateProcessing - previous patch failed " +
+            "and no patch available");
+        cleanupActiveUpdate();
+        return;
+      }
       update = new Update(null);
+    }
 
     var prompter = Cc["@mozilla.org/updates/update-prompt;1"].
                    createInstance(Ci.nsIUpdatePrompt);
 
     update.state = status;
     this._sendStatusCodeTelemetryPing(status);
 
     if (status == STATE_SUCCEEDED) {
@@ -2485,23 +2492,31 @@ UpdateManager.prototype = {
   },
 
   /**
    * See nsIUpdateService.idl
    */
   get activeUpdate() {
     if (this._activeUpdate &&
         this._activeUpdate.channel != UpdateChannel.get()) {
-      // User switched channels, clear out any old active updates and remove
-      // partial downloads
-      this._activeUpdate = null;
-      this.saveUpdates();
-
-      // Destroy the updates directory, since we're done with it.
-      cleanUpUpdatesDir();
+      LOG("UpdateManager:get activeUpdate - channel has changed, " +
+          "reloading default preferences to workaround bug 802022");
+      // Workaround to get distribution preferences loaded (Bug 774618). This
+      // can be removed after bug 802022 is fixed.
+      let prefSvc = Services.prefs.QueryInterface(Ci.nsIObserver);
+      prefSvc.observe(null, "reload-default-prefs", null);
+      if (this._activeUpdate.channel != UpdateChannel.get()) {
+        // User switched channels, clear out any old active updates and remove
+        // partial downloads
+        this._activeUpdate = null;
+        this.saveUpdates();
+
+        // Destroy the updates directory, since we're done with it.
+        cleanUpUpdatesDir();
+      }
     }
     return this._activeUpdate;
   },
   set activeUpdate(activeUpdate) {
     this._addUpdate(activeUpdate);
     this._activeUpdate = activeUpdate;
     if (!activeUpdate) {
       // If |activeUpdate| is null, we have updated both lists - the active list