Bug 619432 - AUS notification fails and is not offered again if Fennec closes during update [r=mfinkle]
authorAlex Pakhotin <alexp@mozilla.com>
Tue, 28 Dec 2010 20:39:36 -0800
changeset 67231 713735c00c2fabefee5265ea6b1595d60a349b02
parent 67230 34b5e0badd3ebeaa7c1d1eefa76923466891b90e
child 67232 c34e9d016a0f435d937fb44353b8e3851eaf26c7
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs619432
Bug 619432 - AUS notification fails and is not offered again if Fennec closes during update [r=mfinkle]
mobile/chrome/content/browser-ui.js
mobile/components/UpdatePrompt.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -503,16 +503,22 @@ var BrowserUI = {
 
       // Init helpers
       BadgeHandlers.register(BrowserUI._edit.popup);
       FormHelperUI.init();
       FindHelperUI.init();
       PageActions.init();
       FullScreenVideo.init();
       NewTabPopup.init();
+
+#ifdef MOZ_UPDATER
+      // Check for updates in progress
+      let updatePrompt = Cc["@mozilla.org/updates/update-prompt;1"].createInstance(Ci.nsIUpdatePrompt);
+      updatePrompt.checkForUpdates();
+#endif
     }, false);
   },
 
   uninit: function() {
     ExtensionsView.uninit();
     ConsoleView.uninit();
   },
 
--- a/mobile/components/UpdatePrompt.js
+++ b/mobile/components/UpdatePrompt.js
@@ -35,16 +35,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 const UPDATE_NOTIFICATION_NAME = "update-app";
+const UPDATE_NOTIFICATION_ICON = "drawable://alert_download_progress";
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 
 XPCOMUtils.defineLazyGetter(this, "gUpdateBundle", function aus_gUpdateBundle() {
   return Services.strings.createBundle("chrome://mozapps/locale/update/updates.properties");
 });
@@ -109,18 +110,17 @@ UpdatePrompt.prototype = {
       let flags = prompt.BUTTON_POS_0 * prompt.BUTTON_TITLE_IS_STRING + prompt.BUTTON_POS_1 * prompt.BUTTON_TITLE_IS_STRING;
 
       let download = (prompt.confirmEx(window, title, message, flags, button0, button1, null, null, {value: false}) == 0);
       if (download) {
         // Start downloading the update in the background
         let aus = Cc["@mozilla.org/updates/update-service;1"].getService(Ci.nsIApplicationUpdateService);
         if (aus.downloadUpdate(aUpdate, true) != "failed") {
           let title = gBrowserBundle.formatStringFromName("alertDownloadsStart", [aUpdate.name], 1);
-          let imageUrl = "drawable://alert_download_progress";
-          this._showNotification(aUpdate, title, "", imageUrl, "download");
+          this._showNotification(aUpdate, title, "", UPDATE_NOTIFICATION_ICON, "download");
 
           // Add this UI as a listener for active downloads
           aus.addDownloadListener(this);
         }
       }
     } else if(aMode == "downloaded") {
       // Notify all windows that an application quit has been requested
       let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
@@ -139,19 +139,35 @@ UpdatePrompt.prototype = {
     let progressListener = alertsService.QueryInterface(Ci.nsIAlertsProgressListener);
     if (progressListener)
       progressListener.onProgress(UPDATE_NOTIFICATION_NAME, aProgress, aTotal);
   },
 
   // -------------------------
   // nsIUpdatePrompt interface
   // -------------------------
-  
+
+  // Right now this is used only to check for updates in progress
   checkForUpdates: function UP_checkForUpdates() {
-    // NOT IMPL
+    if (!this._enabled)
+      return;
+
+    let aus = Cc["@mozilla.org/updates/update-service;1"].getService(Ci.nsIApplicationUpdateService);
+    if (!aus.isDownloading)
+      return;
+
+    let updateManager = Cc["@mozilla.org/updates/update-manager;1"].getService(Ci.nsIUpdateManager);
+
+    let updateName = updateManager.activeUpdate ? updateManager.activeUpdate.name : gBrandBundle.GetStringFromName("brandShortName");
+    let title = gBrowserBundle.formatStringFromName("alertDownloadsStart", [updateName], 1);
+
+    this._showNotification(updateManager.activeUpdate, title, "", UPDATE_NOTIFICATION_ICON, "downloading");
+
+    aus.removeDownloadListener(this); // just in case it's already added
+    aus.addDownloadListener(this);
   },
 
   showUpdateAvailable: function UP_showUpdateAvailable(aUpdate) {
     if (!this._enabled)
       return;
 
     let stringsPrefix = "updateAvailable_" + aUpdate.type + ".";
     let title = gUpdateBundle.formatStringFromName(stringsPrefix + "title", [aUpdate.name], 1);