Bug 1086936 part 2 - Add a flag to nsIAppStartup::quit that restarts the browser without using the same profile and use it for the Aurora UI switch. r=bsmedberg
authorPanos Astithas <past@mozilla.com>
Wed, 22 Oct 2014 20:39:20 +0300
changeset 233712 f0abb6e26c0902efc46823166ea9489ee737412c
parent 233711 b8162870a2086db971aee986dbe8d04cdb6cdb95
child 233713 19e3dd4d73657d3a053c782872f8e60bc848f22b
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1086936
milestone35.0a2
Bug 1086936 part 2 - Add a flag to nsIAppStartup::quit that restarts the browser without using the same profile and use it for the Aurora UI switch. r=bsmedberg
browser/components/preferences/in-content/main.js
browser/components/preferences/main.js
toolkit/components/startup/nsAppStartup.cpp
toolkit/components/startup/nsAppStartup.h
toolkit/components/startup/public/nsIAppStartup.idl
toolkit/xre/nsAppRunner.cpp
xpcom/base/ErrorList.h
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -166,17 +166,17 @@ var gMainPane = {
     e10sCheckbox.checked = e10sPref.value || e10sTempPref.value;
   },
 #endif
 
 #ifdef MOZ_DEV_EDITION
   separateProfileModeChange: function ()
   {
     function quitApp() {
-      Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit |  Ci.nsIAppStartup.eRestart);
+      Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit |  Ci.nsIAppStartup.eRestartNotSameProfile);
     }
     function revertCheckbox(error) {
       separateProfileModeCheckbox.checked = !separateProfileModeCheckbox.checked;
       if (error) {
         Cu.reportError("Failed to toggle separate profile mode: " + error);
       }
     }
 
--- a/browser/components/preferences/main.js
+++ b/browser/components/preferences/main.js
@@ -82,17 +82,17 @@ var gMainPane = {
               .getService(Components.interfaces.nsIObserverService)
               .notifyObservers(window, "main-pane-loaded", null);
   },
 
 #ifdef MOZ_DEV_EDITION
   separateProfileModeChange: function ()
   {
     function quitApp() {
-      Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit |  Ci.nsIAppStartup.eRestart);
+      Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit |  Ci.nsIAppStartup.eRestartNotSameProfile);
     }
     function revertCheckbox(error) {
       separateProfileModeCheckbox.checked = !separateProfileModeCheckbox.checked;
       if (error) {
         Cu.reportError("Failed to toggle separate profile mode: " + error);
       }
     }
 
--- a/toolkit/components/startup/nsAppStartup.cpp
+++ b/toolkit/components/startup/nsAppStartup.cpp
@@ -138,17 +138,18 @@ nsAppStartup::nsAppStartup() :
   mRunning(false),
   mShuttingDown(false),
   mStartingUp(true),
   mAttemptingQuit(false),
   mRestart(false),
   mInterrupted(false),
   mIsSafeModeNecessary(false),
   mStartupCrashTrackingEnded(false),
-  mRestartTouchEnvironment(false)
+  mRestartTouchEnvironment(false),
+  mRestartNotSameProfile(false)
 { }
 
 
 nsresult
 nsAppStartup::Init()
 {
   nsresult rv;
 
@@ -282,16 +283,18 @@ nsAppStartup::Run(void)
       return rv;
   }
 
   nsresult retval = NS_OK;
   if (mRestartTouchEnvironment) {
     retval = NS_SUCCESS_RESTART_METRO_APP;
   } else if (mRestart) {
     retval = NS_SUCCESS_RESTART_APP;
+  } else if (mRestartNotSameProfile) {
+    retval = NS_SUCCESS_RESTART_APP_NOT_SAME_PROFILE;
   }
 
   return retval;
 }
 
 
 
 NS_IMETHODIMP
@@ -381,17 +384,22 @@ nsAppStartup::Quit(uint32_t aMode)
       gRestartMode = (aMode & 0xF0);
     }
 
     if (!mRestartTouchEnvironment) {
       mRestartTouchEnvironment = (aMode & eRestartTouchEnvironment) != 0;
       gRestartMode = (aMode & 0xF0);
     }
 
-    if (mRestart || mRestartTouchEnvironment) {
+    if (!mRestartNotSameProfile) {
+      mRestartNotSameProfile = (aMode & eRestartNotSameProfile) != 0;
+      gRestartMode = (aMode & 0xF0);
+    }
+
+    if (mRestart || mRestartTouchEnvironment || mRestartNotSameProfile) {
       // Mark the next startup as a restart.
       PR_SetEnv("MOZ_APP_RESTART=1");
 
       /* Firefox-restarts reuse the process so regular process start-time isn't
          a useful indicator of startup time anymore. */
       TimeStamp::RecordProcessRestart();
     }
 
@@ -451,17 +459,17 @@ nsAppStartup::Quit(uint32_t aMode)
     // do it!
 
     // No chance of the shutdown being cancelled from here on; tell people
     // we're shutting down for sure while all services are still available.
     if (obsService) {
       NS_NAMED_LITERAL_STRING(shutdownStr, "shutdown");
       NS_NAMED_LITERAL_STRING(restartStr, "restart");
       obsService->NotifyObservers(nullptr, "quit-application",
-        (mRestart || mRestartTouchEnvironment) ?
+        (mRestart || mRestartTouchEnvironment || mRestartNotSameProfile) ?
          restartStr.get() : shutdownStr.get());
     }
 
     if (!mRunning) {
       postedExitEvent = true;
     }
     else {
       // no matter what, make sure we send the exit event.  If
--- a/toolkit/components/startup/nsAppStartup.h
+++ b/toolkit/components/startup/nsAppStartup.h
@@ -57,17 +57,18 @@ private:
   bool mRunning;        // Have we started the main event loop?
   bool mShuttingDown;   // Quit method reentrancy check
   bool mStartingUp;     // Have we passed final-ui-startup?
   bool mAttemptingQuit; // Quit(eAttemptQuit) still trying
   bool mRestart;        // Quit(eRestart)
   bool mInterrupted;    // Was startup interrupted by an interactive prompt?
   bool mIsSafeModeNecessary;       // Whether safe mode is necessary
   bool mStartupCrashTrackingEnded; // Whether startup crash tracking has already ended
-  bool mRestartTouchEnvironment; // Quit (eRestartTouchEnvironment)
+  bool mRestartTouchEnvironment;   // Quit (eRestartTouchEnvironment)
+  bool mRestartNotSameProfile;     // Quit(eRestartNotSameProfile)
 
 #if defined(XP_WIN)
   //Interaction with OS-provided profiling probes
   typedef mozilla::probes::ProbeManager ProbeManager;
   typedef mozilla::probes::Probe        Probe;
   nsRefPtr<ProbeManager> mProbesManager;
   nsRefPtr<Probe> mPlacesInitCompleteProbe;
   nsRefPtr<Probe> mSessionWindowRestoredProbe;
--- a/toolkit/components/startup/public/nsIAppStartup.idl
+++ b/toolkit/components/startup/public/nsIAppStartup.idl
@@ -31,16 +31,21 @@ interface nsIAppStartup : nsISupports
      * @returnCode NS_SUCCESS_RESTART_APP
      *             This return code indicates that the application should be
      *             restarted because quit was called with the eRestart flag.
 
      * @returnCode NS_SUCCESS_RESTART_METRO_APP
      *             This return code indicates that the application should be
      *             restarted in metro because quit was called with the
      *             eRestartTouchEnviroment flag.
+
+     * @returnCode NS_SUCCESS_RESTART_APP_NOT_SAME_PROFILE
+     *             This return code indicates that the application should be
+     *             restarted without necessarily using the same profile because
+     *             quit was called with the eRestartNotSameProfile flag.
      */
     void run();
 
     /**
      * There are situations where all application windows will be
      * closed but we don't want to take this as a signal to quit the
      * app. Bracket the code where the last window could close with
      * these.
@@ -130,16 +135,23 @@ interface nsIAppStartup : nsISupports
     /**
      * Restart the application in a touch-optimized environment (such as Metro)
      * after quitting. The application will be restarted with the same profile
      * and an empty command line.
      */
     const uint32_t eRestartTouchEnvironment = 0x80;
 
     /**
+     * Restart the application after quitting.  The application will be
+     * restarted with an empty command line and the normal profile selection
+     * process will take place on startup.
+     */
+    const uint32_t eRestartNotSameProfile = 0x100;
+
+    /**
      * Exit the event loop, and shut down the app.
      *
      * @param aMode
      *        This parameter modifies how the app is shutdown, and it is
      *        constructed from the constants defined above.
      */
     void quit(in uint32_t aMode);
 
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -4241,17 +4241,19 @@ XREMain::XRE_main(int argc, char* argv[]
   rv = XRE_mainRun();
 
 #ifdef MOZ_INSTRUMENT_EVENT_LOOP
   mozilla::ShutdownEventTracing();
 #endif
 
   // Check for an application initiated restart.  This is one that
   // corresponds to nsIAppStartup.quit(eRestart)
-  if (rv == NS_SUCCESS_RESTART_APP || rv == NS_SUCCESS_RESTART_METRO_APP) {
+  if (rv == NS_SUCCESS_RESTART_APP
+      || rv == NS_SUCCESS_RESTART_METRO_APP
+      || rv == NS_SUCCESS_RESTART_APP_NOT_SAME_PROFILE) {
     appInitiatedRestart = true;
 
     // We have an application restart don't do any shutdown checks here
     // In particular we don't want to poison IO for checking late-writes.
     gShutdownChecks = SCM_NOTHING;
   }
 
   if (!mShuttingDown) {
@@ -4274,20 +4276,22 @@ XREMain::XRE_main(int argc, char* argv[]
 #if defined(MOZ_WIDGET_QT)
   nsQAppInstance::Release();
 #endif
 
   // Restart the app after XPCOM has been shut down cleanly. 
   if (appInitiatedRestart) {
     RestoreStateForAppInitiatedRestart();
 
-    // Ensure that these environment variables are set:
-    SaveFileToEnvIfUnset("XRE_PROFILE_PATH", mProfD);
-    SaveFileToEnvIfUnset("XRE_PROFILE_LOCAL_PATH", mProfLD);
-    SaveWordToEnvIfUnset("XRE_PROFILE_NAME", mProfileName);
+    if (rv != NS_SUCCESS_RESTART_APP_NOT_SAME_PROFILE) {
+      // Ensure that these environment variables are set:
+      SaveFileToEnvIfUnset("XRE_PROFILE_PATH", mProfD);
+      SaveFileToEnvIfUnset("XRE_PROFILE_LOCAL_PATH", mProfLD);
+      SaveWordToEnvIfUnset("XRE_PROFILE_NAME", mProfileName);
+    }
 
 #ifdef MOZ_WIDGET_GTK
     MOZ_gdk_display_close(mGdkDisplay);
 #endif
 
 #if defined(MOZ_METRO) && defined(XP_WIN)
     if (rv == NS_SUCCESS_RESTART_METRO_APP) {
       LaunchDefaultMetroBrowser();
--- a/xpcom/base/ErrorList.h
+++ b/xpcom/base/ErrorList.h
@@ -901,16 +901,17 @@
   ERROR(NS_ERROR_DOCUMENT_IS_PRINTMODE,  FAILURE(2001)),
 
   ERROR(NS_SUCCESS_DONT_FIXUP,           SUCCESS(1)),
   /* This success code may be returned by nsIAppStartup::Run to indicate that
    * the application should be restarted.  This condition corresponds to the
    * case in which nsIAppStartup::Quit was called with the eRestart flag. */
   ERROR(NS_SUCCESS_RESTART_APP,          SUCCESS(1)),
   ERROR(NS_SUCCESS_RESTART_METRO_APP,    SUCCESS(2)),
+  ERROR(NS_SUCCESS_RESTART_APP_NOT_SAME_PROFILE,    SUCCESS(3)),
   ERROR(NS_SUCCESS_UNORM_NOTFOUND,  SUCCESS(17)),
 
 
   /* a11y */
   /* raised when current pivot's position is needed but it's not in the tree */
   ERROR(NS_ERROR_NOT_IN_TREE,  FAILURE(38)),
 
   /* see nsTextEquivUtils */