| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 if (channel_id.empty()) | 187 if (channel_id.empty()) |
| 188 return false; | 188 return false; |
| 189 | 189 |
| 190 if (RenderProcessHost::run_renderer_in_process()) { | 190 if (RenderProcessHost::run_renderer_in_process()) { |
| 191 DCHECK(g_utility_main_thread_factory); | 191 DCHECK(g_utility_main_thread_factory); |
| 192 // See comment in RenderProcessHostImpl::Init() for the background on why we | 192 // See comment in RenderProcessHostImpl::Init() for the background on why we |
| 193 // support single process mode this way. | 193 // support single process mode this way. |
| 194 in_process_thread_.reset(g_utility_main_thread_factory(channel_id)); | 194 in_process_thread_.reset(g_utility_main_thread_factory(channel_id)); |
| 195 in_process_thread_->Start(); | 195 in_process_thread_->Start(); |
| 196 } else { | 196 } else { |
| 197 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 197 const base::CommandLine& browser_command_line = |
| 198 *base::CommandLine::ForCurrentProcess(); |
| 198 int child_flags = child_flags_; | 199 int child_flags = child_flags_; |
| 199 | 200 |
| 200 #if defined(OS_POSIX) | 201 #if defined(OS_POSIX) |
| 201 bool has_cmd_prefix = browser_command_line.HasSwitch( | 202 bool has_cmd_prefix = browser_command_line.HasSwitch( |
| 202 switches::kUtilityCmdPrefix); | 203 switches::kUtilityCmdPrefix); |
| 203 | 204 |
| 204 // When running under gdb, forking /proc/self/exe ends up forking the gdb | 205 // When running under gdb, forking /proc/self/exe ends up forking the gdb |
| 205 // executable instead of Chromium. It is almost safe to assume that no | 206 // executable instead of Chromium. It is almost safe to assume that no |
| 206 // updates will happen while a developer is running with | 207 // updates will happen while a developer is running with |
| 207 // |switches::kUtilityCmdPrefix|. See ChildProcessHost::GetChildPath() for | 208 // |switches::kUtilityCmdPrefix|. See ChildProcessHost::GetChildPath() for |
| 208 // a similar case with Valgrind. | 209 // a similar case with Valgrind. |
| 209 if (has_cmd_prefix) | 210 if (has_cmd_prefix) |
| 210 child_flags = ChildProcessHost::CHILD_NORMAL; | 211 child_flags = ChildProcessHost::CHILD_NORMAL; |
| 211 #endif | 212 #endif |
| 212 | 213 |
| 213 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); | 214 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); |
| 214 if (exe_path.empty()) { | 215 if (exe_path.empty()) { |
| 215 NOTREACHED() << "Unable to get utility process binary name."; | 216 NOTREACHED() << "Unable to get utility process binary name."; |
| 216 return false; | 217 return false; |
| 217 } | 218 } |
| 218 | 219 |
| 219 CommandLine* cmd_line = new CommandLine(exe_path); | 220 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
| 220 cmd_line->AppendSwitchASCII(switches::kProcessType, | 221 cmd_line->AppendSwitchASCII(switches::kProcessType, |
| 221 switches::kUtilityProcess); | 222 switches::kUtilityProcess); |
| 222 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 223 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
| 223 std::string locale = GetContentClient()->browser()->GetApplicationLocale(); | 224 std::string locale = GetContentClient()->browser()->GetApplicationLocale(); |
| 224 cmd_line->AppendSwitchASCII(switches::kLang, locale); | 225 cmd_line->AppendSwitchASCII(switches::kLang, locale); |
| 225 | 226 |
| 226 if (no_sandbox_ || browser_command_line.HasSwitch(switches::kNoSandbox)) | 227 if (no_sandbox_ || browser_command_line.HasSwitch(switches::kNoSandbox)) |
| 227 cmd_line->AppendSwitch(switches::kNoSandbox); | 228 cmd_line->AppendSwitch(switches::kNoSandbox); |
| 228 #if defined(OS_MACOSX) | 229 #if defined(OS_MACOSX) |
| 229 if (browser_command_line.HasSwitch(switches::kEnableSandboxLogging)) | 230 if (browser_command_line.HasSwitch(switches::kEnableSandboxLogging)) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 284 } |
| 284 | 285 |
| 285 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { | 286 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { |
| 286 client_task_runner_->PostTask( | 287 client_task_runner_->PostTask( |
| 287 FROM_HERE, | 288 FROM_HERE, |
| 288 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), | 289 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), |
| 289 exit_code)); | 290 exit_code)); |
| 290 } | 291 } |
| 291 | 292 |
| 292 } // namespace content | 293 } // namespace content |
| OLD | NEW |