| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/utility_process_host_impl.h" | 5 #include "content/browser/utility_process_host_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 249 |
| 250 if (is_batch_mode_) | 250 if (is_batch_mode_) |
| 251 return true; | 251 return true; |
| 252 | 252 |
| 253 // Name must be set or metrics_service will crash in any test which | 253 // Name must be set or metrics_service will crash in any test which |
| 254 // launches a UtilityProcessHost. | 254 // launches a UtilityProcessHost. |
| 255 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this, | 255 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this, |
| 256 child_token_)); | 256 child_token_)); |
| 257 process_->SetName(name_); | 257 process_->SetName(name_); |
| 258 | 258 |
| 259 std::string channel_id = process_->GetHost()->CreateChannel(); | 259 std::string mojo_channel_token = |
| 260 if (channel_id.empty()) { | 260 process_->GetHost()->CreateChannelMojo(child_token_); |
| 261 if (mojo_channel_token.empty()) { |
| 261 NotifyAndDelete(LAUNCH_RESULT_FAILURE); | 262 NotifyAndDelete(LAUNCH_RESULT_FAILURE); |
| 262 return false; | 263 return false; |
| 263 } | 264 } |
| 264 | 265 |
| 265 if (RenderProcessHost::run_renderer_in_process()) { | 266 if (RenderProcessHost::run_renderer_in_process()) { |
| 266 DCHECK(g_utility_main_thread_factory); | 267 DCHECK(g_utility_main_thread_factory); |
| 267 // See comment in RenderProcessHostImpl::Init() for the background on why we | 268 // See comment in RenderProcessHostImpl::Init() for the background on why we |
| 268 // support single process mode this way. | 269 // support single process mode this way. |
| 269 in_process_thread_.reset( | 270 in_process_thread_.reset( |
| 270 g_utility_main_thread_factory(InProcessChildThreadParams( | 271 g_utility_main_thread_factory(InProcessChildThreadParams( |
| 271 channel_id, BrowserThread::UnsafeGetMessageLoopForThread( | 272 std::string(), BrowserThread::UnsafeGetMessageLoopForThread( |
| 272 BrowserThread::IO)->task_runner(), | 273 BrowserThread::IO)->task_runner(), |
| 273 std::string(), mojo_application_host_->GetToken()))); | 274 mojo_channel_token, mojo_application_host_->GetToken()))); |
| 274 in_process_thread_->Start(); | 275 in_process_thread_->Start(); |
| 275 } else { | 276 } else { |
| 276 const base::CommandLine& browser_command_line = | 277 const base::CommandLine& browser_command_line = |
| 277 *base::CommandLine::ForCurrentProcess(); | 278 *base::CommandLine::ForCurrentProcess(); |
| 278 | 279 |
| 279 bool has_cmd_prefix = browser_command_line.HasSwitch( | 280 bool has_cmd_prefix = browser_command_line.HasSwitch( |
| 280 switches::kUtilityCmdPrefix); | 281 switches::kUtilityCmdPrefix); |
| 281 | 282 |
| 282 #if defined(OS_ANDROID) | 283 #if defined(OS_ANDROID) |
| 283 // readlink("/prof/self/exe") sometimes fails on Android at startup. | 284 // readlink("/prof/self/exe") sometimes fails on Android at startup. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 300 if (exe_path.empty()) { | 301 if (exe_path.empty()) { |
| 301 NOTREACHED() << "Unable to get utility process binary name."; | 302 NOTREACHED() << "Unable to get utility process binary name."; |
| 302 return false; | 303 return false; |
| 303 } | 304 } |
| 304 | 305 |
| 305 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | 306 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
| 306 #endif | 307 #endif |
| 307 | 308 |
| 308 cmd_line->AppendSwitchASCII(switches::kProcessType, | 309 cmd_line->AppendSwitchASCII(switches::kProcessType, |
| 309 switches::kUtilityProcess); | 310 switches::kUtilityProcess); |
| 310 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 311 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, |
| 312 mojo_channel_token); |
| 311 std::string locale = GetContentClient()->browser()->GetApplicationLocale(); | 313 std::string locale = GetContentClient()->browser()->GetApplicationLocale(); |
| 312 cmd_line->AppendSwitchASCII(switches::kLang, locale); | 314 cmd_line->AppendSwitchASCII(switches::kLang, locale); |
| 313 | 315 |
| 314 #if defined(OS_WIN) | 316 #if defined(OS_WIN) |
| 315 if (GetContentClient()->browser()->ShouldUseWindowsPrefetchArgument()) | 317 if (GetContentClient()->browser()->ShouldUseWindowsPrefetchArgument()) |
| 316 cmd_line->AppendArg(switches::kPrefetchArgumentOther); | 318 cmd_line->AppendArg(switches::kPrefetchArgumentOther); |
| 317 #endif // defined(OS_WIN) | 319 #endif // defined(OS_WIN) |
| 318 | 320 |
| 319 if (no_sandbox_) | 321 if (no_sandbox_) |
| 320 cmd_line->AppendSwitch(switches::kNoSandbox); | 322 cmd_line->AppendSwitch(switches::kNoSandbox); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 base::WeakPtr<UtilityProcessHostImpl> host, | 413 base::WeakPtr<UtilityProcessHostImpl> host, |
| 412 int error_code) { | 414 int error_code) { |
| 413 if (!host) | 415 if (!host) |
| 414 return; | 416 return; |
| 415 | 417 |
| 416 host->OnProcessLaunchFailed(error_code); | 418 host->OnProcessLaunchFailed(error_code); |
| 417 delete host.get(); | 419 delete host.get(); |
| 418 } | 420 } |
| 419 | 421 |
| 420 } // namespace content | 422 } // namespace content |
| OLD | NEW |