summaryrefslogtreecommitdiffstats
path: root/content/browser/browser_main.cc
diff options
context:
space:
mode:
authorstevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-26 18:03:30 +0000
committerstevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-26 18:03:30 +0000
commitb48c918f8397747d9a157a87a5cfc63eeed74710 (patch)
tree20bf06e2bb203915d5e135498538550d6b891e4f /content/browser/browser_main.cc
parent45952868429c278087b68d0e0e96f33ec70388fa (diff)
downloadchromium_src-b48c918f8397747d9a157a87a5cfc63eeed74710.zip
chromium_src-b48c918f8397747d9a157a87a5cfc63eeed74710.tar.gz
chromium_src-b48c918f8397747d9a157a87a5cfc63eeed74710.tar.bz2
Make GTK and Aura parts orthogonal to OS parts
This CL moves GTK and Aura "Parts" out of the primary BrowserMainParts tree and into orthogonal parts that can be added independently. This was done in a way that will facilitate adding additional parts if (when) we need them. The motivation for this was to a) eliminate the existing typedef in chrome_browser_main_chromeos.h b) reduce the number of #ifdefs required in the setup / parts code For an outline of the new parts see: https://docs.google.com/drawings/d/1-gIMl-81c4SvcMrT1xaxnDGibDe7VQfMkFT1bMnIvrg/edit?hl=en_US Please consider this a proposal; I am entirely open to feedback. BUG=none TEST=Chrome compiles and passes tests on all platfroms. Review URL: http://codereview.chromium.org/8302016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107383 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/browser_main.cc')
-rw-r--r--content/browser/browser_main.cc341
1 files changed, 13 insertions, 328 deletions
diff --git a/content/browser/browser_main.cc b/content/browser/browser_main.cc
index c0ef41e..9627f36 100644
--- a/content/browser/browser_main.cc
+++ b/content/browser/browser_main.cc
@@ -8,54 +8,17 @@
#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 "base/threading/thread_restrictions.h"
-#include "base/tracked_objects.h"
+#include "content/browser/browser_main_loop.h"
#include "content/browser/browser_thread.h"
#include "content/browser/notification_service_impl.h"
-#include "content/common/hi_res_timer_manager.h"
#include "content/common/main_function_params.h"
-#include "content/common/sandbox_policy.h"
-#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_switches.h"
-#include "content/public/common/result_codes.h"
-#include "crypto/nss_util.h"
-#include "net/base/network_change_notifier.h"
-#include "net/base/ssl_config_service.h"
-#include "net/socket/client_socket_factory.h"
-#include "net/socket/tcp_client_socket.h"
#if defined(OS_WIN)
-#include <windows.h>
-#include <commctrl.h>
-#include <ole2.h>
-#include <shellapi.h>
-
#include "base/win/scoped_com_initializer.h"
-#include "net/base/winsock_init.h"
+#include "content/common/sandbox_policy.h"
#include "sandbox/src/sandbox.h"
-#include "ui/base/l10n/l10n_util_win.h"
-#endif
-
-#if defined(OS_LINUX)
-#include <glib-object.h>
-#endif
-
-#if defined(OS_CHROMEOS)
-#include <dbus/dbus-glib.h>
-#endif
-
-#if defined(OS_POSIX) && !defined(OS_MACOSX)
-#include <sys/stat.h>
-
-#include "content/browser/renderer_host/render_sandbox_host_linux.h"
-#include "content/browser/zygote_host_linux.h"
-#endif
-
-#if defined(TOOLKIT_USES_GTK)
-#include "ui/gfx/gtk_util.h"
#endif
namespace {
@@ -79,292 +42,14 @@ void InitializeBrokerServices(const MainFunctionParams& parameters,
}
}
}
-#elif defined(OS_POSIX) && !defined(OS_MACOSX)
-void SetupSandbox(const CommandLine& parsed_command_line) {
- // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this
- // code en masse out of chrome_main for now.
- const char* sandbox_binary = NULL;
- struct stat st;
-
- // In Chromium branded builds, developers can set an environment variable to
- // use the development sandbox. See
- // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment
- if (stat("/proc/self/exe", &st) == 0 && st.st_uid == getuid())
- sandbox_binary = getenv("CHROME_DEVEL_SANDBOX");
-
-#if defined(LINUX_SANDBOX_PATH)
- if (!sandbox_binary)
- sandbox_binary = LINUX_SANDBOX_PATH;
-#endif
-
- std::string sandbox_cmd;
- if (sandbox_binary && !parsed_command_line.HasSwitch(switches::kNoSandbox))
- sandbox_cmd = sandbox_binary;
-
- // Tickle the sandbox host and zygote host so they fork now.
- RenderSandboxHostLinux* shost = RenderSandboxHostLinux::GetInstance();
- shost->Init(sandbox_cmd);
- ZygoteHost* zhost = ZygoteHost::GetInstance();
- zhost->Init(sandbox_cmd);
-}
#endif
-#if defined(OS_LINUX)
-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 if (strstr(message, "XDG_RUNTIME_DIR variable not set")) {
- LOG(ERROR) << message << " (http://bugs.chromium.org/97293)";
- } 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
+bool g_exited_main_message_loop = false;
} // namespace
namespace content {
-BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters)
- : parameters_(parameters),
- parsed_command_line_(parameters.command_line_),
- result_code_(content::RESULT_CODE_NORMAL_EXIT) {
-#if defined(OS_WIN)
- OleInitialize(NULL);
-#endif
-}
-
-BrowserMainParts::~BrowserMainParts() {
-#if defined(OS_WIN)
- OleUninitialize();
-#endif
-}
-
-void BrowserMainParts::EarlyInitialization() {
- PreEarlyInitialization();
-
-#if defined(OS_WIN)
- net::EnsureWinsockInit();
-#endif
-
- // Use NSS for SSL by default.
- // The default client socket factory uses NSS for SSL by default on
- // Windows and Mac.
-#if defined(OS_WIN) || defined(OS_MACOSX)
- if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) {
- net::ClientSocketFactory::UseSystemSSL();
- } else {
-#elif defined(USE_NSS)
- if (true) {
-#else
- if (false) {
-#endif
- // We want to be sure to init NSPR on the main thread.
- crypto::EnsureNSPRInit();
- }
-
-#if defined(OS_POSIX) && !defined(OS_MACOSX)
- SetupSandbox(parsed_command_line());
-#endif
-
- 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 SSL initialization().
- if (parsed_command_line().HasSwitch(switches::kEnableTcpFastOpen))
- net::set_tcp_fastopen_enabled(true);
-
- PostEarlyInitialization();
-}
-
-void BrowserMainParts::MainMessageLoopStart() {
- PreMainMessageLoopStart();
-
-#if defined(OS_WIN)
- // If we're running tests (ui_task is non-null), then the ResourceBundle
- // has already been initialized.
- if (!parameters().ui_task) {
- // Override the configured locale with the user's preferred UI language.
- l10n_util::OverrideLocaleWithUILanguageList();
- }
-#endif
-
- main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI));
-
- InitializeMainThread();
-
- system_monitor_.reset(new base::SystemMonitor);
- hi_res_timer_manager_.reset(new HighResolutionTimerManager);
-
- network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
-
- PostMainMessageLoopStart();
-}
-
-static bool g_exited_main_message_loop = false;
-
-void BrowserMainParts::RunMainMessageLoopParts() {
- PreMainMessageLoopRun();
-
- TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
- // If the UI thread blocks, the whole UI is unresponsive.
- // Do not allow disk IO from the UI thread.
- base::ThreadRestrictions::SetIOAllowed(false);
- MainMessageLoopRun();
- TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
-
- g_exited_main_message_loop = true;
-
- PostMainMessageLoopRun();
-}
-
-void BrowserMainParts::InitializeMainThread() {
- const char* kThreadName = "CrBrowserMain";
- base::PlatformThread::SetName(kThreadName);
- main_message_loop().set_thread_name(kThreadName);
-
-#if defined(TRACK_ALL_TASK_OBJECTS)
- tracked_objects::ThreadData::InitializeThreadContext(kThreadName);
-#endif // TRACK_ALL_TASK_OBJECTS
-
- // 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(OS_LINUX)
- // 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();
-#if defined(OS_CHROMEOS)
- // ChromeOS still uses dbus-glib, so initialize its threading here.
- // TODO(satorux, stevenjb): remove this once it is no longer needed.
- dbus_g_thread_init();
-#endif
-#if !defined(USE_AURA)
- gfx::GtkInitFromCommandLine(parameters().command_line_);
-#endif
- 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::PreMainMessageLoopRun() {
-}
-
-void BrowserMainParts::MainMessageLoopRun() {
- if (parameters().ui_task)
- MessageLoopForUI::current()->PostTask(FROM_HERE, parameters().ui_task);
-
-#if defined(OS_MACOSX)
- MessageLoopForUI::current()->Run();
-#else
- MessageLoopForUI::current()->RunWithDispatcher(NULL);
-#endif
-}
-
-void BrowserMainParts::PostMainMessageLoopRun() {
-}
-
-void BrowserMainParts::ToolkitInitialized() {
-}
-
bool ExitedMainMessageLoop() {
return g_exited_main_message_loop;
}
@@ -377,18 +62,17 @@ int BrowserMain(const MainFunctionParams& parameters) {
NotificationServiceImpl main_notification_service;
- scoped_ptr<content::BrowserMainParts> parts(
- content::GetContentClient()->browser()->CreateBrowserMainParts(
- parameters));
- if (!parts.get())
- parts.reset(new content::BrowserMainParts(parameters));
+ scoped_ptr<content::BrowserMainLoop> main_loop(
+ new content::BrowserMainLoop(parameters));
+
+ main_loop->Init();
- parts->EarlyInitialization();
+ main_loop->EarlyInitialization();
// Must happen before we try to use a message loop or display any UI.
- parts->InitializeToolkit();
+ main_loop->InitializeToolkit();
- parts->MainMessageLoopStart();
+ main_loop->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
@@ -434,8 +118,9 @@ int BrowserMain(const MainFunctionParams& parameters) {
base::StatisticsRecorder statistics;
- parts->RunMainMessageLoopParts();
+ main_loop->RunMainMessageLoopParts(&g_exited_main_message_loop);
TRACE_EVENT_END_ETW("BrowserMain", 0, 0);
- return parts->result_code();
+
+ return main_loop->GetResultCode();
}