diff options
author | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-29 18:48:58 +0000 |
---|---|---|
committer | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-29 18:48:58 +0000 |
commit | cb62c76837ca651a5d02f679ddb67767a61c35c6 (patch) | |
tree | aa2a67935236e1fa659529c15cd15ba9259689ce | |
parent | 8a0f990d4a22d1d6a6c1ba37227321b7729f40fe (diff) | |
download | chromium_src-cb62c76837ca651a5d02f679ddb67767a61c35c6.zip chromium_src-cb62c76837ca651a5d02f679ddb67767a61c35c6.tar.gz chromium_src-cb62c76837ca651a5d02f679ddb67767a61c35c6.tar.bz2 |
Fixed the restore on startup pref on Lion's first run.
BUG=114525
TEST=Set System Preferences -> General -> Reopen windows... on Lion. Start Chromium with a new profile. The "open on startup" preference is to restore the last session.
Review URL: http://codereview.chromium.org/9481003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124217 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/tab_closeable_state_watcher_browsertest.cc | 11 | ||||
-rw-r--r-- | chrome/browser/defaults.cc | 4 | ||||
-rw-r--r-- | chrome/browser/defaults.h | 3 | ||||
-rw-r--r-- | chrome/browser/prefs/session_startup_pref.cc | 29 | ||||
-rw-r--r-- | chrome/browser/sessions/session_restore_browsertest.cc | 13 | ||||
-rw-r--r-- | chrome/browser/ui/browser_init.cc | 16 | ||||
-rw-r--r-- | chrome/browser/ui/browser_init_browsertest.cc | 11 |
7 files changed, 49 insertions, 38 deletions
diff --git a/chrome/browser/chromeos/tab_closeable_state_watcher_browsertest.cc b/chrome/browser/chromeos/tab_closeable_state_watcher_browsertest.cc index 41603ce..8dc3e57 100644 --- a/chrome/browser/chromeos/tab_closeable_state_watcher_browsertest.cc +++ b/chrome/browser/chromeos/tab_closeable_state_watcher_browsertest.cc @@ -1,10 +1,11 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/chromeos/tab_closeable_state_watcher.h" #include "base/file_path.h" +#include "chrome/browser/first_run/first_run.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" @@ -38,6 +39,14 @@ class TabCloseableStateWatcherTest : public InProcessBrowserTest { FilePath(FILE_PATH_LITERAL("title2.html"))); } + virtual bool SetUpUserDataDirectory() OVERRIDE { + // Make sure the first run sentinel file exists before running these tests, + // since some of them depend on not running during the first run. + // TODO(bauerb): set the first run flag instead of creating a sentinel file. + first_run::CreateSentinel(); + return InProcessBrowserTest::SetUpUserDataDirectory(); + } + protected: // Wrapper for Browser::AddTabWithURL void AddTabWithURL(Browser* browser, const GURL& url) { diff --git a/chrome/browser/defaults.cc b/chrome/browser/defaults.cc index ea25a7e..2be9c42 100644 --- a/chrome/browser/defaults.cc +++ b/chrome/browser/defaults.cc @@ -31,8 +31,6 @@ const int kAutocompleteEditFontPixelSize = 15; const int kAutocompleteEditFontPixelSizeInPopup = 10; -const SessionStartupPref::Type kDefaultSessionStartupType = - SessionStartupPref::LAST; const int kMiniTabWidth = 64; const bool kCanToggleSystemTitleBar = false; const bool kRestorePopups = false; @@ -64,8 +62,6 @@ const bool kCanToggleSystemTitleBar = true; #if !defined(OS_CHROMEOS) -const SessionStartupPref::Type kDefaultSessionStartupType = - SessionStartupPref::DEFAULT; const int kMiniTabWidth = 56; const bool kRestorePopups = false; const bool kShowImportOnBookmarkBar = true; diff --git a/chrome/browser/defaults.h b/chrome/browser/defaults.h index c4fe2e6..364220a 100644 --- a/chrome/browser/defaults.h +++ b/chrome/browser/defaults.h @@ -27,9 +27,6 @@ extern const bool kCanToggleSystemTitleBar; #endif -// The default value for session startup. -extern const SessionStartupPref::Type kDefaultSessionStartupType; - // Width of mini-tabs. extern const int kMiniTabWidth; diff --git a/chrome/browser/prefs/session_startup_pref.cc b/chrome/browser/prefs/session_startup_pref.cc index 8ed1cae..68835ef 100644 --- a/chrome/browser/prefs/session_startup_pref.cc +++ b/chrome/browser/prefs/session_startup_pref.cc @@ -6,17 +6,13 @@ #include <string> -#include "base/string_piece.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/defaults.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/pref_names.h" -#ifdef OS_MACOSX -#include "chrome/browser/first_run/first_run.h" +#if defined(OS_MACOSX) #include "chrome/browser/ui/cocoa/window_restore_utils.h" #endif @@ -41,19 +37,16 @@ int TypeToPrefValue(SessionStartupPref::Type type) { // static void SessionStartupPref::RegisterUserPrefs(PrefService* prefs) { - SessionStartupPref::Type type = browser_defaults::kDefaultSessionStartupType; - -#ifdef OS_MACOSX - // During first run the calling code relies on |DEFAULT| session preference - // value to avoid session restore. That is respected here. - if (!first_run::IsChromeFirstRun()) { - // |DEFAULT| really means "Don't restore". The actual default value could - // change, so explicitly set both. - if (restore_utils::IsWindowRestoreEnabled()) - type = SessionStartupPref::LAST; - else - type = SessionStartupPref::DEFAULT; - } +#if defined(OS_CHROMEOS) + SessionStartupPref::Type type = SessionStartupPref::LAST; +#else + SessionStartupPref::Type type = SessionStartupPref::DEFAULT; +#endif + +#if defined(OS_MACOSX) + // Use Lion's system preference, if it is set. + if (restore_utils::IsWindowRestoreEnabled()) + type = SessionStartupPref::LAST; #endif prefs->RegisterIntegerPref(prefs::kRestoreOnStartup, diff --git a/chrome/browser/sessions/session_restore_browsertest.cc b/chrome/browser/sessions/session_restore_browsertest.cc index 0ba1431..791eac9 100644 --- a/chrome/browser/sessions/session_restore_browsertest.cc +++ b/chrome/browser/sessions/session_restore_browsertest.cc @@ -4,6 +4,7 @@ #include "base/file_path.h" #include "chrome/browser/defaults.h" +#include "chrome/browser/first_run/first_run.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sessions/tab_restore_service.h" #include "chrome/browser/sessions/tab_restore_service_factory.h" @@ -60,7 +61,17 @@ class BrowserListObserverImpl : public BrowserList::Observer { } // namespace -typedef InProcessBrowserTest SessionRestoreTest; +class SessionRestoreTest : public InProcessBrowserTest { + protected: + virtual bool SetUpUserDataDirectory() OVERRIDE { + // Make sure the first run sentinel file exists before running these tests, + // since some of them customize the session startup pref whose value can + // be different than the default during the first run. + // TODO(bauerb): set the first run flag instead of creating a sentinel file. + first_run::CreateSentinel(); + return InProcessBrowserTest::SetUpUserDataDirectory(); + } +}; #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS) // Crashes on Linux Views: http://crbug.com/39476 diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc index c873ebb..47715310 100644 --- a/chrome/browser/ui/browser_init.cc +++ b/chrome/browser/ui/browser_init.cc @@ -800,6 +800,11 @@ SessionStartupPref BrowserInit::GetSessionStartupPref( const CommandLine& command_line, Profile* profile) { SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile); + + // Session restore should be avoided on the first run. + if (first_run::IsChromeFirstRun()) + pref.type = SessionStartupPref::DEFAULT; + if (command_line.HasSwitch(switches::kRestoreLastSession) || BrowserInit::WasRestarted()) { pref.type = SessionStartupPref::LAST; @@ -1109,15 +1114,6 @@ void BrowserInit::LaunchWithProfile::ProcessLaunchURLs( bool BrowserInit::LaunchWithProfile::ProcessStartupURLs( const std::vector<GURL>& urls_to_open) { SessionStartupPref pref = GetSessionStartupPref(command_line_, profile_); - if (command_line_.HasSwitch(switches::kTestingChannelID) && - !command_line_.HasSwitch(switches::kRestoreLastSession) && - browser_defaults::kDefaultSessionStartupType != - SessionStartupPref::DEFAULT) { - // When we have non DEFAULT session start type, then we won't open up a - // fresh session. But none of the tests are written with this in mind, so - // we explicitly ignore it during testing. - return false; - } if (pref.type == SessionStartupPref::LAST) { if (!profile_->DidLastSessionExitCleanly() && @@ -1162,7 +1158,7 @@ Browser* BrowserInit::LaunchWithProfile::ProcessSpecifiedURLs( SessionStartupPref pref = GetSessionStartupPref(command_line_, profile_); std::vector<Tab> tabs; // Pinned tabs should not be displayed when chrome is launched - // in icognito mode. + // in incognito mode. if (!IncognitoModePrefs::ShouldLaunchIncognito(command_line_, profile_->GetPrefs())) { tabs = PinnedTabCodec::ReadPinnedTabs(profile_); diff --git a/chrome/browser/ui/browser_init_browsertest.cc b/chrome/browser/ui/browser_init_browsertest.cc index b12d84f..f922136 100644 --- a/chrome/browser/ui/browser_init_browsertest.cc +++ b/chrome/browser/ui/browser_init_browsertest.cc @@ -31,7 +31,16 @@ class BrowserInitTest : public ExtensionBrowserTest { protected: - virtual void SetUpCommandLine(CommandLine* command_line) { + virtual bool SetUpUserDataDirectory() OVERRIDE { + // Make sure the first run sentinel file exists before running these tests, + // since some of them customize the session startup pref whose value can + // be different than the default during the first run. + // TODO(bauerb): set the first run flag instead of creating a sentinel file. + first_run::CreateSentinel(); + return ExtensionBrowserTest::SetUpUserDataDirectory(); + } + + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { ExtensionBrowserTest::SetUpCommandLine(command_line); command_line->AppendSwitch(switches::kEnablePanels); } |