| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 15 #include "content/common/chrome_descriptors.h" | 16 #include "content/common/chrome_descriptors.h" |
| 16 #include "content/common/process_watcher.h" | 17 #include "content/common/process_watcher.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 int ipcfd, | 65 int ipcfd, |
| 65 #endif | 66 #endif |
| 66 CommandLine* cmd_line, | 67 CommandLine* cmd_line, |
| 67 Client* client) { | 68 Client* client) { |
| 68 client_ = client; | 69 client_ = client; |
| 69 | 70 |
| 70 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 71 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
| 71 | 72 |
| 72 BrowserThread::PostTask( | 73 BrowserThread::PostTask( |
| 73 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 74 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| 74 NewRunnableFunction( | 75 base::Bind( |
| 75 &Context::LaunchInternal, | 76 &Context::LaunchInternal, |
| 76 make_scoped_refptr(this), | 77 make_scoped_refptr(this), |
| 77 client_thread_id_, | 78 client_thread_id_, |
| 78 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
| 79 exposed_dir, | 80 exposed_dir, |
| 80 #elif defined(OS_POSIX) | 81 #elif defined(OS_POSIX) |
| 81 use_zygote, | 82 use_zygote, |
| 82 environ, | 83 environ, |
| 83 ipcfd, | 84 ipcfd, |
| 84 #endif | 85 #endif |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } | 199 } |
| 199 #endif // defined(OS_MACOSX) | 200 #endif // defined(OS_MACOSX) |
| 200 | 201 |
| 201 if (!launched) | 202 if (!launched) |
| 202 handle = base::kNullProcessHandle; | 203 handle = base::kNullProcessHandle; |
| 203 } | 204 } |
| 204 #endif // else defined(OS_POSIX) | 205 #endif // else defined(OS_POSIX) |
| 205 | 206 |
| 206 BrowserThread::PostTask( | 207 BrowserThread::PostTask( |
| 207 client_thread_id, FROM_HERE, | 208 client_thread_id, FROM_HERE, |
| 208 NewRunnableMethod( | 209 base::Bind( |
| 210 &Context::Notify, |
| 209 this_object.get(), | 211 this_object.get(), |
| 210 &Context::Notify, | |
| 211 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 212 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 212 use_zygote, | 213 use_zygote, |
| 213 #endif | 214 #endif |
| 214 handle)); | 215 handle)); |
| 215 } | 216 } |
| 216 | 217 |
| 217 void Notify( | 218 void Notify( |
| 218 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 219 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 219 bool zygote, | 220 bool zygote, |
| 220 #endif | 221 #endif |
| (...skipping 17 matching lines...) Expand all Loading... |
| 238 if (!process_.handle()) | 239 if (!process_.handle()) |
| 239 return; | 240 return; |
| 240 | 241 |
| 241 if (!terminate_child_on_shutdown_) | 242 if (!terminate_child_on_shutdown_) |
| 242 return; | 243 return; |
| 243 | 244 |
| 244 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So | 245 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So |
| 245 // don't this on the UI/IO threads. | 246 // don't this on the UI/IO threads. |
| 246 BrowserThread::PostTask( | 247 BrowserThread::PostTask( |
| 247 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 248 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| 248 NewRunnableFunction( | 249 base::Bind( |
| 249 &Context::TerminateInternal, | 250 &Context::TerminateInternal, |
| 250 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 251 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 251 zygote_, | 252 zygote_, |
| 252 #endif | 253 #endif |
| 253 process_.handle())); | 254 process_.handle())); |
| 254 process_.set_handle(base::kNullProcessHandle); | 255 process_.set_handle(base::kNullProcessHandle); |
| 255 } | 256 } |
| 256 | 257 |
| 257 static void SetProcessBackgrounded(base::ProcessHandle handle, | 258 static void SetProcessBackgrounded(base::ProcessHandle handle, |
| 258 bool background) { | 259 bool background) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 // Terminate via ProcessWatcher. So we can't close the handle here. | 369 // Terminate via ProcessWatcher. So we can't close the handle here. |
| 369 if (context_->termination_status_ != base::TERMINATION_STATUS_STILL_RUNNING) | 370 if (context_->termination_status_ != base::TERMINATION_STATUS_STILL_RUNNING) |
| 370 context_->process_.Close(); | 371 context_->process_.Close(); |
| 371 | 372 |
| 372 return context_->termination_status_; | 373 return context_->termination_status_; |
| 373 } | 374 } |
| 374 | 375 |
| 375 void ChildProcessLauncher::SetProcessBackgrounded(bool background) { | 376 void ChildProcessLauncher::SetProcessBackgrounded(bool background) { |
| 376 BrowserThread::PostTask( | 377 BrowserThread::PostTask( |
| 377 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 378 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| 378 NewRunnableFunction( | 379 base::Bind( |
| 379 &ChildProcessLauncher::Context::SetProcessBackgrounded, | 380 &ChildProcessLauncher::Context::SetProcessBackgrounded, |
| 380 GetHandle(), background)); | 381 GetHandle(), background)); |
| 381 } | 382 } |
| 382 | 383 |
| 383 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 384 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
| 384 bool terminate_on_shutdown) { | 385 bool terminate_on_shutdown) { |
| 385 if (context_) | 386 if (context_) |
| 386 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 387 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
| 387 } | 388 } |
| OLD | NEW |