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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 259 kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
260 } | 260 } |
261 #endif // defined(OS_MACOSX) | 261 #endif // defined(OS_MACOSX) |
262 | 262 |
263 // Actually launch the app. | 263 // Actually launch the app. |
264 base::LaunchOptions options; | 264 base::LaunchOptions options; |
265 options.environ = &env; | 265 options.environ = &env; |
266 options.fds_to_remap = &fds_to_map; | 266 options.fds_to_remap = &fds_to_map; |
267 | 267 |
268 #if defined(OS_MACOSX) | 268 #if defined(OS_MACOSX) |
269 // Use synchronization to make sure that the MachBroker is ready to | 269 // Hold the MachBroker lock for the duration of LaunchProcess. The child |
270 // receive a check-in from the new process before the new process | 270 // will send its task port to the parent almost immediately after startup. |
271 // actually tries to check in. | 271 // The Mach message will be delivered to the parent, but updating the |
272 base::LaunchSynchronizationHandle synchronization_handle; | 272 // record of the launch will wait until after the placeholder PID is |
273 options.synchronize = &synchronization_handle; | 273 // inserted below. This ensures that while the child process may send its |
| 274 // port to the parent prior to the parent leaving LaunchProcess, the |
| 275 // order in which the record in MachBroker is updated is correct. |
| 276 MachBroker* broker = MachBroker::GetInstance(); |
| 277 broker->GetLock().Acquire(); |
| 278 |
| 279 // Make sure the MachBroker is running, and inform it to expect a |
| 280 // check-in from the new process. |
| 281 broker->EnsureRunning(); |
274 #endif // defined(OS_MACOSX) | 282 #endif // defined(OS_MACOSX) |
275 | 283 |
276 bool launched = base::LaunchProcess(*cmd_line, options, &handle); | 284 bool launched = base::LaunchProcess(*cmd_line, options, &handle); |
277 | 285 |
278 #if defined(OS_MACOSX) | 286 #if defined(OS_MACOSX) |
279 if (launched) { | 287 if (launched) |
280 MachBroker* broker = MachBroker::GetInstance(); | 288 broker->AddPlaceholderForPid(handle); |
281 { | |
282 base::AutoLock lock(broker->GetLock()); | |
283 | 289 |
284 // Make sure the MachBroker is running, and inform it to expect a | 290 // After updating the broker, release the lock and let the child's |
285 // check-in from the new process. | 291 // messasge be processed on the broker's thread. |
286 broker->EnsureRunning(); | 292 broker->GetLock().Release(); |
287 broker->AddPlaceholderForPid(handle); | |
288 } | |
289 | |
290 // Now that the MachBroker is ready, the child may continue. | |
291 base::LaunchSynchronize(synchronization_handle); | |
292 } | |
293 #endif // defined(OS_MACOSX) | 293 #endif // defined(OS_MACOSX) |
294 | 294 |
295 if (!launched) | 295 if (!launched) |
296 handle = base::kNullProcessHandle; | 296 handle = base::kNullProcessHandle; |
297 } | 297 } |
298 #endif // else defined(OS_POSIX) | 298 #endif // else defined(OS_POSIX) |
299 #if !defined(OS_ANDROID) | 299 #if !defined(OS_ANDROID) |
300 if (handle) | 300 if (handle) |
301 RecordHistograms(begin_launch_time); | 301 RecordHistograms(begin_launch_time); |
302 BrowserThread::PostTask( | 302 BrowserThread::PostTask( |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 GetHandle(), background)); | 493 GetHandle(), background)); |
494 } | 494 } |
495 | 495 |
496 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 496 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
497 bool terminate_on_shutdown) { | 497 bool terminate_on_shutdown) { |
498 if (context_) | 498 if (context_) |
499 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 499 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
500 } | 500 } |
501 | 501 |
502 } // namespace content | 502 } // namespace content |
OLD | NEW |