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/result_codes.h" | 21 #include "content/public/common/result_codes.h" |
22 | 22 |
23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
24 #include "base/file_path.h" | 24 #include "base/file_path.h" |
25 #include "content/common/sandbox_policy.h" | 25 #include "content/common/sandbox_policy.h" |
26 #elif defined(OS_MACOSX) | 26 #elif defined(OS_MACOSX) |
27 #include "content/browser/mach_broker_mac.h" | 27 #include "content/browser/mach_broker_mac.h" |
28 #elif defined(OS_POSIX) | 28 #elif defined(OS_POSIX) |
29 #include "base/memory/singleton.h" | 29 #include "base/memory/singleton.h" |
30 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 30 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
31 #include "content/browser/zygote_host_linux.h" | 31 #include "content/browser/zygote_host_impl_linux.h" |
32 #endif | 32 #endif |
33 | 33 |
34 #if defined(OS_POSIX) | 34 #if defined(OS_POSIX) |
35 #include "base/global_descriptors_posix.h" | 35 #include "base/global_descriptors_posix.h" |
36 #endif | 36 #endif |
37 | 37 |
38 using content::BrowserThread; | 38 using content::BrowserThread; |
39 | 39 |
40 // Having the functionality of ChildProcessLauncher be in an internal | 40 // Having the functionality of ChildProcessLauncher be in an internal |
41 // ref counted object allows us to automatically terminate the process when the | 41 // ref counted object allows us to automatically terminate the process when the |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 133 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
134 int crash_signal_fd = | 134 int crash_signal_fd = |
135 content::GetContentClient()->browser()->GetCrashSignalFD(*cmd_line); | 135 content::GetContentClient()->browser()->GetCrashSignalFD(*cmd_line); |
136 if (use_zygote) { | 136 if (use_zygote) { |
137 base::GlobalDescriptors::Mapping mapping; | 137 base::GlobalDescriptors::Mapping mapping; |
138 mapping.push_back(std::pair<uint32_t, int>(kPrimaryIPCChannel, ipcfd)); | 138 mapping.push_back(std::pair<uint32_t, int>(kPrimaryIPCChannel, ipcfd)); |
139 if (crash_signal_fd >= 0) { | 139 if (crash_signal_fd >= 0) { |
140 mapping.push_back(std::pair<uint32_t, int>(kCrashDumpSignal, | 140 mapping.push_back(std::pair<uint32_t, int>(kCrashDumpSignal, |
141 crash_signal_fd)); | 141 crash_signal_fd)); |
142 } | 142 } |
143 handle = ZygoteHost::GetInstance()->ForkRequest(cmd_line->argv(), | 143 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(), |
144 mapping, | 144 mapping, |
145 process_type); | 145 process_type); |
146 } else | 146 } else |
147 // Fall through to the normal posix case below when we're not zygoting. | 147 // Fall through to the normal posix case below when we're not zygoting. |
148 #endif | 148 #endif |
149 { | 149 { |
150 base::FileHandleMappingVector fds_to_map; | 150 base::FileHandleMappingVector fds_to_map; |
151 fds_to_map.push_back(std::make_pair( | 151 fds_to_map.push_back(std::make_pair( |
152 ipcfd, | 152 ipcfd, |
153 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 153 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
154 | 154 |
155 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 155 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 base::Process process(handle); | 269 base::Process process(handle); |
270 // Client has gone away, so just kill the process. Using exit code 0 | 270 // Client has gone away, so just kill the process. Using exit code 0 |
271 // means that UMA won't treat this as a crash. | 271 // means that UMA won't treat this as a crash. |
272 process.Terminate(content::RESULT_CODE_NORMAL_EXIT); | 272 process.Terminate(content::RESULT_CODE_NORMAL_EXIT); |
273 // On POSIX, we must additionally reap the child. | 273 // On POSIX, we must additionally reap the child. |
274 #if defined(OS_POSIX) | 274 #if defined(OS_POSIX) |
275 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 275 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
276 if (zygote) { | 276 if (zygote) { |
277 // If the renderer was created via a zygote, we have to proxy the reaping | 277 // If the renderer was created via a zygote, we have to proxy the reaping |
278 // through the zygote process. | 278 // through the zygote process. |
279 ZygoteHost::GetInstance()->EnsureProcessTerminated(handle); | 279 ZygoteHostImpl::GetInstance()->EnsureProcessTerminated(handle); |
280 } else | 280 } else |
281 #endif // !OS_MACOSX | 281 #endif // !OS_MACOSX |
282 { | 282 { |
283 base::EnsureProcessTerminated(handle); | 283 base::EnsureProcessTerminated(handle); |
284 } | 284 } |
285 #endif // OS_POSIX | 285 #endif // OS_POSIX |
286 process.Close(); | 286 process.Close(); |
287 } | 287 } |
288 | 288 |
289 Client* client_; | 289 Client* client_; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 int* exit_code) { | 342 int* exit_code) { |
343 base::ProcessHandle handle = context_->process_.handle(); | 343 base::ProcessHandle handle = context_->process_.handle(); |
344 if (handle == base::kNullProcessHandle) { | 344 if (handle == base::kNullProcessHandle) { |
345 // Process is already gone, so return the cached termination status. | 345 // Process is already gone, so return the cached termination status. |
346 if (exit_code) | 346 if (exit_code) |
347 *exit_code = context_->exit_code_; | 347 *exit_code = context_->exit_code_; |
348 return context_->termination_status_; | 348 return context_->termination_status_; |
349 } | 349 } |
350 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 350 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
351 if (context_->zygote_) { | 351 if (context_->zygote_) { |
352 context_->termination_status_ = ZygoteHost::GetInstance()-> | 352 context_->termination_status_ = ZygoteHostImpl::GetInstance()-> |
353 GetTerminationStatus(handle, &context_->exit_code_); | 353 GetTerminationStatus(handle, &context_->exit_code_); |
354 } else | 354 } else |
355 #endif | 355 #endif |
356 { | 356 { |
357 context_->termination_status_ = | 357 context_->termination_status_ = |
358 base::GetTerminationStatus(handle, &context_->exit_code_); | 358 base::GetTerminationStatus(handle, &context_->exit_code_); |
359 } | 359 } |
360 | 360 |
361 if (exit_code) | 361 if (exit_code) |
362 *exit_code = context_->exit_code_; | 362 *exit_code = context_->exit_code_; |
(...skipping 16 matching lines...) Expand all Loading... |
379 base::Bind( | 379 base::Bind( |
380 &ChildProcessLauncher::Context::SetProcessBackgrounded, | 380 &ChildProcessLauncher::Context::SetProcessBackgrounded, |
381 GetHandle(), background)); | 381 GetHandle(), background)); |
382 } | 382 } |
383 | 383 |
384 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 384 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
385 bool terminate_on_shutdown) { | 385 bool terminate_on_shutdown) { |
386 if (context_) | 386 if (context_) |
387 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 387 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
388 } | 388 } |
OLD | NEW |