Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(706)

Unified Diff: chrome/browser/ui/startup/startup_tab_provider.cc

Issue 2164033002: Refactoring startup logic for upcoming FRE changes (non-Win 10). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Win build issue Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/startup/startup_tab_provider.cc
diff --git a/chrome/browser/ui/startup/startup_tab_provider.cc b/chrome/browser/ui/startup/startup_tab_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..44e768037a71db9201da6c70155e1270761fbf22
--- /dev/null
+++ b/chrome/browser/ui/startup/startup_tab_provider.cc
@@ -0,0 +1,127 @@
+// Copyright 2016 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/ui/startup/startup_tab_provider.h"
+
+#include "build/build_config.h"
+#include "chrome/browser/first_run/first_run.h"
+#include "chrome/browser/ui/chrome_pages.h"
+#include "chrome/common/url_constants.h"
+#include "chrome/grit/locale_settings.h"
+#include "ui/base/l10n/l10n_util.h"
+
+#if defined(OS_WIN)
+#include "base/win/windows_version.h"
+#include "chrome/browser/profile_resetter/triggered_profile_resetter.h"
+#include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h"
+#endif
+
+namespace {
+// Constants: Magic words used by Master Preferences files in place of a URL
+// host to indicate that internal pages should appear on first run.
+constexpr char kNewTabUrlHost[] = "new_tab_page";
Peter Kasting 2016/09/29 07:23:35 Nit: Prefer to declare constants in the narrowest
+constexpr char kWelcomePageUrlHost[] = "welcome_page";
Peter Kasting 2016/09/29 07:23:35 Oh dear... these are valid hostnames for intranets
tmartino 2016/09/30 20:55:02 I hate, hate, hate this too. I was horrified when
Peter Kasting 2016/09/30 21:50:03 That's something we can change over time. It woul
tmartino 2016/10/03 23:26:06 Added a line to the tech debt phase of my project
+} // namespace
+
+bool StartupTabProviderImpl::AddOnboardingTabs(StartupTabs* tabs) const {
+#if defined(OS_WIN)
Peter Kasting 2016/09/29 07:23:35 Nit: If it wouldn't add excessive indirection/boil
tmartino 2016/09/30 20:55:02 We discussed this quite a few patchsets ago (first
Peter Kasting 2016/09/30 21:50:03 I'm open to any working solution, and admittedly i
tmartino 2016/10/03 23:26:06 I think I'm OK with the second; for reasons of sco
+ // Windows 10 has unique onboarding policies and content.
+ if (base::win::GetVersion() >= base::win::VERSION_WIN10) {
+ // TODO(tmartino): * Add a function, GetWin10SystemState, which gathers
+ // system state relevant to Win10 Onboarding and returns
+ // a struct.
+ // * Add a function, CheckWin10OnboardingTabPolicy, which
+ // takes such a struct as input and returns StartupTabs.
+ return false;
+ }
+#endif
+
+ return CheckStandardOnboardingTabPolicy(first_run::IsChromeFirstRun(), tabs);
+}
+
+bool StartupTabProviderImpl::AddDistributionFirstRunTabs(
+ StartupBrowserCreator* browser_creator,
+ StartupTabs* tabs) const {
+ if (!browser_creator)
+ return false;
+ bool added_tabs = CheckMasterPrefsTabPolicy(
+ first_run::IsChromeFirstRun(), browser_creator->first_run_tabs_, tabs);
+ browser_creator->first_run_tabs_.clear();
+ return added_tabs;
+}
+
+bool StartupTabProviderImpl::AddResetTriggerTabs(Profile* profile,
+ StartupTabs* tabs) const {
+ bool has_reset_trigger = false;
+#if defined(OS_WIN)
Peter Kasting 2016/09/29 07:23:35 Why does this code only run for Windows? it seems
+ TriggeredProfileResetter* triggered_profile_resetter =
Peter Kasting 2016/09/29 07:23:35 Nit: Can this be const? auto* might reduce redund
+ TriggeredProfileResetterFactory::GetForBrowserContext(profile);
+ if (triggered_profile_resetter)
+ has_reset_trigger = triggered_profile_resetter->HasResetTrigger();
Peter Kasting 2016/09/29 07:23:35 Nit: Or this. Not really different in this implem
+#endif // defined(OS_WIN)
+ return CheckResetTriggerTabPolicy(has_reset_trigger, tabs);
+}
+
+bool StartupTabProviderImpl::AddPinnedTabs(StartupTabs* tabs) const {
+ // TODO(tmartino): Copy/clean up logic from
+ // StartupBrowserCreatorImpl::ProcessSpecifiedUrls.
+ return false;
+}
+
+bool StartupTabProviderImpl::AddPreferencesTabs(StartupTabs* tabs) const {
+ // TODO(tmartino): Copy/clean up logic from
+ // StartupBrowserCreatorImpl::ProcessStartupUrls.
+ return false;
+}
+
+// static
+bool StartupTabProviderImpl::CheckStandardOnboardingTabPolicy(
+ bool is_first_run,
+ StartupTabs* tabs) {
+ if (is_first_run) {
+ tabs->push_back(StartupTab(GetWelcomePageUrl(), false));
Peter Kasting 2016/09/29 07:23:35 Nit: Same emplace_back() comment applies in this f
+ return true;
+ }
+ return false;
Peter Kasting 2016/09/29 07:23:35 Nit: Shorter: if (is_first_run) tabs->...
+}
+
+// static
+bool StartupTabProviderImpl::CheckMasterPrefsTabPolicy(
+ bool is_first_run,
+ const std::vector<GURL>& first_run_tabs,
+ StartupTabs* tabs) {
+ size_t initial_size = tabs->size();
+ if (is_first_run) {
+ tabs->reserve(initial_size + first_run_tabs.size());
+ for (const GURL& url : first_run_tabs) {
+ if (url.host() == kNewTabUrlHost) {
+ tabs->push_back(StartupTab(GURL(chrome::kChromeUINewTabURL), false));
Peter Kasting 2016/09/29 07:23:35 Nit: Rather than duplicate the construction of Sta
+ } else if (url.host() == kWelcomePageUrlHost) {
+ tabs->push_back(StartupTab(GetWelcomePageUrl(), false));
+ } else {
+ tabs->push_back(StartupTab(url, false));
+ }
+ }
+ }
+ return tabs->size() > initial_size;
+}
+
+// static
+bool StartupTabProviderImpl::CheckResetTriggerTabPolicy(
+ bool profile_has_trigger,
+ StartupTabs* tabs) {
+ if (!profile_has_trigger)
+ return false;
+ tabs->push_back(StartupTab(GetTriggeredResetSettingsUrl(), false));
+ return true;
Peter Kasting 2016/09/29 07:23:35 Nit: Shorter: if (profile_has_trigger) tabs
+}
+
+GURL GetWelcomePageUrl() {
+ return GURL(l10n_util::GetStringUTF8(IDS_WELCOME_PAGE_URL));
+}
+
+GURL GetTriggeredResetSettingsUrl() {
+ return GURL(
+ chrome::GetSettingsUrl(chrome::kTriggeredResetProfileSettingsSubPage));
+}

Powered by Google App Engine
This is Rietveld 408576698