OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_ | 5 #ifndef CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_ |
6 #define CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_ | 6 #define CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "chrome/browser/ui/startup/startup_tab.h" | 14 #include "chrome/browser/ui/startup/startup_tab.h" |
15 #include "chrome/browser/ui/startup/startup_tab_provider.h" | |
15 #include "chrome/browser/ui/startup/startup_types.h" | 16 #include "chrome/browser/ui/startup/startup_types.h" |
16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
17 | 18 |
18 class Browser; | 19 class Browser; |
19 class Profile; | 20 class Profile; |
20 class StartupBrowserCreator; | 21 class StartupBrowserCreator; |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class CommandLine; | 24 class CommandLine; |
24 class FilePath; | 25 class FilePath; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 | 61 |
61 // Convenience for OpenTabsInBrowser that converts |urls| into a set of | 62 // Convenience for OpenTabsInBrowser that converts |urls| into a set of |
62 // Tabs. | 63 // Tabs. |
63 Browser* OpenURLsInBrowser(Browser* browser, | 64 Browser* OpenURLsInBrowser(Browser* browser, |
64 bool process_startup, | 65 bool process_startup, |
65 const std::vector<GURL>& urls); | 66 const std::vector<GURL>& urls); |
66 | 67 |
67 private: | 68 private: |
68 FRIEND_TEST_ALL_PREFIXES(BrowserTest, RestorePinnedTabs); | 69 FRIEND_TEST_ALL_PREFIXES(BrowserTest, RestorePinnedTabs); |
69 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch); | 70 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch); |
71 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest, DetermineStartupTabs); | |
72 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest, | |
73 DetermineStartupTabs_IncognitoOrCrash); | |
74 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest, | |
75 DetermineStartupTabs_MasterPrefs); | |
76 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest, | |
77 DetermineStartupTabs_CommandLine); | |
78 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest, | |
79 DetermineStartupTabs_NewTabPage); | |
70 | 80 |
71 enum class WelcomeRunType { | 81 enum class WelcomeRunType { |
72 NONE, // Do not inject the welcome page for this run. | 82 NONE, // Do not inject the welcome page for this run. |
73 FIRST_TAB, // Inject the welcome page as the first tab. | 83 FIRST_TAB, // Inject the welcome page as the first tab. |
74 FIRST_RUN_LAST_TAB, // Inject the welcome page as the last first-run tab. | 84 FIRST_RUN_LAST_TAB, // Inject the welcome page as the last first-run tab. |
75 }; | 85 }; |
76 | 86 |
77 // Creates a tab for each of the Tabs in |tabs|. If browser is non-null | 87 // Creates a tab for each of the Tabs in |tabs|. If browser is non-null |
78 // and a tabbed browser, the tabs are added to it. Otherwise a new tabbed | 88 // and a tabbed browser, the tabs are added to it. Otherwise a new tabbed |
79 // browser is created and the tabs are added to it. The browser the tabs | 89 // browser is created and the tabs are added to it. The browser the tabs |
(...skipping 10 matching lines...) Expand all Loading... | |
90 | 100 |
91 // If IsAppLaunch is true, tries to open an application window. | 101 // If IsAppLaunch is true, tries to open an application window. |
92 // If the app is specified to start in a tab, or IsAppLaunch is false, | 102 // If the app is specified to start in a tab, or IsAppLaunch is false, |
93 // returns false to specify default processing. | 103 // returns false to specify default processing. |
94 bool OpenApplicationWindow(Profile* profile); | 104 bool OpenApplicationWindow(Profile* profile); |
95 | 105 |
96 // If IsAppLaunch is true and the user set a pref indicating that the app | 106 // If IsAppLaunch is true and the user set a pref indicating that the app |
97 // should open in a tab, do so. | 107 // should open in a tab, do so. |
98 bool OpenApplicationTab(Profile* profile); | 108 bool OpenApplicationTab(Profile* profile); |
99 | 109 |
100 // Invoked from Launch to handle processing of urls. This may do any of the | 110 // Determines the URLs to be shown at startup by way of various policies |
101 // following: | 111 // (onboarding, pinned tabs, etc.), determines whether a session restore |
102 // . Invoke ProcessStartupURLs if |process_startup| is true. | 112 // is necessary, and opens the URLs in a new or restored browser accordingly. |
103 // . If |process_startup| is false, restore the last session if necessary, | 113 void ProcessLaunchUrlsUsingConsolidatedFlow( |
Peter Kasting
2016/10/06 05:49:08
Nit: Make sure before you land that .cc order matc
| |
104 // or invoke ProcessSpecifiedURLs. | 114 bool process_startup, |
105 // . Open the urls directly. | 115 const std::vector<GURL>& cmd_line_urls); |
106 void ProcessLaunchURLs(bool process_startup, | 116 |
107 const std::vector<GURL>& urls_to_open); | 117 // Returns the tabs to be shown on startup, based on the policy functions in |
118 // the given StartupTabProvider, the given tabs passed by the command line, | |
119 // and the interactions between those policies. | |
120 StartupTabs DetermineStartupTabs(const StartupTabProvider& provider, | |
121 const StartupTabs& cmd_line_tabs, | |
122 bool is_incognito, | |
123 bool is_post_crash_launch); | |
108 | 124 |
109 // Does the following: | 125 // Does the following: |
110 // . If the user's startup pref is to restore the last session (or the | 126 // . If the user's startup pref is to restore the last session (or the |
111 // command line flag is present to force using last session), it is | 127 // command line flag is present to force using last session), it is |
112 // restored. | 128 // restored. |
113 // . Otherwise invoke ProcessSpecifiedURLs | 129 // . Otherwise invoke ProcessSpecifiedURLs |
114 // If a browser was created, true is returned. Otherwise returns false and | 130 // If a browser was created, true is returned. Otherwise returns false and |
115 // the caller must create a new browser. | 131 // the caller must create a new browser. |
116 bool ProcessStartupURLs(const std::vector<GURL>& urls_to_open); | 132 bool ProcessStartupURLs(const std::vector<GURL>& urls_to_open); |
117 | 133 |
134 // Adds a Tab to |tabs| for each url in |urls| that doesn't already exist | |
135 // in |tabs|. | |
136 void AddUniqueURLs(const std::vector<GURL>& urls, StartupTabs* tabs); | |
137 | |
138 // Adds any startup infobars to the selected tab of the given browser. | |
139 void AddInfoBarsIfNecessary( | |
140 Browser* browser, | |
141 chrome::startup::IsProcessStartup is_process_startup); | |
142 | |
143 // Record Rappor metrics on startup URLs. | |
Peter Kasting
2016/10/06 05:49:08
Nit: Records
| |
144 void RecordRapporOnStartupURLs(const std::vector<GURL>& urls_to_open); | |
145 | |
146 // TODO(crbug.com/651465): The following functions are deprecated. They will | |
147 // be removed once kUseConsolidatedStartupFlow is enabled by default. | |
148 | |
149 // Invoked from Launch to handle processing of urls. This may do any of the | |
150 // following: | |
151 // . Invoke ProcessStartupURLs if |process_startup| is true. | |
152 // . If |process_startup| is false, restore the last session if necessary, | |
153 // or invoke ProcessSpecifiedURLs. | |
154 // . Open the urls directly. | |
155 // Under the kUseConsolidatedStartupFlow feature, this is replaced by | |
156 // ProcessLaunchUrlsUsingConsolidatedFlow(). | |
157 void ProcessLaunchURLs(bool process_startup, | |
158 const std::vector<GURL>& urls_to_open); | |
159 | |
118 // Invoked from either ProcessLaunchURLs or ProcessStartupURLs to handle | 160 // Invoked from either ProcessLaunchURLs or ProcessStartupURLs to handle |
119 // processing of URLs where the behavior is common between process startup | 161 // processing of URLs where the behavior is common between process startup |
120 // and launch via an existing process (i.e. those explicitly specified by | 162 // and launch via an existing process (i.e. those explicitly specified by |
121 // the user somehow). Does the following: | 163 // the user somehow). Does the following: |
122 // . Attempts to restore any pinned tabs from last run of chrome. | 164 // . Attempts to restore any pinned tabs from last run of chrome. |
123 // . If urls_to_open is non-empty, they are opened. | 165 // . If urls_to_open is non-empty, they are opened. |
124 // . If the user's startup pref is to launch a specific set of URLs they | 166 // . If the user's startup pref is to launch a specific set of URLs they |
125 // are opened. | 167 // are opened. |
126 // | 168 // |
127 // If any tabs were opened, the Browser which was created is returned. | 169 // If any tabs were opened, the Browser which was created is returned. |
128 // Otherwise null is returned and the caller must create a new browser. | 170 // Otherwise null is returned and the caller must create a new browser. |
129 Browser* ProcessSpecifiedURLs(const std::vector<GURL>& urls_to_open); | 171 Browser* ProcessSpecifiedURLs(const std::vector<GURL>& urls_to_open); |
130 | 172 |
131 // Adds a Tab to |tabs| for each url in |urls| that doesn't already exist | |
132 // in |tabs|. | |
133 void AddUniqueURLs(const std::vector<GURL>& urls, StartupTabs* tabs); | |
134 | |
135 // Adds any startup infobars to the selected tab of the given browser. | |
136 void AddInfoBarsIfNecessary( | |
137 Browser* browser, | |
138 chrome::startup::IsProcessStartup is_process_startup); | |
139 | |
140 // Adds additional startup URLs to the specified vector. | 173 // Adds additional startup URLs to the specified vector. |
141 void AddStartupURLs(std::vector<GURL>* startup_urls) const; | 174 void AddStartupURLs(std::vector<GURL>* startup_urls) const; |
142 | 175 |
143 // Adds special URLs to the specified vector. These URLs are triggered by | 176 // Adds special URLs to the specified vector. These URLs are triggered by |
144 // special-case logic, such as profile reset or presentation of the welcome | 177 // special-case logic, such as profile reset or presentation of the welcome |
145 // page. | 178 // page. |
146 void AddSpecialURLs(std::vector<GURL>* startup_urls) const; | 179 void AddSpecialURLs(std::vector<GURL>* startup_urls) const; |
147 | 180 |
148 // Initializes |welcome_run_type_| for this launch. Also persists state to | 181 // Initializes |welcome_run_type_| for this launch. Also persists state to |
149 // suppress injecting the welcome page for future launches. | 182 // suppress injecting the welcome page for future launches. |
150 void InitializeWelcomeRunType(const std::vector<GURL>& urls_to_open); | 183 void InitializeWelcomeRunType(const std::vector<GURL>& urls_to_open); |
151 | 184 |
152 // Record Rappor metrics on startup URLs. | |
153 void RecordRapporOnStartupURLs(const std::vector<GURL>& urls_to_open); | |
154 | |
155 // Checks whether |profile_| has a reset trigger set. | 185 // Checks whether |profile_| has a reset trigger set. |
156 bool ProfileHasResetTrigger() const; | 186 bool ProfileHasResetTrigger() const; |
157 | 187 |
158 const base::FilePath cur_dir_; | 188 const base::FilePath cur_dir_; |
159 const base::CommandLine& command_line_; | 189 const base::CommandLine& command_line_; |
160 Profile* profile_; | 190 Profile* profile_; |
161 StartupBrowserCreator* browser_creator_; | 191 StartupBrowserCreator* browser_creator_; |
162 bool is_first_run_; | 192 bool is_first_run_; |
163 WelcomeRunType welcome_run_type_; | 193 WelcomeRunType welcome_run_type_; |
164 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreatorImpl); | 194 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreatorImpl); |
165 }; | 195 }; |
166 | 196 |
167 #endif // CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_ | 197 #endif // CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_ |
OLD | NEW |