OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/startup/startup_tab_provider.h" | 5 #include "chrome/browser/ui/startup/startup_tab_provider.h" |
6 | 6 |
7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/first_run/first_run.h" | 9 #include "chrome/browser/first_run/first_run.h" |
10 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" | 10 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "components/signin/core/browser/signin_manager.h" | 22 #include "components/signin/core/browser/signin_manager.h" |
23 #include "net/base/url_util.h" | 23 #include "net/base/url_util.h" |
24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
25 | 25 |
26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
27 #include "base/win/windows_version.h" | 27 #include "base/win/windows_version.h" |
28 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
29 #include "chrome/browser/shell_integration.h" | 29 #include "chrome/browser/shell_integration.h" |
30 #endif | 30 #endif |
31 | 31 |
| 32 namespace { |
| 33 |
| 34 // Attempts to find an existing, non-empty tabbed browser for this profile. |
| 35 bool ProfileHasOtherTabbedBrowser(Profile* profile) { |
| 36 BrowserList* browser_list = BrowserList::GetInstance(); |
| 37 auto other_tabbed_browser = std::find_if( |
| 38 browser_list->begin(), browser_list->end(), [profile](Browser* browser) { |
| 39 return browser->profile() == profile && browser->is_type_tabbed() && |
| 40 !browser->tab_strip_model()->empty(); |
| 41 }); |
| 42 return other_tabbed_browser != browser_list->end(); |
| 43 } |
| 44 |
| 45 } // namespace |
| 46 |
32 StartupTabs StartupTabProviderImpl::GetOnboardingTabs(Profile* profile) const { | 47 StartupTabs StartupTabProviderImpl::GetOnboardingTabs(Profile* profile) const { |
33 // Onboarding content has not been launched on Chrome OS. | 48 // Onboarding content has not been launched on Chrome OS. |
34 #if defined(OS_CHROMEOS) | 49 #if defined(OS_CHROMEOS) |
35 return StartupTabs(); | 50 return StartupTabs(); |
36 #else | 51 #else |
37 if (!profile) | 52 if (!profile) |
38 return StartupTabs(); | 53 return StartupTabs(); |
39 | 54 |
40 bool is_first_run = first_run::IsChromeFirstRun(); | 55 bool is_first_run = first_run::IsChromeFirstRun(); |
41 PrefService* prefs = profile->GetPrefs(); | 56 PrefService* prefs = profile->GetPrefs(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 bool has_reset_trigger = triggered_profile_resetter && | 109 bool has_reset_trigger = triggered_profile_resetter && |
95 triggered_profile_resetter->HasResetTrigger(); | 110 triggered_profile_resetter->HasResetTrigger(); |
96 return GetResetTriggerTabsForState(has_reset_trigger); | 111 return GetResetTriggerTabsForState(has_reset_trigger); |
97 } | 112 } |
98 | 113 |
99 StartupTabs StartupTabProviderImpl::GetPinnedTabs( | 114 StartupTabs StartupTabProviderImpl::GetPinnedTabs( |
100 const base::CommandLine& command_line, | 115 const base::CommandLine& command_line, |
101 Profile* profile) const { | 116 Profile* profile) const { |
102 return GetPinnedTabsForState( | 117 return GetPinnedTabsForState( |
103 StartupBrowserCreator::GetSessionStartupPref(command_line, profile), | 118 StartupBrowserCreator::GetSessionStartupPref(command_line, profile), |
104 PinnedTabCodec::ReadPinnedTabs(profile)); | 119 PinnedTabCodec::ReadPinnedTabs(profile), |
| 120 ProfileHasOtherTabbedBrowser(profile)); |
105 } | 121 } |
106 | 122 |
107 StartupTabs StartupTabProviderImpl::GetPreferencesTabs( | 123 StartupTabs StartupTabProviderImpl::GetPreferencesTabs( |
108 const base::CommandLine& command_line, | 124 const base::CommandLine& command_line, |
109 Profile* profile) const { | 125 Profile* profile) const { |
110 // Attempt to find an existing, non-empty tabbed browser for this profile. If | |
111 // one exists, preferences tabs are not used. | |
112 BrowserList* browser_list = BrowserList::GetInstance(); | |
113 auto other_tabbed_browser = std::find_if( | |
114 browser_list->begin(), browser_list->end(), [profile](Browser* browser) { | |
115 return browser->profile() == profile && browser->is_type_tabbed() && | |
116 !browser->tab_strip_model()->empty(); | |
117 }); | |
118 bool profile_has_other_tabbed_browser = | |
119 other_tabbed_browser != browser_list->end(); | |
120 | |
121 return GetPreferencesTabsForState( | 126 return GetPreferencesTabsForState( |
122 StartupBrowserCreator::GetSessionStartupPref(command_line, profile), | 127 StartupBrowserCreator::GetSessionStartupPref(command_line, profile), |
123 profile_has_other_tabbed_browser); | 128 ProfileHasOtherTabbedBrowser(profile)); |
124 } | 129 } |
125 | 130 |
126 StartupTabs StartupTabProviderImpl::GetNewTabPageTabs( | 131 StartupTabs StartupTabProviderImpl::GetNewTabPageTabs( |
127 const base::CommandLine& command_line, | 132 const base::CommandLine& command_line, |
128 Profile* profile) const { | 133 Profile* profile) const { |
129 return GetNewTabPageTabsForState( | 134 return GetNewTabPageTabsForState( |
130 StartupBrowserCreator::GetSessionStartupPref(command_line, profile)); | 135 StartupBrowserCreator::GetSessionStartupPref(command_line, profile)); |
131 } | 136 } |
132 | 137 |
133 // static | 138 // static |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 bool profile_has_trigger) { | 200 bool profile_has_trigger) { |
196 StartupTabs tabs; | 201 StartupTabs tabs; |
197 if (profile_has_trigger) | 202 if (profile_has_trigger) |
198 tabs.emplace_back(GetTriggeredResetSettingsUrl(), false); | 203 tabs.emplace_back(GetTriggeredResetSettingsUrl(), false); |
199 return tabs; | 204 return tabs; |
200 } | 205 } |
201 | 206 |
202 // static | 207 // static |
203 StartupTabs StartupTabProviderImpl::GetPinnedTabsForState( | 208 StartupTabs StartupTabProviderImpl::GetPinnedTabsForState( |
204 const SessionStartupPref& pref, | 209 const SessionStartupPref& pref, |
205 const StartupTabs& pinned_tabs) { | 210 const StartupTabs& pinned_tabs, |
206 return (pref.type == SessionStartupPref::Type::LAST) ? StartupTabs() | 211 bool profile_has_other_tabbed_browser) { |
207 : pinned_tabs; | 212 if (pref.type == SessionStartupPref::Type::LAST || |
| 213 profile_has_other_tabbed_browser) |
| 214 return StartupTabs(); |
| 215 return pinned_tabs; |
208 } | 216 } |
209 | 217 |
210 // static | 218 // static |
211 StartupTabs StartupTabProviderImpl::GetPreferencesTabsForState( | 219 StartupTabs StartupTabProviderImpl::GetPreferencesTabsForState( |
212 const SessionStartupPref& pref, | 220 const SessionStartupPref& pref, |
213 bool profile_has_other_tabbed_browser) { | 221 bool profile_has_other_tabbed_browser) { |
214 StartupTabs tabs; | 222 StartupTabs tabs; |
215 if (pref.type == SessionStartupPref::Type::URLS && !pref.urls.empty() && | 223 if (pref.type == SessionStartupPref::Type::URLS && !pref.urls.empty() && |
216 !profile_has_other_tabbed_browser) { | 224 !profile_has_other_tabbed_browser) { |
217 for (const auto& url : pref.urls) | 225 for (const auto& url : pref.urls) |
(...skipping 30 matching lines...) Expand all Loading... |
248 ? net::AppendQueryParameter(url, "text", "faster") | 256 ? net::AppendQueryParameter(url, "text", "faster") |
249 : url; | 257 : url; |
250 } | 258 } |
251 #endif | 259 #endif |
252 | 260 |
253 // static | 261 // static |
254 GURL StartupTabProviderImpl::GetTriggeredResetSettingsUrl() { | 262 GURL StartupTabProviderImpl::GetTriggeredResetSettingsUrl() { |
255 return GURL( | 263 return GURL( |
256 chrome::GetSettingsUrl(chrome::kTriggeredResetProfileSettingsSubPage)); | 264 chrome::GetSettingsUrl(chrome::kTriggeredResetProfileSettingsSubPage)); |
257 } | 265 } |
OLD | NEW |