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/child_process_launcher.h" | 5 #include "content/browser/child_process_launcher.h" |
6 | 6 |
7 #include <utility> // For std::pair. | 7 #include <utility> // For std::pair. |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 base::EnvironmentMap env = delegate->GetEnvironment(); | 317 base::EnvironmentMap env = delegate->GetEnvironment(); |
318 base::ScopedFD ipcfd = delegate->TakeIpcFd(); | 318 base::ScopedFD ipcfd = delegate->TakeIpcFd(); |
319 #elif defined(OS_POSIX) | 319 #elif defined(OS_POSIX) |
320 bool use_zygote = delegate->ShouldUseZygote(); | 320 bool use_zygote = delegate->ShouldUseZygote(); |
321 base::EnvironmentMap env = delegate->GetEnvironment(); | 321 base::EnvironmentMap env = delegate->GetEnvironment(); |
322 base::ScopedFD ipcfd = delegate->TakeIpcFd(); | 322 base::ScopedFD ipcfd = delegate->TakeIpcFd(); |
323 #endif | 323 #endif |
324 scoped_ptr<base::CommandLine> cmd_line_deleter(cmd_line); | 324 scoped_ptr<base::CommandLine> cmd_line_deleter(cmd_line); |
325 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); | 325 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); |
326 | 326 |
| 327 base::Process process; |
327 #if defined(OS_WIN) | 328 #if defined(OS_WIN) |
328 base::Process process; | |
329 if (launch_elevated) { | 329 if (launch_elevated) { |
330 base::LaunchOptions options; | 330 base::LaunchOptions options; |
331 options.start_hidden = true; | 331 options.start_hidden = true; |
332 process = base::LaunchElevatedProcess(*cmd_line, options); | 332 process = base::LaunchElevatedProcess(*cmd_line, options); |
333 } else { | 333 } else { |
334 process = StartSandboxedProcess(delegate, cmd_line); | 334 process = StartSandboxedProcess(delegate, cmd_line); |
335 } | 335 } |
336 #elif defined(OS_POSIX) | 336 #elif defined(OS_POSIX) |
337 std::string process_type = | 337 std::string process_type = |
338 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 338 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
(...skipping 25 matching lines...) Expand all Loading... |
364 StartChildProcess( | 364 StartChildProcess( |
365 cmd_line->argv(), | 365 cmd_line->argv(), |
366 child_process_id, | 366 child_process_id, |
367 files_to_register.Pass(), | 367 files_to_register.Pass(), |
368 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, | 368 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, |
369 this_object, | 369 this_object, |
370 client_thread_id, | 370 client_thread_id, |
371 begin_launch_time)); | 371 begin_launch_time)); |
372 | 372 |
373 #elif defined(OS_POSIX) | 373 #elif defined(OS_POSIX) |
374 base::ProcessHandle handle = base::kNullProcessHandle; | |
375 // We need to close the client end of the IPC channel to reliably detect | 374 // We need to close the client end of the IPC channel to reliably detect |
376 // child termination. | 375 // child termination. |
377 | 376 |
378 #if !defined(OS_MACOSX) | 377 #if !defined(OS_MACOSX) |
379 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess( | 378 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess( |
380 *cmd_line, child_process_id, files_to_register.get()); | 379 *cmd_line, child_process_id, files_to_register.get()); |
381 if (use_zygote) { | 380 if (use_zygote) { |
382 handle = ZygoteHostImpl::GetInstance()->ForkRequest( | 381 base::ProcessHandle handle = ZygoteHostImpl::GetInstance()->ForkRequest( |
383 cmd_line->argv(), files_to_register.Pass(), process_type); | 382 cmd_line->argv(), files_to_register.Pass(), process_type); |
| 383 process = base::Process(handle); |
384 } else | 384 } else |
385 // Fall through to the normal posix case below when we're not zygoting. | 385 // Fall through to the normal posix case below when we're not zygoting. |
386 #endif // !defined(OS_MACOSX) | 386 #endif // !defined(OS_MACOSX) |
387 { | 387 { |
388 // Convert FD mapping to FileHandleMappingVector | 388 // Convert FD mapping to FileHandleMappingVector |
389 base::FileHandleMappingVector fds_to_map = | 389 base::FileHandleMappingVector fds_to_map = |
390 files_to_register->GetMappingWithIDAdjustment( | 390 files_to_register->GetMappingWithIDAdjustment( |
391 base::GlobalDescriptors::kBaseDescriptor); | 391 base::GlobalDescriptors::kBaseDescriptor); |
392 | 392 |
393 #if !defined(OS_MACOSX) | 393 #if !defined(OS_MACOSX) |
(...skipping 29 matching lines...) Expand all Loading... |
423 const int bootstrap_sandbox_policy = delegate->GetSandboxType(); | 423 const int bootstrap_sandbox_policy = delegate->GetSandboxType(); |
424 if (ShouldEnableBootstrapSandbox() && | 424 if (ShouldEnableBootstrapSandbox() && |
425 bootstrap_sandbox_policy != SANDBOX_TYPE_INVALID) { | 425 bootstrap_sandbox_policy != SANDBOX_TYPE_INVALID) { |
426 options.replacement_bootstrap_name = | 426 options.replacement_bootstrap_name = |
427 GetBootstrapSandbox()->server_bootstrap_name(); | 427 GetBootstrapSandbox()->server_bootstrap_name(); |
428 GetBootstrapSandbox()->PrepareToForkWithPolicy( | 428 GetBootstrapSandbox()->PrepareToForkWithPolicy( |
429 bootstrap_sandbox_policy); | 429 bootstrap_sandbox_policy); |
430 } | 430 } |
431 #endif // defined(OS_MACOSX) | 431 #endif // defined(OS_MACOSX) |
432 | 432 |
433 bool launched = base::LaunchProcess(*cmd_line, options, &handle); | 433 process = base::LaunchProcess(*cmd_line, options); |
434 if (!launched) | |
435 handle = base::kNullProcessHandle; | |
436 | 434 |
437 #if defined(OS_MACOSX) | 435 #if defined(OS_MACOSX) |
438 if (ShouldEnableBootstrapSandbox() && | 436 if (ShouldEnableBootstrapSandbox() && |
439 bootstrap_sandbox_policy != SANDBOX_TYPE_INVALID) { | 437 bootstrap_sandbox_policy != SANDBOX_TYPE_INVALID) { |
440 GetBootstrapSandbox()->FinishedFork(handle); | 438 GetBootstrapSandbox()->FinishedFork(process.Handle()); |
441 } | 439 } |
442 | 440 |
443 if (launched) | 441 if (process.IsValid()) |
444 broker->AddPlaceholderForPid(handle, child_process_id); | 442 broker->AddPlaceholderForPid(process.pid(), child_process_id); |
445 | 443 |
446 // After updating the broker, release the lock and let the child's | 444 // After updating the broker, release the lock and let the child's |
447 // messasge be processed on the broker's thread. | 445 // messasge be processed on the broker's thread. |
448 broker->GetLock().Release(); | 446 broker->GetLock().Release(); |
449 #endif // defined(OS_MACOSX) | 447 #endif // defined(OS_MACOSX) |
450 } | 448 } |
451 base::Process process(handle); | |
452 #endif // else defined(OS_POSIX) | 449 #endif // else defined(OS_POSIX) |
453 #if !defined(OS_ANDROID) | 450 #if !defined(OS_ANDROID) |
454 if (process.IsValid()) | 451 if (process.IsValid()) |
455 RecordHistograms(begin_launch_time); | 452 RecordHistograms(begin_launch_time); |
456 BrowserThread::PostTask( | 453 BrowserThread::PostTask( |
457 client_thread_id, FROM_HERE, | 454 client_thread_id, FROM_HERE, |
458 base::Bind(&Context::Notify, | 455 base::Bind(&Context::Notify, |
459 this_object.get(), | 456 this_object.get(), |
460 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 457 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
461 use_zygote, | 458 use_zygote, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 context_->SetProcessBackgrounded(background); | 603 context_->SetProcessBackgrounded(background); |
607 } | 604 } |
608 | 605 |
609 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 606 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
610 bool terminate_on_shutdown) { | 607 bool terminate_on_shutdown) { |
611 if (context_.get()) | 608 if (context_.get()) |
612 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 609 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
613 } | 610 } |
614 | 611 |
615 } // namespace content | 612 } // namespace content |
OLD | NEW |