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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 #endif | 388 #endif |
389 } | 389 } |
390 | 390 |
391 } // namespace | 391 } // namespace |
392 | 392 |
393 ChildProcessLauncher::ChildProcessLauncher( | 393 ChildProcessLauncher::ChildProcessLauncher( |
394 SandboxedProcessLauncherDelegate* delegate, | 394 SandboxedProcessLauncherDelegate* delegate, |
395 base::CommandLine* cmd_line, | 395 base::CommandLine* cmd_line, |
396 int child_process_id, | 396 int child_process_id, |
397 Client* client, | 397 Client* client, |
| 398 const std::string& mojo_child_token, |
398 bool terminate_on_shutdown) | 399 bool terminate_on_shutdown) |
399 : client_(client), | 400 : client_(client), |
400 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), | 401 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), |
401 exit_code_(RESULT_CODE_NORMAL_EXIT), | 402 exit_code_(RESULT_CODE_NORMAL_EXIT), |
402 zygote_(nullptr), | 403 zygote_(nullptr), |
403 starting_(true), | 404 starting_(true), |
404 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ | 405 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ |
405 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ | 406 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ |
406 defined(UNDEFINED_SANITIZER) | 407 defined(UNDEFINED_SANITIZER) |
407 terminate_child_on_shutdown_(false), | 408 terminate_child_on_shutdown_(false), |
408 #else | 409 #else |
409 terminate_child_on_shutdown_(terminate_on_shutdown), | 410 terminate_child_on_shutdown_(terminate_on_shutdown), |
410 #endif | 411 #endif |
| 412 mojo_child_token_(mojo_child_token), |
411 weak_factory_(this) { | 413 weak_factory_(this) { |
412 DCHECK(CalledOnValidThread()); | 414 DCHECK(CalledOnValidThread()); |
413 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 415 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
414 Launch(delegate, cmd_line, child_process_id); | 416 Launch(delegate, cmd_line, child_process_id); |
415 } | 417 } |
416 | 418 |
417 ChildProcessLauncher::~ChildProcessLauncher() { | 419 ChildProcessLauncher::~ChildProcessLauncher() { |
418 DCHECK(CalledOnValidThread()); | 420 DCHECK(CalledOnValidThread()); |
419 if (process_.IsValid() && terminate_child_on_shutdown_) { | 421 if (process_.IsValid() && terminate_child_on_shutdown_) { |
420 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So | 422 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 #endif | 552 #endif |
551 base::Process process, | 553 base::Process process, |
552 int error_code) { | 554 int error_code) { |
553 DCHECK(CalledOnValidThread()); | 555 DCHECK(CalledOnValidThread()); |
554 starting_ = false; | 556 starting_ = false; |
555 process_ = std::move(process); | 557 process_ = std::move(process); |
556 | 558 |
557 if (process_.IsValid()) { | 559 if (process_.IsValid()) { |
558 // Set up Mojo IPC to the new process. | 560 // Set up Mojo IPC to the new process. |
559 mojo::edk::ChildProcessLaunched(process_.Handle(), | 561 mojo::edk::ChildProcessLaunched(process_.Handle(), |
560 std::move(mojo_host_platform_handle_)); | 562 std::move(mojo_host_platform_handle_), |
| 563 mojo_child_token_); |
561 } | 564 } |
562 | 565 |
563 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 566 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
564 zygote_ = zygote; | 567 zygote_ = zygote; |
565 #endif | 568 #endif |
566 if (process_.IsValid()) { | 569 if (process_.IsValid()) { |
567 client_->OnProcessLaunched(); | 570 client_->OnProcessLaunched(); |
568 } else { | 571 } else { |
| 572 mojo::edk::ChildProcessLaunchFailed(mojo_child_token_); |
569 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; | 573 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; |
570 client_->OnProcessLaunchFailed(error_code); | 574 client_->OnProcessLaunchFailed(error_code); |
571 } | 575 } |
572 } | 576 } |
573 | 577 |
574 bool ChildProcessLauncher::IsStarting() { | 578 bool ChildProcessLauncher::IsStarting() { |
575 // TODO(crbug.com/469248): This fails in some tests. | 579 // TODO(crbug.com/469248): This fails in some tests. |
576 // DCHECK(CalledOnValidThread()); | 580 // DCHECK(CalledOnValidThread()); |
577 return starting_; | 581 return starting_; |
578 } | 582 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 } | 615 } |
612 | 616 |
613 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 617 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
614 Client* client) { | 618 Client* client) { |
615 Client* ret = client_; | 619 Client* ret = client_; |
616 client_ = client; | 620 client_ = client; |
617 return ret; | 621 return ret; |
618 } | 622 } |
619 | 623 |
620 } // namespace content | 624 } // namespace content |
OLD | NEW |