| 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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 client_->OnProcessLaunched(); | 332 client_->OnProcessLaunched(); |
| 333 } else { | 333 } else { |
| 334 Terminate(); | 334 Terminate(); |
| 335 } | 335 } |
| 336 } | 336 } |
| 337 | 337 |
| 338 void Terminate() { | 338 void Terminate() { |
| 339 if (!process_.handle()) | 339 if (!process_.handle()) |
| 340 return; | 340 return; |
| 341 | 341 |
| 342 if (!terminate_child_on_shutdown_) | 342 if (CommandLine::ForCurrentProcess()-> |
| 343 return; | 343 HasSwitch(switches::kWaitForChildrenBeforeExiting)) |
| 344 | 344 // When --wait-for-children-before-exiting is provided on the command |
| 345 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So | 345 // line, we want the UI thread to wait for the zygote to exit before |
| 346 // don't this on the UI/IO threads. | 346 // proceeding with the rest of the shut down. |
| 347 BrowserThread::PostTask( | 347 TerminateAndWaitForExit(zygote_, process_.handle()); |
| 348 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 348 else |
| 349 base::Bind( | 349 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So |
| 350 &Context::TerminateInternal, | 350 // don't this on the UI/IO threads. |
| 351 BrowserThread::PostTask( |
| 352 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| 353 base::Bind( |
| 354 &Context::TerminateInternal, |
| 351 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 355 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 352 zygote_, | 356 zygote_, |
| 353 #endif | 357 #endif |
| 354 process_.handle())); | 358 process_.handle())); |
| 355 process_.set_handle(base::kNullProcessHandle); | 359 process_.set_handle(base::kNullProcessHandle); |
| 356 } | 360 } |
| 357 | 361 |
| 358 static void SetProcessBackgrounded(base::ProcessHandle handle, | 362 static void SetProcessBackgrounded(base::ProcessHandle handle, |
| 359 bool background) { | 363 bool background) { |
| 360 base::Process process(handle); | 364 base::Process process(handle); |
| 361 process.SetProcessBackgrounded(background); | 365 process.SetProcessBackgrounded(background); |
| 362 } | 366 } |
| 363 | 367 |
| 368 static void TerminateAndWaitForExit( |
| 369 bool zygote, |
| 370 base::ProcessHandle handle) { |
| 371 base::Process process(handle); |
| 372 if (zygote) { |
| 373 while(ZygoteHostImpl::GetInstance()->GetTerminationStatus( |
| 374 handle, |
| 375 false, |
| 376 NULL) == base::TERMINATION_STATUS_STILL_RUNNING) |
| 377 sleep(2); |
| 378 } |
| 379 process.Close(); |
| 380 } |
| 381 |
| 364 static void TerminateInternal( | 382 static void TerminateInternal( |
| 365 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 383 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 366 bool zygote, | 384 bool zygote, |
| 367 #endif | 385 #endif |
| 368 base::ProcessHandle handle) { | 386 base::ProcessHandle handle) { |
| 369 #if defined(OS_ANDROID) | 387 #if defined(OS_ANDROID) |
| 370 LOG(INFO) << "ChromeProcess: Stopping process with handle " << handle; | 388 LOG(INFO) << "ChromeProcess: Stopping process with handle " << handle; |
| 371 StopChildProcess(handle); | 389 StopChildProcess(handle); |
| 372 #else | 390 #else |
| 373 base::Process process(handle); | 391 base::Process process(handle); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 GetHandle(), background)); | 511 GetHandle(), background)); |
| 494 } | 512 } |
| 495 | 513 |
| 496 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 514 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
| 497 bool terminate_on_shutdown) { | 515 bool terminate_on_shutdown) { |
| 498 if (context_.get()) | 516 if (context_.get()) |
| 499 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 517 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
| 500 } | 518 } |
| 501 | 519 |
| 502 } // namespace content | 520 } // namespace content |
| OLD | NEW |