diff options
| author | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-05 16:29:58 +0000 |
|---|---|---|
| committer | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-05 16:29:58 +0000 |
| commit | 88c887847a7e19356adccb1b94cc79712343ca93 (patch) | |
| tree | eff0f67cd3e24ccaf2d7310f73eaed3035a5cd32 | |
| parent | a995d04ab4c452670e4b14d83182ccea49aad41b (diff) | |
| download | chromium_src-88c887847a7e19356adccb1b94cc79712343ca93.zip chromium_src-88c887847a7e19356adccb1b94cc79712343ca93.tar.gz chromium_src-88c887847a7e19356adccb1b94cc79712343ca93.tar.bz2 | |
Store the "browser autorestarted, last session must be restored" information in a preference.
This way ChromiumOS can run the same session restore code as Chrome.
BUG=1870
TEST=NONE
Review URL: http://codereview.chromium.org/8745015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112985 0039d316-1c4b-4281-b951-d872f2087c98
| -rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 2 | ||||
| -rw-r--r-- | chrome/browser/background/background_mode_manager.cc | 2 | ||||
| -rw-r--r-- | chrome/browser/browser_process_impl.cc | 2 | ||||
| -rw-r--r-- | chrome/browser/browser_shutdown.cc | 4 | ||||
| -rw-r--r-- | chrome/browser/chrome_browser_main_posix.cc | 2 | ||||
| -rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 3 | ||||
| -rw-r--r-- | chrome/browser/ui/browser.cc | 2 | ||||
| -rw-r--r-- | chrome/browser/ui/browser_init.cc | 5 | ||||
| -rw-r--r-- | chrome/browser/ui/browser_list.cc | 16 | ||||
| -rw-r--r-- | chrome/browser/ui/browser_list.h | 6 | ||||
| -rw-r--r-- | chrome/browser/upgrade_detector.cc | 1 | ||||
| -rw-r--r-- | chrome/common/pref_names.cc | 3 | ||||
| -rw-r--r-- | chrome/common/pref_names.h | 1 | ||||
| -rw-r--r-- | chrome/test/base/in_process_browser_test.cc | 3 |
14 files changed, 30 insertions, 22 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index bd3528b..2f3f628 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -477,7 +477,7 @@ bool TestingAutomationProvider::OnMessageReceived( void TestingAutomationProvider::OnChannelError() { if (!reinitialize_on_channel_error_ && browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID) - BrowserList::AttemptExit(); + BrowserList::AttemptExit(false); AutomationProvider::OnChannelError(); } diff --git a/chrome/browser/background/background_mode_manager.cc b/chrome/browser/background/background_mode_manager.cc index de71250..151bfac 100644 --- a/chrome/browser/background/background_mode_manager.cc +++ b/chrome/browser/background/background_mode_manager.cc @@ -396,7 +396,7 @@ void BackgroundModeManager::ExecuteCommand(int command_id) { break; case IDC_EXIT: UserMetrics::RecordAction(UserMetricsAction("Exit")); - BrowserList::AttemptExit(); + BrowserList::AttemptExit(false); break; case IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND: { // Background mode must already be enabled (as otherwise this menu would diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index fc7aeda..cf3861a 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -983,7 +983,7 @@ void BrowserProcessImpl::RestartBackgroundInstance() { } DLOG(WARNING) << "Shutting down current instance of the browser."; - BrowserList::AttemptExit(); + BrowserList::AttemptExit(true); // Transfer ownership to Upgrade. upgrade_util::SetNewCommandLine(new_cl.release()); diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc index 044b505..7f46b5e 100644 --- a/chrome/browser/browser_shutdown.cc +++ b/chrome/browser/browser_shutdown.cc @@ -218,10 +218,6 @@ void ShutdownPostThreadsStop(bool restart_last_session) { else new_cl->AppendSwitch(i->first); } - // Ensure restore last session is set. - if (!new_cl->HasSwitch(switches::kRestoreLastSession)) - new_cl->AppendSwitch(switches::kRestoreLastSession); - upgrade_util::RelaunchChromeBrowser(*new_cl.get()); #else NOTIMPLEMENTED(); diff --git a/chrome/browser/chrome_browser_main_posix.cc b/chrome/browser/chrome_browser_main_posix.cc index 67e2371..8ef704f 100644 --- a/chrome/browser/chrome_browser_main_posix.cc +++ b/chrome/browser/chrome_browser_main_posix.cc @@ -140,7 +140,7 @@ void ShutdownDetector::ThreadMain() { // On ChromeOS, exiting on signal should be always clean. base::Closure task = base::Bind(&BrowserList::ExitCleanly); #else - base::Closure task = base::Bind(&BrowserList::AttemptExit); + base::Closure task = base::Bind(&BrowserList::AttemptExit, false); #endif if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task)) { diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index b70b68b..cd280cd 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -380,7 +380,8 @@ void ProfileImpl::DoFinalInit() { session_restore_enabled_ && (!DidLastSessionExitCleanly() || CommandLine::ForCurrentProcess()->HasSwitch( - switches::kRestoreLastSession)); + switches::kRestoreLastSession) || + local_state->GetBoolean(prefs::kWasRestarted)); // Make sure we initialize the ProfileIOData after everything else has been // initialized that we might be reading from the IO thread. diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 4e81a7c..98b39e7 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -1776,7 +1776,7 @@ void Browser::ShowKeyboardOverlay() { void Browser::Exit() { UserMetrics::RecordAction(UserMetricsAction("Exit")); - BrowserList::AttemptUserExit(); + BrowserList::AttemptUserExit(false); } void Browser::BookmarkCurrentPage() { diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc index b1dd2db..87c15a1 100644 --- a/chrome/browser/ui/browser_init.cc +++ b/chrome/browser/ui/browser_init.cc @@ -332,9 +332,12 @@ bool IncognitoIsForced(const CommandLine& command_line, SessionStartupPref GetSessionStartupPref(const CommandLine& command_line, Profile* profile) { + PrefService* pref_service = g_browser_process->local_state(); SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile); - if (command_line.HasSwitch(switches::kRestoreLastSession)) + if (command_line.HasSwitch(switches::kRestoreLastSession) || + pref_service->GetBoolean(prefs::kWasRestarted)) { pref.type = SessionStartupPref::LAST; + } if (pref.type == SessionStartupPref::LAST && IncognitoIsForced(command_line, profile->GetPrefs())) { // We don't store session information when incognito. If the user has diff --git a/chrome/browser/ui/browser_list.cc b/chrome/browser/ui/browser_list.cc index 3ce3e51..8c7fd14 100644 --- a/chrome/browser/ui/browser_list.cc +++ b/chrome/browser/ui/browser_list.cc @@ -302,7 +302,9 @@ void BrowserList::MarkAsCleanShutdown() { } } -void BrowserList::AttemptExitInternal() { +void BrowserList::AttemptExitInternal(bool restart) { + PrefService* pref_service = g_browser_process->local_state(); + pref_service->SetBoolean(prefs::kWasRestarted, restart); content::NotificationService::current()->Notify( content::NOTIFICATION_APP_EXITING, content::NotificationService::AllSources(), @@ -479,7 +481,7 @@ void BrowserList::CloseAllBrowsersWithProfile(Profile* profile) { } // static -void BrowserList::AttemptUserExit() { +void BrowserList::AttemptUserExit(bool restart) { #if defined(OS_CHROMEOS) chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutStarted", false); // Write /tmp/uptime-logout-started as well. @@ -506,7 +508,7 @@ void BrowserList::AttemptUserExit() { PrefService* pref_service = g_browser_process->local_state(); pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); #endif - AttemptExitInternal(); + AttemptExitInternal(restart); } // static @@ -522,24 +524,24 @@ void BrowserList::AttemptRestart() { // For CrOS instead of browser restart (which is not supported) perform a full // sign out. Session will be only restored if user has that setting set. // Same session restore behavior happens in case of full restart after update. - AttemptUserExit(); + AttemptUserExit(true); #else // Set the flag to restore state after the restart. PrefService* pref_service = g_browser_process->local_state(); pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); - AttemptExit(); + AttemptExit(true); #endif } // static -void BrowserList::AttemptExit() { +void BrowserList::AttemptExit(bool restart) { // If we know that all browsers can be closed without blocking, // don't notify users of crashes beyond this point. // Note that MarkAsCleanShutdown does not set UMA's exit cleanly bit // so crashes during shutdown are still reported in UMA. if (AreAllBrowsersCloseable()) MarkAsCleanShutdown(); - AttemptExitInternal(); + AttemptExitInternal(restart); } #if defined(OS_CHROMEOS) diff --git a/chrome/browser/ui/browser_list.h b/chrome/browser/ui/browser_list.h index 700c51a..5d33412 100644 --- a/chrome/browser/ui/browser_list.h +++ b/chrome/browser/ui/browser_list.h @@ -115,7 +115,7 @@ class BrowserList { // CloseAllBrowsersAndExit. On ChromeOS, this tells session manager // that chrome is signing out, which lets session manager send // SIGTERM to start actual exit process. - static void AttemptUserExit(); + static void AttemptUserExit(bool restart); // Starts a user initiated restart process. On platforms other than // chromeos, this sets a restart bit in the preference so that @@ -131,7 +131,7 @@ class BrowserList { // successfully closed. // Note that he exit process may be interrupted by download or // unload handler, and the browser may or may not exit. - static void AttemptExit(); + static void AttemptExit(bool restart); #if defined(OS_CHROMEOS) // This is equivalent to AttemptUserExit, except that it always set @@ -210,7 +210,7 @@ class BrowserList { // Helper method to remove a browser instance from a list of browsers static void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list); static void MarkAsCleanShutdown(); - static void AttemptExitInternal(); + static void AttemptExitInternal(bool restart); // Counter of calls to StartKeepAlive(). If non-zero, the application will // continue running after the last browser has exited. diff --git a/chrome/browser/upgrade_detector.cc b/chrome/browser/upgrade_detector.cc index e083375..df6c331 100644 --- a/chrome/browser/upgrade_detector.cc +++ b/chrome/browser/upgrade_detector.cc @@ -33,6 +33,7 @@ bool UseTestingIntervals() { // static void UpgradeDetector::RegisterPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kRestartLastSessionOnShutdown, false); + prefs->RegisterBooleanPref(prefs::kWasRestarted, false); } int UpgradeDetector::GetIconResourceID(UpgradeNotificationIconType type) { diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index eaee7c8..6743d18 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -1201,6 +1201,9 @@ const char kShutdownNumProcessesSlow[] = "shutdown.num_processes_slow"; // before shutting everything down. const char kRestartLastSessionOnShutdown[] = "restart.last.session.on.shutdown"; +// Set before autorestarting Chrome, cleared on clean exit. +const char kWasRestarted[] = "was.restarted"; + // Number of bookmarks/folders on the bookmark bar/other bookmark folder. const char kNumBookmarksOnBookmarkBar[] = "user_experience_metrics.num_bookmarks_on_bookmark_bar"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index e60d9a1..3fee3a1 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -423,6 +423,7 @@ extern const char kShutdownNumProcesses[]; extern const char kShutdownNumProcessesSlow[]; extern const char kRestartLastSessionOnShutdown[]; +extern const char kWasRestarted[]; extern const char kNumBookmarksOnBookmarkBar[]; extern const char kNumFoldersOnBookmarkBar[]; diff --git a/chrome/test/base/in_process_browser_test.cc b/chrome/test/base/in_process_browser_test.cc index b26c80b..1dfca8b 100644 --- a/chrome/test/base/in_process_browser_test.cc +++ b/chrome/test/base/in_process_browser_test.cc @@ -328,6 +328,7 @@ void InProcessBrowserTest::QuitBrowsers() { // CloseAllBrowsersAndMayExit exits the message loop after everything has been // shut down properly. MessageLoopForUI::current()->PostTask(FROM_HERE, - base::Bind(&BrowserList::AttemptExit)); + base::Bind(&BrowserList::AttemptExit, + false)); ui_test_utils::RunMessageLoop(); } |
