| 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 started_ = true; | 246 started_ = true; |
| 247 | 247 |
| 248 if (is_batch_mode_) | 248 if (is_batch_mode_) |
| 249 return true; | 249 return true; |
| 250 | 250 |
| 251 // Name must be set or metrics_service will crash in any test which | 251 // Name must be set or metrics_service will crash in any test which |
| 252 // launches a UtilityProcessHost. | 252 // launches a UtilityProcessHost. |
| 253 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); | 253 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); |
| 254 process_->SetName(name_); | 254 process_->SetName(name_); |
| 255 | 255 |
| 256 std::string channel_id = process_->GetHost()->CreateChannel(); | 256 std::string mojo_channel_token = process_->GetHost()->CreateChannelMojo(); |
| 257 if (channel_id.empty()) { | 257 if (mojo_channel_token.empty()) { |
| 258 NotifyAndDelete(LAUNCH_RESULT_FAILURE); | 258 NotifyAndDelete(LAUNCH_RESULT_FAILURE); |
| 259 return false; | 259 return false; |
| 260 } | 260 } |
| 261 | 261 |
| 262 if (RenderProcessHost::run_renderer_in_process()) { | 262 if (RenderProcessHost::run_renderer_in_process()) { |
| 263 DCHECK(g_utility_main_thread_factory); | 263 DCHECK(g_utility_main_thread_factory); |
| 264 // See comment in RenderProcessHostImpl::Init() for the background on why we | 264 // See comment in RenderProcessHostImpl::Init() for the background on why we |
| 265 // support single process mode this way. | 265 // support single process mode this way. |
| 266 in_process_thread_.reset( | 266 in_process_thread_.reset( |
| 267 g_utility_main_thread_factory(InProcessChildThreadParams( | 267 g_utility_main_thread_factory(InProcessChildThreadParams( |
| 268 channel_id, BrowserThread::UnsafeGetMessageLoopForThread( | 268 std::string(), BrowserThread::UnsafeGetMessageLoopForThread( |
| 269 BrowserThread::IO)->task_runner(), | 269 BrowserThread::IO)->task_runner(), |
| 270 std::string(), mojo_application_host_->GetToken()))); | 270 mojo_channel_token, mojo_application_host_->GetToken()))); |
| 271 in_process_thread_->Start(); | 271 in_process_thread_->Start(); |
| 272 } else { | 272 } else { |
| 273 const base::CommandLine& browser_command_line = | 273 const base::CommandLine& browser_command_line = |
| 274 *base::CommandLine::ForCurrentProcess(); | 274 *base::CommandLine::ForCurrentProcess(); |
| 275 | 275 |
| 276 bool has_cmd_prefix = browser_command_line.HasSwitch( | 276 bool has_cmd_prefix = browser_command_line.HasSwitch( |
| 277 switches::kUtilityCmdPrefix); | 277 switches::kUtilityCmdPrefix); |
| 278 | 278 |
| 279 #if defined(OS_ANDROID) | 279 #if defined(OS_ANDROID) |
| 280 // readlink("/prof/self/exe") sometimes fails on Android at startup. | 280 // readlink("/prof/self/exe") sometimes fails on Android at startup. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 297 if (exe_path.empty()) { | 297 if (exe_path.empty()) { |
| 298 NOTREACHED() << "Unable to get utility process binary name."; | 298 NOTREACHED() << "Unable to get utility process binary name."; |
| 299 return false; | 299 return false; |
| 300 } | 300 } |
| 301 | 301 |
| 302 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | 302 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
| 303 #endif | 303 #endif |
| 304 | 304 |
| 305 cmd_line->AppendSwitchASCII(switches::kProcessType, | 305 cmd_line->AppendSwitchASCII(switches::kProcessType, |
| 306 switches::kUtilityProcess); | 306 switches::kUtilityProcess); |
| 307 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 307 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, |
| 308 mojo_channel_token); |
| 308 std::string locale = GetContentClient()->browser()->GetApplicationLocale(); | 309 std::string locale = GetContentClient()->browser()->GetApplicationLocale(); |
| 309 cmd_line->AppendSwitchASCII(switches::kLang, locale); | 310 cmd_line->AppendSwitchASCII(switches::kLang, locale); |
| 310 | 311 |
| 311 #if defined(OS_WIN) | 312 #if defined(OS_WIN) |
| 312 if (GetContentClient()->browser()->ShouldUseWindowsPrefetchArgument()) | 313 if (GetContentClient()->browser()->ShouldUseWindowsPrefetchArgument()) |
| 313 cmd_line->AppendArg(switches::kPrefetchArgumentOther); | 314 cmd_line->AppendArg(switches::kPrefetchArgumentOther); |
| 314 #endif // defined(OS_WIN) | 315 #endif // defined(OS_WIN) |
| 315 | 316 |
| 316 if (no_sandbox_) | 317 if (no_sandbox_) |
| 317 cmd_line->AppendSwitch(switches::kNoSandbox); | 318 cmd_line->AppendSwitch(switches::kNoSandbox); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 base::WeakPtr<UtilityProcessHostImpl> host, | 409 base::WeakPtr<UtilityProcessHostImpl> host, |
| 409 int error_code) { | 410 int error_code) { |
| 410 if (!host) | 411 if (!host) |
| 411 return; | 412 return; |
| 412 | 413 |
| 413 host->OnProcessLaunchFailed(error_code); | 414 host->OnProcessLaunchFailed(error_code); |
| 414 delete host.get(); | 415 delete host.get(); |
| 415 } | 416 } |
| 416 | 417 |
| 417 } // namespace content | 418 } // namespace content |
| OLD | NEW |