| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 #endif | 159 #endif |
| 160 CommandLine* cmd_line) { | 160 CommandLine* cmd_line) { |
| 161 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); | 161 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); |
| 162 | 162 |
| 163 #if defined(OS_WIN) | 163 #if defined(OS_WIN) |
| 164 base::ProcessHandle handle = sandbox::StartProcessWithAccess( | 164 base::ProcessHandle handle = sandbox::StartProcessWithAccess( |
| 165 cmd_line, exposed_dir); | 165 cmd_line, exposed_dir); |
| 166 #elif defined(OS_ANDROID) | 166 #elif defined(OS_ANDROID) |
| 167 std::string process_type = | 167 std::string process_type = |
| 168 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 168 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
| 169 base::GlobalDescriptors::Mapping files_to_register; | 169 std::vector<content::FileDescriptorInfo> files_to_register; |
| 170 files_to_register.push_back(std::pair<base::GlobalDescriptors::Key, int>( | 170 files_to_register.push_back( |
| 171 kPrimaryIPCChannel, ipcfd)); | 171 content::FileDescriptorInfo(kPrimaryIPCChannel, |
| 172 base::FileDescriptor(ipcfd, false))); |
| 173 |
| 172 content::GetContentClient()->browser()-> | 174 content::GetContentClient()->browser()-> |
| 173 GetAdditionalMappedFilesForChildProcess(*cmd_line, &files_to_register); | 175 GetAdditionalMappedFilesForChildProcess(*cmd_line, &files_to_register); |
| 174 | 176 |
| 175 content::StartSandboxedProcess(cmd_line->argv(), | 177 content::StartSandboxedProcess(cmd_line->argv(), files_to_register, |
| 176 ipcfd, files_to_register, | |
| 177 base::Bind(&ChildProcessLauncher::Context::OnSandboxedProcessStarted, | 178 base::Bind(&ChildProcessLauncher::Context::OnSandboxedProcessStarted, |
| 178 this_object, client_thread_id)); | 179 this_object, client_thread_id)); |
| 179 | 180 |
| 180 #elif defined(OS_POSIX) | 181 #elif defined(OS_POSIX) |
| 181 base::ProcessHandle handle = base::kNullProcessHandle; | 182 base::ProcessHandle handle = base::kNullProcessHandle; |
| 182 // We need to close the client end of the IPC channel | 183 // We need to close the client end of the IPC channel to reliably detect |
| 183 // to reliably detect child termination. | 184 // child termination. |
| 184 file_util::ScopedFD ipcfd_closer(&ipcfd); | 185 file_util::ScopedFD ipcfd_closer(&ipcfd); |
| 185 | 186 |
| 186 std::string process_type = | 187 std::string process_type = |
| 187 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 188 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
| 188 base::GlobalDescriptors::Mapping files_to_register; | 189 std::vector<content::FileDescriptorInfo> files_to_register; |
| 189 files_to_register.push_back(std::pair<base::GlobalDescriptors::Key, int>( | 190 files_to_register.push_back( |
| 190 kPrimaryIPCChannel, ipcfd)); | 191 content::FileDescriptorInfo(kPrimaryIPCChannel, |
| 192 base::FileDescriptor(ipcfd, false))); |
| 193 |
| 191 #if !defined(OS_MACOSX) | 194 #if !defined(OS_MACOSX) |
| 192 content::GetContentClient()->browser()-> | 195 content::GetContentClient()->browser()-> |
| 193 GetAdditionalMappedFilesForChildProcess(*cmd_line, &files_to_register); | 196 GetAdditionalMappedFilesForChildProcess(*cmd_line, &files_to_register); |
| 194 if (use_zygote) { | 197 if (use_zygote) { |
| 195 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(), | 198 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(), |
| 196 files_to_register, | 199 files_to_register, |
| 197 process_type); | 200 process_type); |
| 198 } else | 201 } else |
| 199 // Fall through to the normal posix case below when we're not zygoting. | 202 // Fall through to the normal posix case below when we're not zygoting. |
| 200 #endif // !defined(OS_MACOSX) | 203 #endif // !defined(OS_MACOSX) |
| 201 { | 204 { |
| 202 // Convert FD mapping to FileHandleMappingVector | 205 // Convert FD mapping to FileHandleMappingVector |
| 203 base::FileHandleMappingVector fds_to_map; | 206 base::FileHandleMappingVector fds_to_map; |
| 204 for (size_t i = 0; i < files_to_register.size(); ++i) { | 207 for (std::vector<content::FileDescriptorInfo>::const_iterator |
| 205 const base::GlobalDescriptors::KeyFDPair& id_file = | 208 i = files_to_register.begin(); i != files_to_register.end(); ++i) { |
| 206 files_to_register[i]; | 209 const content::FileDescriptorInfo& fd_info = *i; |
| 207 fds_to_map.push_back(std::make_pair( | 210 fds_to_map.push_back(std::make_pair( |
| 208 id_file.second, | 211 fd_info.fd.fd, |
| 209 id_file.first + base::GlobalDescriptors::kBaseDescriptor)); | 212 fd_info.id + base::GlobalDescriptors::kBaseDescriptor)); |
| 210 } | 213 } |
| 211 | 214 |
| 212 #if !defined(OS_MACOSX) | 215 #if !defined(OS_MACOSX) |
| 213 if (process_type == switches::kRendererProcess) { | 216 if (process_type == switches::kRendererProcess) { |
| 214 const int sandbox_fd = | 217 const int sandbox_fd = |
| 215 RenderSandboxHostLinux::GetInstance()->GetRendererSocket(); | 218 RenderSandboxHostLinux::GetInstance()->GetRendererSocket(); |
| 216 fds_to_map.push_back(std::make_pair( | 219 fds_to_map.push_back(std::make_pair( |
| 217 sandbox_fd, | 220 sandbox_fd, |
| 218 kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 221 kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
| 219 } | 222 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 base::Bind( | 448 base::Bind( |
| 446 &ChildProcessLauncher::Context::SetProcessBackgrounded, | 449 &ChildProcessLauncher::Context::SetProcessBackgrounded, |
| 447 GetHandle(), background)); | 450 GetHandle(), background)); |
| 448 } | 451 } |
| 449 | 452 |
| 450 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 453 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
| 451 bool terminate_on_shutdown) { | 454 bool terminate_on_shutdown) { |
| 452 if (context_) | 455 if (context_) |
| 453 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 456 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
| 454 } | 457 } |
| OLD | NEW |