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 #include "content/common/child_process_sandbox_support_impl_linux.h" | 39 #include "content/common/child_process_sandbox_support_impl_linux.h" |
39 #endif | 40 #endif |
40 | 41 |
41 #if defined(OS_POSIX) | 42 #if defined(OS_POSIX) |
| 43 #include "base/metrics/stats_table.h" |
42 #include "base/posix/global_descriptors.h" | 44 #include "base/posix/global_descriptors.h" |
43 #endif | 45 #endif |
44 | 46 |
45 namespace content { | 47 namespace content { |
46 | 48 |
47 // Having the functionality of ChildProcessLauncher be in an internal | 49 // Having the functionality of ChildProcessLauncher be in an internal |
48 // ref counted object allows us to automatically terminate the process when the | 50 // ref counted object allows us to automatically terminate the process when the |
49 // parent class destructs, while still holding on to state that we need. | 51 // parent class destructs, while still holding on to state that we need. |
50 class ChildProcessLauncher::Context | 52 class ChildProcessLauncher::Context |
51 : public base::RefCountedThreadSafe<ChildProcessLauncher::Context> { | 53 : public base::RefCountedThreadSafe<ChildProcessLauncher::Context> { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 const base::EnvironmentMap& env, | 192 const base::EnvironmentMap& env, |
191 int ipcfd, | 193 int ipcfd, |
192 #endif | 194 #endif |
193 CommandLine* cmd_line) { | 195 CommandLine* cmd_line) { |
194 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); | 196 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); |
195 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); | 197 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); |
196 | 198 |
197 #if defined(OS_WIN) | 199 #if defined(OS_WIN) |
198 scoped_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); | 200 scoped_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); |
199 base::ProcessHandle handle = StartSandboxedProcess(delegate, cmd_line); | 201 base::ProcessHandle handle = StartSandboxedProcess(delegate, cmd_line); |
200 #elif defined(OS_ANDROID) | 202 #elif defined(OS_POSIX) |
201 // Android WebView runs in single process, ensure that we never get here | |
202 // when running in single process mode. | |
203 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); | |
204 | |
205 std::string process_type = | 203 std::string process_type = |
206 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 204 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
207 std::vector<FileDescriptorInfo> files_to_register; | 205 std::vector<FileDescriptorInfo> files_to_register; |
208 files_to_register.push_back( | 206 files_to_register.push_back( |
209 FileDescriptorInfo(kPrimaryIPCChannel, | 207 FileDescriptorInfo(kPrimaryIPCChannel, |
210 base::FileDescriptor(ipcfd, false))); | 208 base::FileDescriptor(ipcfd, false))); |
| 209 base::StatsTable* stats_table = base::StatsTable::current(); |
| 210 if (stats_table && |
| 211 base::SharedMemory::IsHandleValid( |
| 212 stats_table->GetSharedMemoryHandle())) { |
| 213 files_to_register.push_back( |
| 214 FileDescriptorInfo(kStatsTableSharedMemFd, |
| 215 stats_table->GetSharedMemoryHandle())); |
| 216 } |
| 217 #endif |
| 218 |
| 219 #if defined(OS_ANDROID) |
| 220 // Android WebView runs in single process, ensure that we never get here |
| 221 // when running in single process mode. |
| 222 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); |
211 | 223 |
212 GetContentClient()->browser()-> | 224 GetContentClient()->browser()-> |
213 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, | 225 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, |
214 &files_to_register); | 226 &files_to_register); |
215 | 227 |
216 StartChildProcess(cmd_line->argv(), files_to_register, | 228 StartChildProcess(cmd_line->argv(), files_to_register, |
217 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, | 229 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, |
218 this_object, client_thread_id, begin_launch_time)); | 230 this_object, client_thread_id, begin_launch_time)); |
219 | 231 |
220 #elif defined(OS_POSIX) | 232 #elif defined(OS_POSIX) |
221 base::ProcessHandle handle = base::kNullProcessHandle; | 233 base::ProcessHandle handle = base::kNullProcessHandle; |
222 // We need to close the client end of the IPC channel to reliably detect | 234 // We need to close the client end of the IPC channel to reliably detect |
223 // child termination. | 235 // child termination. |
224 file_util::ScopedFD ipcfd_closer(&ipcfd); | 236 file_util::ScopedFD ipcfd_closer(&ipcfd); |
225 | 237 |
226 std::string process_type = | |
227 cmd_line->GetSwitchValueASCII(switches::kProcessType); | |
228 std::vector<FileDescriptorInfo> files_to_register; | |
229 files_to_register.push_back( | |
230 FileDescriptorInfo(kPrimaryIPCChannel, | |
231 base::FileDescriptor(ipcfd, false))); | |
232 | |
233 #if !defined(OS_MACOSX) | 238 #if !defined(OS_MACOSX) |
234 GetContentClient()->browser()-> | 239 GetContentClient()->browser()-> |
235 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, | 240 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, |
236 &files_to_register); | 241 &files_to_register); |
237 if (use_zygote) { | 242 if (use_zygote) { |
238 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(), | 243 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(), |
239 files_to_register, | 244 files_to_register, |
240 process_type); | 245 process_type); |
241 } else | 246 } else |
242 // Fall through to the normal posix case below when we're not zygoting. | 247 // Fall through to the normal posix case below when we're not zygoting. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 GetHandle(), background)); | 504 GetHandle(), background)); |
500 } | 505 } |
501 | 506 |
502 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 507 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
503 bool terminate_on_shutdown) { | 508 bool terminate_on_shutdown) { |
504 if (context_.get()) | 509 if (context_.get()) |
505 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 510 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
506 } | 511 } |
507 | 512 |
508 } // namespace content | 513 } // namespace content |
OLD | NEW |