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 14 matching lines...) Expand all Loading... | |
25 #include "base/files/file_path.h" | 25 #include "base/files/file_path.h" |
26 #include "content/common/sandbox_win.h" | 26 #include "content/common/sandbox_win.h" |
27 #include "content/public/common/sandbox_init.h" | 27 #include "content/public/common/sandbox_init.h" |
28 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 28 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
29 #elif defined(OS_MACOSX) | 29 #elif defined(OS_MACOSX) |
30 #include "content/browser/mach_broker_mac.h" | 30 #include "content/browser/mach_broker_mac.h" |
31 #elif defined(OS_ANDROID) | 31 #elif defined(OS_ANDROID) |
32 #include "base/android/jni_android.h" | 32 #include "base/android/jni_android.h" |
33 #include "content/browser/android/child_process_launcher_android.h" | 33 #include "content/browser/android/child_process_launcher_android.h" |
34 #elif defined(OS_POSIX) | 34 #elif defined(OS_POSIX) |
35 #include "base/memory/shared_memory.h" | |
35 #include "base/memory/singleton.h" | 36 #include "base/memory/singleton.h" |
36 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 37 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
37 #include "content/browser/zygote_host/zygote_host_impl_linux.h" | 38 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
38 #endif | 39 #endif |
39 | 40 |
40 #if defined(OS_POSIX) | 41 #if defined(OS_POSIX) |
42 #include "base/metrics/stats_table.h" | |
41 #include "base/posix/global_descriptors.h" | 43 #include "base/posix/global_descriptors.h" |
42 #endif | 44 #endif |
43 | 45 |
44 namespace content { | 46 namespace content { |
45 | 47 |
46 // Having the functionality of ChildProcessLauncher be in an internal | 48 // Having the functionality of ChildProcessLauncher be in an internal |
47 // ref counted object allows us to automatically terminate the process when the | 49 // ref counted object allows us to automatically terminate the process when the |
48 // parent class destructs, while still holding on to state that we need. | 50 // parent class destructs, while still holding on to state that we need. |
49 class ChildProcessLauncher::Context | 51 class ChildProcessLauncher::Context |
50 : public base::RefCountedThreadSafe<ChildProcessLauncher::Context> { | 52 : public base::RefCountedThreadSafe<ChildProcessLauncher::Context> { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 #elif defined(OS_ANDROID) | 201 #elif defined(OS_ANDROID) |
200 // Android WebView runs in single process, ensure that we never get here | 202 // Android WebView runs in single process, ensure that we never get here |
201 // when running in single process mode. | 203 // when running in single process mode. |
202 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); | 204 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); |
203 | 205 |
204 std::string process_type = | 206 std::string process_type = |
205 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 207 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
206 std::vector<FileDescriptorInfo> files_to_register; | 208 std::vector<FileDescriptorInfo> files_to_register; |
207 files_to_register.push_back( | 209 files_to_register.push_back( |
208 FileDescriptorInfo(kPrimaryIPCChannel, | 210 FileDescriptorInfo(kPrimaryIPCChannel, |
209 base::FileDescriptor(ipcfd, false))); | 211 base::FileDescriptor(ipcfd, false))); |
212 base::StatsTable* stats_table = base::StatsTable::current(); | |
213 if (stats_table && | |
214 base::SharedMemory::IsHandleValid( | |
215 stats_table->GetSharedMemoryHandle())) { | |
216 files_to_register.push_back( | |
217 FileDescriptorInfo(kStatsTableSharedMemFd, | |
218 stats_table->GetSharedMemoryHandle())); | |
219 } | |
210 | 220 |
211 GetContentClient()->browser()-> | 221 GetContentClient()->browser()-> |
212 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, | 222 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, |
213 &files_to_register); | 223 &files_to_register); |
214 | 224 |
215 StartChildProcess(cmd_line->argv(), files_to_register, | 225 StartChildProcess(cmd_line->argv(), files_to_register, |
216 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, | 226 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, |
217 this_object, client_thread_id, begin_launch_time)); | 227 this_object, client_thread_id, begin_launch_time)); |
218 | 228 |
219 #elif defined(OS_POSIX) | 229 #elif defined(OS_POSIX) |
220 base::ProcessHandle handle = base::kNullProcessHandle; | 230 base::ProcessHandle handle = base::kNullProcessHandle; |
221 // We need to close the client end of the IPC channel to reliably detect | 231 // We need to close the client end of the IPC channel to reliably detect |
222 // child termination. | 232 // child termination. |
223 file_util::ScopedFD ipcfd_closer(&ipcfd); | 233 file_util::ScopedFD ipcfd_closer(&ipcfd); |
224 | 234 |
225 std::string process_type = | 235 std::string process_type = |
226 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 236 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
227 std::vector<FileDescriptorInfo> files_to_register; | 237 std::vector<FileDescriptorInfo> files_to_register; |
228 files_to_register.push_back( | 238 files_to_register.push_back( |
229 FileDescriptorInfo(kPrimaryIPCChannel, | 239 FileDescriptorInfo(kPrimaryIPCChannel, |
230 base::FileDescriptor(ipcfd, false))); | 240 base::FileDescriptor(ipcfd, false))); |
231 | 241 base::StatsTable* stats_table = base::StatsTable::current(); |
jam
2013/08/25 16:22:25
we need to have one copy of this code, not two, an
rmcilroy
2013/08/27 14:13:06
Done (combined ifdefs).
| |
242 if (stats_table && | |
243 base::SharedMemory::IsHandleValid( | |
244 stats_table->GetSharedMemoryHandle())) { | |
245 files_to_register.push_back( | |
246 FileDescriptorInfo(kStatsTableSharedMemFd, | |
247 stats_table->GetSharedMemoryHandle())); | |
248 } | |
232 #if !defined(OS_MACOSX) | 249 #if !defined(OS_MACOSX) |
233 GetContentClient()->browser()-> | 250 GetContentClient()->browser()-> |
234 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, | 251 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, |
235 &files_to_register); | 252 &files_to_register); |
236 if (use_zygote) { | 253 if (use_zygote) { |
237 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(), | 254 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(), |
238 files_to_register, | 255 files_to_register, |
239 process_type); | 256 process_type); |
240 } else | 257 } else |
241 // Fall through to the normal posix case below when we're not zygoting. | 258 // Fall through to the normal posix case below when we're not zygoting. |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 GetHandle(), background)); | 510 GetHandle(), background)); |
494 } | 511 } |
495 | 512 |
496 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 513 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
497 bool terminate_on_shutdown) { | 514 bool terminate_on_shutdown) { |
498 if (context_.get()) | 515 if (context_.get()) |
499 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 516 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
500 } | 517 } |
501 | 518 |
502 } // namespace content | 519 } // namespace content |
OLD | NEW |