| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 425 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| 426 base::Bind(&TerminateOnLauncherThread, zygote_, | 426 base::Bind(&TerminateOnLauncherThread, zygote_, |
| 427 base::Passed(&process_))); | 427 base::Passed(&process_))); |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 | 430 |
| 431 void ChildProcessLauncher::Launch( | 431 void ChildProcessLauncher::Launch( |
| 432 SandboxedProcessLauncherDelegate* delegate, | 432 SandboxedProcessLauncherDelegate* delegate, |
| 433 base::CommandLine* cmd_line, | 433 base::CommandLine* cmd_line, |
| 434 int child_process_id) { | 434 int child_process_id) { |
| 435 fprintf(stderr, "Launch: %s\n", cmd_line->GetCommandLineString().c_str()); ffl
ush(stderr); |
| 435 DCHECK(CalledOnValidThread()); | 436 DCHECK(CalledOnValidThread()); |
| 436 | 437 |
| 437 #if defined(OS_ANDROID) | 438 #if defined(OS_ANDROID) |
| 438 // Android only supports renderer, sandboxed utility and gpu. | 439 // Android only supports renderer, sandboxed utility and gpu. |
| 439 std::string process_type = | 440 std::string process_type = |
| 440 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 441 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
| 441 CHECK(process_type == switches::kGpuProcess || | 442 CHECK(process_type == switches::kGpuProcess || |
| 442 process_type == switches::kRendererProcess || | 443 process_type == switches::kRendererProcess || |
| 443 #if defined(ENABLE_PLUGINS) | 444 #if defined(ENABLE_PLUGINS) |
| 444 process_type == switches::kPpapiPluginProcess || | 445 process_type == switches::kPpapiPluginProcess || |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 base::WeakPtr<ChildProcessLauncher> instance, | 523 base::WeakPtr<ChildProcessLauncher> instance, |
| 523 bool terminate_on_shutdown, | 524 bool terminate_on_shutdown, |
| 524 mojo::edk::ScopedPlatformHandle server_handle, | 525 mojo::edk::ScopedPlatformHandle server_handle, |
| 525 ZygoteHandle zygote, | 526 ZygoteHandle zygote, |
| 526 #if defined(OS_ANDROID) | 527 #if defined(OS_ANDROID) |
| 527 base::ScopedFD ipcfd, | 528 base::ScopedFD ipcfd, |
| 528 base::ScopedFD mojo_fd, | 529 base::ScopedFD mojo_fd, |
| 529 #endif | 530 #endif |
| 530 base::Process process, | 531 base::Process process, |
| 531 int error_code) { | 532 int error_code) { |
| 533 fprintf(stderr, "DidLaunch\n"); fflush(stderr); |
| 532 if (!process.IsValid()) | 534 if (!process.IsValid()) |
| 533 LOG(ERROR) << "Failed to launch child process"; | 535 LOG(ERROR) << "Failed to launch child process"; |
| 534 | 536 |
| 535 if (instance.get()) { | 537 if (instance.get()) { |
| 536 instance->Notify(zygote, std::move(server_handle), | 538 instance->Notify(zygote, std::move(server_handle), |
| 537 #if defined(OS_ANDROID) | 539 #if defined(OS_ANDROID) |
| 538 std::move(ipcfd), | 540 std::move(ipcfd), |
| 539 #endif | 541 #endif |
| 540 std::move(process), error_code); | 542 std::move(process), error_code); |
| 541 } else { | 543 } else { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 | 588 |
| 587 const base::Process& ChildProcessLauncher::GetProcess() const { | 589 const base::Process& ChildProcessLauncher::GetProcess() const { |
| 588 // TODO(crbug.com/469248): This fails in some tests. | 590 // TODO(crbug.com/469248): This fails in some tests. |
| 589 // DCHECK(CalledOnValidThread()); | 591 // DCHECK(CalledOnValidThread()); |
| 590 return process_; | 592 return process_; |
| 591 } | 593 } |
| 592 | 594 |
| 593 base::TerminationStatus ChildProcessLauncher::GetChildTerminationStatus( | 595 base::TerminationStatus ChildProcessLauncher::GetChildTerminationStatus( |
| 594 bool known_dead, | 596 bool known_dead, |
| 595 int* exit_code) { | 597 int* exit_code) { |
| 598 fprintf(stderr, "GetChildTerminationStatus\n"); fflush(stderr); |
| 596 DCHECK(CalledOnValidThread()); | 599 DCHECK(CalledOnValidThread()); |
| 597 if (!process_.IsValid()) { | 600 if (!process_.IsValid()) { |
| 601 fprintf(stderr, "cached status: %d\n", termination_status_); fflush(stderr); |
| 598 // Process is already gone, so return the cached termination status. | 602 // Process is already gone, so return the cached termination status. |
| 599 if (exit_code) | 603 if (exit_code) |
| 600 *exit_code = exit_code_; | 604 *exit_code = exit_code_; |
| 601 return termination_status_; | 605 return termination_status_; |
| 602 } | 606 } |
| 603 | 607 |
| 608 fprintf(stderr, "UpdateTerminationStatus\n"); fflush(stderr); |
| 604 UpdateTerminationStatus(known_dead); | 609 UpdateTerminationStatus(known_dead); |
| 605 if (exit_code) | 610 if (exit_code) |
| 606 *exit_code = exit_code_; | 611 *exit_code = exit_code_; |
| 607 | 612 |
| 608 // POSIX: If the process crashed, then the kernel closed the socket | 613 // POSIX: If the process crashed, then the kernel closed the socket |
| 609 // for it and so the child has already died by the time we get | 614 // for it and so the child has already died by the time we get |
| 610 // here. Since GetTerminationStatus called waitpid with WNOHANG, | 615 // here. Since GetTerminationStatus called waitpid with WNOHANG, |
| 611 // it'll reap the process. However, if GetTerminationStatus didn't | 616 // it'll reap the process. However, if GetTerminationStatus didn't |
| 612 // reap the child (because it was still running), we'll need to | 617 // reap the child (because it was still running), we'll need to |
| 613 // Terminate via ProcessWatcher. So we can't close the handle here. | 618 // Terminate via ProcessWatcher. So we can't close the handle here. |
| 614 if (termination_status_ != base::TERMINATION_STATUS_STILL_RUNNING) | 619 if (termination_status_ != base::TERMINATION_STATUS_STILL_RUNNING) |
| 615 process_.Close(); | 620 process_.Close(); |
| 616 | 621 |
| 617 return termination_status_; | 622 return termination_status_; |
| 618 } | 623 } |
| 619 | 624 |
| 620 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 625 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
| 621 Client* client) { | 626 Client* client) { |
| 622 Client* ret = client_; | 627 Client* ret = client_; |
| 623 client_ = client; | 628 client_ = client; |
| 624 return ret; | 629 return ret; |
| 625 } | 630 } |
| 626 | 631 |
| 627 } // namespace content | 632 } // namespace content |
| OLD | NEW |