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 10 matching lines...) Expand all Loading... |
21 #include "content/public/common/content_descriptors.h" | 21 #include "content/public/common/content_descriptors.h" |
22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
23 #include "content/public/common/result_codes.h" | 23 #include "content/public/common/result_codes.h" |
24 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 24 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
25 | 25 |
26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
27 #include "base/files/file_path.h" | 27 #include "base/files/file_path.h" |
28 #include "content/common/sandbox_win.h" | 28 #include "content/common/sandbox_win.h" |
29 #include "content/public/common/sandbox_init.h" | 29 #include "content/public/common/sandbox_init.h" |
30 #elif defined(OS_MACOSX) | 30 #elif defined(OS_MACOSX) |
| 31 #include "content/browser/bootstrap_sandbox_mac.h" |
31 #include "content/browser/mach_broker_mac.h" | 32 #include "content/browser/mach_broker_mac.h" |
| 33 #include "sandbox/mac/bootstrap_sandbox.h" |
32 #elif defined(OS_ANDROID) | 34 #elif defined(OS_ANDROID) |
33 #include "base/android/jni_android.h" | 35 #include "base/android/jni_android.h" |
34 #include "content/browser/android/child_process_launcher_android.h" | 36 #include "content/browser/android/child_process_launcher_android.h" |
35 #elif defined(OS_POSIX) | 37 #elif defined(OS_POSIX) |
36 #include "base/memory/shared_memory.h" | 38 #include "base/memory/shared_memory.h" |
37 #include "base/memory/singleton.h" | 39 #include "base/memory/singleton.h" |
38 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 40 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
39 #include "content/browser/zygote_host/zygote_host_impl_linux.h" | 41 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
40 #include "content/common/child_process_sandbox_support_impl_linux.h" | 42 #include "content/common/child_process_sandbox_support_impl_linux.h" |
41 #endif | 43 #endif |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 // record of the launch will wait until after the placeholder PID is | 277 // record of the launch will wait until after the placeholder PID is |
276 // inserted below. This ensures that while the child process may send its | 278 // inserted below. This ensures that while the child process may send its |
277 // port to the parent prior to the parent leaving LaunchProcess, the | 279 // port to the parent prior to the parent leaving LaunchProcess, the |
278 // order in which the record in MachBroker is updated is correct. | 280 // order in which the record in MachBroker is updated is correct. |
279 MachBroker* broker = MachBroker::GetInstance(); | 281 MachBroker* broker = MachBroker::GetInstance(); |
280 broker->GetLock().Acquire(); | 282 broker->GetLock().Acquire(); |
281 | 283 |
282 // Make sure the MachBroker is running, and inform it to expect a | 284 // Make sure the MachBroker is running, and inform it to expect a |
283 // check-in from the new process. | 285 // check-in from the new process. |
284 broker->EnsureRunning(); | 286 broker->EnsureRunning(); |
| 287 |
| 288 const int bootstrap_sandbox_policy = delegate->GetSandboxType(); |
| 289 if (bootstrap_sandbox_policy != -1) { |
| 290 GetBootstrapSandbox()->PrepareToForkWithPolicy( |
| 291 bootstrap_sandbox_policy); |
| 292 } |
285 #endif // defined(OS_MACOSX) | 293 #endif // defined(OS_MACOSX) |
286 | 294 |
287 bool launched = base::LaunchProcess(*cmd_line, options, &handle); | 295 bool launched = base::LaunchProcess(*cmd_line, options, &handle); |
| 296 if (!launched) |
| 297 handle = base::kNullProcessHandle; |
288 | 298 |
289 #if defined(OS_MACOSX) | 299 #if defined(OS_MACOSX) |
| 300 if (bootstrap_sandbox_policy != -1) { |
| 301 GetBootstrapSandbox()->FinishedFork(handle); |
| 302 } |
| 303 |
290 if (launched) | 304 if (launched) |
291 broker->AddPlaceholderForPid(handle); | 305 broker->AddPlaceholderForPid(handle); |
292 | 306 |
293 // After updating the broker, release the lock and let the child's | 307 // After updating the broker, release the lock and let the child's |
294 // messasge be processed on the broker's thread. | 308 // messasge be processed on the broker's thread. |
295 broker->GetLock().Release(); | 309 broker->GetLock().Release(); |
296 #endif // defined(OS_MACOSX) | 310 #endif // defined(OS_MACOSX) |
297 | |
298 if (!launched) | |
299 handle = base::kNullProcessHandle; | |
300 } | 311 } |
301 #endif // else defined(OS_POSIX) | 312 #endif // else defined(OS_POSIX) |
302 #if !defined(OS_ANDROID) | 313 #if !defined(OS_ANDROID) |
303 if (handle) | 314 if (handle) |
304 RecordHistograms(begin_launch_time); | 315 RecordHistograms(begin_launch_time); |
305 BrowserThread::PostTask( | 316 BrowserThread::PostTask( |
306 client_thread_id, FROM_HERE, | 317 client_thread_id, FROM_HERE, |
307 base::Bind( | 318 base::Bind( |
308 &Context::Notify, | 319 &Context::Notify, |
309 this_object.get(), | 320 this_object.get(), |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 GetHandle(), background)); | 513 GetHandle(), background)); |
503 } | 514 } |
504 | 515 |
505 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 516 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
506 bool terminate_on_shutdown) { | 517 bool terminate_on_shutdown) { |
507 if (context_.get()) | 518 if (context_.get()) |
508 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 519 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
509 } | 520 } |
510 | 521 |
511 } // namespace content | 522 } // namespace content |
OLD | NEW |