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

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: Fixing android build error 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 27 matching lines...) Expand all
38 #include "base/memory/shared_memory.h" 38 #include "base/memory/shared_memory.h"
39 #include "base/memory/singleton.h" 39 #include "base/memory/singleton.h"
40 #include "content/browser/renderer_host/render_sandbox_host_linux.h" 40 #include "content/browser/renderer_host/render_sandbox_host_linux.h"
41 #include "content/browser/zygote_host/zygote_host_impl_linux.h" 41 #include "content/browser/zygote_host/zygote_host_impl_linux.h"
42 #include "content/common/child_process_sandbox_support_impl_linux.h" 42 #include "content/common/child_process_sandbox_support_impl_linux.h"
43 #endif 43 #endif
44 44
45 #if defined(OS_POSIX) 45 #if defined(OS_POSIX)
46 #include "base/metrics/stats_table.h" 46 #include "base/metrics/stats_table.h"
47 #include "base/posix/global_descriptors.h" 47 #include "base/posix/global_descriptors.h"
48 #include "content/browser/file_descriptor_info_impl.h"
48 #endif 49 #endif
49 50
50 namespace content { 51 namespace content {
51 52
52 // Having the functionality of ChildProcessLauncher be in an internal 53 // Having the functionality of ChildProcessLauncher be in an internal
53 // ref counted object allows us to automatically terminate the process when the 54 // ref counted object allows us to automatically terminate the process when the
54 // parent class destructs, while still holding on to state that we need. 55 // parent class destructs, while still holding on to state that we need.
55 class ChildProcessLauncher::Context 56 class ChildProcessLauncher::Context
56 : public base::RefCountedThreadSafe<ChildProcessLauncher::Context> { 57 : public base::RefCountedThreadSafe<ChildProcessLauncher::Context> {
57 public: 58 public:
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 if (launch_elevated) { 195 if (launch_elevated) {
195 base::LaunchOptions options; 196 base::LaunchOptions options;
196 options.start_hidden = true; 197 options.start_hidden = true;
197 base::LaunchElevatedProcess(*cmd_line, options, &handle); 198 base::LaunchElevatedProcess(*cmd_line, options, &handle);
198 } else { 199 } else {
199 handle = StartSandboxedProcess(delegate, cmd_line); 200 handle = StartSandboxedProcess(delegate, cmd_line);
200 } 201 }
201 #elif defined(OS_POSIX) 202 #elif defined(OS_POSIX)
202 std::string process_type = 203 std::string process_type =
203 cmd_line->GetSwitchValueASCII(switches::kProcessType); 204 cmd_line->GetSwitchValueASCII(switches::kProcessType);
204 std::vector<FileDescriptorInfo> files_to_register; 205 scoped_ptr<FileDescriptorInfo> files_to_register(
205 files_to_register.push_back( 206 FileDescriptorInfoImpl::Create());
206 FileDescriptorInfo(kPrimaryIPCChannel, 207 files_to_register->Share(kPrimaryIPCChannel, ipcfd);
207 base::FileDescriptor(ipcfd, false)));
208 base::StatsTable* stats_table = base::StatsTable::current(); 208 base::StatsTable* stats_table = base::StatsTable::current();
209 if (stats_table && 209 if (stats_table &&
210 base::SharedMemory::IsHandleValid( 210 base::SharedMemory::IsHandleValid(
211 stats_table->GetSharedMemoryHandle())) { 211 stats_table->GetSharedMemoryHandle())) {
212 files_to_register.push_back( 212 base::FileDescriptor fd = stats_table->GetSharedMemoryHandle();
213 FileDescriptorInfo(kStatsTableSharedMemFd, 213 DCHECK(fd.auto_close);
214 stats_table->GetSharedMemoryHandle())); 214 files_to_register->Transfer(kStatsTableSharedMemFd,
215 base::ScopedFD(fd.fd));
215 } 216 }
216 #endif 217 #endif
217 218
218 #if defined(OS_ANDROID) 219 #if defined(OS_ANDROID)
219 // Android WebView runs in single process, ensure that we never get here 220 // Android WebView runs in single process, ensure that we never get here
220 // when running in single process mode. 221 // when running in single process mode.
221 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); 222 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess));
222 223
223 GetContentClient()->browser()-> 224 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess(
224 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, 225 *cmd_line, child_process_id, files_to_register.get());
225 &files_to_register);
226 226
227 StartChildProcess(cmd_line->argv(), child_process_id, files_to_register, 227 StartChildProcess(
228 cmd_line->argv(),
229 child_process_id,
230 files_to_register.Pass(),
228 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, 231 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted,
229 this_object, client_thread_id, begin_launch_time)); 232 this_object,
233 client_thread_id,
234 begin_launch_time));
230 235
231 #elif defined(OS_POSIX) 236 #elif defined(OS_POSIX)
232 base::ProcessHandle handle = base::kNullProcessHandle; 237 base::ProcessHandle handle = base::kNullProcessHandle;
233 // We need to close the client end of the IPC channel to reliably detect 238 // We need to close the client end of the IPC channel to reliably detect
234 // child termination. 239 // child termination.
235 base::ScopedFD ipcfd_closer(ipcfd); 240 base::ScopedFD ipcfd_closer(ipcfd);
236 241
237 #if !defined(OS_MACOSX) 242 #if !defined(OS_MACOSX)
238 GetContentClient()->browser()-> 243 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess(
239 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, 244 *cmd_line, child_process_id, files_to_register.get());
240 &files_to_register);
241 if (use_zygote) { 245 if (use_zygote) {
242 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(), 246 handle = ZygoteHostImpl::GetInstance()->ForkRequest(
243 files_to_register, 247 cmd_line->argv(), files_to_register.Pass(), process_type);
244 process_type);
245 } else 248 } else
246 // Fall through to the normal posix case below when we're not zygoting. 249 // Fall through to the normal posix case below when we're not zygoting.
247 #endif // !defined(OS_MACOSX) 250 #endif // !defined(OS_MACOSX)
248 { 251 {
249 // Convert FD mapping to FileHandleMappingVector 252 // Convert FD mapping to FileHandleMappingVector
250 base::FileHandleMappingVector fds_to_map; 253 base::FileHandleMappingVector fds_to_map =
251 for (size_t i = 0; i < files_to_register.size(); ++i) { 254 files_to_register->GetMappingWithIDAdjustment(
252 fds_to_map.push_back(std::make_pair( 255 base::GlobalDescriptors::kBaseDescriptor);
253 files_to_register[i].fd.fd,
254 files_to_register[i].id +
255 base::GlobalDescriptors::kBaseDescriptor));
256 }
257 256
258 #if !defined(OS_MACOSX) 257 #if !defined(OS_MACOSX)
259 if (process_type == switches::kRendererProcess) { 258 if (process_type == switches::kRendererProcess) {
260 const int sandbox_fd = 259 const int sandbox_fd =
261 RenderSandboxHostLinux::GetInstance()->GetRendererSocket(); 260 RenderSandboxHostLinux::GetInstance()->GetRendererSocket();
262 fds_to_map.push_back(std::make_pair( 261 fds_to_map.push_back(std::make_pair(
263 sandbox_fd, 262 sandbox_fd,
264 GetSandboxFD())); 263 GetSandboxFD()));
265 } 264 }
266 #endif // defined(OS_MACOSX) 265 #endif // defined(OS_MACOSX)
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 GetHandle(), background)); 516 GetHandle(), background));
518 } 517 }
519 518
520 void ChildProcessLauncher::SetTerminateChildOnShutdown( 519 void ChildProcessLauncher::SetTerminateChildOnShutdown(
521 bool terminate_on_shutdown) { 520 bool terminate_on_shutdown) {
522 if (context_.get()) 521 if (context_.get())
523 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); 522 context_->set_terminate_child_on_shutdown(terminate_on_shutdown);
524 } 523 }
525 524
526 } // namespace content 525 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698