Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: content/browser/child_process_launcher.cc

Issue 585203002: Turn FileDescriptorInfo a collection class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 if (launch_elevated) { 194 if (launch_elevated) {
195 base::LaunchOptions options; 195 base::LaunchOptions options;
196 options.start_hidden = true; 196 options.start_hidden = true;
197 base::LaunchElevatedProcess(*cmd_line, options, &handle); 197 base::LaunchElevatedProcess(*cmd_line, options, &handle);
198 } else { 198 } else {
199 handle = StartSandboxedProcess(delegate, cmd_line); 199 handle = StartSandboxedProcess(delegate, cmd_line);
200 } 200 }
201 #elif defined(OS_POSIX) 201 #elif defined(OS_POSIX)
202 std::string process_type = 202 std::string process_type =
203 cmd_line->GetSwitchValueASCII(switches::kProcessType); 203 cmd_line->GetSwitchValueASCII(switches::kProcessType);
204 std::vector<FileDescriptorInfo> files_to_register; 204 scoped_ptr<FileDescriptorInfo> files_to_register =
205 files_to_register.push_back( 205 make_scoped_ptr(new FileDescriptorInfo());
206 FileDescriptorInfo(kPrimaryIPCChannel, 206 files_to_register->Share(kPrimaryIPCChannel, ipcfd);
207 base::FileDescriptor(ipcfd, false)));
208 base::StatsTable* stats_table = base::StatsTable::current(); 207 base::StatsTable* stats_table = base::StatsTable::current();
209 if (stats_table && 208 if (stats_table &&
210 base::SharedMemory::IsHandleValid( 209 base::SharedMemory::IsHandleValid(
211 stats_table->GetSharedMemoryHandle())) { 210 stats_table->GetSharedMemoryHandle())) {
212 files_to_register.push_back( 211 base::FileDescriptor fd = stats_table->GetSharedMemoryHandle();
213 FileDescriptorInfo(kStatsTableSharedMemFd, 212 DCHECK(fd.auto_close);
214 stats_table->GetSharedMemoryHandle())); 213 files_to_register->Transfer(kStatsTableSharedMemFd,
214 base::ScopedFD(fd.fd));
215 } 215 }
216 #endif 216 #endif
217 217
218 #if defined(OS_ANDROID) 218 #if defined(OS_ANDROID)
219 // Android WebView runs in single process, ensure that we never get here 219 // Android WebView runs in single process, ensure that we never get here
220 // when running in single process mode. 220 // when running in single process mode.
221 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); 221 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess));
222 222
223 GetContentClient()->browser()-> 223 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess(
224 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, 224 *cmd_line, child_process_id, files_to_register.get());
225 &files_to_register);
226 225
227 StartChildProcess(cmd_line->argv(), child_process_id, files_to_register, 226 StartChildProcess(
227 cmd_line->argv(),
228 child_process_id,
229 files_to_register.Pass(),
228 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, 230 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted,
229 this_object, client_thread_id, begin_launch_time)); 231 this_object,
232 client_thread_id,
233 begin_launch_time));
230 234
231 #elif defined(OS_POSIX) 235 #elif defined(OS_POSIX)
232 base::ProcessHandle handle = base::kNullProcessHandle; 236 base::ProcessHandle handle = base::kNullProcessHandle;
233 // We need to close the client end of the IPC channel to reliably detect 237 // We need to close the client end of the IPC channel to reliably detect
234 // child termination. 238 // child termination.
235 base::ScopedFD ipcfd_closer(ipcfd); 239 base::ScopedFD ipcfd_closer(ipcfd);
236 240
237 #if !defined(OS_MACOSX) 241 #if !defined(OS_MACOSX)
238 GetContentClient()->browser()-> 242 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess(
239 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, 243 *cmd_line, child_process_id, files_to_register.get());
240 &files_to_register);
241 if (use_zygote) { 244 if (use_zygote) {
242 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(), 245 handle = ZygoteHostImpl::GetInstance()->ForkRequest(
243 files_to_register, 246 cmd_line->argv(), files_to_register.Pass(), process_type);
244 process_type);
245 } else 247 } else
246 // Fall through to the normal posix case below when we're not zygoting. 248 // Fall through to the normal posix case below when we're not zygoting.
247 #endif // !defined(OS_MACOSX) 249 #endif // !defined(OS_MACOSX)
248 { 250 {
249 // Convert FD mapping to FileHandleMappingVector 251 // Convert FD mapping to FileHandleMappingVector
250 base::FileHandleMappingVector fds_to_map; 252 base::FileHandleMappingVector fds_to_map =
251 for (size_t i = 0; i < files_to_register.size(); ++i) { 253 files_to_register->descriptors();
252 fds_to_map.push_back(std::make_pair( 254 for (size_t i = 0; i < fds_to_map.size(); ++i) {
253 files_to_register[i].fd.fd, 255 fds_to_map[i].second += base::GlobalDescriptors::kBaseDescriptor;
mdempsky 2014/09/22 18:30:51 I know FileHandleMappingVector predates your CL, b
Hajime Morrita 2014/09/22 22:59:26 Agreed. I cannot kill FileHandleMappingVector so l
254 files_to_register[i].id +
255 base::GlobalDescriptors::kBaseDescriptor));
256 } 256 }
257 257
258 #if !defined(OS_MACOSX) 258 #if !defined(OS_MACOSX)
259 if (process_type == switches::kRendererProcess) { 259 if (process_type == switches::kRendererProcess) {
260 const int sandbox_fd = 260 const int sandbox_fd =
261 RenderSandboxHostLinux::GetInstance()->GetRendererSocket(); 261 RenderSandboxHostLinux::GetInstance()->GetRendererSocket();
262 fds_to_map.push_back(std::make_pair( 262 fds_to_map.push_back(std::make_pair(
263 sandbox_fd, 263 sandbox_fd,
264 GetSandboxFD())); 264 GetSandboxFD()));
265 } 265 }
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 GetHandle(), background)); 517 GetHandle(), background));
518 } 518 }
519 519
520 void ChildProcessLauncher::SetTerminateChildOnShutdown( 520 void ChildProcessLauncher::SetTerminateChildOnShutdown(
521 bool terminate_on_shutdown) { 521 bool terminate_on_shutdown) {
522 if (context_.get()) 522 if (context_.get())
523 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); 523 context_->set_terminate_child_on_shutdown(terminate_on_shutdown);
524 } 524 }
525 525
526 } // namespace content 526 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698