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

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

Issue 22911027: Pass StatsTable shared memory via global descriptors on Posix rather than using named shared memory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Jar's comments. Created 7 years, 4 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 14 matching lines...) Expand all
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 #elif defined(OS_ANDROID) 201 #elif defined(OS_ANDROID)
200 // Android WebView runs in single process, ensure that we never get here 202 // Android WebView runs in single process, ensure that we never get here
201 // when running in single process mode. 203 // when running in single process mode.
202 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); 204 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess));
203 205
204 std::string process_type = 206 std::string process_type =
205 cmd_line->GetSwitchValueASCII(switches::kProcessType); 207 cmd_line->GetSwitchValueASCII(switches::kProcessType);
206 std::vector<FileDescriptorInfo> files_to_register; 208 std::vector<FileDescriptorInfo> files_to_register;
207 files_to_register.push_back( 209 files_to_register.push_back(
208 FileDescriptorInfo(kPrimaryIPCChannel, 210 FileDescriptorInfo(kPrimaryIPCChannel,
209 base::FileDescriptor(ipcfd, false))); 211 base::FileDescriptor(ipcfd, false)));
212 base::StatsTable* stats_table = base::StatsTable::current();
213 if (stats_table &&
214 base::SharedMemory::IsHandleValid(stats_table->GetSharedMemoryHandle()))
215 files_to_register.push_back(
216 FileDescriptorInfo(kStatsTableSharedMemFd,
217 stats_table->GetSharedMemoryHandle()));
210 218
211 GetContentClient()->browser()-> 219 GetContentClient()->browser()->
212 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, 220 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id,
213 &files_to_register); 221 &files_to_register);
214 222
215 StartChildProcess(cmd_line->argv(), files_to_register, 223 StartChildProcess(cmd_line->argv(), files_to_register,
216 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, 224 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted,
217 this_object, client_thread_id, begin_launch_time)); 225 this_object, client_thread_id, begin_launch_time));
218 226
219 #elif defined(OS_POSIX) 227 #elif defined(OS_POSIX)
220 base::ProcessHandle handle = base::kNullProcessHandle; 228 base::ProcessHandle handle = base::kNullProcessHandle;
221 // We need to close the client end of the IPC channel to reliably detect 229 // We need to close the client end of the IPC channel to reliably detect
222 // child termination. 230 // child termination.
223 file_util::ScopedFD ipcfd_closer(&ipcfd); 231 file_util::ScopedFD ipcfd_closer(&ipcfd);
224 232
225 std::string process_type = 233 std::string process_type =
226 cmd_line->GetSwitchValueASCII(switches::kProcessType); 234 cmd_line->GetSwitchValueASCII(switches::kProcessType);
227 std::vector<FileDescriptorInfo> files_to_register; 235 std::vector<FileDescriptorInfo> files_to_register;
228 files_to_register.push_back( 236 files_to_register.push_back(
229 FileDescriptorInfo(kPrimaryIPCChannel, 237 FileDescriptorInfo(kPrimaryIPCChannel,
230 base::FileDescriptor(ipcfd, false))); 238 base::FileDescriptor(ipcfd, false)));
231 239 base::StatsTable* stats_table = base::StatsTable::current();
240 if (stats_table &&
241 base::SharedMemory::IsHandleValid(stats_table->GetSharedMemoryHandle()))
242 files_to_register.push_back(
243 FileDescriptorInfo(kStatsTableSharedMemFd,
244 stats_table->GetSharedMemoryHandle()));
232 #if !defined(OS_MACOSX) 245 #if !defined(OS_MACOSX)
233 GetContentClient()->browser()-> 246 GetContentClient()->browser()->
234 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, 247 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id,
235 &files_to_register); 248 &files_to_register);
236 if (use_zygote) { 249 if (use_zygote) {
237 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(), 250 handle = ZygoteHostImpl::GetInstance()->ForkRequest(cmd_line->argv(),
238 files_to_register, 251 files_to_register,
239 process_type); 252 process_type);
240 } else 253 } else
241 // Fall through to the normal posix case below when we're not zygoting. 254 // 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
493 GetHandle(), background)); 506 GetHandle(), background));
494 } 507 }
495 508
496 void ChildProcessLauncher::SetTerminateChildOnShutdown( 509 void ChildProcessLauncher::SetTerminateChildOnShutdown(
497 bool terminate_on_shutdown) { 510 bool terminate_on_shutdown) {
498 if (context_.get()) 511 if (context_.get())
499 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); 512 context_->set_terminate_child_on_shutdown(terminate_on_shutdown);
500 } 513 }
501 514
502 } // namespace content 515 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698