Bug 874323 - Start updater manually for Metro to apply update. r=rstrong
authorBrian R. Bondy <netzen@gmail.com>
Wed, 12 Jun 2013 10:31:10 -0400
changeset 146255 c6e7f96503d9e07cafdde5090971c1c2cd020c15
parent 146254 fa1e4a3085277286a717fc48418f295b83aaabea
child 146256 03ff0bc0c319b6b547f1793dbea9be421c4b85e9
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong
bugs874323
milestone24.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 874323 - Start updater manually for Metro to apply update. r=rstrong
browser/metro/base/content/aboutPanel.js
toolkit/mozapps/update/nsIUpdateService.idl
toolkit/xre/nsUpdateDriver.cpp
--- a/browser/metro/base/content/aboutPanel.js
+++ b/browser/metro/base/content/aboutPanel.js
@@ -232,27 +232,39 @@ appUpdater.prototype =
       let cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"].
                        createInstance(Components.interfaces.nsISupportsPRBool);
       Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
 
       // Something aborted the quit process.
       if (cancelQuit.data)
         return;
 
+      // It's not possible for the Metro browser to restart itself.
+      // The Windows background process ensures only one instance exists.
+      // So start the update while the browser is open and close the browser
+      // right after.
+      try {
+        Components.classes["@mozilla.org/updates/update-processor;1"].
+          createInstance(Components.interfaces.nsIUpdateProcessor).
+          processUpdate(null);
+      } catch (e) {
+        // If there was an error just close down and the next startup
+        // will do this.
+      }
+
       let appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"].
                        getService(Components.interfaces.nsIAppStartup);
 
       // If already in safe mode restart in safe mode (bug 327119)
       if (Services.appinfo.inSafeMode) {
         appStartup.restartInSafeMode(Components.interfaces.nsIAppStartup.eAttemptQuit);
         return;
       }
 
-      appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit |
-                      Components.interfaces.nsIAppStartup.eRestart);
+      appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
       return;
     }
 
     const URI_UPDATE_PROMPT_DIALOG = "chrome://mozapps/content/update/updates.xul";
     // Firefox no longer displays a license for updates and the licenseURL check
     // is just in case a distibution does.
     if (this.update && (this.update.billboardURL || this.update.licenseURL ||
         this.addons.length != 0)) {
--- a/toolkit/mozapps/update/nsIUpdateService.idl
+++ b/toolkit/mozapps/update/nsIUpdateService.idl
@@ -449,16 +449,20 @@ interface nsIApplicationUpdateService : 
  * an update after it's been downloaded.
  */
 [scriptable, uuid(74439497-d796-4915-8cef-3dfe43027e4d)]
 interface nsIUpdateProcessor : nsISupports
 {
   /**
    * Processes the update which has been downloaded.
    * This happens without restarting the application.
+   * On Windows, this can also be used for switching to an applied
+   * update request.
+   * @param update The update being applied, or null if this is a switch
+   *               to updated application request.  Must be non-null on GONK.
    */
   void processUpdate(in nsIUpdate update);
 };
 
 /**
  * An interface describing a global application service that maintains a list
  * of updates previously performed as well as the current active update.
  */
--- a/toolkit/xre/nsUpdateDriver.cpp
+++ b/toolkit/xre/nsUpdateDriver.cpp
@@ -1029,18 +1029,16 @@ nsUpdateProcessor::nsUpdateProcessor()
 NS_IMETHODIMP
 nsUpdateProcessor::ProcessUpdate(nsIUpdate* aUpdate)
 {
   nsCOMPtr<nsIFile> greDir, appDir, updRoot;
   nsAutoCString appVersion;
   int argc;
   char **argv;
 
-  NS_ENSURE_ARG_POINTER(aUpdate);
-
   nsAutoCString binPath;
   nsXREDirProvider* dirProvider = nsXREDirProvider::GetSingleton();
   if (dirProvider) { // Normal code path
     // Check for and process any available updates
     bool persistent;
     nsresult rv = NS_ERROR_FAILURE; // Take the NS_FAILED path when non-GONK
 #ifdef MOZ_WIDGET_GONK
     // Check in the sdcard for updates first, since that's our preferred
@@ -1127,16 +1125,18 @@ nsUpdateProcessor::ProcessUpdate(nsIUpda
     MOZ_ASSERT(argc == 1); // see above
     const size_t length = binPath.Length();
     mInfo.mArgv[0] = new char[length + 1];
     strcpy(mInfo.mArgv[0], binPath.get());
   }
   mInfo.mAppVersion = appVersion;
 
 #if defined(MOZ_WIDGET_GONK)
+  NS_ENSURE_ARG_POINTER(aUpdate);
+
   bool isOSUpdate;
   if (NS_SUCCEEDED(aUpdate->GetIsOSUpdate(&isOSUpdate)) &&
       isOSUpdate) {
     nsAutoCString osApplyToDir;
 
     // This needs to be done on the main thread, so we pass it along in
     // BackgroundThreadInfo
     nsresult rv = GetOSApplyToDir(osApplyToDir);
@@ -1209,15 +1209,15 @@ nsUpdateProcessor::WaitForProcess()
 
 void
 nsUpdateProcessor::UpdateDone()
 {
   NS_ABORT_IF_FALSE(NS_IsMainThread(), "not main thread");
 
   nsCOMPtr<nsIUpdateManager> um =
     do_GetService("@mozilla.org/updates/update-manager;1");
-  if (um) {
+  if (um && mUpdate) {
     um->RefreshUpdateStatus(mUpdate);
   }
 
   ShutdownWatcherThread();
 }