From 8a820c8276581a82f263c7e3603ab4bc73a221db Mon Sep 17 00:00:00 2001 From: "jam@chromium.org" Date: Sun, 9 Mar 2014 18:06:58 +0000 Subject: Convert ContentMain to take a struct instead of parameters that vary depending on the platform. This helps reduce ifdef mess, and makes it easier to add extra optional parameters. In a followup cl, I'll move the ui_task parameter from MainFunctionParams to ContentMainParams. BUG=350550 R=sky@chromium.org Review URL: https://codereview.chromium.org/190853004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255866 0039d316-1c4b-4281-b951-d872f2087c98 --- content/app/android/content_main.cc | 10 +++---- content/app/content_main.cc | 20 ++----------- content/app/content_main_runner.cc | 58 +++++++++++++++++++------------------ 3 files changed, 36 insertions(+), 52 deletions(-) (limited to 'content/app') diff --git a/content/app/android/content_main.cc b/content/app/android/content_main.cc index 00074b8..55657496 100644 --- a/content/app/android/content_main.cc +++ b/content/app/android/content_main.cc @@ -16,8 +16,8 @@ #include "jni/ContentMain_jni.h" using base::LazyInstance; -using content::ContentMainRunner; -using content::ContentMainDelegate; + +namespace content { namespace { LazyInstance > g_content_runner = @@ -28,8 +28,6 @@ LazyInstance > g_content_main_delegate = } // namespace -namespace content { - static void InitApplicationContext(JNIEnv* env, jclass clazz, jobject context) { base::android::ScopedJavaLocalRef scoped_context(env, context); base::android::InitApplicationContext(env, scoped_context); @@ -43,9 +41,9 @@ static jint Start(JNIEnv* env, jclass clazz) { // request then we have to call this a second time to finish starting the // browser synchronously. if (!g_content_runner.Get().get()) { + ContentMainParams params(g_content_main_delegate.Get().get()); g_content_runner.Get().reset(ContentMainRunner::Create()); - g_content_runner.Get()->Initialize( - 0, NULL, g_content_main_delegate.Get().get()); + g_content_runner.Get()->Initialize(params); } return g_content_runner.Get()->Run(); } diff --git a/content/app/content_main.cc b/content/app/content_main.cc index c82d790..77277ff 100644 --- a/content/app/content_main.cc +++ b/content/app/content_main.cc @@ -9,26 +9,10 @@ namespace content { -#if defined(OS_WIN) -int ContentMain(HINSTANCE instance, - sandbox::SandboxInterfaceInfo* sandbox_info, - ContentMainDelegate* delegate) { -#else -int ContentMain(int argc, - const char** argv, - ContentMainDelegate* delegate) { -#endif // OS_WIN - +int ContentMain(const ContentMainParams& params) { scoped_ptr main_runner(ContentMainRunner::Create()); - int exit_code; - -#if defined(OS_WIN) - exit_code = main_runner->Initialize(instance, sandbox_info, delegate); -#else - exit_code = main_runner->Initialize(argc, argv, delegate); -#endif // OS_WIN - + int exit_code = main_runner->Initialize(params); if (exit_code >= 0) return exit_code; diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc index 99d0818..13d112ab 100644 --- a/content/app/content_main_runner.cc +++ b/content/app/content_main_runner.cc @@ -30,6 +30,7 @@ #include "content/common/set_process_title.h" #include "content/common/url_schemes.h" #include "content/gpu/in_process_gpu_thread.h" +#include "content/public/app/content_main.h" #include "content/public/app/content_main_delegate.h" #include "content/public/app/startup_helper_win.h" #include "content/public/browser/content_browser_client.h" @@ -524,22 +525,13 @@ class ContentMainRunnerImpl : public ContentMainRunner { } #endif -#if defined(OS_WIN) - virtual int Initialize(HINSTANCE instance, - sandbox::SandboxInterfaceInfo* sandbox_info, - ContentMainDelegate* delegate) OVERRIDE { - // argc/argv are ignored on Windows; see command_line.h for details. - int argc = 0; - char** argv = NULL; - + virtual int Initialize(const ContentMainParams& params) OVERRIDE { +#if defined(OS_WIN) RegisterInvalidParamHandler(); - _Module.Init(NULL, static_cast(instance)); + _Module.Init(NULL, static_cast(params.instance)); - sandbox_info_ = *sandbox_info; + sandbox_info_ = *params.sandbox_info; #else // !OS_WIN - virtual int Initialize(int argc, - const char** argv, - ContentMainDelegate* delegate) OVERRIDE { #if defined(OS_ANDROID) // See note at the initialization of ExitManager, below; basically, @@ -609,7 +601,7 @@ class ContentMainRunnerImpl : public ContentMainRunner { #endif // !OS_WIN is_initialized_ = true; - delegate_ = delegate; + delegate_ = params.delegate; base::EnableTerminationOnHeapCorruption(); base::EnableTerminationOnOutOfMemory(); @@ -634,11 +626,25 @@ class ContentMainRunnerImpl : public ContentMainRunner { // On Android, the command line is initialized when library is loaded and // we have already started our TRACE_EVENT0. #if !defined(OS_ANDROID) + // argc/argv are ignored on Windows and Android; see command_line.h for + // details. + int argc = 0; + const char** argv = NULL; + +#if !defined(OS_WIN) + argc = params.argc; + argv = params.argv; +#endif + CommandLine::Init(argc, argv); + +#if !defined(OS_IOS) + SetProcessTitleFromCommandLine(argv); +#endif #endif // !OS_ANDROID int exit_code; - if (delegate && delegate->BasicStartupComplete(&exit_code)) + if (delegate_ && delegate_->BasicStartupComplete(&exit_code)) return exit_code; completed_basic_startup_ = true; @@ -680,13 +686,13 @@ class ContentMainRunnerImpl : public ContentMainRunner { // It's important not to allocate the ports for processes which don't // register with the power monitor - see crbug.com/88867. if (process_type.empty() || - (delegate && - delegate->ProcessRegistersWithSystemProcess(process_type))) { + (delegate_ && + delegate_->ProcessRegistersWithSystemProcess(process_type))) { base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); } if (!process_type.empty() && - (!delegate || delegate->ShouldSendMachPort(process_type))) { + (!delegate_ || delegate_->ShouldSendMachPort(process_type))) { MachBroker::ChildSendTaskPortToParent(); } #elif defined(OS_WIN) @@ -729,18 +735,18 @@ class ContentMainRunnerImpl : public ContentMainRunner { InitializeStatsTable(command_line); - if (delegate) - delegate->PreSandboxStartup(); + if (delegate_) + delegate_->PreSandboxStartup(); if (!process_type.empty()) CommonSubprocessInit(process_type); #if defined(OS_WIN) - CHECK(InitializeSandbox(sandbox_info)); + CHECK(InitializeSandbox(params.sandbox_info)); #elif defined(OS_MACOSX) && !defined(OS_IOS) if (process_type == switches::kRendererProcess || process_type == switches::kPpapiPluginProcess || - (delegate && delegate->DelaySandboxInitialization(process_type))) { + (delegate_ && delegate_->DelaySandboxInitialization(process_type))) { // On OS X the renderer sandbox needs to be initialized later in the // startup sequence in RendererMainPlatformDelegate::EnableSandbox(). } else { @@ -748,12 +754,8 @@ class ContentMainRunnerImpl : public ContentMainRunner { } #endif - if (delegate) - delegate->SandboxInitialized(process_type); - -#if defined(OS_POSIX) && !defined(OS_IOS) - SetProcessTitleFromCommandLine(argv); -#endif + if (delegate_) + delegate_->SandboxInitialized(process_type); // Return -1 to indicate no early termination. return -1; -- cgit v1.1