diff options
-rw-r--r-- | chrome/browser/browser_main.cc | 250 | ||||
-rw-r--r-- | chrome/browser/browser_main.h | 23 | ||||
-rw-r--r-- | chrome/browser/browser_main_gtk.cc | 41 | ||||
-rw-r--r-- | chrome/browser/browser_main_gtk.h | 1 | ||||
-rw-r--r-- | chrome/browser/browser_main_mac.h | 1 | ||||
-rw-r--r-- | chrome/browser/browser_main_mac.mm | 13 | ||||
-rw-r--r-- | chrome/browser/browser_main_posix.cc | 11 | ||||
-rw-r--r-- | chrome/browser/browser_main_posix.h | 5 | ||||
-rw-r--r-- | chrome/browser/browser_main_win.cc | 28 | ||||
-rw-r--r-- | chrome/browser/browser_main_win.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/browser_main_chromeos.cc | 13 | ||||
-rw-r--r-- | chrome/browser/chromeos/browser_main_chromeos.h | 1 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 5 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 6 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 4 | ||||
-rw-r--r-- | content/browser/browser_main.cc | 138 | ||||
-rw-r--r-- | content/browser/browser_main.h | 14 | ||||
-rw-r--r-- | content/common/content_switches.cc | 6 | ||||
-rw-r--r-- | content/common/content_switches.h | 4 | ||||
-rw-r--r-- | content/content_browser.gypi | 7 |
20 files changed, 289 insertions, 284 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index a069e422..c199682 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -24,21 +24,18 @@ #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "base/threading/platform_thread.h" -#include "base/threading/thread_restrictions.h" #include "base/time.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "build/build_config.h" #include "chrome/browser/about_flags.h" #include "chrome/browser/browser_main_win.h" -#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process_impl.h" #include "chrome/browser/browser_shutdown.h" #include "chrome/browser/defaults.h" #include "chrome/browser/extensions/extension_protocols.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extensions_startup.h" -#include "chrome/browser/first_run/first_run.h" #include "chrome/browser/first_run/first_run_browser_process.h" #include "chrome/browser/first_run/upgrade_util.h" #include "chrome/browser/google/google_url_tracker.h" @@ -155,7 +152,6 @@ #if defined(OS_WIN) #include "base/environment.h" // For PreRead experiment. -#include "base/win/scoped_com_initializer.h" #include "base/win/windows_version.h" #include "chrome/browser/browser_trial.h" #include "chrome/browser/browser_util_win.h" @@ -228,33 +224,6 @@ void HandleTestParameters(const CommandLine& command_line) { #endif } -void RunUIMessageLoop(BrowserProcess* browser_process) { - TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); - // This should be invoked as close to the start of the browser's - // UI thread message loop as possible to get a stable measurement - // across versions. - RecordBrowserStartupTime(); - - // If the UI thread blocks, the whole UI is unresponsive. - // Do not allow disk IO from the UI thread. - base::ThreadRestrictions::SetIOAllowed(false); - -#if defined(TOOLKIT_VIEWS) - views::AcceleratorHandler accelerator_handler; - MessageLoopForUI::current()->Run(&accelerator_handler); -#elif defined(USE_X11) - MessageLoopForUI::current()->Run(NULL); -#elif defined(OS_POSIX) - MessageLoopForUI::current()->Run(); -#endif -#if defined(OS_CHROMEOS) - chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("UIMessageLoopEnded", - true); -#endif - - TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); -} - void AddFirstRunNewTabs(BrowserInit* browser_init, const std::vector<GURL>& new_tabs) { for (std::vector<GURL>::const_iterator it = new_tabs.begin(); @@ -698,7 +667,11 @@ const char kMissingLocaleDataMessage[] = ChromeBrowserMainParts::ChromeBrowserMainParts( const MainFunctionParams& parameters) : BrowserMainParts(parameters), - shutdown_watcher_(new ShutdownWatcherHelper()) { + shutdown_watcher_(new ShutdownWatcherHelper()), + record_search_engine_(false), + translate_manager_(NULL), + profile_(NULL), + run_message_loop_(true) { // If we're running tests (ui_task is non-null). if (parameters.ui_task) browser_defaults::enable_help_app = false; @@ -707,10 +680,6 @@ ChromeBrowserMainParts::ChromeBrowserMainParts( ChromeBrowserMainParts::~ChromeBrowserMainParts() { } -void ChromeBrowserMainParts::SetupHistogramSynchronizer() { - histogram_synchronizer_ = new HistogramSynchronizer(); -} - // This will be called after the command-line has been mutated by about:flags MetricsService* ChromeBrowserMainParts::SetupMetricsAndFieldTrials( const CommandLine& parsed_command_line, @@ -1108,25 +1077,12 @@ void ChromeBrowserMainParts::PostMainMessageLoopStart() { Profiling::MainMessageLoopStarted(); } -void ChromeBrowserMainParts::ToolkitInitialized() { -#if defined(TOOLKIT_VIEWS) - // The delegate needs to be set before any UI is created so that windows - // display the correct icon. - if (!views::ViewsDelegate::views_delegate) - views::ViewsDelegate::views_delegate = new ChromeViewsDelegate; - - // TODO(beng): Move to WidgetImpl and implement on Windows too! - if (parameters().command_line_.HasSwitch(switches::kDebugViewsPaint)) - views::Widget::SetDebugPaintEnabled(true); -#endif - -#if defined(OS_WIN) - gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; - gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; -#endif +void ChromeBrowserMainParts::PreMainMessageLoopRun() { + set_result_code(PreMainMessageLoopRunInternal()); } -int ChromeBrowserMainParts::TemporaryContinue() { +int ChromeBrowserMainParts::PreMainMessageLoopRunInternal() { + run_message_loop_ = false; FilePath user_data_dir; #if defined(OS_WIN) PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); @@ -1140,21 +1096,20 @@ int ChromeBrowserMainParts::TemporaryContinue() { << "Must be able to get user data directory!"; #endif - ProcessSingleton process_singleton(user_data_dir); + process_singleton_.reset(new ProcessSingleton(user_data_dir)); bool is_first_run = FirstRun::IsChromeFirstRun() || parsed_command_line().HasSwitch(switches::kFirstRun); - scoped_ptr<BrowserProcessImpl> browser_process; if (parsed_command_line().HasSwitch(switches::kImport) || parsed_command_line().HasSwitch(switches::kImportFromFile)) { // We use different BrowserProcess when importing so no GoogleURLTracker is // instantiated (as it makes a net::URLRequest and we don't have an IO // thread, see bug #1292702). - browser_process.reset(new FirstRunBrowserProcess(parsed_command_line())); + browser_process_.reset(new FirstRunBrowserProcess(parsed_command_line())); is_first_run = false; } else { - browser_process.reset(new BrowserProcessImpl(parsed_command_line())); + browser_process_.reset(new BrowserProcessImpl(parsed_command_line())); } // This forces the TabCloseableStateWatcher to be created and, on chromeos, @@ -1216,7 +1171,7 @@ int ChromeBrowserMainParts::TemporaryContinue() { #if defined(OS_WIN) && !defined(USE_AURA) // Setup.exe has determined that we need to run a retention experiment // and has lauched chrome to show the experiment UI. - if (process_singleton.FoundOtherProcessWindow()) { + if (process_singleton_->FoundOtherProcessWindow()) { // It seems that we don't need to run the experiment since chrome // in the same profile is already running. VLOG(1) << "Retention experiment not required"; @@ -1225,7 +1180,7 @@ int ChromeBrowserMainParts::TemporaryContinue() { int try_chrome_int; base::StringToInt(try_chrome, &try_chrome_int); TryChromeDialogView::Result answer = - TryChromeDialogView::Show(try_chrome_int, &process_singleton); + TryChromeDialogView::Show(try_chrome_int, process_singleton_.get()); if (answer == TryChromeDialogView::NOT_NOW) return chrome::RESULT_CODE_NORMAL_EXIT_CANCEL; if (answer == TryChromeDialogView::UNINSTALL_CHROME) @@ -1269,12 +1224,12 @@ int ChromeBrowserMainParts::TemporaryContinue() { // On first run, we need to process the predictor preferences before the // browser's profile_manager object is created, but after ResourceBundle // is initialized. - FirstRun::MasterPrefs master_prefs; + master_prefs_.reset(new FirstRun::MasterPrefs); bool first_run_ui_bypass = false; // True to skip first run UI. if (is_first_run) { first_run_ui_bypass = - !FirstRun::ProcessMasterPreferences(user_data_dir, &master_prefs); - AddFirstRunNewTabs(&browser_init, master_prefs.new_tabs); + !FirstRun::ProcessMasterPreferences(user_data_dir, master_prefs_.get()); + AddFirstRunNewTabs(&browser_init, master_prefs_->new_tabs); // If we are running in App mode, we do not want to show the importer // (first run) UI. @@ -1305,18 +1260,18 @@ int ChromeBrowserMainParts::TemporaryContinue() { CommandLine::ForCurrentProcess()); InitializeNetworkOptions(parsed_command_line()); - InitializeURLRequestThrottlerManager(browser_process->net_log()); + InitializeURLRequestThrottlerManager(browser_process_->net_log()); // Initialize histogram synchronizer system. This is a singleton and is used // for posting tasks via NewRunnableMethod. Its deleted when it goes out of // scope. Even though NewRunnableMethod does AddRef and Release, the object // will not be deleted after the Task is executed. - SetupHistogramSynchronizer(); + histogram_synchronizer_ = new HistogramSynchronizer(); // Now the command line has been mutated based on about:flags, we can // set up metrics and initialize field trials. - MetricsService* metrics = SetupMetricsAndFieldTrials( - parsed_command_line(), local_state); + MetricsService* metrics = + SetupMetricsAndFieldTrials(parsed_command_line(), local_state); // Now that all preferences have been registered, set the install date // for the uninstall metrics if this is our first run. This only actually @@ -1338,7 +1293,7 @@ int ChromeBrowserMainParts::TemporaryContinue() { SecKeychainAddCallback(&KeychainCallback, 0, NULL); #endif - CreateChildThreads(browser_process.get()); + CreateChildThreads(browser_process_.get()); #if defined(OS_CHROMEOS) // Now that the file thread exists we can record our stats. @@ -1364,13 +1319,15 @@ int ChromeBrowserMainParts::TemporaryContinue() { // If the command line specifies 'uninstall' then we need to work here // unless we detect another chrome browser running. - if (parsed_command_line().HasSwitch(switches::kUninstall)) + if (parsed_command_line().HasSwitch(switches::kUninstall)) { return DoUninstallTasks(already_running); + } #endif if (parsed_command_line().HasSwitch(switches::kHideIcons) || - parsed_command_line().HasSwitch(switches::kShowIcons)) + parsed_command_line().HasSwitch(switches::kShowIcons)) { return HandleIconsCommands(parsed_command_line()); + } if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) { return ShellIntegration::SetAsDefaultBrowser() ? static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) : @@ -1381,11 +1338,9 @@ int ChromeBrowserMainParts::TemporaryContinue() { // startup action and exit. if (parsed_command_line().HasSwitch(switches::kPackExtension)) { ExtensionsStartupUtil extension_startup_util; - if (extension_startup_util.PackExtension(parsed_command_line())) { + if (extension_startup_util.PackExtension(parsed_command_line())) return content::RESULT_CODE_NORMAL_EXIT; - } else { - return chrome::RESULT_CODE_PACK_EXTENSION_ERROR; - } + return chrome::RESULT_CODE_PACK_EXTENSION_ERROR; } #if !defined(OS_MACOSX) @@ -1400,7 +1355,7 @@ int ChromeBrowserMainParts::TemporaryContinue() { // new one. NotifyOtherProcess will currently give the other process up to // 20 seconds to respond. Note that this needs to be done before we attempt // to read the profile. - switch (process_singleton.NotifyOtherProcessOrCreate()) { + switch (process_singleton_->NotifyOtherProcessOrCreate()) { case ProcessSingleton::PROCESS_NONE: // No process already running, fall through to starting a new one. break; @@ -1478,9 +1433,8 @@ int ChromeBrowserMainParts::TemporaryContinue() { g_browser_process->profile_manager()->SetWillImport(); } - Profile* profile = CreateProfile(parameters(), user_data_dir, - parsed_command_line()); - if (!profile) + profile_ = CreateProfile(parameters(), user_data_dir, parsed_command_line()); + if (!profile_) return content::RESULT_CODE_NORMAL_EXIT; // Post-profile init --------------------------------------------------------- @@ -1492,18 +1446,17 @@ int ChromeBrowserMainParts::TemporaryContinue() { if (parsed_command_line().HasSwitch(switches::kLoginUser) && !parsed_command_line().HasSwitch(switches::kLoginPassword)) { g_browser_process->browser_policy_connector()->SetUserPolicyTokenService( - profile->GetTokenService()); + profile_->GetTokenService()); } #endif - PrefService* user_prefs = profile->GetPrefs(); + PrefService* user_prefs = profile_->GetPrefs(); DCHECK(user_prefs); // Tests should be able to tune login manager before showing it. // Thus only show login manager in normal (non-testing) mode. - if (!parameters().ui_task) { - OptionallyRunChromeOSLoginManager(parsed_command_line(), profile); - } + if (!parameters().ui_task) + OptionallyRunChromeOSLoginManager(parsed_command_line(), profile_); #if !defined(OS_MACOSX) // Importing other browser settings is done in a browser-like process @@ -1512,7 +1465,7 @@ int ChromeBrowserMainParts::TemporaryContinue() { // replace this implementation. http://crbug.com/22142 if (parsed_command_line().HasSwitch(switches::kImport) || parsed_command_line().HasSwitch(switches::kImportFromFile)) { - return FirstRun::ImportNow(profile, parsed_command_line()); + return FirstRun::ImportNow(profile_, parsed_command_line()); } #endif @@ -1531,12 +1484,13 @@ int ChromeBrowserMainParts::TemporaryContinue() { // processes etc). // Do not allow this to occur for Chrome Frame user-to-system handoffs. if (!parsed_command_line().HasSwitch(switches::kChromeFrame) && - CheckMachineLevelInstall()) + CheckMachineLevelInstall()) { return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS; + } // Create the TranslateManager singleton. - TranslateManager* translate_manager = TranslateManager::GetInstance(); - DCHECK(translate_manager != NULL); + translate_manager_ = TranslateManager::GetInstance(); + DCHECK(translate_manager_ != NULL); #if defined(OS_MACOSX) if (!parsed_command_line().HasSwitch(switches::kNoFirstRun)) { @@ -1557,14 +1511,14 @@ int ChromeBrowserMainParts::TemporaryContinue() { // touches reads preferences. if (is_first_run) { if (!first_run_ui_bypass) { - FirstRun::AutoImport(profile, - master_prefs.homepage_defined, - master_prefs.do_import_items, - master_prefs.dont_import_items, - master_prefs.run_search_engine_experiment, - master_prefs.randomize_search_engine_experiment, - master_prefs.make_chrome_default, - &process_singleton); + FirstRun::AutoImport(profile_, + master_prefs_->homepage_defined, + master_prefs_->do_import_items, + master_prefs_->dont_import_items, + master_prefs_->run_search_engine_experiment, + master_prefs_->randomize_search_engine_experiment, + master_prefs_->make_chrome_default, + process_singleton_.get()); #if defined(OS_POSIX) // On Windows, the download is tagged with enable/disable stats so there // is no need for this code. @@ -1577,7 +1531,7 @@ int ChromeBrowserMainParts::TemporaryContinue() { } // if (!first_run_ui_bypass) Browser::SetNewHomePagePrefs(user_prefs); - g_browser_process->profile_manager()->OnImportFinished(profile); + g_browser_process->profile_manager()->OnImportFinished(profile_); } // if (is_first_run) // Sets things up so that if we crash from this point on, a dialog will @@ -1609,16 +1563,13 @@ int ChromeBrowserMainParts::TemporaryContinue() { local_state, preconnect_enabled); -#if defined(OS_WIN) - base::win::ScopedCOMInitializer com_initializer; - -#if defined(GOOGLE_CHROME_BUILD) +#if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) // Init the RLZ library. This just binds the dll and schedules a task on the // file thread to be run sometime later. If this is the first run we record // the installation event. bool google_search_default = false; TemplateURLService* template_url_service = - TemplateURLServiceFactory::GetForProfile(profile); + TemplateURLServiceFactory::GetForProfile(profile_); if (template_url_service) { const TemplateURL* url_template = template_url_service->GetDefaultSearchProvider(); @@ -1631,23 +1582,21 @@ int ChromeBrowserMainParts::TemporaryContinue() { } bool google_search_homepage = false; - PrefService* pref_service = profile->GetPrefs(); + PrefService* pref_service = profile_->GetPrefs(); if (pref_service) { std::string homepage = pref_service->GetString(prefs::kHomePage); google_search_homepage = homepage == GoogleURLTracker::kDefaultGoogleHomepage; } - RLZTracker::InitRlzDelayed(is_first_run, master_prefs.ping_delay, + RLZTracker::InitRlzDelayed(is_first_run, master_prefs_->ping_delay, google_search_default, google_search_homepage); // Prime the RLZ cache for the home page access point so that its avaiable // for the startup page if needed (i.e., when the startup page is set to // the home page). RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_HOME_PAGE, NULL); - -#endif // GOOGLE_CHROME_BUILD -#endif // OS_WIN +#endif // GOOGLE_CHROME_BUILD && OS_WIN // Configure modules that need access to resources. net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider); @@ -1664,8 +1613,8 @@ int ChromeBrowserMainParts::TemporaryContinue() { // // These can't be created in the BrowserProcessImpl constructor because they // need to read prefs that get set after that runs. - browser_process->google_url_tracker(); - browser_process->intranet_redirect_detector(); + browser_process_->google_url_tracker(); + browser_process_->intranet_redirect_detector(); // Prepare for memory caching of SDCH dictionaries. // Perform A/B test to measure global impact of SDCH support. @@ -1714,7 +1663,7 @@ int ChromeBrowserMainParts::TemporaryContinue() { RecordBreakpadStatusUMA(metrics); about_flags::RecordUMAStatistics(local_state); LanguageUsageMetrics::RecordAcceptLanguages( - profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); + profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); LanguageUsageMetrics::RecordApplicationLanguage( g_browser_process->GetApplicationLocale()); @@ -1741,17 +1690,15 @@ int ChromeBrowserMainParts::TemporaryContinue() { // action. if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) { ExtensionsStartupUtil ext_startup_util; - if (ext_startup_util.UninstallExtension(parsed_command_line(), profile)) { + if (ext_startup_util.UninstallExtension(parsed_command_line(), profile_)) return content::RESULT_CODE_NORMAL_EXIT; - } else { - return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR; - } + return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR; } #if defined(OS_WIN) // We check this here because if the profile is OTR (chromeos possibility) // it won't still be accessible after browser is destroyed. - bool record_search_engine = is_first_run && !profile->IsOffTheRecord(); + record_search_engine_ = is_first_run && !profile_->IsOffTheRecord(); #endif // ChildProcess:: is a misnomer unless you consider context. Use @@ -1774,7 +1721,7 @@ int ChromeBrowserMainParts::TemporaryContinue() { // might have shutdown because an update was available. // TODO(torne): this should maybe be done with // ProfileKeyedServiceFactory::ServiceIsCreatedWithProfile() instead? - CloudPrintProxyServiceFactory::GetForProfile(profile); + CloudPrintProxyServiceFactory::GetForProfile(profile_); // Initialize GpuDataManager and collect preliminary gpu info on FILE thread. // Upon completion, it posts GpuBlacklist auto update task on UI thread. @@ -1800,7 +1747,7 @@ int ChromeBrowserMainParts::TemporaryContinue() { // We are in regular browser boot sequence. Open initial tabs and enter the // main message loop. - if (browser_init.Start(parsed_command_line(), FilePath(), profile, + if (browser_init.Start(parsed_command_line(), FilePath(), profile_, &result_code)) { #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) // Initialize autoupdate timer. Timer callback costs basically nothing @@ -1833,20 +1780,47 @@ int ChromeBrowserMainParts::TemporaryContinue() { #if !defined(OS_CHROMEOS) // If we're running tests (ui_task is non-null), then we don't want to // call FetchLanguageListFromTranslateServer - if (parameters().ui_task == NULL && translate_manager != NULL) { + if (parameters().ui_task == NULL && translate_manager_ != NULL) { // TODO(willchan): Get rid of this after TranslateManager doesn't use // the default request context. http://crbug.com/89396. // This is necessary to force |default_request_context_| to be // initialized. - profile->GetRequestContext(); - translate_manager->FetchLanguageListFromTranslateServer(user_prefs); + profile_->GetRequestContext(); + translate_manager_->FetchLanguageListFromTranslateServer(user_prefs); } #endif - RunUIMessageLoop(browser_process.get()); + run_message_loop_ = true; } } + return result_code; +} + +void ChromeBrowserMainParts::MainMessageLoopRun() { + if (!run_message_loop_) + return; + + // This should be invoked as close to the start of the browser's + // UI thread message loop as possible to get a stable measurement + // across versions. + RecordBrowserStartupTime(); + +#if defined(TOOLKIT_VIEWS) + views::AcceleratorHandler accelerator_handler; + MessageLoopForUI::current()->Run(&accelerator_handler); +#elif defined(USE_X11) + MessageLoopForUI::current()->Run(NULL); +#elif defined(OS_POSIX) + MessageLoopForUI::current()->Run(); +#endif +#if defined(OS_CHROMEOS) + chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("UIMessageLoopEnded", + true); +#endif +} + +void ChromeBrowserMainParts::PostMainMessageLoopRun() { // Start watching for jank during shutdown. It gets disarmed when // |shutdown_watcher_| object is destructed. shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(45)); @@ -1856,9 +1830,9 @@ int ChromeBrowserMainParts::TemporaryContinue() { // shutdown because otherwise we can't be sure the user has finished // selecting a search engine through the dialog reached from the first run // bubble link. - if (record_search_engine) { + if (record_search_engine_) { TemplateURLService* url_service = - TemplateURLServiceFactory::GetForProfile(profile); + TemplateURLServiceFactory::GetForProfile(profile_); const TemplateURL* default_search_engine = url_service->GetDefaultSearchProvider(); // The default engine can be NULL if the administrator has disabled @@ -1867,13 +1841,13 @@ int ChromeBrowserMainParts::TemporaryContinue() { default_search_engine ? default_search_engine->search_engine_type() : SEARCH_ENGINE_OTHER; // Record the search engine chosen. - if (master_prefs.run_search_engine_experiment) { + if (master_prefs_->run_search_engine_experiment) { UMA_HISTOGRAM_ENUMERATION( "Chrome.SearchSelectExperiment", search_engine_type, SEARCH_ENGINE_MAX); // If the selection has been randomized, also record the winner by slot. - if (master_prefs.randomize_search_engine_experiment) { + if (master_prefs_->randomize_search_engine_experiment) { size_t engine_pos = url_service->GetSearchEngineDialogSlot(); if (engine_pos < 4) { std::string experiment_type = "Chrome.SearchSelectExperimentSlot"; @@ -1903,22 +1877,40 @@ int ChromeBrowserMainParts::TemporaryContinue() { // Some tests don't set parameters.ui_task, so they started translate // language fetch that was never completed so we need to cleanup here // otherwise it will be done by the destructor in a wrong thread. - if (parameters().ui_task == NULL && translate_manager != NULL) - translate_manager->CleanupPendingUlrFetcher(); + if (parameters().ui_task == NULL && translate_manager_ != NULL) + translate_manager_->CleanupPendingUlrFetcher(); - process_singleton.Cleanup(); + process_singleton_->Cleanup(); // Stop all tasks that might run on WatchDogThread. ThreadWatcherList::StopWatchingAll(); - metrics->Stop(); + g_browser_process->metrics_service()->Stop(); // browser_shutdown takes care of deleting browser_process, so we need to // release it. - ignore_result(browser_process.release()); + ignore_result(browser_process_.release()); browser_shutdown::Shutdown(); + master_prefs_.reset(); + process_singleton_.reset(); +} - return result_code; +void ChromeBrowserMainParts::ToolkitInitialized() { +#if defined(TOOLKIT_VIEWS) + // The delegate needs to be set before any UI is created so that windows + // display the correct icon. + if (!views::ViewsDelegate::views_delegate) + views::ViewsDelegate::views_delegate = new ChromeViewsDelegate; + + // TODO(beng): Move to WidgetImpl and implement on Windows too! + if (parameters().command_line_.HasSwitch(switches::kDebugViewsPaint)) + views::Widget::SetDebugPaintEnabled(true); +#endif + +#if defined(OS_WIN) + gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; + gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; +#endif } // This code is specific to the Windows-only PreReadExperiment field-trial. diff --git a/chrome/browser/browser_main.h b/chrome/browser/browser_main.h index 177ed1c..0dcde47 100644 --- a/chrome/browser/browser_main.h +++ b/chrome/browser/browser_main.h @@ -10,13 +10,18 @@ #include "base/gtest_prod_util.h" #include "base/metrics/field_trial.h" #include "base/tracked_objects.h" +#include "chrome/browser/first_run/first_run.h" #include "content/browser/browser_main.h" +class BrowserProcessImpl; class FieldTrialSynchronizer; class HistogramSynchronizer; class MetricsService; class PrefService; +class ProcessSingleton; +class Profile; class ShutdownWatcherHelper; +class TranslateManager; namespace chrome_browser { // For use by ShowMissingLocaleMessageBox. @@ -28,10 +33,6 @@ class ChromeBrowserMainParts : public content::BrowserMainParts { public: virtual ~ChromeBrowserMainParts(); - // Constructs HistogramSynchronizer which gets released early (before - // main_message_loop_). - void SetupHistogramSynchronizer(); - // Constructs metrics service and does related initialization, including // creation of field trials. Call only after labs have been converted to // switches. @@ -43,10 +44,12 @@ class ChromeBrowserMainParts : public content::BrowserMainParts { explicit ChromeBrowserMainParts(const MainFunctionParams& parameters); virtual void PostMainMessageLoopStart() OVERRIDE; + virtual void PreMainMessageLoopRun() OVERRIDE; + int PreMainMessageLoopRunInternal(); + virtual void MainMessageLoopRun() OVERRIDE; + virtual void PostMainMessageLoopRun() OVERRIDE; virtual void ToolkitInitialized() OVERRIDE; - virtual int TemporaryContinue() OVERRIDE; - private: // Methods for |EarlyInitialization()| --------------------------------------- @@ -102,8 +105,14 @@ class ChromeBrowserMainParts : public content::BrowserMainParts { // Members initialized after / released before main_message_loop_ ------------ - // Initialized in SetupHistogramSynchronizer. + scoped_ptr<BrowserProcessImpl> browser_process_; scoped_refptr<HistogramSynchronizer> histogram_synchronizer_; + scoped_ptr<ProcessSingleton> process_singleton_; + scoped_ptr<FirstRun::MasterPrefs> master_prefs_; + bool record_search_engine_; + TranslateManager* translate_manager_; + Profile* profile_; + bool run_message_loop_; // Initialized in SetupMetricsAndFieldTrials. scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_; diff --git a/chrome/browser/browser_main_gtk.cc b/chrome/browser/browser_main_gtk.cc index 2b8432a..2f8fc83 100644 --- a/chrome/browser/browser_main_gtk.cc +++ b/chrome/browser/browser_main_gtk.cc @@ -16,8 +16,6 @@ #include "chrome/browser/ui/browser_list.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_result_codes.h" -#include "content/browser/renderer_host/render_sandbox_host_linux.h" -#include "content/browser/zygote_host_linux.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -26,10 +24,6 @@ #include "ui/base/x/x11_util_internal.h" #include "ui/gfx/gtk_util.h" -#if defined(USE_NSS) -#include "crypto/nss_util.h" -#endif - #if defined(USE_LINUX_BREAKPAD) #include "chrome/app/breakpad_linux.h" #endif @@ -89,13 +83,6 @@ void BrowserMainPartsGtk::PreEarlyInitialization() { DetectRunningAsRoot(); BrowserMainPartsPosix::PreEarlyInitialization(); - - SetupSandbox(); - -#if defined(USE_NSS) - // We want to be sure to init NSPR on the main thread. - crypto::EnsureNSPRInit(); -#endif } void BrowserMainPartsGtk::DetectRunningAsRoot() { @@ -139,34 +126,6 @@ void BrowserMainPartsGtk::DetectRunningAsRoot() { } } -void BrowserMainPartsGtk::SetupSandbox() { - // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this - // code en masse out of chrome_main for now. - const char* sandbox_binary = NULL; - struct stat st; - - // In Chromium branded builds, developers can set an environment variable to - // use the development sandbox. See - // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment - if (stat("/proc/self/exe", &st) == 0 && st.st_uid == getuid()) - sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); - -#if defined(LINUX_SANDBOX_PATH) - if (!sandbox_binary) - sandbox_binary = LINUX_SANDBOX_PATH; -#endif - - std::string sandbox_cmd; - if (sandbox_binary && !parsed_command_line().HasSwitch(switches::kNoSandbox)) - sandbox_cmd = sandbox_binary; - - // Tickle the sandbox host and zygote host so they fork now. - RenderSandboxHostLinux* shost = RenderSandboxHostLinux::GetInstance(); - shost->Init(sandbox_cmd); - ZygoteHost* zhost = ZygoteHost::GetInstance(); - zhost->Init(sandbox_cmd); -} - namespace content { void DidEndMainMessageLoop() { diff --git a/chrome/browser/browser_main_gtk.h b/chrome/browser/browser_main_gtk.h index 22558e3..c892f40 100644 --- a/chrome/browser/browser_main_gtk.h +++ b/chrome/browser/browser_main_gtk.h @@ -19,7 +19,6 @@ class BrowserMainPartsGtk : public BrowserMainPartsPosix { private: void DetectRunningAsRoot(); - void SetupSandbox(); }; // Installs the X11 error handlers for the browser process. This will diff --git a/chrome/browser/browser_main_mac.h b/chrome/browser/browser_main_mac.h index fcc9215..455c790 100644 --- a/chrome/browser/browser_main_mac.h +++ b/chrome/browser/browser_main_mac.h @@ -14,7 +14,6 @@ class BrowserMainPartsMac : public BrowserMainPartsPosix { virtual void PreEarlyInitialization() OVERRIDE; virtual void PreMainMessageLoopStart() OVERRIDE; - virtual void InitializeSSL() OVERRIDE; }; #endif // CHROME_BROWSER_BROWSER_MAIN_WIN_H_ diff --git a/chrome/browser/browser_main_mac.mm b/chrome/browser/browser_main_mac.mm index 41badcc..040f3b5 100644 --- a/chrome/browser/browser_main_mac.mm +++ b/chrome/browser/browser_main_mac.mm @@ -12,7 +12,6 @@ #include "base/mac/mac_util.h" #include "base/memory/scoped_nsobject.h" #include "base/path_service.h" -#include "crypto/nss_util.h" #include "chrome/app/breakpad_mac.h" #import "chrome/browser/app_controller_mac.h" #include "chrome/browser/browser_main_win.h" @@ -23,7 +22,6 @@ #include "chrome/common/chrome_switches.h" #include "content/common/main_function_params.h" #include "content/common/result_codes.h" -#include "net/socket/client_socket_factory.h" #include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/resource/resource_bundle.h" @@ -138,14 +136,3 @@ void BrowserMainPartsMac::PreMainMessageLoopStart() { [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; } - - void BrowserMainPartsMac::InitializeSSL() { - // Use NSS for SSL by default. - // The default client socket factory uses NSS for SSL by default on Mac. - if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { - net::ClientSocketFactory::UseSystemSSL(); - } else { - // We want to be sure to init NSPR on the main thread. - crypto::EnsureNSPRInit(); - } -} diff --git a/chrome/browser/browser_main_posix.cc b/chrome/browser/browser_main_posix.cc index 518daaa..8ed5a3b 100644 --- a/chrome/browser/browser_main_posix.cc +++ b/chrome/browser/browser_main_posix.cc @@ -16,7 +16,6 @@ #include "base/eintr_wrapper.h" #include "base/logging.h" #include "base/string_number_conversions.h" -#include "chrome/browser/defaults.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/common/chrome_switches.h" #include "content/browser/browser_thread.h" @@ -233,16 +232,6 @@ void BrowserMainPartsPosix::PreEarlyInitialization() { #endif // OS_MACOSX if (fd_limit > 0) SetFileDescriptorLimit(fd_limit); - -#if defined(OS_CHROMEOS) - if (parsed_command_line().HasSwitch(switches::kGuestSession)) { - // Disable sync and extensions if we're in "browse without sign-in" mode. - CommandLine* singleton_command_line = CommandLine::ForCurrentProcess(); - singleton_command_line->AppendSwitch(switches::kDisableSync); - singleton_command_line->AppendSwitch(switches::kDisableExtensions); - browser_defaults::bookmarks_enabled = false; - } -#endif } void BrowserMainPartsPosix::PostMainMessageLoopStart() { diff --git a/chrome/browser/browser_main_posix.h b/chrome/browser/browser_main_posix.h index 0b83fdd..27d59f9 100644 --- a/chrome/browser/browser_main_posix.h +++ b/chrome/browser/browser_main_posix.h @@ -13,11 +13,6 @@ class BrowserMainPartsPosix : public ChromeBrowserMainParts { virtual void PreEarlyInitialization() OVERRIDE; virtual void PostMainMessageLoopStart() OVERRIDE; - - private: -#if !defined(OS_MACOSX) - virtual void InitializeSSL() {} -#endif }; #endif // CHROME_BROWSER_BROWSER_MAIN_POSIX_H_ diff --git a/chrome/browser/browser_main_win.cc b/chrome/browser/browser_main_win.cc index 6fbd782..110ac65 100644 --- a/chrome/browser/browser_main_win.cc +++ b/chrome/browser/browser_main_win.cc @@ -32,13 +32,9 @@ #include "chrome/installer/util/install_util.h" #include "chrome/installer/util/shell_util.h" #include "content/common/main_function_params.h" -#include "crypto/nss_util.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" -#include "net/base/winsock_init.h" -#include "net/socket/client_socket_factory.h" #include "ui/base/l10n/l10n_util.h" -#include "ui/base/l10n/l10n_util_win.h" #include "ui/base/message_box_win.h" #include "views/focus/accelerator_handler.h" #include "views/widget/widget.h" @@ -287,33 +283,9 @@ BrowserMainPartsWin::BrowserMainPartsWin(const MainFunctionParams& parameters) : ChromeBrowserMainParts(parameters) { } -void BrowserMainPartsWin::PreEarlyInitialization() { - // Initialize Winsock. - net::EnsureWinsockInit(); -} - void BrowserMainPartsWin::PreMainMessageLoopStart() { - OleInitialize(NULL); - - // If we're running tests (ui_task is non-null), then the ResourceBundle - // has already been initialized. if (!parameters().ui_task) { - // Override the configured locale with the user's preferred UI language. - l10n_util::OverrideLocaleWithUILanguageList(); - // Make sure that we know how to handle exceptions from the message loop. InitializeWindowProcExceptions(); } } - -void BrowserMainPartsWin::InitializeSSL() { - // Use NSS for SSL by default. - // The default client socket factory uses NSS for SSL by default on - // Windows. - if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { - net::ClientSocketFactory::UseSystemSSL(); - } else { - // We want to be sure to init NSPR on the main thread. - crypto::EnsureNSPRInit(); - } -} diff --git a/chrome/browser/browser_main_win.h b/chrome/browser/browser_main_win.h index 6183a18..ff8b6a5 100644 --- a/chrome/browser/browser_main_win.h +++ b/chrome/browser/browser_main_win.h @@ -43,9 +43,7 @@ class BrowserMainPartsWin : public ChromeBrowserMainParts { public: explicit BrowserMainPartsWin(const MainFunctionParams& parameters); - virtual void PreEarlyInitialization() OVERRIDE; virtual void PreMainMessageLoopStart() OVERRIDE; - virtual void InitializeSSL() OVERRIDE; }; #endif // CHROME_BROWSER_BROWSER_MAIN_WIN_H_ diff --git a/chrome/browser/chromeos/browser_main_chromeos.cc b/chrome/browser/chromeos/browser_main_chromeos.cc index 93be779..954802b 100644 --- a/chrome/browser/chromeos/browser_main_chromeos.cc +++ b/chrome/browser/chromeos/browser_main_chromeos.cc @@ -10,6 +10,7 @@ #include "chrome/browser/chromeos/boot_times_loader.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/net/cros_network_change_notifier_factory.h" +#include "chrome/browser/defaults.h" #include "chrome/common/chrome_switches.h" #include "content/common/main_function_params.h" #include "net/base/network_change_notifier.h" @@ -63,7 +64,19 @@ BrowserMainPartsChromeos::~BrowserMainPartsChromeos() { chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); } +void BrowserMainPartsChromeos::PreEarlyInitialization() { + BrowserMainPartsGtk::PreEarlyInitialization(); + if (parsed_command_line().HasSwitch(switches::kGuestSession)) { + // Disable sync and extensions if we're in "browse without sign-in" mode. + CommandLine* singleton_command_line = CommandLine::ForCurrentProcess(); + singleton_command_line->AppendSwitch(switches::kDisableSync); + singleton_command_line->AppendSwitch(switches::kDisableExtensions); + browser_defaults::bookmarks_enabled = false; + } +} + void BrowserMainPartsChromeos::PreMainMessageLoopStart() { + BrowserMainPartsGtk::PreMainMessageLoopStart(); // Initialize CrosLibrary only for the browser, unless running tests // (which do their own CrosLibrary setup). if (!parameters().ui_task) { diff --git a/chrome/browser/chromeos/browser_main_chromeos.h b/chrome/browser/chromeos/browser_main_chromeos.h index 778a568..8e12f16 100644 --- a/chrome/browser/chromeos/browser_main_chromeos.h +++ b/chrome/browser/chromeos/browser_main_chromeos.h @@ -13,6 +13,7 @@ class BrowserMainPartsChromeos : public BrowserMainPartsGtk { virtual ~BrowserMainPartsChromeos(); + virtual void PreEarlyInitialization() OVERRIDE; virtual void PreMainMessageLoopStart() OVERRIDE; virtual void PostMainMessageLoopStart() OVERRIDE; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 40537fc..6619587 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -4163,11 +4163,6 @@ 'third_party/mozilla_security_manager/nsUsageArrayHelper.h', ], }], - ['linux_sandbox_path != ""', { - 'defines': [ - 'LINUX_SANDBOX_PATH="<(linux_sandbox_path)"', - ], - }], ], }, { # toolkit_uses_gtk != 1 'sources!': [ diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 810859d..79a5da2 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -1122,12 +1122,6 @@ const char kFileManagerExtensionPath[] = "filemgr-ext-path"; #endif #endif -#if defined(OS_MACOSX) || defined(OS_WIN) -// Use the system SSL library (Secure Transport on Mac, SChannel on Windows) -// instead of NSS for SSL. -const char kUseSystemSSL[] = "use-system-ssl"; -#endif - #if defined(OS_POSIX) // A flag, generated internally by Chrome for renderer and other helper process // command lines on Linux and Mac. It tells the helper process to enable crash diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 38494ff..73b4f33 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -311,10 +311,6 @@ extern const char kFileManagerExtensionPath[]; #endif #endif -#if defined(OS_MACOSX) || defined(OS_WIN) -extern const char kUseSystemSSL[]; -#endif - #if defined(OS_POSIX) extern const char kEnableCrashReporter[]; extern const char kNoProcessSingletonDialog[]; diff --git a/content/browser/browser_main.cc b/content/browser/browser_main.cc index 7d7a599..dd497bf 100644 --- a/content/browser/browser_main.cc +++ b/content/browser/browser_main.cc @@ -11,26 +11,38 @@ #include "base/metrics/field_trial.h" #include "base/metrics/histogram.h" #include "base/system_monitor/system_monitor.h" +#include "base/threading/thread_restrictions.h" #include "content/browser/browser_thread.h" #include "content/browser/content_browser_client.h" #include "content/common/content_switches.h" #include "content/common/hi_res_timer_manager.h" #include "content/common/main_function_params.h" +#include "content/common/result_codes.h" #include "content/common/sandbox_policy.h" +#include "crypto/nss_util.h" #include "net/base/network_change_notifier.h" #include "net/base/ssl_config_service.h" +#include "net/socket/client_socket_factory.h" #include "net/socket/tcp_client_socket.h" #if defined(OS_WIN) #include <windows.h> #include <commctrl.h> +#include <ole2.h> #include <shellapi.h> +#include "base/win/scoped_com_initializer.h" +#include "net/base/winsock_init.h" #include "sandbox/src/sandbox.h" +#include "ui/base/l10n/l10n_util_win.h" #endif #if defined(OS_POSIX) && !defined(OS_MACOSX) #include <dbus/dbus-glib.h> +#include <sys/stat.h> + +#include "content/browser/renderer_host/render_sandbox_host_linux.h" +#include "content/browser/zygote_host_linux.h" #endif #if defined(TOOLKIT_USES_GTK) @@ -39,11 +51,10 @@ namespace { -// Windows-specific initialization code for the sandbox broker services. This -// is just a NOP on non-Windows platforms to reduce ifdefs later on. +#if defined(OS_WIN) +// Windows-specific initialization code for the sandbox broker services. void InitializeBrokerServices(const MainFunctionParams& parameters, const CommandLine& parsed_command_line) { -#if defined(OS_WIN) sandbox::BrokerServices* broker_services = parameters.sandbox_info_.BrokerServices(); if (broker_services) { @@ -58,8 +69,36 @@ void InitializeBrokerServices(const MainFunctionParams& parameters, policy->Release(); } } +} +#elif defined(OS_POSIX) && !defined(OS_MACOSX) +void SetupSandbox(const CommandLine& parsed_command_line) { + // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this + // code en masse out of chrome_main for now. + const char* sandbox_binary = NULL; + struct stat st; + + // In Chromium branded builds, developers can set an environment variable to + // use the development sandbox. See + // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment + if (stat("/proc/self/exe", &st) == 0 && st.st_uid == getuid()) + sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); + +#if defined(LINUX_SANDBOX_PATH) + if (!sandbox_binary) + sandbox_binary = LINUX_SANDBOX_PATH; #endif + + std::string sandbox_cmd; + if (sandbox_binary && !parsed_command_line.HasSwitch(switches::kNoSandbox)) + sandbox_cmd = sandbox_binary; + + // Tickle the sandbox host and zygote host so they fork now. + RenderSandboxHostLinux* shost = RenderSandboxHostLinux::GetInstance(); + shost->Init(sandbox_cmd); + ZygoteHost* zhost = ZygoteHost::GetInstance(); + zhost->Init(sandbox_cmd); } +#endif #if defined(TOOLKIT_USES_GTK) static void GLibLogHandler(const gchar* log_domain, @@ -119,7 +158,8 @@ namespace content { BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters) : parameters_(parameters), - parsed_command_line_(parameters.command_line_) { + parsed_command_line_(parameters.command_line_), + result_code_(content::RESULT_CODE_NORMAL_EXIT) { } BrowserMainParts::~BrowserMainParts() { @@ -128,11 +168,32 @@ BrowserMainParts::~BrowserMainParts() { void BrowserMainParts::EarlyInitialization() { PreEarlyInitialization(); - if (parsed_command_line().HasSwitch(switches::kEnableBenchmarking)) - base::FieldTrial::EnableBenchmarking(); +#if defined(OS_WIN) + net::EnsureWinsockInit(); +#endif + + // Use NSS for SSL by default. + // The default client socket factory uses NSS for SSL by default on + // Windows and Mac. +#if defined(OS_WIN) || defined(OS_MACOSX) + if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { + net::ClientSocketFactory::UseSystemSSL(); + } else { +#elif defined(USE_NSS) + if (true) { +#else + if (false) { +#endif + // We want to be sure to init NSPR on the main thread. + crypto::EnsureNSPRInit(); + } - InitializeSSL(); +#if defined(OS_POSIX) && !defined(OS_MACOSX) + SetupSandbox(parsed_command_line()); +#endif + if (parsed_command_line().HasSwitch(switches::kEnableBenchmarking)) + base::FieldTrial::EnableBenchmarking(); if (parsed_command_line().HasSwitch(switches::kDisableSSLFalseStart)) net::SSLConfigService::DisableFalseStart(); if (parsed_command_line().HasSwitch(switches::kEnableSSLCachedInfo)) @@ -145,7 +206,7 @@ void BrowserMainParts::EarlyInitialization() { } // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't - // seem dependent on InitializeSSL(). + // seem dependent on SSL initialization(). if (parsed_command_line().HasSwitch(switches::kEnableTcpFastOpen)) net::set_tcp_fastopen_enabled(true); @@ -155,6 +216,17 @@ void BrowserMainParts::EarlyInitialization() { void BrowserMainParts::MainMessageLoopStart() { PreMainMessageLoopStart(); +#if defined(OS_WIN) + OleInitialize(NULL); + + // If we're running tests (ui_task is non-null), then the ResourceBundle + // has already been initialized. + if (!parameters().ui_task) { + // Override the configured locale with the user's preferred UI language. + l10n_util::OverrideLocaleWithUILanguageList(); + } +#endif + main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); // TODO(viettrungluu): should these really go before setting the thread name? @@ -168,6 +240,19 @@ void BrowserMainParts::MainMessageLoopStart() { PostMainMessageLoopStart(); } +void BrowserMainParts::RunMainMessageLoopParts() { + PreMainMessageLoopRun(); + + TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); + // If the UI thread blocks, the whole UI is unresponsive. + // Do not allow disk IO from the UI thread. + base::ThreadRestrictions::SetIOAllowed(false); + MainMessageLoopRun(); + TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); + + PostMainMessageLoopRun(); +} + void BrowserMainParts::InitializeMainThread() { const char* kThreadName = "CrBrowserMain"; base::PlatformThread::SetName(kThreadName); @@ -214,7 +299,6 @@ void BrowserMainParts::InitializeToolkit() { #endif #if defined(OS_WIN) - // Init common control sex. INITCOMMONCONTROLSEX config; config.dwSize = sizeof(config); config.dwICC = ICC_WIN95_CLASSES; @@ -237,14 +321,21 @@ void BrowserMainParts::PreMainMessageLoopStart() { void BrowserMainParts::PostMainMessageLoopStart() { } -void BrowserMainParts::InitializeSSL() { +void BrowserMainParts::PreMainMessageLoopRun() { } -void BrowserMainParts::ToolkitInitialized() { +void BrowserMainParts::MainMessageLoopRun() { +#if defined(OS_MACOSX) + MessageLoopForUI::current()->Run(); +#else + MessageLoopForUI::current()->Run(NULL); +#endif } -int BrowserMainParts::TemporaryContinue() { - return 0; +void BrowserMainParts::PostMainMessageLoopRun() { +} + +void BrowserMainParts::ToolkitInitialized() { } } // namespace content @@ -288,32 +379,29 @@ int BrowserMain(const MainFunctionParams& parameters) { // Thanks! // TODO(viettrungluu): put the remainder into BrowserMainParts - const CommandLine& parsed_command_line = parameters.command_line_; -#if defined(OS_WIN) && !defined(NO_TCMALLOC) +#if defined(OS_WIN) +#if !defined(NO_TCMALLOC) // When linking shared libraries, NO_TCMALLOC is defined, and dynamic // allocator selection is not supported. // Make this call before going multithreaded, or spawning any subprocesses. base::allocator::SetupSubprocessAllocator(); -#endif // OS_WIN - +#endif // The broker service initialization needs to run early because it will // initialize the sandbox broker, which requires the process to swap its // window station. During this time all the UI will be broken. This has to // run before threads and windows are created. - InitializeBrokerServices(parameters, parsed_command_line); + InitializeBrokerServices(parameters, parameters.command_line_); + + base::win::ScopedCOMInitializer com_initializer; +#endif // OS_WIN // Initialize histogram statistics gathering system. base::StatisticsRecorder statistics; - // TODO(jam): bring the content parts from this chrome function here. - int result_code = parts->TemporaryContinue(); - - // Release BrowserMainParts here, before shutting down CrosLibrary, since - // some of the classes initialized there have CrosLibrary dependencies. - parts.reset(NULL); + parts->RunMainMessageLoopParts(); TRACE_EVENT_END_ETW("BrowserMain", 0, 0); - return result_code; + return parts->result_code(); } diff --git a/content/browser/browser_main.h b/content/browser/browser_main.h index 931bd9a..bab45a0 100644 --- a/content/browser/browser_main.h +++ b/content/browser/browser_main.h @@ -73,11 +73,11 @@ class BrowserMainParts { // Parts to be called by |BrowserMain()|. void EarlyInitialization(); - void MainMessageLoopStart(); void InitializeToolkit(); + void MainMessageLoopStart(); + void RunMainMessageLoopParts(); - // Temporary function since not all the code from chrome is moved over yet. - virtual int TemporaryContinue(); + int result_code() const { return result_code_; } protected: // Methods to be overridden to provide platform-specific code; these @@ -86,9 +86,9 @@ class BrowserMainParts { virtual void PostEarlyInitialization(); virtual void PreMainMessageLoopStart(); virtual void PostMainMessageLoopStart(); - - // Used to initialize NSPR where appropriate. - virtual void InitializeSSL(); + virtual void PreMainMessageLoopRun(); + virtual void MainMessageLoopRun(); + virtual void PostMainMessageLoopRun(); // Allows an embedder to do any extra toolkit initialization. virtual void ToolkitInitialized(); @@ -103,6 +103,7 @@ class BrowserMainParts { MessageLoop& main_message_loop() const { return *main_message_loop_; } + void set_result_code(int result_code) { result_code_ = result_code; } private: void InitializeMainThread(); @@ -111,6 +112,7 @@ class BrowserMainParts { const MainFunctionParams& parameters_; const CommandLine& parsed_command_line_; + int result_code_; // Members initialized in |MainMessageLoopStart()| --------------------------- scoped_ptr<MessageLoop> main_message_loop_; diff --git a/content/common/content_switches.cc b/content/common/content_switches.cc index 31d4b93..0587a60 100644 --- a/content/common/content_switches.cc +++ b/content/common/content_switches.cc @@ -503,6 +503,12 @@ const char kAuditAllHandles[] = "enable-handle-auditing-all"; const char kScrollPixels[] = "scroll-pixels"; #endif +#if defined(OS_MACOSX) || defined(OS_WIN) +// Use the system SSL library (Secure Transport on Mac, SChannel on Windows) +// instead of NSS for SSL. +const char kUseSystemSSL[] = "use-system-ssl"; +#endif + #if !defined(OFFICIAL_BUILD) // Causes the renderer process to throw an assertion on launch. const char kRendererCheckFalseTest[] = "renderer-check-false-test"; diff --git a/content/common/content_switches.h b/content/common/content_switches.h index 07e1c97..478b9b8 100644 --- a/content/common/content_switches.h +++ b/content/common/content_switches.h @@ -162,6 +162,10 @@ extern const char kAuditAllHandles[]; extern const char kScrollPixels[]; #endif +#if defined(OS_MACOSX) || defined(OS_WIN) +extern const char kUseSystemSSL[]; +#endif + #if !defined(OFFICIAL_BUILD) extern const char kRendererCheckFalseTest[]; #endif diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 2ecde32..7700d44 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -570,6 +570,13 @@ '../build/linux/system.gyp:x11', '../dbus/dbus.gyp:dbus', ], + 'conditions': [ + ['linux_sandbox_path != ""', { + 'defines': [ + 'LINUX_SANDBOX_PATH="<(linux_sandbox_path)"', + ], + }], + ], }], ['OS=="linux" and toolkit_views==1',{ 'dependencies': [ |