Commit 56be508a authored by skuhne's avatar skuhne Committed by Commit bot

Fixing problem where a session restore gets performed even though users don't want it

The problem: In various cases we have seen that the user setting to ignore the restore option (nothing / all) gets ignored.
Examples: Per user command line changes enforce a restart of chrome after login. After update, ...

On ChromeOS we need only to overwrite the user setting when chrome crashed - which would be identified by the commandline option.

I run all browser tests and changed some tests to respect this behavior.

BUG=395925
TEST=existing unit tests

Review URL: https://codereview.chromium.org/653773003

Cr-Commit-Position: refs/heads/master@{#299995}
parent 0181f4ac
......@@ -579,13 +579,16 @@ IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest,
CheckFormRestored(new_browser, false, false);
}
// ChromeOS does not override the SessionStartupPreference upon controlled
// system restart.
#if !defined(OS_CHROMEOS)
class RestartTest : public BetterSessionRestoreTest {
public:
RestartTest() { }
virtual ~RestartTest() { }
protected:
void Restart() {
// Simluate restarting the browser, but let the test exit peacefully.
// Simulate restarting the browser, but let the test exit peacefully.
for (chrome::BrowserIterator it; !it.done(); it.Next())
content::BrowserContext::SaveSessionState(it->profile());
PrefService* pref_service = g_browser_process->local_state();
......@@ -658,6 +661,7 @@ IN_PROC_BROWSER_TEST_F(RestartTest, PostWithPassword) {
// The form data contained passwords, so it's removed completely.
CheckFormRestored(false, false);
}
#endif
// These tests ensure that the Better Session Restore features are not triggered
// when they shouldn't be.
......
......@@ -5,6 +5,7 @@
#include <list>
#include <vector>
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
......@@ -14,6 +15,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/sessions/serialized_navigation_entry_test_helper.h"
......@@ -67,10 +69,10 @@ class SessionRestoreTestChromeOS : public InProcessBrowserTest {
name, trusted, gfx::Rect(), profile(), chrome::GetActiveDesktop());
}
// Simluate restarting the browser
void SetRestart() {
PrefService* pref_service = g_browser_process->local_state();
pref_service->SetBoolean(prefs::kWasRestarted, true);
// Turn on session restore before we restart.
void TurnOnSessionRestore() {
SessionStartupPref::SetStartupPref(
browser()->profile(), SessionStartupPref(SessionStartupPref::LAST));
}
Profile* profile() { return browser()->profile(); }
......@@ -91,7 +93,7 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreBrowserWindows) {
// Create a third incognito browser window which should not get restored.
CreateBrowserWithParams(Browser::CreateParams(
profile()->GetOffTheRecordProfile(), chrome::GetActiveDesktop()));
SetRestart();
TurnOnSessionRestore();
}
IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreBrowserWindows) {
......@@ -115,7 +117,7 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreAppsV1) {
// Create a third untrusted (child) app3 popup. This should not get restored.
CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name2, false));
SetRestart();
TurnOnSessionRestore();
}
IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreAppsV1) {
......@@ -154,7 +156,7 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreMaximized) {
EXPECT_FALSE(app_browser1->window()->IsMaximized());
EXPECT_TRUE(app_browser2->window()->IsMaximized());
SetRestart();
TurnOnSessionRestore();
}
IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreMaximized) {
......
......@@ -362,8 +362,13 @@ SessionStartupPref StartupBrowserCreator::GetSessionStartupPref(
#if defined(OS_CHROMEOS)
const bool is_first_run =
user_manager::UserManager::Get()->IsCurrentUserNew();
// On ChromeOS restarts force the user to login again. The expectation is that
// after a login the user gets clean state. For this reason we ignore
// StartupBrowserCreator::WasRestarted().
const bool did_restart = false;
#else
const bool is_first_run = first_run::IsChromeFirstRun();
const bool did_restart = StartupBrowserCreator::WasRestarted();
#endif
// The pref has an OS-dependent default value. For the first run only, this
......@@ -379,8 +384,7 @@ SessionStartupPref StartupBrowserCreator::GetSessionStartupPref(
// However, new profiles can be created from a browser process that has this
// switch so do not set the session pref to SessionStartupPref::LAST for
// those as there is nothing to restore.
if ((command_line.HasSwitch(switches::kRestoreLastSession) ||
StartupBrowserCreator::WasRestarted()) &&
if ((command_line.HasSwitch(switches::kRestoreLastSession) || did_restart) &&
!profile->IsNewProfile()) {
pref.type = SessionStartupPref::LAST;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment