Commit 09e26aa4 authored by Peter Collingbourne's avatar Peter Collingbourne Committed by Commit Bot

content: Assume that there is a ContentMainDelegate.

It looks like every client of this code is passing in a delegate,
so we can simplify it a little by removing the if checks.

Change-Id: Ie32edc629117d9c204482d518f13c7beb5bf1cf7
Reviewed-on: https://chromium-review.googlesource.com/1106801Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Peter Collingbourne <pcc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568698}
parent f0e4626d
...@@ -462,7 +462,6 @@ class ContentClientInitializer { ...@@ -462,7 +462,6 @@ class ContentClientInitializer {
ContentClient* content_client = GetContentClient(); ContentClient* content_client = GetContentClient();
#if !defined(CHROME_MULTIPLE_DLL_CHILD) #if !defined(CHROME_MULTIPLE_DLL_CHILD)
if (process_type.empty()) { if (process_type.empty()) {
if (delegate)
content_client->browser_ = delegate->CreateContentBrowserClient(); content_client->browser_ = delegate->CreateContentBrowserClient();
if (!content_client->browser_) if (!content_client->browser_)
content_client->browser_ = &g_empty_content_browser_client.Get(); content_client->browser_ = &g_empty_content_browser_client.Get();
...@@ -474,7 +473,6 @@ class ContentClientInitializer { ...@@ -474,7 +473,6 @@ class ContentClientInitializer {
if (process_type == switches::kGpuProcess || if (process_type == switches::kGpuProcess ||
cmd->HasSwitch(switches::kSingleProcess) || cmd->HasSwitch(switches::kSingleProcess) ||
(process_type.empty() && cmd->HasSwitch(switches::kInProcessGPU))) { (process_type.empty() && cmd->HasSwitch(switches::kInProcessGPU))) {
if (delegate)
content_client->gpu_ = delegate->CreateContentGpuClient(); content_client->gpu_ = delegate->CreateContentGpuClient();
if (!content_client->gpu_) if (!content_client->gpu_)
content_client->gpu_ = &g_empty_content_gpu_client.Get(); content_client->gpu_ = &g_empty_content_gpu_client.Get();
...@@ -482,7 +480,6 @@ class ContentClientInitializer { ...@@ -482,7 +480,6 @@ class ContentClientInitializer {
if (process_type == switches::kRendererProcess || if (process_type == switches::kRendererProcess ||
cmd->HasSwitch(switches::kSingleProcess)) { cmd->HasSwitch(switches::kSingleProcess)) {
if (delegate)
content_client->renderer_ = delegate->CreateContentRendererClient(); content_client->renderer_ = delegate->CreateContentRendererClient();
if (!content_client->renderer_) if (!content_client->renderer_)
content_client->renderer_ = &g_empty_content_renderer_client.Get(); content_client->renderer_ = &g_empty_content_renderer_client.Get();
...@@ -490,7 +487,6 @@ class ContentClientInitializer { ...@@ -490,7 +487,6 @@ class ContentClientInitializer {
if (process_type == switches::kUtilityProcess || if (process_type == switches::kUtilityProcess ||
cmd->HasSwitch(switches::kSingleProcess)) { cmd->HasSwitch(switches::kSingleProcess)) {
if (delegate)
content_client->utility_ = delegate->CreateContentUtilityClient(); content_client->utility_ = delegate->CreateContentUtilityClient();
// TODO(scottmg): http://crbug.com/237249 Should be in _child. // TODO(scottmg): http://crbug.com/237249 Should be in _child.
if (!content_client->utility_) if (!content_client->utility_)
...@@ -523,10 +519,8 @@ int RunZygote(ContentMainDelegate* delegate) { ...@@ -523,10 +519,8 @@ int RunZygote(ContentMainDelegate* delegate) {
std::vector<std::unique_ptr<service_manager::ZygoteForkDelegate>> std::vector<std::unique_ptr<service_manager::ZygoteForkDelegate>>
zygote_fork_delegates; zygote_fork_delegates;
if (delegate) {
delegate->ZygoteStarting(&zygote_fork_delegates); delegate->ZygoteStarting(&zygote_fork_delegates);
media::InitializeMediaLibrary(); media::InitializeMediaLibrary();
}
#if defined(OS_LINUX) #if defined(OS_LINUX)
PreSandboxInit(); PreSandboxInit();
...@@ -537,7 +531,6 @@ int RunZygote(ContentMainDelegate* delegate) { ...@@ -537,7 +531,6 @@ int RunZygote(ContentMainDelegate* delegate) {
return 1; return 1;
} }
if (delegate)
delegate->ZygoteForked(); delegate->ZygoteForked();
// Zygote::HandleForkRequest may have reallocated the command // Zygote::HandleForkRequest may have reallocated the command
...@@ -568,11 +561,7 @@ int RunZygote(ContentMainDelegate* delegate) { ...@@ -568,11 +561,7 @@ int RunZygote(ContentMainDelegate* delegate) {
return kMainFunctions[i].function(main_params); return kMainFunctions[i].function(main_params);
} }
if (delegate)
return delegate->RunProcess(process_type, main_params); return delegate->RunProcess(process_type, main_params);
NOTREACHED() << "Unknown zygote process type: " << process_type;
return 1;
} }
#endif // BUILDFLAG(USE_ZYGOTE_HANDLE) #endif // BUILDFLAG(USE_ZYGOTE_HANDLE)
...@@ -603,7 +592,6 @@ int RunBrowserProcessMain( ...@@ -603,7 +592,6 @@ int RunBrowserProcessMain(
const MainFunctionParams& main_function_params, const MainFunctionParams& main_function_params,
ContentMainDelegate* delegate, ContentMainDelegate* delegate,
std::unique_ptr<BrowserProcessSubThread> service_manager_thread) { std::unique_ptr<BrowserProcessSubThread> service_manager_thread) {
if (delegate) {
int exit_code = delegate->RunProcess("", main_function_params); int exit_code = delegate->RunProcess("", main_function_params);
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// In Android's browser process, the negative exit code doesn't mean the // In Android's browser process, the negative exit code doesn't mean the
...@@ -611,14 +599,14 @@ int RunBrowserProcessMain( ...@@ -611,14 +599,14 @@ int RunBrowserProcessMain(
// the Java and the browser process's default behavior is always // the Java and the browser process's default behavior is always
// overridden. // overridden.
return exit_code; return exit_code;
#endif #else
if (exit_code >= 0) if (exit_code >= 0)
return exit_code; return exit_code;
}
// GetServiceManagerTaskRunnerForEmbedderProcess() needs to be invoked before // GetServiceManagerTaskRunnerForEmbedderProcess() needs to be invoked before
// Run() for the browser process. // Run() for the browser process.
DCHECK(service_manager_thread); DCHECK(service_manager_thread);
return BrowserMain(main_function_params, std::move(service_manager_thread)); return BrowserMain(main_function_params, std::move(service_manager_thread));
#endif
} }
#endif // !defined(CHROME_MULTIPLE_DLL_CHILD) #endif // !defined(CHROME_MULTIPLE_DLL_CHILD)
...@@ -640,12 +628,9 @@ int RunOtherNamedProcessTypeMain(const std::string& process_type, ...@@ -640,12 +628,9 @@ int RunOtherNamedProcessTypeMain(const std::string& process_type,
for (size_t i = 0; i < base::size(kMainFunctions); ++i) { for (size_t i = 0; i < base::size(kMainFunctions); ++i) {
if (process_type == kMainFunctions[i].name) { if (process_type == kMainFunctions[i].name) {
if (delegate) { int exit_code = delegate->RunProcess(process_type, main_function_params);
int exit_code =
delegate->RunProcess(process_type, main_function_params);
if (exit_code >= 0) if (exit_code >= 0)
return exit_code; return exit_code;
}
return kMainFunctions[i].function(main_function_params); return kMainFunctions[i].function(main_function_params);
} }
} }
...@@ -659,11 +644,7 @@ int RunOtherNamedProcessTypeMain(const std::string& process_type, ...@@ -659,11 +644,7 @@ int RunOtherNamedProcessTypeMain(const std::string& process_type,
#endif // BUILDFLAG(USE_ZYGOTE_HANDLE) #endif // BUILDFLAG(USE_ZYGOTE_HANDLE)
// If it's a process we don't know about, the embedder should know. // If it's a process we don't know about, the embedder should know.
if (delegate)
return delegate->RunProcess(process_type, main_function_params); return delegate->RunProcess(process_type, main_function_params);
NOTREACHED() << "Unknown process type: " << process_type;
return 1;
} }
// static // static
...@@ -683,11 +664,7 @@ ContentMainRunnerImpl::~ContentMainRunnerImpl() { ...@@ -683,11 +664,7 @@ ContentMainRunnerImpl::~ContentMainRunnerImpl() {
} }
int ContentMainRunnerImpl::TerminateForFatalInitializationError() { int ContentMainRunnerImpl::TerminateForFatalInitializationError() {
if (delegate_)
return delegate_->TerminateForFatalInitializationError(); return delegate_->TerminateForFatalInitializationError();
CHECK(false);
return 0;
} }
int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) { int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) {
...@@ -748,7 +725,7 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) { ...@@ -748,7 +725,7 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) {
#endif // !OS_ANDROID #endif // !OS_ANDROID
int exit_code = 0; int exit_code = 0;
if (delegate_ && delegate_->BasicStartupComplete(&exit_code)) if (delegate_->BasicStartupComplete(&exit_code))
return exit_code; return exit_code;
completed_basic_startup_ = true; completed_basic_startup_ = true;
...@@ -809,13 +786,11 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) { ...@@ -809,13 +786,11 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) {
// It's important not to allocate the ports for processes which don't // It's important not to allocate the ports for processes which don't
// register with the power monitor - see https://crbug.com/88867. // register with the power monitor - see https://crbug.com/88867.
if (process_type.empty() || if (process_type.empty() ||
(delegate_ && delegate_->ProcessRegistersWithSystemProcess(process_type)) {
delegate_->ProcessRegistersWithSystemProcess(process_type))) {
base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
} }
if (!process_type.empty() && if (!process_type.empty() && delegate_->ShouldSendMachPort(process_type)) {
(!delegate_ || delegate_->ShouldSendMachPort(process_type))) {
MachBroker::ChildSendTaskPortToParent(); MachBroker::ChildSendTaskPortToParent();
} }
#endif #endif
...@@ -890,7 +865,6 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) { ...@@ -890,7 +865,6 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) {
} }
#endif // !defined(OFFICIAL_BUILD) #endif // !defined(OFFICIAL_BUILD)
if (delegate_)
delegate_->PreSandboxStartup(); delegate_->PreSandboxStartup();
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -906,7 +880,7 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) { ...@@ -906,7 +880,7 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) {
if (process_type == switches::kRendererProcess || if (process_type == switches::kRendererProcess ||
process_type == switches::kPpapiPluginProcess || v2_enabled || process_type == switches::kPpapiPluginProcess || v2_enabled ||
(delegate_ && delegate_->DelaySandboxInitialization(process_type))) { delegate_->DelaySandboxInitialization(process_type)) {
// On OS X the renderer sandbox needs to be initialized later in the // On OS X the renderer sandbox needs to be initialized later in the
// startup sequence in RendererMainPlatformDelegate::EnableSandbox(). // startup sequence in RendererMainPlatformDelegate::EnableSandbox().
} else { } else {
...@@ -915,7 +889,6 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) { ...@@ -915,7 +889,6 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) {
} }
#endif #endif
if (delegate_)
delegate_->SandboxInitialized(process_type); delegate_->SandboxInitialized(process_type);
#if BUILDFLAG(USE_ZYGOTE_HANDLE) #if BUILDFLAG(USE_ZYGOTE_HANDLE)
...@@ -971,7 +944,6 @@ int ContentMainRunnerImpl::Run() { ...@@ -971,7 +944,6 @@ int ContentMainRunnerImpl::Run() {
base::TaskScheduler::Create("Browser"); base::TaskScheduler::Create("Browser");
} }
if (delegate_)
delegate_->PreContentInitialization(); delegate_->PreContentInitialization();
// Create a MessageLoop if one does not already exist for the current // Create a MessageLoop if one does not already exist for the current
...@@ -992,7 +964,7 @@ void ContentMainRunnerImpl::Shutdown() { ...@@ -992,7 +964,7 @@ void ContentMainRunnerImpl::Shutdown() {
DCHECK(is_initialized_); DCHECK(is_initialized_);
DCHECK(!is_shutdown_); DCHECK(!is_shutdown_);
if (completed_basic_startup_ && delegate_) { if (completed_basic_startup_) {
const base::CommandLine& command_line = const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess(); *base::CommandLine::ForCurrentProcess();
std::string process_type = std::string process_type =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment