Chromium Code Reviews| Index: chrome/browser/ui/startup/startup_browser_creator_impl.cc |
| diff --git a/chrome/browser/ui/startup/startup_browser_creator_impl.cc b/chrome/browser/ui/startup/startup_browser_creator_impl.cc |
| index b6a1fdde98ad4522137de8b3d1e13ac83510e9c2..9ceeadae96f48275c1609aabca262f8d98aaee4e 100644 |
| --- a/chrome/browser/ui/startup/startup_browser_creator_impl.cc |
| +++ b/chrome/browser/ui/startup/startup_browser_creator_impl.cc |
| @@ -22,6 +22,7 @@ |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/threading/thread_restrictions.h" |
| #include "chrome/browser/apps/install_chrome_app.h" |
| @@ -76,6 +77,7 @@ |
| #include "chrome/common/chrome_version_info.h" |
| #include "chrome/common/extensions/extension_constants.h" |
| #include "chrome/common/extensions/extension_metrics.h" |
| +#include "chrome/common/pref_names.h" |
| #include "chrome/common/url_constants.h" |
| #include "chrome/grit/locale_settings.h" |
| #include "chrome/installer/util/browser_distribution.h" |
| @@ -91,6 +93,7 @@ |
| #include "extensions/common/constants.h" |
| #include "extensions/common/extension.h" |
| #include "extensions/common/extension_set.h" |
| +#include "net/base/network_change_notifier.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #if defined(OS_MACOSX) |
| @@ -287,6 +290,14 @@ GURL GetWelcomePageURL() { |
| return GURL(welcome_url); |
| } |
| +bool ShowWelcomePageAfterFirstRun() { |
| +#if defined(OS_WIN) |
| + return base::win::GetVersion() >= base::win::VERSION_WIN10; |
| +#else |
| + return false; |
| +#endif |
| +} |
| + |
| } // namespace internals |
| StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( |
| @@ -297,7 +308,8 @@ StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( |
| command_line_(command_line), |
| profile_(NULL), |
| browser_creator_(NULL), |
| - is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) { |
| + is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN), |
| + welcome_run_type_(WelcomeRunType::NONE) { |
| } |
| StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( |
| @@ -309,7 +321,8 @@ StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( |
| command_line_(command_line), |
| profile_(NULL), |
| browser_creator_(browser_creator), |
| - is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) { |
| + is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN), |
| + welcome_run_type_(WelcomeRunType::NONE) { |
| } |
| StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() { |
| @@ -535,6 +548,9 @@ void StartupBrowserCreatorImpl::ProcessLaunchURLs( |
| return; |
| } |
| + // Determine whether or not this launch must include the welcome page. |
| + InitializeWelcomeRunType(urls_to_open); |
| + |
| // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor. |
| #if defined(OS_WIN) |
| if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| @@ -561,11 +577,18 @@ void StartupBrowserCreatorImpl::ProcessLaunchURLs( |
| SessionService* service = |
| SessionServiceFactory::GetForProfileForSessionRestore(profile_); |
| if (service && service->ShouldNewWindowStartSession()) { |
| - // Restore the last session if any. |
| - if (!HasPendingUncleanExit(profile_) && |
| - service->RestoreIfNecessary(urls_to_open)) { |
| - return; |
| + // Restore the last session if any, optionally including the welcome page |
| + // if desired. |
| + if (!HasPendingUncleanExit(profile_)) { |
| + std::vector<GURL> adjust_urls(urls_to_open); |
| + if (welcome_run_type_ != WelcomeRunType::NONE) |
| + adjust_urls.push_back(internals::GetWelcomePageURL()); |
| + if (service->RestoreIfNecessary(adjust_urls)) { |
| + RecordWelcomeRunComplete(); |
| + return; |
| + } |
| } |
| + |
| // Open user-specified URLs like pinned tabs and startup tabs. |
| Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); |
| if (browser) { |
| @@ -642,11 +665,17 @@ bool StartupBrowserCreatorImpl::ProcessStartupURLs( |
| } |
| #endif |
| + // Optionally include the welcome page. |
| + std::vector<GURL> adjust_urls(urls_to_open); |
| + if (welcome_run_type_ != WelcomeRunType::NONE) |
| + adjust_urls.push_back(internals::GetWelcomePageURL()); |
| + |
| // The startup code only executes for browsers launched in desktop mode. |
| // i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. |
| Browser* browser = SessionRestore::RestoreSession( |
| - profile_, NULL, desktop_type, restore_behavior, |
| - urls_to_open); |
| + profile_, NULL, desktop_type, restore_behavior, adjust_urls); |
| + |
| + RecordWelcomeRunComplete(); |
| AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); |
| return true; |
| @@ -699,6 +728,9 @@ Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( |
| UrlsToTabs(urls, &tabs); |
| } else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty() && |
| !HasPendingUncleanExit(profile_)) { |
| + // Optionally include the welcome page first. |
| + if (welcome_run_type_ == WelcomeRunType::ANY_RUN_FIRST) |
| + UrlsToTabs(std::vector<GURL>(1, internals::GetWelcomePageURL()), &tabs); |
| // Only use the set of urls specified in preferences if nothing was |
| // specified on the command line. Filter out any urls that are to be |
| // restored by virtue of having been previously pinned. |
| @@ -763,6 +795,7 @@ Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser( |
| browser = new Browser(Browser::CreateParams(profile_, desktop_type)); |
| bool first_tab = true; |
| + const GURL welcome_url(internals::GetWelcomePageURL()); |
| ProtocolHandlerRegistry* registry = profile_ ? |
| ProtocolHandlerRegistryFactory::GetForBrowserContext(profile_) : NULL; |
| for (size_t i = 0; i < tabs.size(); ++i) { |
| @@ -793,6 +826,9 @@ Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser( |
| } |
| #endif // defined(ENABLE_RLZ) && !defined(OS_IOS) |
| + if (welcome_run_type_ != WelcomeRunType::NONE && tabs[i].url == welcome_url) |
| + RecordWelcomeRunComplete(); |
| + |
| chrome::Navigate(¶ms); |
| first_tab = false; |
| @@ -880,12 +916,18 @@ void StartupBrowserCreatorImpl::AddStartupURLs( |
| } |
| } |
| - // Otherwise open at least the new tab page (and the welcome page, if this |
| - // is the first time the browser is being started), or the set of URLs |
| - // specified on the command line. |
| + // Otherwise open at least the new tab page (and the welcome page if this is |
| + // the first time the browser is being started or the first time following an |
| + // upgrade past Windows 10), or the set of URLs specified on the command line. |
| if (startup_urls->empty()) { |
| + // Put the welcome page before the new tab page on Windows 10. |
| + if (welcome_run_type_ == WelcomeRunType::FIRST_RUN_FIRST || |
| + welcome_run_type_ == WelcomeRunType::ANY_RUN_FIRST) { |
| + startup_urls->push_back(internals::GetWelcomePageURL()); |
| + } |
| startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); |
| - if (first_run::ShouldShowWelcomePage()) |
| + // Put the welcome page after the new tab page elsewhere. |
| + if (welcome_run_type_ == WelcomeRunType::FIRST_RUN_LAST) |
| startup_urls->push_back(internals::GetWelcomePageURL()); |
| } |
| @@ -917,3 +959,93 @@ void StartupBrowserCreatorImpl::AddStartupURLs( |
| } |
| } |
| } |
| + |
| +// For first-run, the type will be FIRST_RUN_LAST for all systems except for |
| +// Windows 10+, where it will be FIRST_RUN_FIRST. For non-first run, the type |
| +// will be NONE for all systems except for Windows 10+, where it will be |
| +// ANY_RUN_FIRST if this is the first somewhat normal launch since an OS |
| +// upgrade. |
| +void StartupBrowserCreatorImpl::InitializeWelcomeRunType( |
| + const std::vector<GURL>& urls_to_open) { |
| + DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE), |
| + static_cast<int>(welcome_run_type_)); |
| +#if defined(OS_WIN) |
| + // Do not welcome if there are any URLs to open. |
| + if (!urls_to_open.empty()) |
| + return; |
| + |
| + base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); |
| + |
| + // Always welcome on first run. |
| + if (first_run::ShouldShowWelcomePage()) { |
| + // First tab for Win10+, last tab otherwise. |
| + welcome_run_type_ = os_info->version() >= base::win::VERSION_WIN10 |
| + ? WelcomeRunType::FIRST_RUN_FIRST |
| + : WelcomeRunType::FIRST_RUN_LAST; |
| + return; |
| + } |
| + |
| + // Otherwise, do not welcome pre-Win10. |
| + if (!internals::ShowWelcomePageAfterFirstRun()) |
| + return; |
| + |
| + // Do not welcome if launching into incognito. |
| + if (IncognitoModePrefs::ShouldLaunchIncognito(command_line_, |
| + profile_->GetPrefs())) { |
| + return; |
| + } |
| + |
| + // Do not welcome if there is no local state (tests). |
| + PrefService* local_state = g_browser_process->local_state(); |
| + if (!local_state) |
| + return; |
| + |
| + // Do not welcome if disabled by policy or master_preferences. |
| + if (!local_state->GetBoolean(prefs::kWelcomePageOnOSUpgradeEnabled)) |
| + return; |
| + |
| + base::win::OSInfo::VersionNumber v(os_info->version_number()); |
| + std::string this_os_version(base::StringPrintf("%d.%d", v.major, v.minor)); |
| + |
| + // Do not welcome if already shown for this OS version. |
| + if (local_state->GetString(prefs::kLastWelcomedOSVersion) == this_os_version) |
| + return; |
| + |
| + // Do not welcome if offline. |
| + if (net::NetworkChangeNotifier::IsOffline()) |
| + return; |
| + |
| + // Do not welcome if Chrome is the default browser. |
| + { |
| + // Checking for default browser will touch the filesystem. This phase of |
| + // launch is synchronous, so there is no choice to bounce to another thread |
| + // now. Since this is the last condition checked before adding the welcome |
| + // page, it will be hit only once per user. |
| + base::ThreadRestrictions::ScopedAllowIO allow_io; |
|
jochen (gone - plz use gerrit)
2015/07/10 09:03:31
is it possible to move this check to before the io
grt (UTC plus 2)
2015/07/10 12:05:31
For an ordinary Chrome launch, this does indeed ta
jochen (gone - plz use gerrit)
2015/07/10 12:12:51
that means that we potentially show the page twice
grt (UTC plus 2)
2015/07/10 12:17:31
No. In fact, we'll never his this line if the page
|
| + if (ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT) |
| + return; |
| + } |
| + |
| + // Show the welcome page in the first tab. |
| + welcome_run_type_ = WelcomeRunType::ANY_RUN_FIRST; |
| +#else // OS_WIN |
| + // Show the welcome page as the last tab only on first-run. |
| + if (first_run::ShouldShowWelcomePage()) |
| + welcome_run_type_ = WelcomeRunType::FIRST_RUN_LAST; |
| +#endif // !OS_WIN |
| +} |
| + |
| +void StartupBrowserCreatorImpl::RecordWelcomeRunComplete() const { |
| +#if defined(OS_WIN) |
| + if (welcome_run_type_ == WelcomeRunType::NONE) |
| + return; |
| + |
| + // Remember that the welcome page was shown for this OS version. |
| + using base::win::OSInfo; |
| + OSInfo::VersionNumber v(OSInfo::GetInstance()->version_number()); |
| + g_browser_process->local_state()->SetString( |
| + prefs::kLastWelcomedOSVersion, |
| + base::StringPrintf("%d.%d", v.major, v.minor)); |
| + welcome_run_type_ = WelcomeRunType::NONE; |
| +#endif |
| +} |