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

Side by Side 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, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/startup/startup_tab_provider.h"
6
7 #include "build/build_config.h"
8 #include "chrome/browser/first_run/first_run.h"
9 #include "chrome/browser/ui/chrome_pages.h"
10 #include "chrome/common/url_constants.h"
11 #include "chrome/grit/locale_settings.h"
12 #include "ui/base/l10n/l10n_util.h"
13
14 #if defined(OS_WIN)
15 #include "base/win/windows_version.h"
16 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h"
17 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h"
18 #endif
19
20 namespace {
21 // Constants: Magic words used by Master Preferences files in place of a URL
22 // host to indicate that internal pages should appear on first run.
23 constexpr char kNewTabUrlHost[] = "new_tab_page";
Peter Kasting 2016/09/29 07:23:35 Nit: Prefer to declare constants in the narrowest
24 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
25 } // namespace
26
27 bool StartupTabProviderImpl::AddOnboardingTabs(StartupTabs* tabs) const {
28 #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
29 // Windows 10 has unique onboarding policies and content.
30 if (base::win::GetVersion() >= base::win::VERSION_WIN10) {
31 // TODO(tmartino): * Add a function, GetWin10SystemState, which gathers
32 // system state relevant to Win10 Onboarding and returns
33 // a struct.
34 // * Add a function, CheckWin10OnboardingTabPolicy, which
35 // takes such a struct as input and returns StartupTabs.
36 return false;
37 }
38 #endif
39
40 return CheckStandardOnboardingTabPolicy(first_run::IsChromeFirstRun(), tabs);
41 }
42
43 bool StartupTabProviderImpl::AddDistributionFirstRunTabs(
44 StartupBrowserCreator* browser_creator,
45 StartupTabs* tabs) const {
46 if (!browser_creator)
47 return false;
48 bool added_tabs = CheckMasterPrefsTabPolicy(
49 first_run::IsChromeFirstRun(), browser_creator->first_run_tabs_, tabs);
50 browser_creator->first_run_tabs_.clear();
51 return added_tabs;
52 }
53
54 bool StartupTabProviderImpl::AddResetTriggerTabs(Profile* profile,
55 StartupTabs* tabs) const {
56 bool has_reset_trigger = false;
57 #if defined(OS_WIN)
Peter Kasting 2016/09/29 07:23:35 Why does this code only run for Windows? it seems
58 TriggeredProfileResetter* triggered_profile_resetter =
Peter Kasting 2016/09/29 07:23:35 Nit: Can this be const? auto* might reduce redund
59 TriggeredProfileResetterFactory::GetForBrowserContext(profile);
60 if (triggered_profile_resetter)
61 has_reset_trigger = triggered_profile_resetter->HasResetTrigger();
Peter Kasting 2016/09/29 07:23:35 Nit: Or this. Not really different in this implem
62 #endif // defined(OS_WIN)
63 return CheckResetTriggerTabPolicy(has_reset_trigger, tabs);
64 }
65
66 bool StartupTabProviderImpl::AddPinnedTabs(StartupTabs* tabs) const {
67 // TODO(tmartino): Copy/clean up logic from
68 // StartupBrowserCreatorImpl::ProcessSpecifiedUrls.
69 return false;
70 }
71
72 bool StartupTabProviderImpl::AddPreferencesTabs(StartupTabs* tabs) const {
73 // TODO(tmartino): Copy/clean up logic from
74 // StartupBrowserCreatorImpl::ProcessStartupUrls.
75 return false;
76 }
77
78 // static
79 bool StartupTabProviderImpl::CheckStandardOnboardingTabPolicy(
80 bool is_first_run,
81 StartupTabs* tabs) {
82 if (is_first_run) {
83 tabs->push_back(StartupTab(GetWelcomePageUrl(), false));
Peter Kasting 2016/09/29 07:23:35 Nit: Same emplace_back() comment applies in this f
84 return true;
85 }
86 return false;
Peter Kasting 2016/09/29 07:23:35 Nit: Shorter: if (is_first_run) tabs->...
87 }
88
89 // static
90 bool StartupTabProviderImpl::CheckMasterPrefsTabPolicy(
91 bool is_first_run,
92 const std::vector<GURL>& first_run_tabs,
93 StartupTabs* tabs) {
94 size_t initial_size = tabs->size();
95 if (is_first_run) {
96 tabs->reserve(initial_size + first_run_tabs.size());
97 for (const GURL& url : first_run_tabs) {
98 if (url.host() == kNewTabUrlHost) {
99 tabs->push_back(StartupTab(GURL(chrome::kChromeUINewTabURL), false));
Peter Kasting 2016/09/29 07:23:35 Nit: Rather than duplicate the construction of Sta
100 } else if (url.host() == kWelcomePageUrlHost) {
101 tabs->push_back(StartupTab(GetWelcomePageUrl(), false));
102 } else {
103 tabs->push_back(StartupTab(url, false));
104 }
105 }
106 }
107 return tabs->size() > initial_size;
108 }
109
110 // static
111 bool StartupTabProviderImpl::CheckResetTriggerTabPolicy(
112 bool profile_has_trigger,
113 StartupTabs* tabs) {
114 if (!profile_has_trigger)
115 return false;
116 tabs->push_back(StartupTab(GetTriggeredResetSettingsUrl(), false));
117 return true;
Peter Kasting 2016/09/29 07:23:35 Nit: Shorter: if (profile_has_trigger) tabs
118 }
119
120 GURL GetWelcomePageUrl() {
121 return GURL(l10n_util::GetStringUTF8(IDS_WELCOME_PAGE_URL));
122 }
123
124 GURL GetTriggeredResetSettingsUrl() {
125 return GURL(
126 chrome::GetSettingsUrl(chrome::kTriggeredResetProfileSettingsSubPage));
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698