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); |
70 | 76 |
71 enum class WelcomeRunType { | 77 enum class WelcomeRunType { |
72 NONE, // Do not inject the welcome page for this run. | 78 NONE, // Do not inject the welcome page for this run. |
73 FIRST_TAB, // Inject the welcome page as the first tab. | 79 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. | 80 FIRST_RUN_LAST_TAB, // Inject the welcome page as the last first-run tab. |
75 }; | 81 }; |
76 | 82 |
77 // Creates a tab for each of the Tabs in |tabs|. If browser is non-null | 83 // 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 | 84 // 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 | 85 // browser is created and the tabs are added to it. The browser the tabs |
(...skipping 19 matching lines...) Expand all Loading... |
99 | 105 |
100 // Invoked from Launch to handle processing of urls. This may do any of the | 106 // Invoked from Launch to handle processing of urls. This may do any of the |
101 // following: | 107 // following: |
102 // . Invoke ProcessStartupURLs if |process_startup| is true. | 108 // . Invoke ProcessStartupURLs if |process_startup| is true. |
103 // . If |process_startup| is false, restore the last session if necessary, | 109 // . If |process_startup| is false, restore the last session if necessary, |
104 // or invoke ProcessSpecifiedURLs. | 110 // or invoke ProcessSpecifiedURLs. |
105 // . Open the urls directly. | 111 // . Open the urls directly. |
106 void ProcessLaunchURLs(bool process_startup, | 112 void ProcessLaunchURLs(bool process_startup, |
107 const std::vector<GURL>& urls_to_open); | 113 const std::vector<GURL>& urls_to_open); |
108 | 114 |
| 115 // Determines the URLs to be shown at startup by way of various policies |
| 116 // (onboarding, pinned tabs, etc.), determines whether a session restore |
| 117 // is necessary, and opens the URLs in a new or restored browser accordingly. |
| 118 // This method is a refactoring of ProcessLaunchURLs above, and will replace |
| 119 // that code path entirely once kUseConsolidatedStartupFlow is on by default. |
| 120 void ProcessLaunchUrlsUsingConsolidatedFlow( |
| 121 bool process_startup, |
| 122 const std::vector<GURL>& urls_to_open); |
| 123 |
| 124 // Returns the tabs to be shown on startup when no URLs are provided on the |
| 125 // command line, based on the policy functions in the given |
| 126 // StartupTabProvider, and the interactions between those policies. |
| 127 StartupTabs DetermineStartupTabs(const StartupTabProvider& provider, |
| 128 bool is_incognito, |
| 129 bool is_post_crash_launch); |
| 130 |
| 131 // Opens the given tabs in a new browser. |
| 132 // TODO(tmartino): Add the ability to restore a session, and an additional |
| 133 // argument which indicates which behavior (new or restored) should be used. |
| 134 Browser* RestoreOrCreateBrowser(bool process_startup, |
| 135 const StartupTabs& tabs); |
| 136 |
109 // Does the following: | 137 // Does the following: |
110 // . If the user's startup pref is to restore the last session (or the | 138 // . 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 | 139 // command line flag is present to force using last session), it is |
112 // restored. | 140 // restored. |
113 // . Otherwise invoke ProcessSpecifiedURLs | 141 // . Otherwise invoke ProcessSpecifiedURLs |
114 // If a browser was created, true is returned. Otherwise returns false and | 142 // If a browser was created, true is returned. Otherwise returns false and |
115 // the caller must create a new browser. | 143 // the caller must create a new browser. |
116 bool ProcessStartupURLs(const std::vector<GURL>& urls_to_open); | 144 bool ProcessStartupURLs(const std::vector<GURL>& urls_to_open); |
117 | 145 |
118 // Invoked from either ProcessLaunchURLs or ProcessStartupURLs to handle | 146 // Invoked from either ProcessLaunchURLs or ProcessStartupURLs to handle |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 const base::FilePath cur_dir_; | 186 const base::FilePath cur_dir_; |
159 const base::CommandLine& command_line_; | 187 const base::CommandLine& command_line_; |
160 Profile* profile_; | 188 Profile* profile_; |
161 StartupBrowserCreator* browser_creator_; | 189 StartupBrowserCreator* browser_creator_; |
162 bool is_first_run_; | 190 bool is_first_run_; |
163 WelcomeRunType welcome_run_type_; | 191 WelcomeRunType welcome_run_type_; |
164 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreatorImpl); | 192 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreatorImpl); |
165 }; | 193 }; |
166 | 194 |
167 #endif // CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_ | 195 #endif // CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_ |
OLD | NEW |