| 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 "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 19 | 19 |
| 20 class Browser; | 20 class Browser; |
| 21 class CommandLine; | 21 class CommandLine; |
| 22 class GURL; | 22 class GURL; |
| 23 class PrefService; | 23 class PrefService; |
| 24 class OperationOutput; |
| 24 | 25 |
| 25 // class containing helpers for BrowserMain to spin up a new instance and | 26 // class containing helpers for BrowserMain to spin up a new instance and |
| 26 // initialize the profile. | 27 // initialize the profile. |
| 27 class StartupBrowserCreator { | 28 class StartupBrowserCreator { |
| 28 public: | 29 public: |
| 29 typedef std::vector<Profile*> Profiles; | 30 typedef std::vector<Profile*> Profiles; |
| 30 | 31 |
| 31 StartupBrowserCreator(); | 32 StartupBrowserCreator(); |
| 32 ~StartupBrowserCreator(); | 33 ~StartupBrowserCreator(); |
| 33 | 34 |
| 34 // Adds a url to be opened during first run. This overrides the standard | 35 // Adds a url to be opened during first run. This overrides the standard |
| 35 // tabs shown at first run. | 36 // tabs shown at first run. |
| 36 void AddFirstRunTab(const GURL& url); | 37 void AddFirstRunTab(const GURL& url); |
| 37 | 38 |
| 38 // This function is equivalent to ProcessCommandLine but should only be | 39 // This function is equivalent to ProcessCommandLine but should only be |
| 39 // called during actual process startup. | 40 // called during actual process startup. |
| 41 // Returns true if the current process should continue running. |
| 42 // |operation_output| will be notified of the outcome of the operation |
| 43 // requested via cmd_line. If the process is to exit immediately, this will |
| 44 // happen before Start() returns. Otherwise it may happen asynchronously. |
| 40 bool Start(const CommandLine& cmd_line, | 45 bool Start(const CommandLine& cmd_line, |
| 41 const base::FilePath& cur_dir, | 46 const base::FilePath& cur_dir, |
| 42 Profile* last_used_profile, | 47 Profile* last_used_profile, |
| 43 const Profiles& last_opened_profiles, | 48 const Profiles& last_opened_profiles, |
| 44 int* return_code) { | 49 scoped_ptr<OperationOutput> operation_output); |
| 45 return ProcessCmdLineImpl(cmd_line, cur_dir, true, last_used_profile, | |
| 46 last_opened_profiles, return_code, this); | |
| 47 } | |
| 48 | 50 |
| 49 // This function performs command-line handling and is invoked only after | 51 // 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). | 52 // start up (for example when we get a start request for another process). |
| 51 // |command_line| holds the command line we need to process. | 53 // |command_line| holds the command line we need to process. |
| 52 // |cur_dir| is the current working directory that the original process was | 54 // |cur_dir| is the current working directory that the original process was |
| 53 // invoked from. | 55 // invoked from. |
| 54 // |startup_profile_dir| is the directory that contains the profile that the | 56 // |startup_profile_dir| is the directory that contains the profile that the |
| 55 // command line arguments will be executed under. | 57 // command line arguments will be executed under. |
| 56 static void ProcessCommandLineAlreadyRunning( | 58 static void ProcessCommandLineAlreadyRunning( |
| 57 const CommandLine& command_line, | 59 const CommandLine& command_line, |
| 58 const base::FilePath& cur_dir, | 60 const base::FilePath& cur_dir, |
| 59 const base::FilePath& startup_profile_dir); | 61 const base::FilePath& startup_profile_dir, |
| 62 scoped_ptr<OperationOutput> operation_output); |
| 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 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 static std::vector<GURL> GetURLsFromCommandLine( | 126 static std::vector<GURL> GetURLsFromCommandLine( |
| 124 const CommandLine& command_line, | 127 const 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 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 StartupBrowserCreator* browser_creator, |
| 134 StartupBrowserCreator* browser_creator); | 137 scoped_ptr<OperationOutput> operation_output); |
| 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 CommandLine& command_line, |
| 139 const base::FilePath& cur_dir, | 142 const base::FilePath& cur_dir, |
| 143 scoped_ptr<OperationOutput> operation_output, |
| 140 Profile* profile, | 144 Profile* profile, |
| 141 Profile::CreateStatus status); | 145 Profile::CreateStatus status); |
| 142 | 146 |
| 143 // Returns true once a profile was activated. Used by the | 147 // Returns true once a profile was activated. Used by the |
| 144 // StartupBrowserCreatorTest.LastUsedProfileActivated test. | 148 // StartupBrowserCreatorTest.LastUsedProfileActivated test. |
| 145 static bool ActivatedProfile(); | 149 static bool ActivatedProfile(); |
| 146 | 150 |
| 147 // Additional tabs to open during first run. | 151 // Additional tabs to open during first run. |
| 148 std::vector<GURL> first_run_tabs_; | 152 std::vector<GURL> first_run_tabs_; |
| 149 | 153 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 160 // member variable instead of a static variable inside WasRestarted because | 164 // member variable instead of a static variable inside WasRestarted because |
| 161 // of testing.) | 165 // of testing.) |
| 162 static bool was_restarted_read_; | 166 static bool was_restarted_read_; |
| 163 | 167 |
| 164 static bool in_synchronous_profile_launch_; | 168 static bool in_synchronous_profile_launch_; |
| 165 | 169 |
| 166 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreator); | 170 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreator); |
| 167 }; | 171 }; |
| 168 | 172 |
| 169 #endif // CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_ | 173 #endif // CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_ |
| OLD | NEW |