| 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_H_ | 5 #ifndef CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_ |
| 6 #define CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_ | 6 #define CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "chrome/browser/prefs/session_startup_pref.h" | 14 #include "chrome/browser/prefs/session_startup_pref.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/startup/startup_tab.h" | 16 #include "chrome/browser/ui/startup/startup_tab.h" |
| 17 #include "chrome/browser/ui/startup/startup_types.h" | 17 #include "chrome/browser/ui/startup/startup_types.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 | 19 |
| 20 class Browser; | 20 class Browser; |
| 21 class CommandLine; | |
| 22 class GURL; | 21 class GURL; |
| 23 class PrefService; | 22 class PrefService; |
| 24 | 23 |
| 24 namespace base { |
| 25 class CommandLine; |
| 26 } |
| 27 |
| 25 // class containing helpers for BrowserMain to spin up a new instance and | 28 // class containing helpers for BrowserMain to spin up a new instance and |
| 26 // initialize the profile. | 29 // initialize the profile. |
| 27 class StartupBrowserCreator { | 30 class StartupBrowserCreator { |
| 28 public: | 31 public: |
| 29 typedef std::vector<Profile*> Profiles; | 32 typedef std::vector<Profile*> Profiles; |
| 30 | 33 |
| 31 StartupBrowserCreator(); | 34 StartupBrowserCreator(); |
| 32 ~StartupBrowserCreator(); | 35 ~StartupBrowserCreator(); |
| 33 | 36 |
| 34 // Adds a url to be opened during first run. This overrides the standard | 37 // Adds a url to be opened during first run. This overrides the standard |
| 35 // tabs shown at first run. | 38 // tabs shown at first run. |
| 36 void AddFirstRunTab(const GURL& url); | 39 void AddFirstRunTab(const GURL& url); |
| 37 | 40 |
| 38 // This function is equivalent to ProcessCommandLine but should only be | 41 // This function is equivalent to ProcessCommandLine but should only be |
| 39 // called during actual process startup. | 42 // called during actual process startup. |
| 40 bool Start(const CommandLine& cmd_line, | 43 bool Start(const base::CommandLine& cmd_line, |
| 41 const base::FilePath& cur_dir, | 44 const base::FilePath& cur_dir, |
| 42 Profile* last_used_profile, | 45 Profile* last_used_profile, |
| 43 const Profiles& last_opened_profiles, | 46 const Profiles& last_opened_profiles, |
| 44 int* return_code) { | 47 int* return_code) { |
| 45 return ProcessCmdLineImpl(cmd_line, cur_dir, true, last_used_profile, | 48 return ProcessCmdLineImpl(cmd_line, cur_dir, true, last_used_profile, |
| 46 last_opened_profiles, return_code, this); | 49 last_opened_profiles, return_code, this); |
| 47 } | 50 } |
| 48 | 51 |
| 49 // This function performs command-line handling and is invoked only after | 52 // This function performs command-line handling and is invoked only after |
| 50 // start up (for example when we get a start request for another process). | 53 // start up (for example when we get a start request for another process). |
| 51 // |command_line| holds the command line we need to process. | 54 // |command_line| holds the command line we need to process. |
| 52 // |cur_dir| is the current working directory that the original process was | 55 // |cur_dir| is the current working directory that the original process was |
| 53 // invoked from. | 56 // invoked from. |
| 54 // |startup_profile_dir| is the directory that contains the profile that the | 57 // |startup_profile_dir| is the directory that contains the profile that the |
| 55 // command line arguments will be executed under. | 58 // command line arguments will be executed under. |
| 56 static void ProcessCommandLineAlreadyRunning( | 59 static void ProcessCommandLineAlreadyRunning( |
| 57 const CommandLine& command_line, | 60 const base::CommandLine& command_line, |
| 58 const base::FilePath& cur_dir, | 61 const base::FilePath& cur_dir, |
| 59 const base::FilePath& startup_profile_dir); | 62 const base::FilePath& startup_profile_dir); |
| 60 | 63 |
| 61 template <class AutomationProviderClass> | 64 template <class AutomationProviderClass> |
| 62 static bool CreateAutomationProvider(const std::string& channel_id, | 65 static bool CreateAutomationProvider(const std::string& channel_id, |
| 63 Profile* profile, | 66 Profile* profile, |
| 64 size_t expected_tabs); | 67 size_t expected_tabs); |
| 65 | 68 |
| 66 // Returns true if we're launching a profile synchronously. In that case, the | 69 // Returns true if we're launching a profile synchronously. In that case, the |
| 67 // opened window should not cause a session restore. | 70 // opened window should not cause a session restore. |
| 68 static bool InSynchronousProfileLaunch(); | 71 static bool InSynchronousProfileLaunch(); |
| 69 | 72 |
| 70 // Launches a browser window associated with |profile|. |command_line| should | 73 // Launches a browser window associated with |profile|. |command_line| should |
| 71 // be the command line passed to this process. |cur_dir| can be empty, which | 74 // be the command line passed to this process. |cur_dir| can be empty, which |
| 72 // implies that the directory of the executable should be used. | 75 // implies that the directory of the executable should be used. |
| 73 // |process_startup| indicates whether this is the first browser. | 76 // |process_startup| indicates whether this is the first browser. |
| 74 // |is_first_run| indicates that this is a new profile. | 77 // |is_first_run| indicates that this is a new profile. |
| 75 bool LaunchBrowser(const CommandLine& command_line, | 78 bool LaunchBrowser(const base::CommandLine& command_line, |
| 76 Profile* profile, | 79 Profile* profile, |
| 77 const base::FilePath& cur_dir, | 80 const base::FilePath& cur_dir, |
| 78 chrome::startup::IsProcessStartup is_process_startup, | 81 chrome::startup::IsProcessStartup is_process_startup, |
| 79 chrome::startup::IsFirstRun is_first_run, | 82 chrome::startup::IsFirstRun is_first_run, |
| 80 int* return_code); | 83 int* return_code); |
| 81 | 84 |
| 82 // When called the first time, reads the value of the preference kWasRestarted | 85 // When called the first time, reads the value of the preference kWasRestarted |
| 83 // and resets it to false. Subsequent calls return the value which was read | 86 // and resets it to false. Subsequent calls return the value which was read |
| 84 // the first time. | 87 // the first time. |
| 85 static bool WasRestarted(); | 88 static bool WasRestarted(); |
| 86 | 89 |
| 87 static SessionStartupPref GetSessionStartupPref( | 90 static SessionStartupPref GetSessionStartupPref( |
| 88 const CommandLine& command_line, | 91 const base::CommandLine& command_line, |
| 89 Profile* profile); | 92 Profile* profile); |
| 90 | 93 |
| 91 void set_is_default_browser_dialog_suppressed(bool new_value) { | 94 void set_is_default_browser_dialog_suppressed(bool new_value) { |
| 92 is_default_browser_dialog_suppressed_ = new_value; | 95 is_default_browser_dialog_suppressed_ = new_value; |
| 93 } | 96 } |
| 94 | 97 |
| 95 bool is_default_browser_dialog_suppressed() const { | 98 bool is_default_browser_dialog_suppressed() const { |
| 96 return is_default_browser_dialog_suppressed_; | 99 return is_default_browser_dialog_suppressed_; |
| 97 } | 100 } |
| 98 | 101 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 114 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, | 117 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, |
| 115 ReadingWasRestartedAfterNormalStart); | 118 ReadingWasRestartedAfterNormalStart); |
| 116 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, | 119 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, |
| 117 ReadingWasRestartedAfterRestart); | 120 ReadingWasRestartedAfterRestart); |
| 118 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, UpdateWithTwoProfiles); | 121 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, UpdateWithTwoProfiles); |
| 119 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, LastUsedProfileActivated); | 122 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, LastUsedProfileActivated); |
| 120 | 123 |
| 121 // Returns the list of URLs to open from the command line. The returned | 124 // Returns the list of URLs to open from the command line. The returned |
| 122 // vector is empty if the user didn't specify any URLs on the command line. | 125 // vector is empty if the user didn't specify any URLs on the command line. |
| 123 static std::vector<GURL> GetURLsFromCommandLine( | 126 static std::vector<GURL> GetURLsFromCommandLine( |
| 124 const CommandLine& command_line, | 127 const base::CommandLine& command_line, |
| 125 const base::FilePath& cur_dir, | 128 const base::FilePath& cur_dir, |
| 126 Profile* profile); | 129 Profile* profile); |
| 127 | 130 |
| 128 static bool ProcessCmdLineImpl(const CommandLine& command_line, | 131 static bool ProcessCmdLineImpl(const base::CommandLine& command_line, |
| 129 const base::FilePath& cur_dir, | 132 const base::FilePath& cur_dir, |
| 130 bool process_startup, | 133 bool process_startup, |
| 131 Profile* last_used_profile, | 134 Profile* last_used_profile, |
| 132 const Profiles& last_opened_profiles, | 135 const Profiles& last_opened_profiles, |
| 133 int* return_code, | 136 int* return_code, |
| 134 StartupBrowserCreator* browser_creator); | 137 StartupBrowserCreator* browser_creator); |
| 135 | 138 |
| 136 // Callback after a profile has been created. | 139 // Callback after a profile has been created. |
| 137 static void ProcessCommandLineOnProfileCreated( | 140 static void ProcessCommandLineOnProfileCreated( |
| 138 const CommandLine& command_line, | 141 const base::CommandLine& command_line, |
| 139 const base::FilePath& cur_dir, | 142 const base::FilePath& cur_dir, |
| 140 Profile* profile, | 143 Profile* profile, |
| 141 Profile::CreateStatus status); | 144 Profile::CreateStatus status); |
| 142 | 145 |
| 143 // Returns true once a profile was activated. Used by the | 146 // Returns true once a profile was activated. Used by the |
| 144 // StartupBrowserCreatorTest.LastUsedProfileActivated test. | 147 // StartupBrowserCreatorTest.LastUsedProfileActivated test. |
| 145 static bool ActivatedProfile(); | 148 static bool ActivatedProfile(); |
| 146 | 149 |
| 147 // Additional tabs to open during first run. | 150 // Additional tabs to open during first run. |
| 148 std::vector<GURL> first_run_tabs_; | 151 std::vector<GURL> first_run_tabs_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 166 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreator); | 169 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreator); |
| 167 }; | 170 }; |
| 168 | 171 |
| 169 // Returns true if |profile| has exited uncleanly and has not been launched | 172 // Returns true if |profile| has exited uncleanly and has not been launched |
| 170 // after the unclean exit. | 173 // after the unclean exit. |
| 171 bool HasPendingUncleanExit(Profile* profile); | 174 bool HasPendingUncleanExit(Profile* profile); |
| 172 | 175 |
| 173 // Returns the path that contains the profile that should be loaded on process | 176 // Returns the path that contains the profile that should be loaded on process |
| 174 // startup. | 177 // startup. |
| 175 base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir, | 178 base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir, |
| 176 const CommandLine& command_line); | 179 const base::CommandLine& command_line); |
| 177 | 180 |
| 178 #endif // CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_ | 181 #endif // CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_ |
| OLD | NEW |