diff options
39 files changed, 988 insertions, 782 deletions
diff --git a/chrome/app/chrome_main.cc b/chrome/app/chrome_main.cc index 8cf2898..0bedac4 100644 --- a/chrome/app/chrome_main.cc +++ b/chrome/app/chrome_main.cc @@ -6,13 +6,12 @@ #include "base/lazy_instance.h" #include "base/message_loop.h" #include "base/metrics/stats_counters.h" -#include "base/metrics/stats_table.h" #include "base/path_service.h" #include "base/process_util.h" #include "base/stringprintf.h" -#include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "build/build_config.h" +#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/defaults.h" #include "chrome/browser/diagnostics/diagnostics_main.h" #include "chrome/common/chrome_constants.h" @@ -33,7 +32,6 @@ #include "content/common/content_client.h" #include "content/common/content_counters.h" #include "content/common/content_paths.h" -#include "ipc/ipc_switches.h" #include "media/base/media.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/ui_base_switches.h" @@ -92,6 +90,8 @@ #endif #if !defined(NACL_WIN64) // We don't build the this code on win nacl64. +base::LazyInstance<chrome::ChromeContentBrowserClient> + g_chrome_content_browser_client(base::LINKER_INITIALIZED); base::LazyInstance<chrome::ChromeContentRendererClient> g_chrome_content_renderer_client(base::LINKER_INITIALIZED); base::LazyInstance<chrome::ChromeContentUtilityClient> @@ -101,7 +101,6 @@ base::LazyInstance<chrome::ChromeContentUtilityClient> base::LazyInstance<chrome::ChromeContentPluginClient> g_chrome_content_plugin_client(base::LINKER_INITIALIZED); -extern int BrowserMain(const MainFunctionParams&); extern int RendererMain(const MainFunctionParams&); extern int NaClMain(const MainFunctionParams&); extern int ProfileImportMain(const MainFunctionParams&); @@ -279,7 +278,12 @@ void InitializeChromeContentRendererClient() { } void InitializeChromeContentClient(const std::string& process_type) { - if (process_type == switches::kPluginProcess) { + if (process_type.empty()) { +#if !defined(NACL_WIN64) // We don't build the this code on win nacl64. + content::GetContentClient()->set_browser( + &g_chrome_content_browser_client.Get()); +#endif + } else if (process_type == switches::kPluginProcess) { content::GetContentClient()->set_plugin( &g_chrome_content_plugin_client.Get()); } else if (process_type == switches::kRendererProcess || @@ -339,27 +343,6 @@ void SetMacProcessName(const std::string& process_type) { #endif // defined(OS_MACOSX) -void InitializeStatsTable(base::ProcessId browser_pid, - const CommandLine& command_line) { - // Initialize the Stats Counters table. With this initialized, - // the StatsViewer can be utilized to read counters outside of - // Chrome. These lines can be commented out to effectively turn - // counters 'off'. The table is created and exists for the life - // of the process. It is not cleaned up. - if (command_line.HasSwitch(switches::kEnableStatsTable) || - command_line.HasSwitch(switches::kEnableBenchmarking)) { - // NOTIMPLEMENTED: we probably need to shut this down correctly to avoid - // leaking shared memory regions on posix platforms. - std::string statsfile = - base::StringPrintf("%s-%u", - chrome::kStatsFilename, - static_cast<unsigned int>(browser_pid)); - base::StatsTable *stats_table = new base::StatsTable(statsfile, - chrome::kStatsMaxThreads, chrome::kStatsMaxCounters); - base::StatsTable::set_current(stats_table); - } -} - #if defined(OS_POSIX) // Check for --version and --product-version; return true if we encountered // one of these switches and should exit now. @@ -570,27 +553,6 @@ class ChromeMainDelegate : public content::ContentMainDelegate { if (!user_data_dir.empty()) CHECK(PathService::Override(chrome::DIR_USER_DATA, user_data_dir)); - base::ProcessId browser_pid = base::GetCurrentProcId(); - if (!process_type.empty() && -#if defined(OS_MACOSX) - process_type != switches::kRelauncherProcess && -#endif - process_type != switches::kServiceProcess) { -#if defined(OS_WIN) || defined(OS_MACOSX) - std::string channel_name = - command_line.GetSwitchValueASCII(switches::kProcessChannelID); - - int browser_pid_int; - base::StringToInt(channel_name, &browser_pid_int); - browser_pid = static_cast<base::ProcessId>(browser_pid_int); - DCHECK_NE(browser_pid_int, 0); -#elif defined(OS_POSIX) - // On linux, we're in the zygote here; so we need the parent process' id. - browser_pid = base::GetParentProcessId(base::GetCurrentProcId()); -#endif - } - InitializeStatsTable(browser_pid, command_line); - startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer> (content::Counters::chrome_main())); @@ -694,7 +656,6 @@ class ChromeMainDelegate : public content::ContentMainDelegate { const std::string& process_type, const MainFunctionParams& main_function_params) OVERRIDE { static const MainFunction kMainFunctions[] = { - { "", BrowserMain }, // An extension process is just a renderer process. We use a different // command line argument to differentiate crash reports. { switches::kExtensionProcess, RendererMain }, @@ -775,13 +736,6 @@ class ChromeMainDelegate : public content::ContentMainDelegate { std::string process_type = command_line.GetSwitchValueASCII(switches::kProcessType); - // The StatsTable must be initialized in each process; we already - // initialized for the browser process, now we need to initialize - // within the new processes as well. - pid_t browser_pid = base::GetParentProcessId( - base::GetParentProcessId(base::GetCurrentProcId())); - InitializeStatsTable(browser_pid, command_line); - #if defined(USE_LINUX_BREAKPAD) // Needs to be called after we have chrome::DIR_USER_DATA. BrowserMain sets // this up for the browser process in a different manner. diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 43a888e..298cb52 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -8,7 +8,6 @@ #include <string> #include <vector> -#include "base/allocator/allocator_shim.h" #include "base/at_exit.h" #include "base/command_line.h" #include "base/debug/trace_event.h" @@ -24,7 +23,6 @@ #include "base/string_split.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" -#include "base/system_monitor/system_monitor.h" #include "base/threading/platform_thread.h" #include "base/threading/thread_restrictions.h" #include "base/time.h" @@ -36,7 +34,6 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process_impl.h" #include "chrome/browser/browser_shutdown.h" -#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/defaults.h" #include "chrome/browser/extensions/extension_protocols.h" #include "chrome/browser/extensions/extension_service.h" @@ -96,7 +93,6 @@ #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/common/child_process.h" #include "content/common/content_client.h" -#include "content/common/hi_res_timer_manager.h" #include "content/common/main_function_params.h" #include "grit/app_locale_settings.h" #include "grit/chromium_strings.h" @@ -104,13 +100,11 @@ #include "grit/platform_locale_settings.h" #include "net/base/cookie_monster.h" #include "net/base/net_module.h" -#include "net/base/network_change_notifier.h" #include "net/http/http_basic_stream.h" #include "net/http/http_network_layer.h" #include "net/http/http_stream_factory.h" #include "net/socket/client_socket_pool_base.h" #include "net/socket/client_socket_pool_manager.h" -#include "net/socket/tcp_client_socket.h" #include "net/spdy/spdy_session.h" #include "net/spdy/spdy_session_pool.h" #include "net/url_request/url_request.h" @@ -125,8 +119,6 @@ #endif #if defined(OS_POSIX) && !defined(OS_MACOSX) -#include <dbus/dbus-glib.h> - #include "chrome/browser/browser_main_gtk.h" #include "chrome/browser/ui/gtk/gtk_util.h" #endif @@ -148,7 +140,6 @@ #include "chrome/browser/chromeos/login/ownership_service.h" #include "chrome/browser/chromeos/login/screen_locker.h" #include "chrome/browser/chromeos/login/user_manager.h" -#include "chrome/browser/chromeos/net/cros_network_change_notifier_factory.h" #include "chrome/browser/chromeos/system_key_event_listener.h" #include "chrome/browser/chromeos/user_cros_settings_provider.h" #include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h" @@ -162,9 +153,6 @@ // progress and should not be taken as an indication of a real refactoring. #if defined(OS_WIN) -#include <windows.h> -#include <commctrl.h> -#include <shellapi.h> #include "base/environment.h" // For PreRead experiment. #include "base/win/scoped_com_initializer.h" @@ -180,11 +168,9 @@ #include "chrome/installer/util/install_util.h" #include "chrome/installer/util/shell_util.h" #include "content/browser/user_metrics.h" -#include "content/common/sandbox_policy.h" #include "net/base/net_util.h" #include "net/base/sdch_manager.h" #include "printing/printed_document.h" -#include "sandbox/src/sandbox.h" #include "ui/base/l10n/l10n_util_win.h" #include "ui/gfx/platform_font_win.h" #endif // defined(OS_WIN) @@ -439,28 +425,6 @@ PrefService* InitializeLocalState(const CommandLine& parsed_command_line, return local_state; } -// Windows-specific initialization code for the sandbox broker services. This -// is just a NOP on non-Windows platforms to reduce ifdefs later on. -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) { - sandbox::InitBrokerServices(broker_services); - if (!parsed_command_line.HasSwitch(switches::kNoSandbox)) { - bool use_winsta = !parsed_command_line.HasSwitch( - switches::kDisableAltWinstation); - // Precreate the desktop and window station used by the renderers. - sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); - sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); - CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); - policy->Release(); - } - } -#endif -} - // Initializes the profile, possibly doing some user prompting to pick a // fallback profile. Returns the newly created profile, or NULL if startup // should not continue. @@ -534,117 +498,6 @@ int GetMinimumFontSize() { #endif -#if defined(TOOLKIT_USES_GTK) -static void GLibLogHandler(const gchar* log_domain, - GLogLevelFlags log_level, - const gchar* message, - gpointer userdata) { - if (!log_domain) - log_domain = "<unknown>"; - if (!message) - message = "<no message>"; - - if (strstr(message, "Loading IM context type") || - strstr(message, "wrong ELF class: ELFCLASS64")) { - // http://crbug.com/9643 - // Until we have a real 64-bit build or all of these 32-bit package issues - // are sorted out, don't fatal on ELF 32/64-bit mismatch warnings and don't - // spam the user with more than one of them. - static bool alerted = false; - if (!alerted) { - LOG(ERROR) << "Bug 9643: " << log_domain << ": " << message; - alerted = true; - } - } else if (strstr(message, "Theme file for default has no") || - strstr(message, "Theme directory") || - strstr(message, "theme pixmap")) { - LOG(ERROR) << "GTK theme error: " << message; - } else if (strstr(message, "gtk_drag_dest_leave: assertion")) { - LOG(ERROR) << "Drag destination deleted: http://crbug.com/18557"; - } else if (strstr(message, "Out of memory") && - strstr(log_domain, "<unknown>")) { - LOG(ERROR) << "DBus call timeout or out of memory: " - << "http://crosbug.com/15496"; - } else { - LOG(DFATAL) << log_domain << ": " << message; - } -} - -static void SetUpGLibLogHandler() { - // Register GLib-handled assertions to go through our logging system. - const char* kLogDomains[] = { NULL, "Gtk", "Gdk", "GLib", "GLib-GObject" }; - for (size_t i = 0; i < arraysize(kLogDomains); i++) { - g_log_set_handler(kLogDomains[i], - static_cast<GLogLevelFlags>(G_LOG_FLAG_RECURSION | - G_LOG_FLAG_FATAL | - G_LOG_LEVEL_ERROR | - G_LOG_LEVEL_CRITICAL | - G_LOG_LEVEL_WARNING), - GLibLogHandler, - NULL); - } -} -#endif - -void InitializeToolkit(const MainFunctionParams& parameters) { - // TODO(evan): this function is rather subtle, due to the variety - // of intersecting ifdefs we have. To keep it easy to follow, there - // are no #else branches on any #ifs. - -#if defined(TOOLKIT_USES_GTK) - // We want to call g_thread_init(), but in some codepaths (tests) it - // is possible it has already been called. In older versions of - // GTK, it is an error to call g_thread_init twice; unfortunately, - // the API to tell whether it has been called already was also only - // added in a newer version of GTK! Thankfully, this non-intuitive - // check is actually equivalent and sufficient to work around the - // error. - if (!g_thread_supported()) - g_thread_init(NULL); - // Glib type system initialization. Needed at least for gconf, - // used in net/proxy/proxy_config_service_linux.cc. Most likely - // this is superfluous as gtk_init() ought to do this. It's - // definitely harmless, so retained as a reminder of this - // requirement for gconf. - g_type_init(); - // We use glib-dbus for geolocation and it's possible other libraries - // (e.g. gnome-keyring) will use it, so initialize its threading here - // as well. - dbus_g_thread_init(); - gfx::GtkInitFromCommandLine(parameters.command_line_); - SetUpGLibLogHandler(); -#endif - -#if defined(TOOLKIT_GTK) - // It is important for this to happen before the first run dialog, as it - // styles the dialog as well. - gtk_util::InitRCStyles(); -#endif - -#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; - - // Init common control sex. - INITCOMMONCONTROLSEX config; - config.dwSize = sizeof(config); - config.dwICC = ICC_WIN95_CLASSES; - if (!InitCommonControlsEx(&config)) - LOG_GETLASTERROR(FATAL); -#endif -} - #if defined(OS_CHROMEOS) // Class is used to login using passed username and password. @@ -837,49 +690,24 @@ const char kMissingLocaleDataMessage[] = // BrowserMainParts ------------------------------------------------------------ -BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters) - : parameters_(parameters), - parsed_command_line_(parameters.command_line_) { -} - -BrowserMainParts::~BrowserMainParts() { +ChromeBrowserMainParts::ChromeBrowserMainParts( + const MainFunctionParams& parameters) + : BrowserMainParts(parameters), + shutdown_watcher_(new ShutdownWatcherHelper()) { + // If we're running tests (ui_task is non-null). + if (parameters.ui_task) + browser_defaults::enable_help_app = false; } -// BrowserMainParts: |EarlyInitialization()| and related ----------------------- - -void BrowserMainParts::EarlyInitialization() { - PreEarlyInitialization(); - - if (parsed_command_line().HasSwitch(switches::kEnableBenchmarking)) - base::FieldTrial::EnableBenchmarking(); - - InitializeSSL(); - - if (parsed_command_line().HasSwitch(switches::kDisableSSLFalseStart)) - net::SSLConfigService::DisableFalseStart(); - if (parsed_command_line().HasSwitch(switches::kEnableSSLCachedInfo)) - net::SSLConfigService::EnableCachedInfo(); - if (parsed_command_line().HasSwitch(switches::kEnableOriginBoundCerts)) - net::SSLConfigService::EnableOriginBoundCerts(); - if (parsed_command_line().HasSwitch( - switches::kEnableDNSCertProvenanceChecking)) { - net::SSLConfigService::EnableDNSCertProvenanceChecking(); - } - - // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't - // seem dependent on InitializeSSL(). - if (parsed_command_line().HasSwitch(switches::kEnableTcpFastOpen)) - net::set_tcp_fastopen_enabled(true); - - PostEarlyInitialization(); +ChromeBrowserMainParts::~ChromeBrowserMainParts() { } -void BrowserMainParts::SetupHistogramSynchronizer() { +void ChromeBrowserMainParts::SetupHistogramSynchronizer() { histogram_synchronizer_ = new HistogramSynchronizer(); } // This will be called after the command-line has been mutated by about:flags -MetricsService* BrowserMainParts::SetupMetricsAndFieldTrials( +MetricsService* ChromeBrowserMainParts::SetupMetricsAndFieldTrials( const CommandLine& parsed_command_line, PrefService* local_state) { // Must initialize metrics after labs have been converted into switches, @@ -911,7 +739,7 @@ MetricsService* BrowserMainParts::SetupMetricsAndFieldTrials( // run faster) uses 8. We would like to see how much of an effect this value has // on browsing. Too large a value might cause us to run into SYN flood detection // mechanisms. -void BrowserMainParts::ConnectionFieldTrial() { +void ChromeBrowserMainParts::ConnectionFieldTrial() { const base::FieldTrial::Probability kConnectDivisor = 100; const base::FieldTrial::Probability kConnectProbability = 1; // 1% prob. @@ -960,7 +788,7 @@ void BrowserMainParts::ConnectionFieldTrial() { // connection and instead show an error to the user. So we need to be // conservative here. We've seen that some servers will close the socket after // as short as 10 seconds. See http://crbug.com/84313 for more details. -void BrowserMainParts::SocketTimeoutFieldTrial() { +void ChromeBrowserMainParts::SocketTimeoutFieldTrial() { const base::FieldTrial::Probability kIdleSocketTimeoutDivisor = 100; // 1% probability for all experimental settings. const base::FieldTrial::Probability kSocketTimeoutProbability = 1; @@ -991,7 +819,7 @@ void BrowserMainParts::SocketTimeoutFieldTrial() { } } -void BrowserMainParts::ProxyConnectionsFieldTrial() { +void ChromeBrowserMainParts::ProxyConnectionsFieldTrial() { const base::FieldTrial::Probability kProxyConnectionsDivisor = 100; // 25% probability const base::FieldTrial::Probability kProxyConnectionProbability = 1; @@ -1037,7 +865,7 @@ void BrowserMainParts::ProxyConnectionsFieldTrial() { // Http is still used for all requests. // default group: no npn or spdy is involved. The "old" non-spdy // chrome behavior. -void BrowserMainParts::SpdyFieldTrial() { +void ChromeBrowserMainParts::SpdyFieldTrial() { if (parsed_command_line().HasSwitch(switches::kUseSpdy)) { std::string spdy_mode = parsed_command_line().GetSwitchValueASCII(switches::kUseSpdy); @@ -1105,7 +933,7 @@ void BrowserMainParts::SpdyFieldTrial() { // If --socket-reuse-policy is not specified, run an A/B test for choosing the // warmest socket. -void BrowserMainParts::WarmConnectionFieldTrial() { +void ChromeBrowserMainParts::WarmConnectionFieldTrial() { const CommandLine& command_line = parsed_command_line(); if (command_line.HasSwitch(switches::kSocketReusePolicy)) { std::string socket_reuse_policy_str = command_line.GetSwitchValueASCII( @@ -1146,7 +974,7 @@ void BrowserMainParts::WarmConnectionFieldTrial() { // If neither --enable-connect-backup-jobs or --disable-connect-backup-jobs is // specified, run an A/B test for automatically establishing backup TCP // connections when a certain timeout value is exceeded. -void BrowserMainParts::ConnectBackupJobsFieldTrial() { +void ChromeBrowserMainParts::ConnectBackupJobsFieldTrial() { if (parsed_command_line().HasSwitch(switches::kEnableConnectBackupJobs)) { net::internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled( true); @@ -1174,7 +1002,7 @@ void BrowserMainParts::ConnectBackupJobsFieldTrial() { // Test the impact on subsequent Google searches of getting suggestions from // www.google.TLD instead of clients1.google.TLD. -void BrowserMainParts::SuggestPrefixFieldTrial() { +void ChromeBrowserMainParts::SuggestPrefixFieldTrial() { const base::FieldTrial::Probability kSuggestPrefixDivisor = 100; // 50% probability. const base::FieldTrial::Probability kSuggestPrefixProbability = 50; @@ -1186,40 +1014,11 @@ void BrowserMainParts::SuggestPrefixFieldTrial() { // The field trial is detected directly, so we don't need to call anything. } -// BrowserMainParts: |MainMessageLoopStart()| and related ---------------------- - -void BrowserMainParts::MainMessageLoopStart() { - PreMainMessageLoopStart(); - - main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); - - // TODO(viettrungluu): should these really go before setting the thread name? - system_monitor_.reset(new base::SystemMonitor); - hi_res_timer_manager_.reset(new HighResolutionTimerManager); - - InitializeMainThread(); - - network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); - - PostMainMessageLoopStart(); - Profiling::MainMessageLoopStarted(); -} - -void BrowserMainParts::InitializeMainThread() { - const char* kThreadName = "CrBrowserMain"; - base::PlatformThread::SetName(kThreadName); - main_message_loop().set_thread_name(kThreadName); - - // Register the main thread by instantiating it, but don't call any methods. - main_thread_.reset(new BrowserThread(BrowserThread::UI, - MessageLoop::current())); -} - -// BrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------------- +// ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------- // Initializes the metrics service with the configuration for this process, // returning the created service (guaranteed non-NULL). -MetricsService* BrowserMainParts::InitializeMetrics( +MetricsService* ChromeBrowserMainParts::InitializeMetrics( const CommandLine& parsed_command_line, const PrefService* local_state) { #if defined(OS_WIN) @@ -1256,8 +1055,8 @@ MetricsService* BrowserMainParts::InitializeMetrics( return metrics; } -void BrowserMainParts::SetupFieldTrials(bool metrics_recording_enabled, - bool proxy_policy_is_set) { +void ChromeBrowserMainParts::SetupFieldTrials(bool metrics_recording_enabled, + bool proxy_policy_is_set) { // Note: make sure to call ConnectionFieldTrial() before // ProxyConnectionsFieldTrial(). ConnectionFieldTrial(); @@ -1300,82 +1099,29 @@ DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { } #endif -// Main routine for running as the Browser process. -int BrowserMain(const MainFunctionParams& parameters) { - // Create ShutdownWatcherHelper object for watching jank during shutdown. - // Please keep |shutdown_watcher| as the first object constructed, and hence - // it is destroyed last. - ShutdownWatcherHelper shutdown_watcher; - - TRACE_EVENT_BEGIN_ETW("BrowserMain", 0, ""); - - // Override the default ContentBrowserClient to let Chrome participate in - // content logic. - chrome::ChromeContentBrowserClient browser_client; - content::GetContentClient()->set_browser(&browser_client); - - // If we're running tests (ui_task is non-null). - if (parameters.ui_task) - browser_defaults::enable_help_app = false; - - scoped_ptr<BrowserMainParts> - parts(BrowserMainParts::CreateBrowserMainParts(parameters)); - - parts->EarlyInitialization(); +void ChromeBrowserMainParts::PostMainMessageLoopStart() { + Profiling::MainMessageLoopStarted(); +} - // Must happen before we try to use a message loop or display any UI. - InitializeToolkit(parameters); +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; -#if defined(OS_CHROMEOS) - // Initialize CrosLibrary only for the browser, unless running tests - // (which do their own CrosLibrary setup). - if (!parameters.ui_task) { - bool use_stub = parameters.command_line_.HasSwitch(switches::kStubCros); - chromeos::CrosLibrary::Initialize(use_stub); - } - // Replace the default NetworkChangeNotifierFactory with ChromeOS specific - // implementation. - net::NetworkChangeNotifier::SetFactory( - new chromeos::CrosNetworkChangeNotifierFactory()); + // TODO(beng): Move to WidgetImpl and implement on Windows too! + if (parameters().command_line_.HasSwitch(switches::kDebugViewsPaint)) + views::Widget::SetDebugPaintEnabled(true); #endif - parts->MainMessageLoopStart(); - - // WARNING: If we get a WM_ENDSESSION, objects created on the stack here - // are NOT deleted. If you need something to run during WM_ENDSESSION add it - // to browser_shutdown::Shutdown or BrowserProcess::EndSession. - - // !!!!!!!!!! READ ME !!!!!!!!!! - // I (viettrungluu) am in the process of refactoring |BrowserMain()|. If you - // need to add something above this comment, read the documentation in - // browser_main.h. If you need to add something below, please do the - // following: - // - Figure out where you should add your code. Do NOT just pick a random - // location "which works". - // - Document the dependencies apart from compile-time-checkable ones. What - // must happen before your new code is executed? Does your new code need to - // run before something else? Are there performance reasons for executing - // your code at that point? - // - If you need to create a (persistent) object, heap allocate it and keep a - // |scoped_ptr| to it rather than allocating it on the stack. Otherwise - // I'll have to convert your code when I refactor. - // - Unless your new code is just a couple of lines, factor it out into a - // function with a well-defined purpose. Do NOT just add it inline in - // |BrowserMain()|. - // Thanks! - - // TODO(viettrungluu): put the remainder into BrowserMainParts - const CommandLine& parsed_command_line = parameters.command_line_; - base::mac::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_; - -#if defined(OS_WIN) && !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 +#if defined(OS_WIN) + gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; + gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; +#endif +} +int ChromeBrowserMainParts::TemporaryContinue() { FilePath user_data_dir; #if defined(OS_WIN) PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); @@ -1392,38 +1138,26 @@ int BrowserMain(const MainFunctionParams& parameters) { ProcessSingleton process_singleton(user_data_dir); bool is_first_run = FirstRun::IsChromeFirstRun() || - parsed_command_line.HasSwitch(switches::kFirstRun); + parsed_command_line().HasSwitch(switches::kFirstRun); scoped_ptr<BrowserProcessImpl> browser_process; - if (parsed_command_line.HasSwitch(switches::kImport) || - parsed_command_line.HasSwitch(switches::kImportFromFile)) { + 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())); } - // BrowserProcessImpl's constructor should set g_browser_process. - DCHECK(g_browser_process); - // This forces the TabCloseableStateWatcher to be created and, on chromeos, // register for the notifications it needs to track the closeable state of // tabs. g_browser_process->tab_closeable_state_watcher(); - // 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); - - // Initialize histogram statistics gathering system. - base::StatisticsRecorder statistics; - - PrefService* local_state = InitializeLocalState(parsed_command_line, + PrefService* local_state = InitializeLocalState(parsed_command_line(), is_first_run); #if defined(USE_LINUX_BREAKPAD) @@ -1438,7 +1172,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // If we're running tests (ui_task is non-null), then the ResourceBundle // has already been initialized. - if (parameters.ui_task) { + if (parameters().ui_task) { g_browser_process->SetApplicationLocale("en-US"); } else { // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is @@ -1454,7 +1188,7 @@ int BrowserMain(const MainFunctionParams& parameters) { const std::string loaded_locale = ResourceBundle::InitSharedInstance(locale); if (loaded_locale.empty() && - !parsed_command_line.HasSwitch(switches::kNoErrorDialogs)) { + !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) { ShowMissingLocaleMessageBox(); return chrome::RESULT_CODE_MISSING_DATA; } @@ -1472,7 +1206,7 @@ int BrowserMain(const MainFunctionParams& parameters) { #endif std::string try_chrome = - parsed_command_line.GetSwitchValueASCII(switches::kTryChromeAgain); + parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain); if (!try_chrome.empty()) { #if defined(OS_WIN) // Setup.exe has determined that we need to run a retention experiment @@ -1507,9 +1241,9 @@ int BrowserMain(const MainFunctionParams& parameters) { CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePureViews)); // Launch the views desktop shell window and register it as the default parent // for all unparented views widgets. - if (parsed_command_line.HasSwitch(switches::kViewsDesktop)) { + if (parsed_command_line().HasSwitch(switches::kViewsDesktop)) { std::string desktop_type_cmd = - parsed_command_line.GetSwitchValueASCII(switches::kViewsDesktop); + parsed_command_line().GetSwitchValueASCII(switches::kViewsDesktop); views::desktop::DesktopWindowView::DesktopType desktop_type; if (desktop_type_cmd == "netbook") desktop_type = views::desktop::DesktopWindowView::DESKTOP_NETBOOK; @@ -1540,14 +1274,14 @@ int BrowserMain(const MainFunctionParams& parameters) { // If we are running in App mode, we do not want to show the importer // (first run) UI. if (!first_run_ui_bypass && - (parsed_command_line.HasSwitch(switches::kApp) || - parsed_command_line.HasSwitch(switches::kAppId) || - parsed_command_line.HasSwitch(switches::kNoFirstRun))) + (parsed_command_line().HasSwitch(switches::kApp) || + parsed_command_line().HasSwitch(switches::kAppId) || + parsed_command_line().HasSwitch(switches::kNoFirstRun))) first_run_ui_bypass = true; } // TODO(viettrungluu): why don't we run this earlier? - if (!parsed_command_line.HasSwitch(switches::kNoErrorDialogs)) + if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) WarnAboutMinimumSystemRequirements(); // Enable print preview once for supported platforms. @@ -1565,19 +1299,19 @@ int BrowserMain(const MainFunctionParams& parameters) { about_flags::ConvertFlagsToSwitches(local_state, CommandLine::ForCurrentProcess()); - InitializeNetworkOptions(parsed_command_line); + InitializeNetworkOptions(parsed_command_line()); 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. - parts->SetupHistogramSynchronizer(); + SetupHistogramSynchronizer(); // Now the command line has been mutated based on about:flags, we can // set up metrics and initialize field trials. - MetricsService* metrics = parts->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 @@ -1625,14 +1359,14 @@ int BrowserMain(const MainFunctionParams& parameters) { // 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)) - return HandleIconsCommands(parsed_command_line); - if (parsed_command_line.HasSwitch(switches::kMakeDefaultBrowser)) { + if (parsed_command_line().HasSwitch(switches::kHideIcons) || + 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) : static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED); @@ -1640,9 +1374,9 @@ int BrowserMain(const MainFunctionParams& parameters) { // If the command line specifies --pack-extension, attempt the pack extension // startup action and exit. - if (parsed_command_line.HasSwitch(switches::kPackExtension)) { + 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; @@ -1654,8 +1388,8 @@ int BrowserMain(const MainFunctionParams& parameters) { // from other browsers. In case this process is a short-lived "import" // process that another browser runs just to import the settings, we // don't want to be checking for another browser process, by design. - if (!(parsed_command_line.HasSwitch(switches::kImport) || - parsed_command_line.HasSwitch(switches::kImportFromFile))) { + if (!(parsed_command_line().HasSwitch(switches::kImport) || + parsed_command_line().HasSwitch(switches::kImportFromFile))) { #endif // When another process is running, use that process instead of starting a // new one. NotifyOtherProcess will currently give the other process up to @@ -1708,7 +1442,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // TODO(abarth): Should this move to InitializeNetworkOptions()? // Allow access to file:// on ChromeOS for tests. - if (parsed_command_line.HasSwitch(switches::kAllowFileAccess)) + if (parsed_command_line().HasSwitch(switches::kAllowFileAccess)) net::URLRequest::AllowFileAccess(); // There are two use cases for kLoginUser: @@ -1716,15 +1450,15 @@ int BrowserMain(const MainFunctionParams& parameters) { // 2) if passed alone, to signal that the indicated user has already // logged in and we should behave accordingly. // This handles case 2. - if (parsed_command_line.HasSwitch(switches::kLoginUser) && - !parsed_command_line.HasSwitch(switches::kLoginPassword)) { + if (parsed_command_line().HasSwitch(switches::kLoginUser) && + !parsed_command_line().HasSwitch(switches::kLoginPassword)) { std::string username = - parsed_command_line.GetSwitchValueASCII(switches::kLoginUser); + parsed_command_line().GetSwitchValueASCII(switches::kLoginUser); VLOG(1) << "Relaunching browser for user: " << username; chromeos::UserManager::Get()->UserLoggedIn(username); // Redirects Chrome logging to the user data dir. - logging::RedirectChromeLogging(parsed_command_line); + logging::RedirectChromeLogging(parsed_command_line()); // Initialize user policy before creating the profile so the profile // initialization code sees policy settings. @@ -1739,8 +1473,8 @@ int BrowserMain(const MainFunctionParams& parameters) { g_browser_process->profile_manager()->SetWillImport(); } - Profile* profile = CreateProfile(parameters, user_data_dir, - parsed_command_line); + Profile* profile = CreateProfile(parameters(), user_data_dir, + parsed_command_line()); if (!profile) return content::RESULT_CODE_NORMAL_EXIT; @@ -1750,8 +1484,8 @@ int BrowserMain(const MainFunctionParams& parameters) { // Pass the TokenService pointer to the policy connector so user policy can // grab a token and register with the policy server. // TODO(mnissler): Remove once OAuth is the only authentication mechanism. - if (parsed_command_line.HasSwitch(switches::kLoginUser) && - !parsed_command_line.HasSwitch(switches::kLoginPassword)) { + if (parsed_command_line().HasSwitch(switches::kLoginUser) && + !parsed_command_line().HasSwitch(switches::kLoginPassword)) { g_browser_process->browser_policy_connector()->SetUserPolicyTokenService( profile->GetTokenService()); } @@ -1762,8 +1496,8 @@ int BrowserMain(const MainFunctionParams& parameters) { // 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) @@ -1771,15 +1505,15 @@ int BrowserMain(const MainFunctionParams& parameters) { // that exits when this task has finished. // TODO(port): Port the Mac's IPC-based implementation to other platforms to // 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); + if (parsed_command_line().HasSwitch(switches::kImport) || + parsed_command_line().HasSwitch(switches::kImportFromFile)) { + return FirstRun::ImportNow(profile, parsed_command_line()); } #endif #if defined(OS_WIN) // Do the tasks if chrome has been upgraded while it was last running. - if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line)) + if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line())) return content::RESULT_CODE_NORMAL_EXIT; #endif @@ -1791,7 +1525,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // (uninstall, resource bundle initialization, other chrome browser // processes etc). // Do not allow this to occur for Chrome Frame user-to-system handoffs. - if (!parsed_command_line.HasSwitch(switches::kChromeFrame) && + if (!parsed_command_line().HasSwitch(switches::kChromeFrame) && CheckMachineLevelInstall()) return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS; @@ -1800,7 +1534,7 @@ int BrowserMain(const MainFunctionParams& parameters) { DCHECK(translate_manager != NULL); #if defined(OS_MACOSX) - if (!parsed_command_line.HasSwitch(switches::kNoFirstRun)) { + if (!parsed_command_line().HasSwitch(switches::kNoFirstRun)) { // Disk image installation is sort of a first-run task, so it shares the // kNoFirstRun switch. if (MaybeInstallFromDiskImage()) { @@ -1844,7 +1578,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // Sets things up so that if we crash from this point on, a dialog will // popup asking the user to restart chrome. It is done this late to avoid // testing against a bunch of special cases that are taken care early on. - PrepareRestartOnCrashEnviroment(parsed_command_line); + PrepareRestartOnCrashEnviroment(parsed_command_line()); #if defined(OS_WIN) // Registers Chrome with the Windows Restart Manager, which will restore the @@ -1853,7 +1587,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // but should run on startup if extended to handle crashes/hangs/patches. // Also, better to run once here than once for each HWND's WM_QUERYENDSESSION. if (base::win::GetVersion() >= base::win::VERSION_VISTA) - RegisterApplicationRestart(parsed_command_line); + RegisterApplicationRestart(parsed_command_line()); #endif // OS_WIN // Initialize and maintain network predictor module, which handles DNS @@ -1861,9 +1595,9 @@ int BrowserMain(const MainFunctionParams& parameters) { // This also registers an observer to discard data when closing incognito // mode. bool preconnect_enabled = true; // Default status (easy to change!). - if (parsed_command_line.HasSwitch(switches::kDisablePreconnect)) + if (parsed_command_line().HasSwitch(switches::kDisablePreconnect)) preconnect_enabled = false; - else if (parsed_command_line.HasSwitch(switches::kEnablePreconnect)) + else if (parsed_command_line().HasSwitch(switches::kEnablePreconnect)) preconnect_enabled = true; chrome_browser_net::PredictorInit dns_prefetch( user_prefs, @@ -1942,9 +1676,9 @@ int BrowserMain(const MainFunctionParams& parameters) { // Use default of "" so that all domains are supported. std::string sdch_supported_domain(""); - if (parsed_command_line.HasSwitch(switches::kSdchFilter)) { + if (parsed_command_line().HasSwitch(switches::kSdchFilter)) { sdch_supported_domain = - parsed_command_line.GetSwitchValueASCII(switches::kSdchFilter); + parsed_command_line().GetSwitchValueASCII(switches::kSdchFilter); } else { sdch_trial->AppendGroup("global_disable_sdch", kSDCH_DISABLE_PROBABILITY); @@ -1956,12 +1690,12 @@ int BrowserMain(const MainFunctionParams& parameters) { sdch_manager.set_sdch_fetcher(new SdchDictionaryFetcher); sdch_manager.EnableSdchSupport(sdch_supported_domain); - InstallJankometer(parsed_command_line); + InstallJankometer(parsed_command_line()); #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) - if (parsed_command_line.HasSwitch(switches::kDebugPrint)) { + if (parsed_command_line().HasSwitch(switches::kDebugPrint)) { FilePath path = - parsed_command_line.GetSwitchValuePath(switches::kDebugPrint); + parsed_command_line().GetSwitchValuePath(switches::kDebugPrint); printing::PrintedDocument::set_debug_dump_path(path); } #endif @@ -1971,7 +1705,7 @@ int BrowserMain(const MainFunctionParams& parameters) { CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepMouseCursor)); #endif - HandleTestParameters(parsed_command_line); + HandleTestParameters(parsed_command_line()); RecordBreakpadStatusUMA(metrics); about_flags::RecordUMAStatistics(local_state); LanguageUsageMetrics::RecordAcceptLanguages( @@ -2000,9 +1734,9 @@ int BrowserMain(const MainFunctionParams& parameters) { // The extension service may be available at this point. If the command line // specifies --uninstall-extension, attempt the uninstall extension startup // action. - if (parsed_command_line.HasSwitch(switches::kUninstallExtension)) { + 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; @@ -2018,7 +1752,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // ChildProcess:: is a misnomer unless you consider context. Use // of --wait-for-debugger only makes sense when Chrome itself is a // child process (e.g. when launched by PyAuto). - if (parsed_command_line.HasSwitch(switches::kWaitForDebugger)) { + if (parsed_command_line().HasSwitch(switches::kWaitForDebugger)) { ChildProcess::WaitForDebugger("Browser"); } @@ -2047,15 +1781,16 @@ int BrowserMain(const MainFunctionParams& parameters) { NewRunnableFunction(&GpuBlacklistUpdater::SetupOnFileThread)); // Start watching all browser threads for responsiveness. - ThreadWatcherList::StartWatchingAll(parsed_command_line); + ThreadWatcherList::StartWatchingAll(parsed_command_line()); int result_code = content::RESULT_CODE_NORMAL_EXIT; - if (parameters.ui_task) { + base::mac::ScopedNSAutoreleasePool* pool = parameters().autorelease_pool_; + if (parameters().ui_task) { // We are in test mode. Run one task and enter the main message loop. if (pool) pool->Recycle(); - parameters.ui_task->Run(); - delete parameters.ui_task; + parameters().ui_task->Run(); + delete parameters().ui_task; } else { // Most general initialization is behind us, but opening a // tab and/or session restore and such is still to be done. @@ -2063,7 +1798,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // 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 @@ -2096,7 +1831,7 @@ int BrowserMain(const MainFunctionParams& parameters) { #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 @@ -2111,8 +1846,8 @@ int BrowserMain(const MainFunctionParams& parameters) { } // Start watching for jank during shutdown. It gets disarmed when - // |shutdown_watcher| object is destructed. - shutdown_watcher.Arm(base::TimeDelta::FromSeconds(25)); + // |shutdown_watcher_| object is destructed. + shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(25)); #if defined(OS_WIN) // If it's the first run, log the search engine chosen. We wait until @@ -2162,7 +1897,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // 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) + if (parameters().ui_task == NULL && translate_manager != NULL) translate_manager->CleanupPendingUlrFetcher(); @@ -2178,21 +1913,6 @@ int BrowserMain(const MainFunctionParams& parameters) { ignore_result(browser_process.release()); browser_shutdown::Shutdown(); - // Release BrowserMainParts here, before shutting down CrosLibrary, since - // some of the classes initialized there have CrosLibrary dependencies. - parts.reset(NULL); - -#if defined(OS_CHROMEOS) - if (!parameters.ui_task) - chromeos::CrosLibrary::Shutdown(); - - // To be precise, logout (browser shutdown) is not yet done, but the - // remaining work is negligible, hence we say LogoutDone here. - chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", - false); - chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); -#endif - TRACE_EVENT_END_ETW("BrowserMain", 0, 0); return result_code; } diff --git a/chrome/browser/browser_main.h b/chrome/browser/browser_main.h index ec1dc6e..177ed1c 100644 --- a/chrome/browser/browser_main.h +++ b/chrome/browser/browser_main.h @@ -8,27 +8,15 @@ #include "base/basictypes.h" #include "base/gtest_prod_util.h" -#include "base/memory/scoped_ptr.h" #include "base/metrics/field_trial.h" #include "base/tracked_objects.h" +#include "content/browser/browser_main.h" -class BrowserThread; -class CommandLine; -class HistogramSynchronizer; class FieldTrialSynchronizer; -class HighResolutionTimerManager; -struct MainFunctionParams; -class MessageLoop; +class HistogramSynchronizer; class MetricsService; class PrefService; - -namespace base { -class SystemMonitor; -} - -namespace net { -class NetworkChangeNotifier; -} +class ShutdownWatcherHelper; namespace chrome_browser { // For use by ShowMissingLocaleMessageBox. @@ -36,59 +24,9 @@ extern const char kMissingLocaleDataTitle[]; extern const char kMissingLocaleDataMessage[]; } -// BrowserMainParts: -// This class contains different "stages" to be executed in |BrowserMain()|, -// mostly initialization. This is made into a class rather than just functions -// so each stage can create and maintain state. Each part is represented by a -// single method (e.g., "EarlyInitialization()"), which does the following: -// - calls a method (e.g., "PreEarlyInitialization()") which individual -// platforms can override to provide platform-specific code which is to be -// executed before the common code; -// - calls various methods for things common to all platforms (for that given -// stage); and -// - calls a method (e.g., "PostEarlyInitialization()") for platform-specific -// code to be called after the common code. -// As indicated above, platforms should override the default "Pre...()" and -// "Post...()" methods when necessary; they need not call the superclass's -// implementation (which is empty). -// -// Parts: -// - EarlyInitialization: things which should be done as soon as possible on -// program start (such as setting up signal handlers) and things to be done -// at some generic time before the start of the main message loop. -// - MainMessageLoopStart: things beginning with the start of the main message -// loop and ending with initialization of the main thread; platform-specific -// things which should be done immediately before the start of the main -// message loop should go in |PreMainMessageLoopStart()|. -// - (more to come) -// -// How to add stuff (to existing parts): -// - Figure out when your new code should be executed. What must happen -// before/after your code is executed? Are there performance reasons for -// running your code at a particular time? Document these things! -// - Split out any platform-specific bits. Please avoid #ifdefs it at all -// possible. You have two choices for platform-specific code: (1) Execute it -// from one of the platform-specific |Pre/Post...()| methods; do this if the -// code is unique to a platform type. Or (2) execute it from one of the -// "parts" (e.g., |EarlyInitialization()|) and provide platform-specific -// implementations of your code (in a virtual method); do this if you need to -// provide different implementations across most/all platforms. -// - Unless your new code is just one or two lines, put it into a separate -// method with a well-defined purpose. (Likewise, if you're adding to an -// existing chunk which makes it longer than one or two lines, please move -// the code out into a separate method.) -class BrowserMainParts { +class ChromeBrowserMainParts : public content::BrowserMainParts { public: - // This static method is to be implemented by each platform and should - // instantiate the appropriate subclass. - static BrowserMainParts* CreateBrowserMainParts( - const MainFunctionParams& parameters); - - virtual ~BrowserMainParts(); - - // Parts to be called by |BrowserMain()|. - void EarlyInitialization(); - void MainMessageLoopStart(); + virtual ~ChromeBrowserMainParts(); // Constructs HistogramSynchronizer which gets released early (before // main_message_loop_). @@ -102,25 +40,12 @@ class BrowserMainParts { PrefService* local_state); protected: - explicit BrowserMainParts(const MainFunctionParams& parameters); - - // Accessors for data members (below) ---------------------------------------- - const MainFunctionParams& parameters() const { - return parameters_; - } - const CommandLine& parsed_command_line() const { - return parsed_command_line_; - } - MessageLoop& main_message_loop() const { - return *main_message_loop_; - } - - // Methods to be overridden to provide platform-specific code; these - // correspond to the "parts" above. - virtual void PreEarlyInitialization() {} - virtual void PostEarlyInitialization() {} - virtual void PreMainMessageLoopStart() {} - virtual void PostMainMessageLoopStart() {} + explicit ChromeBrowserMainParts(const MainFunctionParams& parameters); + + virtual void PostMainMessageLoopStart() OVERRIDE; + virtual void ToolkitInitialized() OVERRIDE; + + virtual int TemporaryContinue() OVERRIDE; private: // Methods for |EarlyInitialization()| --------------------------------------- @@ -147,13 +72,6 @@ class BrowserMainParts { // A/B test for using a different host prefix in Google search suggest. void SuggestPrefixFieldTrial(); - // Used to initialize NSPR where appropriate. - virtual void InitializeSSL() = 0; - - // Methods for |MainMessageLoopStart()| -------------------------------------- - - void InitializeMainThread(); - // Methods for |SetupMetricsAndFieldTrials()| -------------------------------- static MetricsService* InitializeMetrics( @@ -166,8 +84,10 @@ class BrowserMainParts { // Members initialized on construction --------------------------------------- - const MainFunctionParams& parameters_; - const CommandLine& parsed_command_line_; + // Create ShutdownWatcherHelper object for watching jank during shutdown. + // Please keep |shutdown_watcher| as the first object constructed, and hence + // it is destroyed last. + scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_; #if defined(TRACK_ALL_TASK_OBJECTS) // Creating this object starts tracking the creation and deletion of Task @@ -180,13 +100,6 @@ class BrowserMainParts { // SetupMetricsAndFieldTrials is called. scoped_ptr<base::FieldTrialList> field_trial_list_; - // Members initialized in |MainMessageLoopStart()| --------------------------- - scoped_ptr<MessageLoop> main_message_loop_; - scoped_ptr<base::SystemMonitor> system_monitor_; - scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_; - scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; - scoped_ptr<BrowserThread> main_thread_; - // Members initialized after / released before main_message_loop_ ------------ // Initialized in SetupHistogramSynchronizer. @@ -198,14 +111,9 @@ class BrowserMainParts { FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket); FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Random); FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Invalid); - DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); + DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts); }; - -// Perform platform-specific work that needs to be done after the main event -// loop has ended. -void DidEndMainMessageLoop(); - // Records the conditions that can prevent Breakpad from generating and // sending crash reports. The presence of a Breakpad handler (after // attempting to initialize crash reporting) and the presence of a debugger diff --git a/chrome/browser/browser_main_gtk.cc b/chrome/browser/browser_main_gtk.cc index 7e718c2..2b8432a 100644 --- a/chrome/browser/browser_main_gtk.cc +++ b/chrome/browser/browser_main_gtk.cc @@ -81,6 +81,10 @@ int BrowserX11IOErrorHandler(Display* d) { } // namespace +BrowserMainPartsGtk::BrowserMainPartsGtk(const MainFunctionParams& parameters) + : BrowserMainPartsPosix(parameters) { +} + void BrowserMainPartsGtk::PreEarlyInitialization() { DetectRunningAsRoot(); @@ -163,9 +167,13 @@ void BrowserMainPartsGtk::SetupSandbox() { zhost->Init(sandbox_cmd); } +namespace content { + void DidEndMainMessageLoop() { } +} + void RecordBreakpadStatusUMA(MetricsService* metrics) { #if defined(USE_LINUX_BREAKPAD) metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); @@ -221,11 +229,3 @@ void SetBrowserX11ErrorHandlers() { // goes away. ui::SetX11ErrorHandlers(BrowserX11ErrorHandler, BrowserX11IOErrorHandler); } - -#if !defined(OS_CHROMEOS) -// static -BrowserMainParts* BrowserMainParts::CreateBrowserMainParts( - const MainFunctionParams& parameters) { - return new BrowserMainPartsGtk(parameters); -} -#endif diff --git a/chrome/browser/browser_main_gtk.h b/chrome/browser/browser_main_gtk.h index 39fb621..22558e3 100644 --- a/chrome/browser/browser_main_gtk.h +++ b/chrome/browser/browser_main_gtk.h @@ -13,8 +13,7 @@ class BrowserMainPartsGtk : public BrowserMainPartsPosix { public: - explicit BrowserMainPartsGtk(const MainFunctionParams& parameters) - : BrowserMainPartsPosix(parameters) {} + explicit BrowserMainPartsGtk(const MainFunctionParams& parameters); virtual void PreEarlyInitialization() OVERRIDE; diff --git a/chrome/browser/browser_main_mac.h b/chrome/browser/browser_main_mac.h new file mode 100644 index 0000000..fcc9215 --- /dev/null +++ b/chrome/browser/browser_main_mac.h @@ -0,0 +1,20 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_BROWSER_MAIN_MAC_H_ +#define CHROME_BROWSER_BROWSER_MAIN_MAC_H_ +#pragma once + +#include "chrome/browser/browser_main_posix.h" + +class BrowserMainPartsMac : public BrowserMainPartsPosix { + public: + explicit BrowserMainPartsMac(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/browser_main_mac.mm b/chrome/browser/browser_main_mac.mm index da805df..41badcc 100644 --- a/chrome/browser/browser_main_mac.mm +++ b/chrome/browser/browser_main_mac.mm @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/browser_main_posix.h" +#include "chrome/browser/browser_main_mac.h" #import <Cocoa/Cocoa.h> @@ -27,11 +27,15 @@ #include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/resource/resource_bundle.h" +namespace content { + void DidEndMainMessageLoop() { AppController* appController = [NSApp delegate]; [appController didEndMainMessageLoop]; } +} + void RecordBreakpadStatusUMA(MetricsService* metrics) { metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged()); @@ -68,90 +72,80 @@ void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) { // BrowserMainPartsMac --------------------------------------------------------- -class BrowserMainPartsMac : public BrowserMainPartsPosix { - public: - explicit BrowserMainPartsMac(const MainFunctionParams& parameters) - : BrowserMainPartsPosix(parameters) {} +BrowserMainPartsMac::BrowserMainPartsMac(const MainFunctionParams& parameters) + : BrowserMainPartsPosix(parameters) { +} - protected: - virtual void PreEarlyInitialization() { - BrowserMainPartsPosix::PreEarlyInitialization(); +void BrowserMainPartsMac::PreEarlyInitialization() { + BrowserMainPartsPosix::PreEarlyInitialization(); - if (base::mac::WasLaunchedAsHiddenLoginItem()) { - CommandLine* singleton_command_line = CommandLine::ForCurrentProcess(); - singleton_command_line->AppendSwitch(switches::kNoStartupWindow); - } + if (base::mac::WasLaunchedAsHiddenLoginItem()) { + CommandLine* singleton_command_line = CommandLine::ForCurrentProcess(); + singleton_command_line->AppendSwitch(switches::kNoStartupWindow); } +} - virtual void PreMainMessageLoopStart() { - BrowserMainPartsPosix::PreMainMessageLoopStart(); - - // Tell Cooca to finish its initalization, which we want to do manually - // instead of calling NSApplicationMain(). The primary reason is that NSAM() - // never returns, which would leave all the objects currently on the stack - // in scoped_ptrs hanging and never cleaned up. We then load the main nib - // directly. The main event loop is run from common code using the - // MessageLoop API, which works out ok for us because it's a wrapper around - // CFRunLoop. - - // Initialize NSApplication using the custom subclass. - [BrowserCrApplication sharedApplication]; - - // If ui_task is not NULL, the app is actually a browser_test, so startup is - // handled outside of BrowserMain (which is what called this). - if (!parameters().ui_task) { - // The browser process only wants to support the language Cocoa will use, - // so force the app locale to be overriden with that value. - l10n_util::OverrideLocaleWithCocoaLocale(); - - // Before we load the nib, we need to start up the resource bundle so we - // have the strings avaiable for localization. - // TODO(markusheintz): Read preference pref::kApplicationLocale in order - // to enforce the application locale. - const std::string loaded_locale = - ResourceBundle::InitSharedInstance(std::string()); - CHECK(!loaded_locale.empty()) << "Default locale could not be found"; - - FilePath resources_pack_path; - PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); - ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); - } - - // Now load the nib (from the right bundle). - scoped_nsobject<NSNib> - nib([[NSNib alloc] initWithNibNamed:@"MainMenu" - bundle:base::mac::MainAppBundle()]); - // TODO(viettrungluu): crbug.com/20504 - This currently leaks, so if you - // change this, you'll probably need to change the Valgrind suppression. - [nib instantiateNibWithOwner:NSApp topLevelObjects:nil]; - // Make sure the app controller has been created. - DCHECK([NSApp delegate]); - - // This is a no-op if the KeystoneRegistration framework is not present. - // The framework is only distributed with branded Google Chrome builds. - [[KeystoneGlue defaultKeystoneGlue] registerWithKeystone]; - - // Prevent Cocoa from turning command-line arguments into - // |-application:openFiles:|, since we already handle them directly. - [[NSUserDefaults standardUserDefaults] - setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; +void BrowserMainPartsMac::PreMainMessageLoopStart() { + BrowserMainPartsPosix::PreMainMessageLoopStart(); + + // Tell Cooca to finish its initialization, which we want to do manually + // instead of calling NSApplicationMain(). The primary reason is that NSAM() + // never returns, which would leave all the objects currently on the stack + // in scoped_ptrs hanging and never cleaned up. We then load the main nib + // directly. The main event loop is run from common code using the + // MessageLoop API, which works out ok for us because it's a wrapper around + // CFRunLoop. + + // Initialize NSApplication using the custom subclass. + [BrowserCrApplication sharedApplication]; + + // If ui_task is not NULL, the app is actually a browser_test, so startup is + // handled outside of BrowserMain (which is what called this). + if (!parameters().ui_task) { + // The browser process only wants to support the language Cocoa will use, + // so force the app locale to be overriden with that value. + l10n_util::OverrideLocaleWithCocoaLocale(); + + // Before we load the nib, we need to start up the resource bundle so we + // have the strings avaiable for localization. + // TODO(markusheintz): Read preference pref::kApplicationLocale in order + // to enforce the application locale. + const std::string loaded_locale = + ResourceBundle::InitSharedInstance(std::string()); + CHECK(!loaded_locale.empty()) << "Default locale could not be found"; + + FilePath resources_pack_path; + PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); + ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); } - private: - virtual void 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(); - } - } -}; + // Now load the nib (from the right bundle). + scoped_nsobject<NSNib> + nib([[NSNib alloc] initWithNibNamed:@"MainMenu" + bundle:base::mac::MainAppBundle()]); + // TODO(viettrungluu): crbug.com/20504 - This currently leaks, so if you + // change this, you'll probably need to change the Valgrind suppression. + [nib instantiateNibWithOwner:NSApp topLevelObjects:nil]; + // Make sure the app controller has been created. + DCHECK([NSApp delegate]); + + // This is a no-op if the KeystoneRegistration framework is not present. + // The framework is only distributed with branded Google Chrome builds. + [[KeystoneGlue defaultKeystoneGlue] registerWithKeystone]; + + // Prevent Cocoa from turning command-line arguments into + // |-application:openFiles:|, since we already handle them directly. + [[NSUserDefaults standardUserDefaults] + setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; +} -// static -BrowserMainParts* BrowserMainParts::CreateBrowserMainParts( - const MainFunctionParams& parameters) { - return new BrowserMainPartsMac(parameters); + 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 cd88cc7..518daaa 100644 --- a/chrome/browser/browser_main_posix.cc +++ b/chrome/browser/browser_main_posix.cc @@ -186,6 +186,11 @@ void SetFileDescriptorLimit(unsigned int max_descriptors) { // BrowserMainPartsPosix ------------------------------------------------------- +BrowserMainPartsPosix::BrowserMainPartsPosix( + const MainFunctionParams& parameters) + : ChromeBrowserMainParts(parameters) { +} + void BrowserMainPartsPosix::PreEarlyInitialization() { // We need to accept SIGCHLD, even though our handler is a no-op because // otherwise we cannot wait on children. (According to POSIX 2001.) diff --git a/chrome/browser/browser_main_posix.h b/chrome/browser/browser_main_posix.h index 817565a..0b83fdd 100644 --- a/chrome/browser/browser_main_posix.h +++ b/chrome/browser/browser_main_posix.h @@ -7,14 +7,12 @@ #include "chrome/browser/browser_main.h" -class BrowserMainPartsPosix : public BrowserMainParts { +class BrowserMainPartsPosix : public ChromeBrowserMainParts { public: - explicit BrowserMainPartsPosix(const MainFunctionParams& parameters) - : BrowserMainParts(parameters) {} + explicit BrowserMainPartsPosix(const MainFunctionParams& parameters); - protected: - virtual void PreEarlyInitialization(); - virtual void PostMainMessageLoopStart(); + virtual void PreEarlyInitialization() OVERRIDE; + virtual void PostMainMessageLoopStart() OVERRIDE; private: #if !defined(OS_MACOSX) diff --git a/chrome/browser/browser_main_unittest.cc b/chrome/browser/browser_main_unittest.cc index f14e5b2..5d609d85 100644 --- a/chrome/browser/browser_main_unittest.cc +++ b/chrome/browser/browser_main_unittest.cc @@ -7,8 +7,11 @@ #include <string> #include <vector> #include "base/command_line.h" +#include "base/memory/scoped_ptr.h" +#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/base/testing_pref_service.h" +#include "content/browser/content_browser_client.h" #include "content/common/main_function_params.h" #include "content/common/sandbox_init_wrapper.h" #include "net/socket/client_socket_pool_base.h" @@ -32,10 +35,12 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) { scoped_ptr<MainFunctionParams> params( new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL)); - scoped_ptr<BrowserMainParts> bw(BrowserMainParts::CreateBrowserMainParts( - *params)); + scoped_ptr<content::BrowserMainParts> bw( + content::GetContentClient()->browser()->CreateBrowserMainParts( + *params)); - bw->WarmConnectionFieldTrial(); + ChromeBrowserMainParts* cbw = static_cast<ChromeBrowserMainParts*>(bw.get()); + cbw->WarmConnectionFieldTrial(); EXPECT_EQ(0, net::GetSocketReusePolicy()); } @@ -43,12 +48,14 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) { TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Random) { scoped_ptr<MainFunctionParams> params( new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL)); - scoped_ptr<BrowserMainParts> bw(BrowserMainParts::CreateBrowserMainParts( - *params)); + scoped_ptr<content::BrowserMainParts> bw( + content::GetContentClient()->browser()->CreateBrowserMainParts( + *params)); + ChromeBrowserMainParts* cbw = static_cast<ChromeBrowserMainParts*>(bw.get()); const int kNumRuns = 1000; for (int i = 0; i < kNumRuns; i++) { - bw->WarmConnectionFieldTrial(); + cbw->WarmConnectionFieldTrial(); int val = net::GetSocketReusePolicy(); EXPECT_LE(val, 2); EXPECT_GE(val, 0); @@ -60,9 +67,17 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Invalid) { scoped_ptr<MainFunctionParams> params( new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL)); - scoped_ptr<BrowserMainParts> bw(BrowserMainParts::CreateBrowserMainParts( - *params)); - - EXPECT_DEBUG_DEATH(bw->WarmConnectionFieldTrial(), + // This test ends up launching a new process, and that doesn't initialize the + // ContentClient interfaces. + scoped_ptr<content::BrowserMainParts> bw; + if (content::GetContentClient()) { + bw.reset(content::GetContentClient()->browser()->CreateBrowserMainParts( + *params)); + } else { + chrome::ChromeContentBrowserClient ccbc; + bw.reset(ccbc.CreateBrowserMainParts(*params)); + } + ChromeBrowserMainParts* cbw = static_cast<ChromeBrowserMainParts*>(bw.get()); + EXPECT_DEBUG_DEATH(cbw->WarmConnectionFieldTrial(), "Not a valid socket reuse policy group"); } diff --git a/chrome/browser/browser_main_win.cc b/chrome/browser/browser_main_win.cc index 9f22b2d..6fbd782 100644 --- a/chrome/browser/browser_main_win.cc +++ b/chrome/browser/browser_main_win.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/browser_main.h" #include "chrome/browser/browser_main_win.h" #include <windows.h> @@ -62,10 +61,14 @@ void InitializeWindowProcExceptions() { } } // namespace +namespace content { + void DidEndMainMessageLoop() { OleUninitialize(); } +} + void RecordBreakpadStatusUMA(MetricsService* metrics) { DWORD len = ::GetEnvironmentVariableW( ASCIIToWide(env_vars::kNoOOBreakpad).c_str() , NULL, 0); @@ -280,47 +283,37 @@ bool CheckMachineLevelInstall() { // BrowserMainPartsWin --------------------------------------------------------- -class BrowserMainPartsWin : public BrowserMainParts { - public: - explicit BrowserMainPartsWin(const MainFunctionParams& parameters) - : BrowserMainParts(parameters) {} +BrowserMainPartsWin::BrowserMainPartsWin(const MainFunctionParams& parameters) + : ChromeBrowserMainParts(parameters) { +} - protected: - virtual void PreEarlyInitialization() { - // Initialize Winsock. - net::EnsureWinsockInit(); - } +void BrowserMainPartsWin::PreEarlyInitialization() { + // Initialize Winsock. + net::EnsureWinsockInit(); +} - virtual void PreMainMessageLoopStart() { - OleInitialize(NULL); +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(); + // 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(); - } + // Make sure that we know how to handle exceptions from the message loop. + InitializeWindowProcExceptions(); } +} - private: - virtual void 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(); - } +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(); } -}; - -// static -BrowserMainParts* BrowserMainParts::CreateBrowserMainParts( - const MainFunctionParams& parameters) { - return new BrowserMainPartsWin(parameters); } diff --git a/chrome/browser/browser_main_win.h b/chrome/browser/browser_main_win.h index 3548605..6183a18 100644 --- a/chrome/browser/browser_main_win.h +++ b/chrome/browser/browser_main_win.h @@ -8,6 +8,8 @@ #define CHROME_BROWSER_BROWSER_MAIN_WIN_H_ #pragma once +#include "chrome/browser/browser_main.h" + class CommandLine; // Handle uninstallation when given the appropriate the command-line switch. @@ -37,4 +39,13 @@ int HandleIconsCommands(const CommandLine& parsed_command_line); // user level Chrome. bool CheckMachineLevelInstall(); +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/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index f40047f..0c5a69f 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -311,7 +311,7 @@ unsigned int BrowserProcessImpl::ReleaseModule() { FROM_HERE, NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true)); MessageLoop::current()->PostTask( - FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop)); + FROM_HERE, NewRunnableFunction(content::DidEndMainMessageLoop)); MessageLoop::current()->Quit(); } return module_ref_count_; diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 1c8d9ce..3e6639c9 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -73,6 +73,7 @@ #if defined(OS_LINUX) #include "base/linux_util.h" +#include "chrome/browser/browser_main_gtk.h" #include "chrome/browser/crash_handler_host_linux.h" #endif @@ -84,6 +85,13 @@ #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" #elif defined(OS_MACOSX) #include "chrome/browser/tab_contents/tab_contents_view_mac.h" +#include "chrome/browser/browser_main_mac.h" +#endif + +#if defined(OS_WIN) +#include "chrome/browser/browser_main_win.h" +#elif defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/browser_main_chromeos.h" #endif #if defined(USE_NSS) @@ -113,6 +121,21 @@ static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { namespace chrome { +content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( + const MainFunctionParams& parameters) { +#if defined(OS_WIN) + return new BrowserMainPartsWin(parameters); +#elif defined(OS_MACOSX) + return new BrowserMainPartsMac(parameters); +#elif defined(OS_CHROMEOS) + return new BrowserMainPartsChromeos(parameters); +#elif defined(OS_LINUX) + return new BrowserMainPartsGtk(parameters); +#else + return NULL; +#endif +} + TabContentsView* ChromeContentBrowserClient::CreateTabContentsView( TabContents* tab_contents) { #if defined(TOUCH_UI) diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index 7d5e322..239bb30 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -15,6 +15,8 @@ namespace chrome { class ChromeContentBrowserClient : public content::ContentBrowserClient { public: + virtual content::BrowserMainParts* CreateBrowserMainParts( + const MainFunctionParams& parameters) OVERRIDE; virtual TabContentsView* CreateTabContentsView( TabContents* tab_contents) OVERRIDE; virtual void RenderViewHostCreated(RenderViewHost* render_view_host) OVERRIDE; diff --git a/chrome/browser/chromeos/browser_main_chromeos.cc b/chrome/browser/chromeos/browser_main_chromeos.cc index 776a82b..93be779 100644 --- a/chrome/browser/chromeos/browser_main_chromeos.cc +++ b/chrome/browser/chromeos/browser_main_chromeos.cc @@ -4,8 +4,15 @@ #include "chrome/browser/chromeos/browser_main_chromeos.h" +#include "base/command_line.h" #include "base/lazy_instance.h" #include "base/message_loop.h" +#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/common/chrome_switches.h" +#include "content/common/main_function_params.h" +#include "net/base/network_change_notifier.h" #include <gtk/gtk.h> @@ -41,14 +48,36 @@ class MessageLoopObserver : public MessageLoopForUI::Observer { static base::LazyInstance<MessageLoopObserver> g_message_loop_observer( base::LINKER_INITIALIZED); +BrowserMainPartsChromeos::BrowserMainPartsChromeos( + const MainFunctionParams& parameters) + : BrowserMainPartsGtk(parameters) { +} +BrowserMainPartsChromeos::~BrowserMainPartsChromeos() { + if (!parameters().ui_task && chromeos::CrosLibrary::Get()) + chromeos::CrosLibrary::Shutdown(); + + // To be precise, logout (browser shutdown) is not yet done, but the + // remaining work is negligible, hence we say LogoutDone here. + chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", + false); + chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); +} + +void BrowserMainPartsChromeos::PreMainMessageLoopStart() { + // Initialize CrosLibrary only for the browser, unless running tests + // (which do their own CrosLibrary setup). + if (!parameters().ui_task) { + bool use_stub = parameters().command_line_.HasSwitch(switches::kStubCros); + chromeos::CrosLibrary::Initialize(use_stub); + } + // Replace the default NetworkChangeNotifierFactory with ChromeOS specific + // implementation. + net::NetworkChangeNotifier::SetFactory( + new chromeos::CrosNetworkChangeNotifierFactory()); +} + void BrowserMainPartsChromeos::PostMainMessageLoopStart() { BrowserMainPartsPosix::PostMainMessageLoopStart(); MessageLoopForUI* message_loop = MessageLoopForUI::current(); message_loop->AddObserver(g_message_loop_observer.Pointer()); } - -// static -BrowserMainParts* BrowserMainParts::CreateBrowserMainParts( - const MainFunctionParams& parameters) { - return new BrowserMainPartsChromeos(parameters); -} diff --git a/chrome/browser/chromeos/browser_main_chromeos.h b/chrome/browser/chromeos/browser_main_chromeos.h index b2fb924..61d281e 100644 --- a/chrome/browser/chromeos/browser_main_chromeos.h +++ b/chrome/browser/chromeos/browser_main_chromeos.h @@ -9,11 +9,14 @@ class BrowserMainPartsChromeos : public BrowserMainPartsGtk { public: - explicit BrowserMainPartsChromeos(const MainFunctionParams& parameters) - : BrowserMainPartsGtk(parameters) {} + explicit BrowserMainPartsChromeos(const MainFunctionParams& parameters); - protected: - virtual void PostMainMessageLoopStart(); + ~BrowserMainPartsChromeos(); + + virtual void PreMainMessageLoopStart() OVERRIDE; + virtual void PostMainMessageLoopStart() OVERRIDE; + + private: DISALLOW_COPY_AND_ASSIGN(BrowserMainPartsChromeos); }; diff --git a/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc b/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc index 8dfc40e..3d16dce 100644 --- a/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc +++ b/chrome/browser/chromeos/net/network_change_notifier_chromeos.cc @@ -81,6 +81,8 @@ NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() { online_notification_task_->Cancel(); online_notification_task_ = NULL; } + if (!chromeos::CrosLibrary::Get()) + return; chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()->GetNetworkLibrary(); lib->RemoveNetworkManagerObserver(this); diff --git a/chrome/browser/ui/gtk/gtk_util.cc b/chrome/browser/ui/gtk/gtk_util.cc index 25edfa6..5107045 100644 --- a/chrome/browser/ui/gtk/gtk_util.cc +++ b/chrome/browser/ui/gtk/gtk_util.cc @@ -496,35 +496,6 @@ void ConvertWidgetPointToScreen(GtkWidget* widget, gfx::Point* p) { p->SetPoint(p->x() + position.x(), p->y() + position.y()); } -void InitRCStyles() { - static const char kRCText[] = - // Make our dialogs styled like the GNOME HIG. - // - // TODO(evanm): content-area-spacing was introduced in a later - // version of GTK, so we need to set that manually on all dialogs. - // Perhaps it would make sense to have a shared FixupDialog() function. - "style \"gnome-dialog\" {\n" - " xthickness = 12\n" - " GtkDialog::action-area-border = 0\n" - " GtkDialog::button-spacing = 6\n" - " GtkDialog::content-area-spacing = 18\n" - " GtkDialog::content-area-border = 12\n" - "}\n" - // Note we set it at the "application" priority, so users can override. - "widget \"GtkDialog\" style : application \"gnome-dialog\"\n" - - // Make our about dialog special, so the image is flush with the edge. - "style \"about-dialog\" {\n" - " GtkDialog::action-area-border = 12\n" - " GtkDialog::button-spacing = 6\n" - " GtkDialog::content-area-spacing = 18\n" - " GtkDialog::content-area-border = 0\n" - "}\n" - "widget \"about-dialog\" style : application \"about-dialog\"\n"; - - gtk_rc_parse_string(kRCText); -} - GtkWidget* CenterWidgetInHBox(GtkWidget* hbox, GtkWidget* widget, bool pack_at_end, int padding) { GtkWidget* centering_vbox = gtk_vbox_new(FALSE, 0); diff --git a/chrome/browser/ui/gtk/gtk_util.h b/chrome/browser/ui/gtk/gtk_util.h index f4e89fd..f2adc4a 100644 --- a/chrome/browser/ui/gtk/gtk_util.h +++ b/chrome/browser/ui/gtk/gtk_util.h @@ -127,9 +127,6 @@ gfx::Size GetWidgetSize(GtkWidget* widget); // relative to the widget's top-left origin. void ConvertWidgetPointToScreen(GtkWidget* widget, gfx::Point* p); -// Initialize some GTK settings so that our dialogs are consistent. -void InitRCStyles(); - // Stick the widget in the given hbox without expanding vertically. The widget // is packed at the start of the hbox. This is useful for widgets that would // otherwise expand to fill the vertical space of the hbox diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 09935b4..1506f69 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -291,6 +291,7 @@ 'browser/browser_main_gtk.cc', 'browser/browser_main_gtk.h', 'browser/browser_main_mac.mm', + 'browser/browser_main_mac.h', 'browser/browser_main_posix.cc', 'browser/browser_main_posix.h', 'browser/browser_main_win.cc', diff --git a/chrome/chrome_dll.gypi b/chrome/chrome_dll.gypi index d5bc950..ea4d845 100644 --- a/chrome/chrome_dll.gypi +++ b/chrome/chrome_dll.gypi @@ -719,6 +719,7 @@ '../content/common/child_process.cc', '../content/common/child_thread.cc', '../content/common/content_client.cc', + '../content/common/content_constants.cc', '../content/common/content_counters.cc', '../content/common/content_message_generator.cc', '../content/common/content_paths.cc', diff --git a/chrome/common/chrome_constants.cc b/chrome/common/chrome_constants.cc index fe086f4..9e1bb3f 100644 --- a/chrome/common/chrome_constants.cc +++ b/chrome/common/chrome_constants.cc @@ -104,10 +104,8 @@ const char* const kHelperFlavorSuffixes[] = { const wchar_t kNaClAppName[] = L"nacl64"; #if defined(GOOGLE_CHROME_BUILD) const wchar_t kBrowserAppName[] = L"Chrome"; -const char kStatsFilename[] = "ChromeStats2"; #else const wchar_t kBrowserAppName[] = L"Chromium"; -const char kStatsFilename[] = "ChromiumStats2"; #endif #if defined(OS_WIN) @@ -158,9 +156,6 @@ const FilePath::CharType kJumpListIconDirname[] = FPL("JumpListIcons"); const FilePath::CharType kWebAppDirname[] = FPL("Web Applications"); const FilePath::CharType kServiceStateFileName[] = FPL("Service State"); -const int kStatsMaxThreads = 32; -const int kStatsMaxCounters = 3000; - // We don't enable record mode in the released product because users could // potentially be tricked into running a product in record mode without // knowing it. Enable in debug builds. Playback mode is allowed always, diff --git a/chrome/common/chrome_constants.h b/chrome/common/chrome_constants.h index 3e3acc4..7f196a3 100644 --- a/chrome/common/chrome_constants.h +++ b/chrome/common/chrome_constants.h @@ -46,7 +46,6 @@ extern const wchar_t kCrashReportLog[]; extern const wchar_t kTestingInterfaceDLL[]; extern const char kInitialProfile[]; extern const char kMultiProfileDirPrefix[]; -extern const char kStatsFilename[]; extern const wchar_t kBrowserResourcesDll[]; extern const wchar_t kNaClAppName[]; extern const FilePath::CharType kExtensionFileExtension[]; @@ -84,9 +83,6 @@ extern const FilePath::CharType kJumpListIconDirname[]; extern const FilePath::CharType kWebAppDirname[]; extern const FilePath::CharType kServiceStateFileName[]; -extern const int kStatsMaxThreads; -extern const int kStatsMaxCounters; - extern const bool kRecordModeEnabled; // Most sequence numbers are used by a renderer when responding to a browser diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 63aa4f7..9fc6437 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -101,12 +101,6 @@ const char kAutomationReinitializeOnChannelError[] = const char kBlockReadingThirdPartyCookies[] = "block-reading-third-party-cookies"; -// Causes the browser process to throw an assertion on startup. -const char kBrowserAssertTest[] = "assert-test"; - -// Causes the browser process to crash on startup. -const char kBrowserCrashTest[] = "crash-test"; - // How often (in seconds) to check for updates. Should only be used for // testing purposes. const char kCheckForUpdateIntervalSec[] = "check-for-update-interval"; @@ -303,9 +297,6 @@ const char kDisableSanitizedClientSidePhishingDetection[] = // Disable site-specific tailoring to compatibility issues in WebKit. const char kDisableSiteSpecificQuirks[] = "disable-site-specific-quirks"; -// Disable False Start in SSL and TLS connections. -const char kDisableSSLFalseStart[] = "disable-ssl-false-start"; - // Disable SSL v3 (usually for testing purposes). const char kDisableSSL3[] = "disable-ssl3"; @@ -441,11 +432,6 @@ const char kEnableConnectBackupJobs[] = "enable-connect-backup-jobs"; // Enables web developers to create apps for Chrome without using crx packages. const char kEnableCrxlessWebApps[] = "enable-crxless-web-apps"; -// Enable DNS side checking of certificates. Still experimental, should only -// be used by developers at the current time. -const char kEnableDNSCertProvenanceChecking[] = - "enable-dns-cert-provenance-checking"; - // Enables extension APIs that are in development. const char kEnableExperimentalExtensionApis[] = "enable-experimental-extension-apis"; @@ -502,9 +488,6 @@ const char kEnableNaCl[] = "enable-nacl"; // Enables debugging via RSP over a socket. const char kEnableNaClDebug[] = "enable-nacl-debug"; -// Enables TLS origin bound certificate extension. -const char kEnableOriginBoundCerts[] = "enable-origin-bound-certs"; - // Enable content settings based on host *and* plug-in. const char kEnableResourceContentSettings[] = "enable-resource-content-settings"; @@ -524,10 +507,6 @@ const char kEnableShortcutsProvider[] = "enable-shortcuts-provider"; // On platforms that support it, enable smooth scroll animation. const char kEnableSmoothScrolling[] = "enable-smooth-scrolling"; - -// Enables TLS cached info extension. -const char kEnableSSLCachedInfo[] = "enable-ssl-cached-info"; - // Enable OAuth sign-in for sync. const char kEnableSyncOAuth[] = "enable-sync-oauth"; @@ -547,10 +526,6 @@ const char kEnableTabGroupsContextMenu[] = "enable-tab-groups-context-menu"; // Enable the "synced bookmarks" folder. const char kEnableSyncedBookmarksFolder[] = "enable-synced-bookmarks-folder"; -// Enable use of experimental TCP sockets API for sending data in the -// SYN packet. -const char kEnableTcpFastOpen[] = "enable-tcp-fastopen"; - // Enables the option to show tabs as a vertical stack down the side of the // browser window. const char kEnableVerticalTabs[] = "enable-vertical-tabs"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 997aabe..36b2e53 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -45,8 +45,6 @@ extern const char kAuthServerWhitelist[]; extern const char kAutomationClientChannelID[]; extern const char kAutomationReinitializeOnChannelError[]; extern const char kBlockReadingThirdPartyCookies[]; -extern const char kBrowserAssertTest[]; -extern const char kBrowserCrashTest[]; extern const char kCheckForUpdateIntervalSec[]; extern const char kChromeVersion[]; extern const char kCipherSuiteBlacklist[]; @@ -92,7 +90,6 @@ extern const char kDisableRestoreBackgroundContents[]; extern const char kDisableSanitizedClientSidePhishingDetection[]; extern const char kDisableSiteSpecificQuirks[]; extern const char kDisableSSL3[]; -extern const char kDisableSSLFalseStart[]; extern const char kDisableSync[]; extern const char kDisableSyncApps[]; extern const char kDisableSyncAutofill[]; @@ -129,7 +126,6 @@ extern const char kEnableCloudPrint[]; extern const char kEnableCompositeToTexture[]; extern const char kEnableConnectBackupJobs[]; extern const char kEnableCrxlessWebApps[]; -extern const char kEnableDNSCertProvenanceChecking[]; extern const char kEnableExperimentalExtensionApis[]; extern const char kEnableExtensionTimelineApi[]; extern const char kEnableFastback[]; @@ -144,21 +140,18 @@ extern const char kEnableMacCookies[]; extern const char kEnableMemoryInfo[]; extern const char kEnableNaCl[]; extern const char kEnableNaClDebug[]; -extern const char kEnableOriginBoundCerts[]; extern const char kEnablePanels[]; extern const char kEnablePreconnect[]; extern const char kEnableResourceContentSettings[]; extern const char kEnableSearchProviderApiV2[]; extern const char kEnableShortcutsProvider[]; extern const char kEnableSmoothScrolling[]; -extern const char kEnableSSLCachedInfo[]; extern const char kEnableSyncOAuth[]; extern const char kEnableSyncSearchEngines[]; extern const char kEnableSyncSessions[]; extern const char kEnableSyncSessionsForOtherClients[]; extern const char kEnableSyncedBookmarksFolder[]; extern const char kEnableTabGroupsContextMenu[]; -extern const char kEnableTcpFastOpen[]; extern const char kEnableTopSites[]; extern const char kEnableVerticalTabs[]; extern const char kEnableWatchdog[]; diff --git a/content/app/content_main.cc b/content/app/content_main.cc index 971766d..eacb2bd 100644 --- a/content/app/content_main.cc +++ b/content/app/content_main.cc @@ -12,15 +12,19 @@ #include "base/logging.h" #include "base/mac/scoped_nsautorelease_pool.h" #include "base/memory/scoped_ptr.h" +#include "base/metrics/stats_table.h" #include "base/process_util.h" #include "base/stringprintf.h" +#include "base/string_number_conversions.h" #include "content/app/content_main_delegate.h" +#include "content/common/content_constants.h" #include "content/common/content_paths.h" #include "content/common/content_switches.h" #include "content/common/main_function_params.h" #include "content/common/sandbox_init_wrapper.h" #include "content/common/set_process_title.h" #include "crypto/nss_util.h" +#include "ipc/ipc_switches.h" #include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_paths.h" @@ -53,6 +57,7 @@ int tc_set_new_mode(int mode); } #endif +extern int BrowserMain(const MainFunctionParams&); extern int RendererMain(const MainFunctionParams&); extern int GpuMain(const MainFunctionParams&); extern int PluginMain(const MainFunctionParams&); @@ -184,6 +189,27 @@ void CommonSubprocessInit(const std::string& process_type) { #endif } +void InitializeStatsTable(base::ProcessId browser_pid, + const CommandLine& command_line) { + // Initialize the Stats Counters table. With this initialized, + // the StatsViewer can be utilized to read counters outside of + // Chrome. These lines can be commented out to effectively turn + // counters 'off'. The table is created and exists for the life + // of the process. It is not cleaned up. + if (command_line.HasSwitch(switches::kEnableStatsTable) || + command_line.HasSwitch(switches::kEnableBenchmarking)) { + // NOTIMPLEMENTED: we probably need to shut this down correctly to avoid + // leaking shared memory regions on posix platforms. + std::string statsfile = + base::StringPrintf("%s-%u", + content::kStatsFilename, + static_cast<unsigned int>(browser_pid)); + base::StatsTable* stats_table = new base::StatsTable(statsfile, + content::kStatsMaxThreads, content::kStatsMaxCounters); + base::StatsTable::set_current(stats_table); + } +} + // We dispatch to a process-type-specific FooMain() based on a command-line // flag. This struct is used to build a table of (flag, main function) pairs. struct MainFunction { @@ -217,6 +243,13 @@ int RunZygote(const MainFunctionParams& main_function_params, // line so update it here with the new version. const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + // The StatsTable must be initialized in each process; we already + // initialized for the browser process, now we need to initialize + // within the new processes as well. + pid_t browser_pid = base::GetParentProcessId( + base::GetParentProcessId(base::GetCurrentProcId())); + InitializeStatsTable(browser_pid, command_line); + MainFunctionParams main_params(command_line, main_function_params.sandbox_info_, main_function_params.autorelease_pool_); @@ -244,6 +277,7 @@ int RunNamedProcessTypeMain(const std::string& process_type, const MainFunctionParams& main_function_params, content::ContentMainDelegate* delegate) { static const MainFunction kMainFunctions[] = { + { "", BrowserMain }, { switches::kRendererProcess, RendererMain }, { switches::kPluginProcess, PluginMain }, { switches::kWorkerProcess, WorkerMain }, @@ -389,6 +423,24 @@ int ContentMain(int argc, CHECK(icu_util::Initialize()); + base::ProcessId browser_pid = base::GetCurrentProcId(); + if (command_line.HasSwitch(switches::kProcessChannelID)) { +#if defined(OS_WIN) || defined(OS_MACOSX) + std::string channel_name = + command_line.GetSwitchValueASCII(switches::kProcessChannelID); + + int browser_pid_int; + base::StringToInt(channel_name, &browser_pid_int); + browser_pid = static_cast<base::ProcessId>(browser_pid_int); + DCHECK_NE(browser_pid_int, 0); +#elif defined(OS_POSIX) + // On linux, we're in the zygote here; so we need the parent process' id. + browser_pid = base::GetParentProcessId(base::GetCurrentProcId()); +#endif + } + + InitializeStatsTable(browser_pid, command_line); + if (delegate) delegate->PreSandboxStartup(); if (!process_type.empty()) diff --git a/content/browser/browser_main.cc b/content/browser/browser_main.cc new file mode 100644 index 0000000..7d7a599 --- /dev/null +++ b/content/browser/browser_main.cc @@ -0,0 +1,319 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/browser_main.h" + +#include "base/allocator/allocator_shim.h" +#include "base/command_line.h" +#include "base/debug/trace_event.h" +#include "base/logging.h" +#include "base/metrics/field_trial.h" +#include "base/metrics/histogram.h" +#include "base/system_monitor/system_monitor.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/sandbox_policy.h" +#include "net/base/network_change_notifier.h" +#include "net/base/ssl_config_service.h" +#include "net/socket/tcp_client_socket.h" + +#if defined(OS_WIN) +#include <windows.h> +#include <commctrl.h> +#include <shellapi.h> + +#include "sandbox/src/sandbox.h" +#endif + +#if defined(OS_POSIX) && !defined(OS_MACOSX) +#include <dbus/dbus-glib.h> +#endif + +#if defined(TOOLKIT_USES_GTK) +#include "ui/gfx/gtk_util.h" +#endif + +namespace { + +// Windows-specific initialization code for the sandbox broker services. This +// is just a NOP on non-Windows platforms to reduce ifdefs later on. +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) { + sandbox::InitBrokerServices(broker_services); + if (!parsed_command_line.HasSwitch(switches::kNoSandbox)) { + bool use_winsta = !parsed_command_line.HasSwitch( + switches::kDisableAltWinstation); + // Precreate the desktop and window station used by the renderers. + sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); + sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); + CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); + policy->Release(); + } + } +#endif +} + +#if defined(TOOLKIT_USES_GTK) +static void GLibLogHandler(const gchar* log_domain, + GLogLevelFlags log_level, + const gchar* message, + gpointer userdata) { + if (!log_domain) + log_domain = "<unknown>"; + if (!message) + message = "<no message>"; + + if (strstr(message, "Loading IM context type") || + strstr(message, "wrong ELF class: ELFCLASS64")) { + // http://crbug.com/9643 + // Until we have a real 64-bit build or all of these 32-bit package issues + // are sorted out, don't fatal on ELF 32/64-bit mismatch warnings and don't + // spam the user with more than one of them. + static bool alerted = false; + if (!alerted) { + LOG(ERROR) << "Bug 9643: " << log_domain << ": " << message; + alerted = true; + } + } else if (strstr(message, "Theme file for default has no") || + strstr(message, "Theme directory") || + strstr(message, "theme pixmap")) { + LOG(ERROR) << "GTK theme error: " << message; + } else if (strstr(message, "gtk_drag_dest_leave: assertion")) { + LOG(ERROR) << "Drag destination deleted: http://crbug.com/18557"; + } else if (strstr(message, "Out of memory") && + strstr(log_domain, "<unknown>")) { + LOG(ERROR) << "DBus call timeout or out of memory: " + << "http://crosbug.com/15496"; + } else { + LOG(DFATAL) << log_domain << ": " << message; + } +} + +static void SetUpGLibLogHandler() { + // Register GLib-handled assertions to go through our logging system. + const char* kLogDomains[] = { NULL, "Gtk", "Gdk", "GLib", "GLib-GObject" }; + for (size_t i = 0; i < arraysize(kLogDomains); i++) { + g_log_set_handler(kLogDomains[i], + static_cast<GLogLevelFlags>(G_LOG_FLAG_RECURSION | + G_LOG_FLAG_FATAL | + G_LOG_LEVEL_ERROR | + G_LOG_LEVEL_CRITICAL | + G_LOG_LEVEL_WARNING), + GLibLogHandler, + NULL); + } +} +#endif + +} // namespace + +namespace content { + +BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters) + : parameters_(parameters), + parsed_command_line_(parameters.command_line_) { +} + +BrowserMainParts::~BrowserMainParts() { +} + +void BrowserMainParts::EarlyInitialization() { + PreEarlyInitialization(); + + if (parsed_command_line().HasSwitch(switches::kEnableBenchmarking)) + base::FieldTrial::EnableBenchmarking(); + + InitializeSSL(); + + if (parsed_command_line().HasSwitch(switches::kDisableSSLFalseStart)) + net::SSLConfigService::DisableFalseStart(); + if (parsed_command_line().HasSwitch(switches::kEnableSSLCachedInfo)) + net::SSLConfigService::EnableCachedInfo(); + if (parsed_command_line().HasSwitch(switches::kEnableOriginBoundCerts)) + net::SSLConfigService::EnableOriginBoundCerts(); + if (parsed_command_line().HasSwitch( + switches::kEnableDNSCertProvenanceChecking)) { + net::SSLConfigService::EnableDNSCertProvenanceChecking(); + } + + // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't + // seem dependent on InitializeSSL(). + if (parsed_command_line().HasSwitch(switches::kEnableTcpFastOpen)) + net::set_tcp_fastopen_enabled(true); + + PostEarlyInitialization(); +} + +void BrowserMainParts::MainMessageLoopStart() { + PreMainMessageLoopStart(); + + main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); + + // TODO(viettrungluu): should these really go before setting the thread name? + system_monitor_.reset(new base::SystemMonitor); + hi_res_timer_manager_.reset(new HighResolutionTimerManager); + + InitializeMainThread(); + + network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); + + PostMainMessageLoopStart(); +} + +void BrowserMainParts::InitializeMainThread() { + const char* kThreadName = "CrBrowserMain"; + base::PlatformThread::SetName(kThreadName); + main_message_loop().set_thread_name(kThreadName); + + // Register the main thread by instantiating it, but don't call any methods. + main_thread_.reset(new BrowserThread(BrowserThread::UI, + MessageLoop::current())); +} + +void BrowserMainParts::InitializeToolkit() { + // TODO(evan): this function is rather subtle, due to the variety + // of intersecting ifdefs we have. To keep it easy to follow, there + // are no #else branches on any #ifs. + +#if defined(TOOLKIT_USES_GTK) + // We want to call g_thread_init(), but in some codepaths (tests) it + // is possible it has already been called. In older versions of + // GTK, it is an error to call g_thread_init twice; unfortunately, + // the API to tell whether it has been called already was also only + // added in a newer version of GTK! Thankfully, this non-intuitive + // check is actually equivalent and sufficient to work around the + // error. + if (!g_thread_supported()) + g_thread_init(NULL); + // Glib type system initialization. Needed at least for gconf, + // used in net/proxy/proxy_config_service_linux.cc. Most likely + // this is superfluous as gtk_init() ought to do this. It's + // definitely harmless, so retained as a reminder of this + // requirement for gconf. + g_type_init(); + // We use glib-dbus for geolocation and it's possible other libraries + // (e.g. gnome-keyring) will use it, so initialize its threading here + // as well. + dbus_g_thread_init(); + gfx::GtkInitFromCommandLine(parameters().command_line_); + SetUpGLibLogHandler(); +#endif + +#if defined(TOOLKIT_GTK) + // It is important for this to happen before the first run dialog, as it + // styles the dialog as well. + gfx::InitRCStyles(); +#endif + +#if defined(OS_WIN) + // Init common control sex. + INITCOMMONCONTROLSEX config; + config.dwSize = sizeof(config); + config.dwICC = ICC_WIN95_CLASSES; + if (!InitCommonControlsEx(&config)) + LOG_GETLASTERROR(FATAL); +#endif + + ToolkitInitialized(); +} + +void BrowserMainParts::PreEarlyInitialization() { +} + +void BrowserMainParts::PostEarlyInitialization() { +} + +void BrowserMainParts::PreMainMessageLoopStart() { +} + +void BrowserMainParts::PostMainMessageLoopStart() { +} + +void BrowserMainParts::InitializeSSL() { +} + +void BrowserMainParts::ToolkitInitialized() { +} + +int BrowserMainParts::TemporaryContinue() { + return 0; +} + +} // namespace content + +// Main routine for running as the Browser process. +int BrowserMain(const MainFunctionParams& parameters) { + TRACE_EVENT_BEGIN_ETW("BrowserMain", 0, ""); + + scoped_ptr<content::BrowserMainParts> parts( + content::GetContentClient()->browser()->CreateBrowserMainParts( + parameters)); + + parts->EarlyInitialization(); + + // Must happen before we try to use a message loop or display any UI. + parts->InitializeToolkit(); + + parts->MainMessageLoopStart(); + + // WARNING: If we get a WM_ENDSESSION, objects created on the stack here + // are NOT deleted. If you need something to run during WM_ENDSESSION add it + // to browser_shutdown::Shutdown or BrowserProcess::EndSession. + + // !!!!!!!!!! READ ME !!!!!!!!!! + // I (viettrungluu) am in the process of refactoring |BrowserMain()|. If you + // need to add something above this comment, read the documentation in + // browser_main.h. If you need to add something below, please do the + // following: + // - Figure out where you should add your code. Do NOT just pick a random + // location "which works". + // - Document the dependencies apart from compile-time-checkable ones. What + // must happen before your new code is executed? Does your new code need to + // run before something else? Are there performance reasons for executing + // your code at that point? + // - If you need to create a (persistent) object, heap allocate it and keep a + // |scoped_ptr| to it rather than allocating it on the stack. Otherwise + // I'll have to convert your code when I refactor. + // - Unless your new code is just a couple of lines, factor it out into a + // function with a well-defined purpose. Do NOT just add it inline in + // |BrowserMain()|. + // Thanks! + + // TODO(viettrungluu): put the remainder into BrowserMainParts + const CommandLine& parsed_command_line = parameters.command_line_; + +#if defined(OS_WIN) && !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 + + // 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); + + // 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); + + TRACE_EVENT_END_ETW("BrowserMain", 0, 0); + return result_code; +} diff --git a/content/browser/browser_main.h b/content/browser/browser_main.h new file mode 100644 index 0000000..931bd9a --- /dev/null +++ b/content/browser/browser_main.h @@ -0,0 +1,133 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_BROWSER_MAIN_H_ +#define CONTENT_BROWSER_BROWSER_MAIN_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" + +class BrowserThread; +class CommandLine; +class HighResolutionTimerManager; +class MessageLoop; +struct MainFunctionParams; + +namespace base { +class SystemMonitor; +} + +namespace net { +class NetworkChangeNotifier; +} + +namespace content { + +// BrowserMainParts: +// This class contains different "stages" to be executed in |BrowserMain()|, +// mostly initialization. This is made into a class rather than just functions +// so each stage can create and maintain state. Each part is represented by a +// single method (e.g., "EarlyInitialization()"), which does the following: +// - calls a method (e.g., "PreEarlyInitialization()") which individual +// platforms can override to provide platform-specific code which is to be +// executed before the common code; +// - calls various methods for things common to all platforms (for that given +// stage); and +// - calls a method (e.g., "PostEarlyInitialization()") for platform-specific +// code to be called after the common code. +// As indicated above, platforms should override the default "Pre...()" and +// "Post...()" methods when necessary; they need not call the superclass's +// implementation (which is empty). +// +// Parts: +// - EarlyInitialization: things which should be done as soon as possible on +// program start (such as setting up signal handlers) and things to be done +// at some generic time before the start of the main message loop. +// - MainMessageLoopStart: things beginning with the start of the main message +// loop and ending with initialization of the main thread; platform-specific +// things which should be done immediately before the start of the main +// message loop should go in |PreMainMessageLoopStart()|. +// - (more to come) +// +// How to add stuff (to existing parts): +// - Figure out when your new code should be executed. What must happen +// before/after your code is executed? Are there performance reasons for +// running your code at a particular time? Document these things! +// - Split out any platform-specific bits. Please avoid #ifdefs it at all +// possible. You have two choices for platform-specific code: (1) Execute it +// from one of the platform-specific |Pre/Post...()| methods; do this if the +// code is unique to a platform type. Or (2) execute it from one of the +// "parts" (e.g., |EarlyInitialization()|) and provide platform-specific +// implementations of your code (in a virtual method); do this if you need to +// provide different implementations across most/all platforms. +// - Unless your new code is just one or two lines, put it into a separate +// method with a well-defined purpose. (Likewise, if you're adding to an +// existing chunk which makes it longer than one or two lines, please move +// the code out into a separate method.) +class BrowserMainParts { + public: + explicit BrowserMainParts(const MainFunctionParams& parameters); + virtual ~BrowserMainParts(); + + // Parts to be called by |BrowserMain()|. + void EarlyInitialization(); + void MainMessageLoopStart(); + void InitializeToolkit(); + + // Temporary function since not all the code from chrome is moved over yet. + virtual int TemporaryContinue(); + + protected: + // Methods to be overridden to provide platform-specific code; these + // correspond to the "parts" above. + virtual void PreEarlyInitialization(); + virtual void PostEarlyInitialization(); + virtual void PreMainMessageLoopStart(); + virtual void PostMainMessageLoopStart(); + + // Used to initialize NSPR where appropriate. + virtual void InitializeSSL(); + + // Allows an embedder to do any extra toolkit initialization. + virtual void ToolkitInitialized(); + + // Accessors for data members (below) ---------------------------------------- + const MainFunctionParams& parameters() const { + return parameters_; + } + const CommandLine& parsed_command_line() const { + return parsed_command_line_; + } + MessageLoop& main_message_loop() const { + return *main_message_loop_; + } + + private: + void InitializeMainThread(); + + // Members initialized on construction --------------------------------------- + + const MainFunctionParams& parameters_; + const CommandLine& parsed_command_line_; + + // Members initialized in |MainMessageLoopStart()| --------------------------- + scoped_ptr<MessageLoop> main_message_loop_; + scoped_ptr<base::SystemMonitor> system_monitor_; + scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_; + scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; + scoped_ptr<BrowserThread> main_thread_; + + DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); +}; + +// Perform platform-specific work that needs to be done after the main event +// loop has ended. The embedder must be sure to call this. +// TODO(jam): change this so that content calls it so that we don't depend on +// the embedder. +void DidEndMainMessageLoop(); + +} // namespace content + +#endif // CONTENT_BROWSER_BROWSER_MAIN_H_ diff --git a/content/browser/content_browser_client.h b/content/browser/content_browser_client.h index 7fdff59..32fa117 100644 --- a/content/browser/content_browser_client.h +++ b/content/browser/content_browser_client.h @@ -32,8 +32,13 @@ class TabContents; class TabContentsView; class WorkerProcessHost; struct DesktopNotificationHostMsg_Show_Params; +struct MainFunctionParams; struct WebPreferences; +namespace content { +class BrowserMainParts; +} + namespace crypto { class CryptoModuleBlockingPasswordDelegate; } @@ -59,6 +64,7 @@ class Clipboard; namespace content { class BrowserContext; +class BrowserMainParts; class ResourceContext; class WebUIFactory; @@ -74,6 +80,12 @@ class ContentBrowserClient { public: virtual ~ContentBrowserClient() {} + // Allows the embedder to return a customed BrowserMainParts implementation + // for the browser staratup code. Can return NULL, in which case the default + // is used. + virtual BrowserMainParts* CreateBrowserMainParts( + const MainFunctionParams& parameters) = 0; + virtual TabContentsView* CreateTabContentsView(TabContents* tab_contents) = 0; // Notifies that a new RenderHostView has been created. diff --git a/content/browser/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc index c47f2c5..1ab31c9 100644 --- a/content/browser/mock_content_browser_client.cc +++ b/content/browser/mock_content_browser_client.cc @@ -19,6 +19,11 @@ namespace content { MockContentBrowserClient::~MockContentBrowserClient() { } +BrowserMainParts* MockContentBrowserClient::CreateBrowserMainParts( + const MainFunctionParams& parameters) { + return NULL; +} + TabContentsView* MockContentBrowserClient::CreateTabContentsView( TabContents* tab_contents) { return new TestTabContentsView; diff --git a/content/browser/mock_content_browser_client.h b/content/browser/mock_content_browser_client.h index e2831dd..4320592 100644 --- a/content/browser/mock_content_browser_client.h +++ b/content/browser/mock_content_browser_client.h @@ -18,6 +18,8 @@ class MockContentBrowserClient : public ContentBrowserClient { public: virtual ~MockContentBrowserClient(); + virtual BrowserMainParts* CreateBrowserMainParts( + const MainFunctionParams& parameters) OVERRIDE; virtual TabContentsView* CreateTabContentsView( TabContents* tab_contents) OVERRIDE; virtual void RenderViewHostCreated( diff --git a/content/common/content_constants.cc b/content/common/content_constants.cc index 6835362..da22264 100644 --- a/content/common/content_constants.cc +++ b/content/common/content_constants.cc @@ -16,6 +16,15 @@ const size_t kMaxURLDisplayChars = 32 * 1024; const char kDefaultPluginRenderViewId[] = "PluginRenderViewId"; const char kDefaultPluginRenderProcessId[] = "PluginRenderProcessId"; -} // namespace content +#if defined(GOOGLE_CHROME_BUILD) +const wchar_t kBrowserAppName[] = L"Chrome"; +const char kStatsFilename[] = "ChromeStats2"; +#else +const wchar_t kBrowserAppName[] = L"Chromium"; +const char kStatsFilename[] = "ChromiumStats2"; +#endif + +const int kStatsMaxThreads = 32; +const int kStatsMaxCounters = 3000; -#undef FPL +} // namespace content diff --git a/content/common/content_constants.h b/content/common/content_constants.h index 1c8b680..ad900d0 100644 --- a/content/common/content_constants.h +++ b/content/common/content_constants.h @@ -35,6 +35,10 @@ extern const size_t kMaxURLDisplayChars; extern const char kDefaultPluginRenderViewId[]; extern const char kDefaultPluginRenderProcessId[]; +extern const char kStatsFilename[]; +extern const int kStatsMaxThreads; +extern const int kStatsMaxCounters; + } // namespace content #endif // CONTENT_COMMON_CHROME_CONSTANTS_H_ diff --git a/content/common/content_switches.cc b/content/common/content_switches.cc index 8657e95..70527a8 100644 --- a/content/common/content_switches.cc +++ b/content/common/content_switches.cc @@ -17,6 +17,12 @@ const char kAllowRunningInsecureContent[] = "allow-running-insecure-content"; // Allows debugging of sandboxed processes (see zygote_main_linux.cc). const char kAllowSandboxDebugging[] = "allow-sandbox-debugging"; +// Causes the browser process to throw an assertion on startup. +const char kBrowserAssertTest[] = "assert-test"; + +// Causes the browser process to crash on startup. +const char kBrowserCrashTest[] = "crash-test"; + // Path to the exe to run for the renderer and plugin subprocesses. const char kBrowserSubprocessPath[] = "browser-subprocess-path"; @@ -117,9 +123,6 @@ const char kDisableLocalStorage[] = "disable-local-storage"; // builds. const char kDisableLogging[] = "disable-logging"; -// Disable smooth scrolling for testing. -const char kDisableSmoothScrolling[] = "disable-smooth-scrolling"; - // Prevent plugins from running. const char kDisablePlugins[] = "disable-plugins"; @@ -129,6 +132,12 @@ const char kDisablePopupBlocking[] = "disable-popup-blocking"; // Turns off the accessibility in the renderer. const char kDisableRendererAccessibility[] = "disable-renderer-accessibility"; +// Disable False Start in SSL and TLS connections. +const char kDisableSSLFalseStart[] = "disable-ssl-false-start"; + +// Disable smooth scrolling for testing. +const char kDisableSmoothScrolling[] = "disable-smooth-scrolling"; + // Disable the seccomp sandbox (Linux only) const char kDisableSeccompSandbox[] = "disable-seccomp-sandbox"; @@ -168,6 +177,11 @@ const char kEnableAccessibilityLogging[] = "enable-accessibility-logging"; // Enables the benchmarking extensions. const char kEnableBenchmarking[] = "enable-benchmarking"; +// Enable DNS side checking of certificates. Still experimental, should only +// be used by developers at the current time. +const char kEnableDNSCertProvenanceChecking[] = + "enable-dns-cert-provenance-checking"; + // Enables device motion events. const char kEnableDeviceMotion[] = "enable-device-motion"; @@ -190,9 +204,15 @@ const char kEnableMediaStream[] = "enable-media-stream"; // assumed to be sRGB. const char kEnableMonitorProfile[] = "enable-monitor-profile"; +// Enables TLS origin bound certificate extension. +const char kEnableOriginBoundCerts[] = "enable-origin-bound-certs"; + // Enable caching of pre-parsed JS script data. See http://crbug.com/32407. const char kEnablePreparsedJsCaching[] = "enable-preparsed-js-caching"; +// Enables TLS cached info extension. +const char kEnableSSLCachedInfo[] = "enable-ssl-cached-info"; + // Cause the OS X sandbox write to syslog every time an access to a resource // is denied by the sandbox. const char kEnableSandboxLogging[] = "enable-sandbox-logging"; @@ -203,6 +223,10 @@ const char kEnableSeccompSandbox[] = "enable-seccomp-sandbox"; // Enables StatsTable, logging statistics to a global named shared memory table. const char kEnableStatsTable[] = "enable-stats-table"; +// Enable use of experimental TCP sockets API for sending data in the +// SYN packet. +const char kEnableTcpFastOpen[] = "enable-tcp-fastopen"; + // Enables support for fullscreen video. Current implementation is // incomplete and this flag is used for development and testing. const char kEnableVideoFullscreen[] = "enable-video-fullscreen"; diff --git a/content/common/content_switches.h b/content/common/content_switches.h index c11bb6f..653ba77 100644 --- a/content/common/content_switches.h +++ b/content/common/content_switches.h @@ -15,6 +15,8 @@ namespace switches { extern const char kAllowFileAccessFromFiles[]; extern const char kAllowRunningInsecureContent[]; extern const char kAllowSandboxDebugging[]; +extern const char kBrowserAssertTest[]; +extern const char kBrowserCrashTest[]; extern const char kBrowserSubprocessPath[]; // TODO(jam): this doesn't belong in content. extern const char kChromeFrame[]; @@ -50,6 +52,7 @@ extern const char kDisableSmoothScrolling[]; extern const char kDisablePlugins[]; extern const char kDisablePopupBlocking[]; extern const char kDisableRendererAccessibility[]; +extern const char kDisableSSLFalseStart[]; extern const char kDisableSeccompSandbox[]; extern const char kDisableSessionStorage[]; extern const char kDisableSharedWorkers[]; @@ -62,16 +65,20 @@ extern const char kEnableAcceleratedDrawing[]; extern const char kEnableAccessibility[]; extern const char kEnableAccessibilityLogging[]; extern const char kEnableBenchmarking[]; +extern const char kEnableDNSCertProvenanceChecking[]; extern const char kEnableDeviceMotion[]; extern const char kEnableFullScreen[]; extern const char kEnableGPUPlugin[]; extern const char kEnableLogging[]; extern const char kEnableMediaStream[]; extern const char kEnableMonitorProfile[]; +extern const char kEnableOriginBoundCerts[]; extern const char kEnablePreparsedJsCaching[]; +extern const char kEnableSSLCachedInfo[]; extern const char kEnableSandboxLogging[]; extern const char kEnableSeccompSandbox[]; extern const char kEnableStatsTable[]; +extern const char kEnableTcpFastOpen[]; extern const char kEnableVideoFullscreen[]; extern const char kEnableVideoLogging[]; extern const char kEnableWebIntents[]; diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 21d16c5..f153a44 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -56,6 +56,8 @@ 'browser/browser_child_process_host.cc', 'browser/browser_child_process_host.h', 'browser/browser_context.h', + 'browser/browser_main.cc', + 'browser/browser_main.h', 'browser/browser_message_filter.cc', 'browser/browser_message_filter.h', 'browser/browser_thread.cc', diff --git a/ui/gfx/gtk_util.cc b/ui/gfx/gtk_util.cc index fb5a31d..45ae56a 100644 --- a/ui/gfx/gtk_util.cc +++ b/ui/gfx/gtk_util.cc @@ -219,4 +219,33 @@ uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) { return new_pixels; } +void InitRCStyles() { + static const char kRCText[] = + // Make our dialogs styled like the GNOME HIG. + // + // TODO(evanm): content-area-spacing was introduced in a later + // version of GTK, so we need to set that manually on all dialogs. + // Perhaps it would make sense to have a shared FixupDialog() function. + "style \"gnome-dialog\" {\n" + " xthickness = 12\n" + " GtkDialog::action-area-border = 0\n" + " GtkDialog::button-spacing = 6\n" + " GtkDialog::content-area-spacing = 18\n" + " GtkDialog::content-area-border = 12\n" + "}\n" + // Note we set it at the "application" priority, so users can override. + "widget \"GtkDialog\" style : application \"gnome-dialog\"\n" + + // Make our about dialog special, so the image is flush with the edge. + "style \"about-dialog\" {\n" + " GtkDialog::action-area-border = 12\n" + " GtkDialog::button-spacing = 6\n" + " GtkDialog::content-area-spacing = 18\n" + " GtkDialog::content-area-border = 0\n" + "}\n" + "widget \"about-dialog\" style : application \"about-dialog\"\n"; + + gtk_rc_parse_string(kRCText); +} + } // namespace gfx diff --git a/ui/gfx/gtk_util.h b/ui/gfx/gtk_util.h index 7438165..71b9e52 100644 --- a/ui/gfx/gtk_util.h +++ b/ui/gfx/gtk_util.h @@ -66,6 +66,9 @@ UI_EXPORT std::string RemoveWindowsStyleAccelerators(const std::string& label); // assumed to be 4 * |width|. uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride); +// Initialize some GTK settings so that our dialogs are consistent. +void InitRCStyles(); + } // namespace gfx // It's not legal C++ to have a templatized typedefs, so we wrap it in a |