diff options
author | cpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-07 23:37:59 +0000 |
---|---|---|
committer | cpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-07 23:37:59 +0000 |
commit | 4a8bca5ce3b7c77514f3a46625c0ac397848b15b (patch) | |
tree | 5b460d39ca15419f076d8cd697223ebdcbaa8574 | |
parent | 7c0bef11a5930ee52e6351248228444889bdc702 (diff) | |
download | chromium_src-4a8bca5ce3b7c77514f3a46625c0ac397848b15b.zip chromium_src-4a8bca5ce3b7c77514f3a46625c0ac397848b15b.tar.gz chromium_src-4a8bca5ce3b7c77514f3a46625c0ac397848b15b.tar.bz2 |
Refactor BrowserInit in preparation for customized first run tabs
- BrowserInit is now a instanciable class
- The 'bag of static functions' part is mostly unchanged
- unused members in the interface moved to the cc file
TEST= no visible change. interactive UI tests sufice
BUG=9706
Review URL: http://codereview.chromium.org/113113
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15595 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_init.cc | 69 | ||||
-rw-r--r-- | chrome/browser/browser_init.h | 67 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 29 |
3 files changed, 82 insertions, 83 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index 67f24f8..68f8828b 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -285,10 +285,37 @@ void RecordLaunchModeHistogram(LaunchMode mode) { UMA_HISTOGRAM_COUNTS_100("Launch.Modes", bucket); } -} // namespace - static bool in_startup = false; +bool LaunchBrowser(const CommandLine& command_line, Profile* profile, + const std::wstring& cur_dir, bool process_startup, + int* return_code) { + in_startup = process_startup; + DCHECK(profile); +#ifdef FRAME_WINDOW + FrameWindow::Show(profile); + return true; +#endif + + // Continue with the off-the-record profile from here on if --incognito + if (command_line.HasSwitch(switches::kIncognito)) + profile = profile->GetOffTheRecordProfile(); + + BrowserInit::LaunchWithProfile lwp(cur_dir, command_line); + bool launched = lwp.Launch(profile, process_startup); + in_startup = false; + + if (!launched) { + LOG(ERROR) << "launch error"; + if (return_code) + *return_code = ResultCodes::INVALID_CMDLINE_URL; + return false; + } + return true; +} + +} // namespace + // static bool BrowserInit::InProcessStartup() { return in_startup; @@ -632,16 +659,6 @@ bool BrowserInit::ProcessCommandLine( return true; } -bool BrowserInit::LaunchBrowser(const CommandLine& command_line, - Profile* profile, const std::wstring& cur_dir, - bool process_startup, int* return_code) { - in_startup = process_startup; - bool result = LaunchBrowserImpl(command_line, profile, cur_dir, - process_startup, return_code); - in_startup = false; - return result; -} - template <class AutomationProviderClass> void BrowserInit::CreateAutomationProvider(const std::wstring& channel_id, Profile* profile, @@ -656,31 +673,3 @@ void BrowserInit::CreateAutomationProvider(const std::wstring& channel_id, DCHECK(list); list->AddProvider(automation); } - -bool BrowserInit::LaunchBrowserImpl(const CommandLine& command_line, - Profile* profile, - const std::wstring& cur_dir, - bool process_startup, - int* return_code) { - DCHECK(profile); - -#ifdef FRAME_WINDOW - FrameWindow::Show(profile); - return true; -#endif - - // Continue with the off-the-record profile from here on if --incognito - if (command_line.HasSwitch(switches::kIncognito)) - profile = profile->GetOffTheRecordProfile(); - - LaunchWithProfile lwp(cur_dir, command_line); - bool launched = lwp.Launch(profile, process_startup); - if (!launched) { - LOG(ERROR) << "launch error"; - if (return_code != NULL) - *return_code = ResultCodes::INVALID_CMDLINE_URL; - return false; - } - - return true; -} diff --git a/chrome/browser/browser_init.h b/chrome/browser/browser_init.h index 6be28502..221f169 100644 --- a/chrome/browser/browser_init.h +++ b/chrome/browser/browser_init.h @@ -9,6 +9,7 @@ #include <vector> #include "base/basictypes.h" +#include "googleurl/src/gurl.h" class Browser; class CommandLine; @@ -17,10 +18,42 @@ class PrefService; class Profile; class TabContents; -// Scoper class containing helpers for BrowserMain to spin up a new instance -// and initialize the profile. +// class containing helpers for BrowserMain to spin up a new instance and +// initialize the profile. class BrowserInit { public: + BrowserInit() {}; + ~BrowserInit() {}; + + // Adds a url to be opened during first run. This overrides the standard + // tabs shown at first run. + void AddFirstRunTab(const GURL& url) { + first_run_tabs_.push_back(url); + } + + // This function is equivalent to ProcessCommandLine but should only be + // called during actual process startup. + bool Start(const CommandLine& cmd_line, const std::wstring& cur_dir, + Profile* profile, int* return_code) { + return ProcessCommandLine(cmd_line, cur_dir, true, profile, return_code); + } + + // This function performs command-line handling and is invoked when + // process starts as well as when we get a start request from another + // process (via the WM_COPYDATA message). |command_line| holds the command + // line we need to process - either from this process or from some other one + // (if |process_startup| is true and we are being called from + // ProcessSingleton::OnCopyData). + static bool ProcessCommandLine(const CommandLine& command_line, + const std::wstring& cur_dir, + bool process_startup, Profile* profile, + int* return_code); + + template <class AutomationProviderClass> + static void CreateAutomationProvider(const std::wstring& channel_id, + Profile* profile, + size_t expected_tabs); + // Returns true if the browser is coming up. static bool InProcessStartup(); @@ -89,36 +122,10 @@ class BrowserInit { DISALLOW_COPY_AND_ASSIGN(LaunchWithProfile); }; - // This function performs command-line handling and is invoked when - // process starts as well as when we get a start request from another - // process (via the WM_COPYDATA message). |command_line| holds the command - // line we need to process - either from this process or from some other one - // (if |process_startup| is true and we are being called from - // ProcessSingleton::OnCopyData). - static bool ProcessCommandLine(const CommandLine& command_line, - const std::wstring& cur_dir, - bool process_startup, Profile* profile, - int* return_code); - - // Helper function to launch a new browser based on command-line arguments - // This function takes in a specific profile to use. - static bool LaunchBrowser(const CommandLine& command_line, - Profile* profile, const std::wstring& cur_dir, - bool process_startup, int* return_code); - - template <class AutomationProviderClass> - static void CreateAutomationProvider(const std::wstring& channel_id, - Profile* profile, - size_t expected_tabs); - private: - // Does the work of LaunchBrowser returning the result. - static bool LaunchBrowserImpl(const CommandLine& command_line, - Profile* profile, const std::wstring& cur_dir, - bool process_startup, int* return_code); + // Additional tabs to open during first run. + std::vector<GURL> first_run_tabs_; - // This class is for scoping purposes. - BrowserInit(); DISALLOW_COPY_AND_ASSIGN(BrowserInit); }; diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 9b675f1..79e6378 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -445,6 +445,7 @@ int BrowserMain(const MainFunctionParams& parameters) { return ResultCodes::MACHINE_LEVEL_INSTALL_EXISTS; process_singleton.Create(); + BrowserInit browser_init; // Show the First Run UI if this is the first time Chrome has been run on // this computer, or we're being compelled to do so by a command line flag. @@ -604,26 +605,28 @@ int BrowserMain(const MainFunctionParams& parameters) { #endif HandleErrorTestParameters(parsed_command_line); - RecordBreakpadStatusUMA(metrics); - - // Start up the extensions service. - // This should happen before ProcessCommandLine. + // Start up the extensions service. This should happen before Start(). profile->InitExtensions(); - // Call Recycle() here as late as possible, just before going into the main - // loop. We can't do it any earlier, as ProcessCommandLine() will add things - // to it in the act of creating the initial browser window. int result_code = ResultCodes::NORMAL_EXIT; if (parameters.ui_task) { - if (pool) pool->Recycle(); + // We are in test mode. Run one task and enter the main message loop. + if (pool) + pool->Recycle(); MessageLoopForUI::current()->PostTask(FROM_HERE, parameters.ui_task); RunUIMessageLoop(browser_process.get()); - } else if (BrowserInit::ProcessCommandLine(parsed_command_line, - std::wstring(), true, profile, - &result_code)) { - if (pool) pool->Recycle(); - RunUIMessageLoop(browser_process.get()); + } else { + // We are in regular browser boot sequence. Open initial stabs and enter + // the main message loop. + if (browser_init.Start(parsed_command_line, std::wstring(), profile, + &result_code)) { + // Call Recycle() here as late as possible, before going into the loop + // because Start() will add things to it while creating the main window. + if (pool) + pool->Recycle(); + RunUIMessageLoop(browser_process.get()); + } } Platform::WillTerminate(); |