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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator_impl.h

Issue 2469363002: Tech Debt Repayment for StartupBrowserCreatorImpl Refactor (Closed)
Patch Set: sky comments Created 3 years, 10 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
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/sessions/session_restore.h"
14 #include "chrome/browser/ui/startup/startup_tab.h" 15 #include "chrome/browser/ui/startup/startup_tab.h"
15 #include "chrome/browser/ui/startup/startup_tab_provider.h" 16 #include "chrome/browser/ui/startup/startup_tab_provider.h"
16 #include "chrome/browser/ui/startup/startup_types.h" 17 #include "chrome/browser/ui/startup/startup_types.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 class Browser; 20 class Browser;
20 class Profile; 21 class Profile;
21 class StartupBrowserCreator; 22 class StartupBrowserCreator;
22 23
23 namespace base { 24 namespace base {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch); 67 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch);
67 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest, DetermineStartupTabs); 68 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest, DetermineStartupTabs);
68 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest, 69 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest,
69 DetermineStartupTabs_IncognitoOrCrash); 70 DetermineStartupTabs_IncognitoOrCrash);
70 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest, 71 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest,
71 DetermineStartupTabs_MasterPrefs); 72 DetermineStartupTabs_MasterPrefs);
72 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest, 73 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest,
73 DetermineStartupTabs_CommandLine); 74 DetermineStartupTabs_CommandLine);
74 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest, 75 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest,
75 DetermineStartupTabs_NewTabPage); 76 DetermineStartupTabs_NewTabPage);
77 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest,
78 DetermineBrowserOpenBehavior_Startup);
79 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest,
80 DetermineBrowserOpenBehavior_CmdLineTabs);
81 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest,
82 DetermineBrowserOpenBehavior_PostCrash);
83 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorImplTest,
84 DetermineBrowserOpenBehavior_NotStartup);
76 85
77 enum class WelcomeRunType { 86 enum class WelcomeRunType {
78 NONE, // Do not inject the welcome page for this run. 87 NONE, // Do not inject the welcome page for this run.
79 FIRST_TAB, // Inject the welcome page as the first tab. 88 FIRST_TAB, // Inject the welcome page as the first tab.
80 FIRST_RUN_LAST_TAB, // Inject the welcome page as the last first-run tab. 89 FIRST_RUN_LAST_TAB, // Inject the welcome page as the last first-run tab.
81 }; 90 };
82 91
92 // Window behaviors possible when opening Chrome.
83 enum class BrowserOpenBehavior { 93 enum class BrowserOpenBehavior {
84 NEW, // Open in a new browser. 94 NEW, // Open in a new browser.
85 SYNCHRONOUS_RESTORE, // Attempt a synchronous session restore. 95 SYNCHRONOUS_RESTORE, // Attempt a synchronous session restore.
86 USE_EXISTING, // Attempt to add to an existing tabbed browser. 96 USE_EXISTING, // Attempt to add to an existing tabbed browser.
87 }; 97 };
88 98
99 // Boolean flags used to indicate state for DetermineBrowserOpenBehavior.
100 enum BehaviorFlags {
101 PROCESS_STARTUP = (1 << 0),
102 IS_POST_CRASH_LAUNCH = (1 << 1),
103 HAS_RESTORE_SWITCH = (1 << 2),
104 HAS_NEW_WINDOW_SWITCH = (1 << 3),
105 HAS_CMD_LINE_TABS = (1 << 4),
106 };
107
108 using BrowserOpenBehaviorOptions = uint32_t;
109
89 // Creates a tab for each of the Tabs in |tabs|. If browser is non-null 110 // Creates a tab for each of the Tabs in |tabs|. If browser is non-null
90 // and a tabbed browser, the tabs are added to it. Otherwise a new tabbed 111 // and a tabbed browser, the tabs are added to it. Otherwise a new tabbed
91 // browser is created and the tabs are added to it. The browser the tabs 112 // browser is created and the tabs are added to it. The browser the tabs
92 // are added to is returned, which is either |browser| or the newly created 113 // are added to is returned, which is either |browser| or the newly created
93 // browser. 114 // browser.
94 Browser* OpenTabsInBrowser(Browser* browser, 115 Browser* OpenTabsInBrowser(Browser* browser,
95 bool process_startup, 116 bool process_startup,
96 const StartupTabs& tabs); 117 const StartupTabs& tabs);
97 118
98 // If the process was launched with the web application command line flags, 119 // If the process was launched with the web application command line flags,
(...skipping 30 matching lines...) Expand all
129 // necessary. Returns true if restore was initiated, or false if launch 150 // necessary. Returns true if restore was initiated, or false if launch
130 // should continue (either synchronously, or asynchronously without 151 // should continue (either synchronously, or asynchronously without
131 // restoring). 152 // restoring).
132 bool MaybeAsyncRestore(const StartupTabs& tabs, 153 bool MaybeAsyncRestore(const StartupTabs& tabs,
133 bool process_startup, 154 bool process_startup,
134 bool is_post_crash_launch); 155 bool is_post_crash_launch);
135 156
136 // Returns a browser displaying the contents of |tabs|. Based on |behavior|, 157 // Returns a browser displaying the contents of |tabs|. Based on |behavior|,
137 // this may attempt a session restore or create a new browser. May also allow 158 // this may attempt a session restore or create a new browser. May also allow
138 // DOM Storage to begin cleanup once it's clear it is not needed anymore. 159 // DOM Storage to begin cleanup once it's clear it is not needed anymore.
139 Browser* RestoreOrCreateBrowser(const StartupTabs& tabs, 160 Browser* RestoreOrCreateBrowser(
140 BrowserOpenBehavior behavior, 161 const StartupTabs& tabs, BrowserOpenBehavior behavior,
141 uint32_t restore_options, 162 SessionRestore::BehaviorBitmask restore_options, bool process_startup,
142 bool process_startup, 163 bool is_post_crash_launch);
143 bool is_post_crash_launch);
144 164
145 // Adds a Tab to |tabs| for each url in |urls| that doesn't already exist 165 // Adds a Tab to |tabs| for each url in |urls| that doesn't already exist
146 // in |tabs|. 166 // in |tabs|.
147 void AddUniqueURLs(const std::vector<GURL>& urls, StartupTabs* tabs); 167 void AddUniqueURLs(const std::vector<GURL>& urls, StartupTabs* tabs);
148 168
149 // Adds any startup infobars to the selected tab of the given browser. 169 // Adds any startup infobars to the selected tab of the given browser.
150 void AddInfoBarsIfNecessary( 170 void AddInfoBarsIfNecessary(
151 Browser* browser, 171 Browser* browser,
152 chrome::startup::IsProcessStartup is_process_startup); 172 chrome::startup::IsProcessStartup is_process_startup);
153 173
154 // Records Rappor metrics on startup URLs. 174 // Records Rappor metrics on startup URLs.
155 void RecordRapporOnStartupURLs(const std::vector<GURL>& urls_to_open); 175 void RecordRapporOnStartupURLs(const std::vector<GURL>& urls_to_open);
156 176
157 // Determines how the launch flow should obtain a Browser. 177 // Determines how the launch flow should obtain a Browser.
158 static BrowserOpenBehavior DetermineBrowserOpenBehavior( 178 static BrowserOpenBehavior DetermineBrowserOpenBehavior(
159 const SessionStartupPref& pref, 179 const SessionStartupPref& pref,
160 bool process_startup, 180 BrowserOpenBehaviorOptions options);
161 bool is_post_crash_launch,
162 bool has_restore_switch,
163 bool has_new_window_switch,
164 bool has_cmd_line_tabs);
165 181
166 // Returns the relevant bitmask options which must be passed when restoring a 182 // Returns the relevant bitmask options which must be passed when restoring a
167 // session. 183 // session.
168 static uint32_t DetermineSynchronousRestoreOptions( 184 static SessionRestore::BehaviorBitmask DetermineSynchronousRestoreOptions(
169 bool has_create_browser_default, 185 bool has_create_browser_default,
170 bool has_create_browser_switch, 186 bool has_create_browser_switch,
171 bool was_mac_login_or_resume); 187 bool was_mac_login_or_resume);
172 188
173 // TODO(crbug.com/651465): The following functions are deprecated. They will 189 // TODO(crbug.com/651465): The following functions are deprecated. They will
174 // be removed once kUseConsolidatedStartupFlow is enabled by default. 190 // be removed once kUseConsolidatedStartupFlow is enabled by default.
175 191
176 // Invoked from Launch to handle processing of urls. This may do any of the 192 // Invoked from Launch to handle processing of urls. This may do any of the
177 // following: 193 // following:
178 // . Invoke ProcessStartupURLs if |process_startup| is true. 194 // . Invoke ProcessStartupURLs if |process_startup| is true.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 const base::FilePath cur_dir_; 240 const base::FilePath cur_dir_;
225 const base::CommandLine& command_line_; 241 const base::CommandLine& command_line_;
226 Profile* profile_; 242 Profile* profile_;
227 StartupBrowserCreator* browser_creator_; 243 StartupBrowserCreator* browser_creator_;
228 bool is_first_run_; 244 bool is_first_run_;
229 WelcomeRunType welcome_run_type_; 245 WelcomeRunType welcome_run_type_;
230 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreatorImpl); 246 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreatorImpl);
231 }; 247 };
232 248
233 #endif // CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_ 249 #endif // CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698