| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 const base::CommandLine& browser_command_line = | 267 const base::CommandLine& browser_command_line = |
| 268 *base::CommandLine::ForCurrentProcess(); | 268 *base::CommandLine::ForCurrentProcess(); |
| 269 | 269 |
| 270 bool has_cmd_prefix = browser_command_line.HasSwitch( | 270 bool has_cmd_prefix = browser_command_line.HasSwitch( |
| 271 switches::kUtilityCmdPrefix); | 271 switches::kUtilityCmdPrefix); |
| 272 | 272 |
| 273 #if defined(OS_ANDROID) | 273 #if defined(OS_ANDROID) |
| 274 // readlink("/prof/self/exe") sometimes fails on Android at startup. | 274 // readlink("/prof/self/exe") sometimes fails on Android at startup. |
| 275 // As a workaround skip calling it here, since the executable name is | 275 // As a workaround skip calling it here, since the executable name is |
| 276 // not needed on Android anyway. See crbug.com/500854. | 276 // not needed on Android anyway. See crbug.com/500854. |
| 277 base::CommandLine* cmd_line = | 277 std::unique_ptr<base::CommandLine> cmd_line = |
| 278 new base::CommandLine(base::CommandLine::NO_PROGRAM); | 278 base::MakeUnique<base::CommandLine>(base::CommandLine::NO_PROGRAM); |
| 279 #else | 279 #else |
| 280 int child_flags = child_flags_; | 280 int child_flags = child_flags_; |
| 281 | 281 |
| 282 // When running under gdb, forking /proc/self/exe ends up forking the gdb | 282 // When running under gdb, forking /proc/self/exe ends up forking the gdb |
| 283 // executable instead of Chromium. It is almost safe to assume that no | 283 // executable instead of Chromium. It is almost safe to assume that no |
| 284 // updates will happen while a developer is running with | 284 // updates will happen while a developer is running with |
| 285 // |switches::kUtilityCmdPrefix|. See ChildProcessHost::GetChildPath() for | 285 // |switches::kUtilityCmdPrefix|. See ChildProcessHost::GetChildPath() for |
| 286 // a similar case with Valgrind. | 286 // a similar case with Valgrind. |
| 287 if (has_cmd_prefix) | 287 if (has_cmd_prefix) |
| 288 child_flags = ChildProcessHost::CHILD_NORMAL; | 288 child_flags = ChildProcessHost::CHILD_NORMAL; |
| 289 | 289 |
| 290 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); | 290 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); |
| 291 if (exe_path.empty()) { | 291 if (exe_path.empty()) { |
| 292 NOTREACHED() << "Unable to get utility process binary name."; | 292 NOTREACHED() << "Unable to get utility process binary name."; |
| 293 return false; | 293 return false; |
| 294 } | 294 } |
| 295 | 295 |
| 296 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | 296 std::unique_ptr<base::CommandLine> cmd_line = |
| 297 base::MakeUnique<base::CommandLine>(exe_path); |
| 297 #endif | 298 #endif |
| 298 | 299 |
| 299 cmd_line->AppendSwitchASCII(switches::kProcessType, | 300 cmd_line->AppendSwitchASCII(switches::kProcessType, |
| 300 switches::kUtilityProcess); | 301 switches::kUtilityProcess); |
| 301 std::string locale = GetContentClient()->browser()->GetApplicationLocale(); | 302 std::string locale = GetContentClient()->browser()->GetApplicationLocale(); |
| 302 cmd_line->AppendSwitchASCII(switches::kLang, locale); | 303 cmd_line->AppendSwitchASCII(switches::kLang, locale); |
| 303 | 304 |
| 304 #if defined(OS_WIN) | 305 #if defined(OS_WIN) |
| 305 cmd_line->AppendArg(switches::kPrefetchArgumentOther); | 306 cmd_line->AppendArg(switches::kPrefetchArgumentOther); |
| 306 #endif // defined(OS_WIN) | 307 #endif // defined(OS_WIN) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 330 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, | 331 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, |
| 331 exposed_dir_); | 332 exposed_dir_); |
| 332 } | 333 } |
| 333 | 334 |
| 334 #if defined(OS_WIN) | 335 #if defined(OS_WIN) |
| 335 // Let the utility process know if it is intended to be elevated. | 336 // Let the utility process know if it is intended to be elevated. |
| 336 if (run_elevated_) | 337 if (run_elevated_) |
| 337 cmd_line->AppendSwitch(switches::kUtilityProcessRunningElevated); | 338 cmd_line->AppendSwitch(switches::kUtilityProcessRunningElevated); |
| 338 #endif | 339 #endif |
| 339 | 340 |
| 340 process_->Launch(new UtilitySandboxedProcessLauncherDelegate( | 341 process_->Launch(base::MakeUnique<UtilitySandboxedProcessLauncherDelegate>( |
| 341 exposed_dir_, run_elevated_, no_sandbox_, env_), | 342 exposed_dir_, run_elevated_, no_sandbox_, env_), |
| 342 cmd_line, true); | 343 std::move(cmd_line), true); |
| 343 } | 344 } |
| 344 | 345 |
| 345 return true; | 346 return true; |
| 346 } | 347 } |
| 347 | 348 |
| 348 bool UtilityProcessHostImpl::OnMessageReceived(const IPC::Message& message) { | 349 bool UtilityProcessHostImpl::OnMessageReceived(const IPC::Message& message) { |
| 349 if (!client_.get()) | 350 if (!client_.get()) |
| 350 return true; | 351 return true; |
| 351 | 352 |
| 352 client_task_runner_->PostTask( | 353 client_task_runner_->PostTask( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 base::WeakPtr<UtilityProcessHostImpl> host, | 394 base::WeakPtr<UtilityProcessHostImpl> host, |
| 394 int error_code) { | 395 int error_code) { |
| 395 if (!host) | 396 if (!host) |
| 396 return; | 397 return; |
| 397 | 398 |
| 398 host->OnProcessLaunchFailed(error_code); | 399 host->OnProcessLaunchFailed(error_code); |
| 399 delete host.get(); | 400 delete host.get(); |
| 400 } | 401 } |
| 401 | 402 |
| 402 } // namespace content | 403 } // namespace content |
| OLD | NEW |