| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 const base::EnvironmentMap& env, | 191 const base::EnvironmentMap& env, |
| 190 int ipcfd, | 192 int ipcfd, |
| 191 #endif | 193 #endif |
| 192 CommandLine* cmd_line) { | 194 CommandLine* cmd_line) { |
| 193 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); | 195 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); |
| 194 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); | 196 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); |
| 195 | 197 |
| 196 #if defined(OS_WIN) | 198 #if defined(OS_WIN) |
| 197 scoped_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); | 199 scoped_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); |
| 198 base::ProcessHandle handle = StartSandboxedProcess(delegate, cmd_line); | 200 base::ProcessHandle handle = StartSandboxedProcess(delegate, cmd_line); |
| 199 #elif defined(OS_ANDROID) | 201 #elif defined(OS_POSIX) |
| 200 // Android WebView runs in single process, ensure that we never get here | |
| 201 // when running in single process mode. | |
| 202 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); | |
| 203 | |
| 204 std::string process_type = | 202 std::string process_type = |
| 205 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 203 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
| 206 std::vector<FileDescriptorInfo> files_to_register; | 204 std::vector<FileDescriptorInfo> files_to_register; |
| 207 files_to_register.push_back( | 205 files_to_register.push_back( |
| 208 FileDescriptorInfo(kPrimaryIPCChannel, | 206 FileDescriptorInfo(kPrimaryIPCChannel, |
| 209 base::FileDescriptor(ipcfd, false))); | 207 base::FileDescriptor(ipcfd, false))); |
| 208 base::StatsTable* stats_table = base::StatsTable::current(); |
| 209 if (stats_table && |
| 210 base::SharedMemory::IsHandleValid( |
| 211 stats_table->GetSharedMemoryHandle())) { |
| 212 files_to_register.push_back( |
| 213 FileDescriptorInfo(kStatsTableSharedMemFd, |
| 214 stats_table->GetSharedMemoryHandle())); |
| 215 } |
| 216 #endif |
| 217 |
| 218 #if defined(OS_ANDROID) |
| 219 // Android WebView runs in single process, ensure that we never get here |
| 220 // when running in single process mode. |
| 221 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); |
| 210 | 222 |
| 211 GetContentClient()->browser()-> | 223 GetContentClient()->browser()-> |
| 212 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, | 224 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, |
| 213 &files_to_register); | 225 &files_to_register); |
| 214 | 226 |
| 215 StartChildProcess(cmd_line->argv(), files_to_register, | 227 StartChildProcess(cmd_line->argv(), files_to_register, |
| 216 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, | 228 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, |
| 217 this_object, client_thread_id, begin_launch_time)); | 229 this_object, client_thread_id, begin_launch_time)); |
| 218 | 230 |
| 219 #elif defined(OS_POSIX) | 231 #elif defined(OS_POSIX) |
| 220 base::ProcessHandle handle = base::kNullProcessHandle; | 232 base::ProcessHandle handle = base::kNullProcessHandle; |
| 221 // We need to close the client end of the IPC channel to reliably detect | 233 // We need to close the client end of the IPC channel to reliably detect |
| 222 // child termination. | 234 // child termination. |
| 223 file_util::ScopedFD ipcfd_closer(&ipcfd); | 235 file_util::ScopedFD ipcfd_closer(&ipcfd); |
| 224 | 236 |
| 225 std::string process_type = | |
| 226 cmd_line->GetSwitchValueASCII(switches::kProcessType); | |
| 227 std::vector<FileDescriptorInfo> files_to_register; | |
| 228 files_to_register.push_back( | |
| 229 FileDescriptorInfo(kPrimaryIPCChannel, | |
| 230 base::FileDescriptor(ipcfd, false))); | |
| 231 | |
| 232 #if !defined(OS_MACOSX) | 237 #if !defined(OS_MACOSX) |
| 233 GetContentClient()->browser()-> | 238 GetContentClient()->browser()-> |
| 234 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, | 239 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, |
| 235 &files_to_register); | 240 &files_to_register); |
| 236 if (use_zygote) { | 241 if (use_zygote) { |
| 237 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(), | 242 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(), |
| 238 files_to_register, | 243 files_to_register, |
| 239 process_type); | 244 process_type); |
| 240 } else | 245 } else |
| 241 // Fall through to the normal posix case below when we're not zygoting. | 246 // 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)); | 498 GetHandle(), background)); |
| 494 } | 499 } |
| 495 | 500 |
| 496 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 501 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
| 497 bool terminate_on_shutdown) { | 502 bool terminate_on_shutdown) { |
| 498 if (context_.get()) | 503 if (context_.get()) |
| 499 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 504 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
| 500 } | 505 } |
| 501 | 506 |
| 502 } // namespace content | 507 } // namespace content |
| OLD | NEW |