Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / startup / startup_browser_creator.h
blob3ace91f511bafa1979f41660970ba677019aef30
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_
6 #define CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "base/gtest_prod_util.h"
14 #include "chrome/browser/prefs/session_startup_pref.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/startup/startup_tab.h"
17 #include "chrome/browser/ui/startup/startup_types.h"
18 #include "url/gurl.h"
20 class Browser;
21 class GURL;
22 class PrefRegistrySimple;
23 class PrefService;
25 namespace base {
26 class CommandLine;
29 // class containing helpers for BrowserMain to spin up a new instance and
30 // initialize the profile.
31 class StartupBrowserCreator {
32 public:
33 typedef std::vector<Profile*> Profiles;
35 StartupBrowserCreator();
36 ~StartupBrowserCreator();
38 // Adds a url to be opened during first run. This overrides the standard
39 // tabs shown at first run.
40 void AddFirstRunTab(const GURL& url);
42 // This function is equivalent to ProcessCommandLine but should only be
43 // called during actual process startup.
44 bool Start(const base::CommandLine& cmd_line,
45 const base::FilePath& cur_dir,
46 Profile* last_used_profile,
47 const Profiles& last_opened_profiles);
49 // 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).
51 // |command_line| holds the command line we need to process.
52 // |cur_dir| is the current working directory that the original process was
53 // invoked from.
54 // |startup_profile_dir| is the directory that contains the profile that the
55 // command line arguments will be executed under.
56 static void ProcessCommandLineAlreadyRunning(
57 const base::CommandLine& command_line,
58 const base::FilePath& cur_dir,
59 const base::FilePath& startup_profile_dir);
61 // Returns true if we're launching a profile synchronously. In that case, the
62 // opened window should not cause a session restore.
63 static bool InSynchronousProfileLaunch();
65 // Launches a browser window associated with |profile|. |command_line| should
66 // be the command line passed to this process. |cur_dir| can be empty, which
67 // implies that the directory of the executable should be used.
68 // |process_startup| indicates whether this is the first browser.
69 // |is_first_run| indicates that this is a new profile.
70 bool LaunchBrowser(const base::CommandLine& command_line,
71 Profile* profile,
72 const base::FilePath& cur_dir,
73 chrome::startup::IsProcessStartup is_process_startup,
74 chrome::startup::IsFirstRun is_first_run);
76 // When called the first time, reads the value of the preference kWasRestarted
77 // and resets it to false. Subsequent calls return the value which was read
78 // the first time.
79 static bool WasRestarted();
81 static SessionStartupPref GetSessionStartupPref(
82 const base::CommandLine& command_line,
83 Profile* profile);
85 void set_is_default_browser_dialog_suppressed(bool new_value) {
86 is_default_browser_dialog_suppressed_ = new_value;
89 bool is_default_browser_dialog_suppressed() const {
90 return is_default_browser_dialog_suppressed_;
93 void set_show_main_browser_window(bool show_main_browser_window) {
94 show_main_browser_window_ = show_main_browser_window;
97 bool show_main_browser_window() const {
98 return show_main_browser_window_;
101 // For faking that no profiles have been launched yet.
102 static void ClearLaunchedProfilesForTesting();
104 static void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
106 private:
107 friend class CloudPrintProxyPolicyTest;
108 friend class CloudPrintProxyPolicyStartupTest;
109 friend class StartupBrowserCreatorImpl;
110 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
111 ReadingWasRestartedAfterNormalStart);
112 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
113 ReadingWasRestartedAfterRestart);
114 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, UpdateWithTwoProfiles);
115 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, LastUsedProfileActivated);
117 // Returns the list of URLs to open from the command line. The returned
118 // vector is empty if the user didn't specify any URLs on the command line.
119 static std::vector<GURL> GetURLsFromCommandLine(
120 const base::CommandLine& command_line,
121 const base::FilePath& cur_dir,
122 Profile* profile);
124 static bool ProcessCmdLineImpl(const base::CommandLine& command_line,
125 const base::FilePath& cur_dir,
126 bool process_startup,
127 Profile* last_used_profile,
128 const Profiles& last_opened_profiles,
129 StartupBrowserCreator* browser_creator);
131 // This function performs command-line handling and is invoked only after
132 // start up (for example when we get a start request for another process).
133 // |command_line| holds the command line being processed.
134 // |cur_dir| is the current working directory that the original process was
135 // invoked from.
136 // |profile| is the profile the apps will be launched in.
137 static bool ProcessLoadApps(const base::CommandLine& command_line,
138 const base::FilePath& cur_dir,
139 Profile* profile);
141 // Callback after a profile has been created.
142 static void ProcessCommandLineOnProfileCreated(
143 const base::CommandLine& command_line,
144 const base::FilePath& cur_dir,
145 Profile* profile,
146 Profile::CreateStatus status);
148 // Returns true once a profile was activated. Used by the
149 // StartupBrowserCreatorTest.LastUsedProfileActivated test.
150 static bool ActivatedProfile();
152 // Additional tabs to open during first run.
153 std::vector<GURL> first_run_tabs_;
155 // True if the set-as-default dialog has been explicitly suppressed.
156 // This information is used to allow the default browser prompt to show on
157 // first-run when the dialog has been suppressed.
158 bool is_default_browser_dialog_suppressed_;
160 // Whether the browser window should be shown immediately after it has been
161 // created. Default is true.
162 bool show_main_browser_window_;
164 // True if we have already read and reset the preference kWasRestarted. (A
165 // member variable instead of a static variable inside WasRestarted because
166 // of testing.)
167 static bool was_restarted_read_;
169 static bool in_synchronous_profile_launch_;
171 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreator);
174 // Returns true if |profile| has exited uncleanly and has not been launched
175 // after the unclean exit.
176 bool HasPendingUncleanExit(Profile* profile);
178 // Returns the path that contains the profile that should be loaded on process
179 // startup.
180 base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir,
181 const base::CommandLine& command_line);
183 #endif // CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_