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 11 matching lines...) Expand all Loading... |
22 #include "content/public/common/result_codes.h" | 22 #include "content/public/common/result_codes.h" |
23 | 23 |
24 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
25 #include "base/files/file_path.h" | 25 #include "base/files/file_path.h" |
26 #include "content/common/sandbox_policy.h" | 26 #include "content/common/sandbox_policy.h" |
27 #include "content/public/common/sandbox_init.h" | 27 #include "content/public/common/sandbox_init.h" |
28 #elif defined(OS_MACOSX) | 28 #elif defined(OS_MACOSX) |
29 #include "content/browser/mach_broker_mac.h" | 29 #include "content/browser/mach_broker_mac.h" |
30 #elif defined(OS_ANDROID) | 30 #elif defined(OS_ANDROID) |
31 #include "base/android/jni_android.h" | 31 #include "base/android/jni_android.h" |
32 #include "content/browser/android/sandboxed_process_launcher.h" | 32 #include "content/browser/android/child_process_launcher.h" |
33 #elif defined(OS_POSIX) | 33 #elif defined(OS_POSIX) |
34 #include "base/memory/singleton.h" | 34 #include "base/memory/singleton.h" |
35 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 35 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
36 #include "content/browser/zygote_host/zygote_host_impl_linux.h" | 36 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
37 #endif | 37 #endif |
38 | 38 |
39 #if defined(OS_POSIX) | 39 #if defined(OS_POSIX) |
40 #include "base/posix/global_descriptors.h" | 40 #include "base/posix/global_descriptors.h" |
41 #endif | 41 #endif |
42 | 42 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 ipcfd, | 102 ipcfd, |
103 #elif defined(OS_POSIX) | 103 #elif defined(OS_POSIX) |
104 use_zygote, | 104 use_zygote, |
105 environ, | 105 environ, |
106 ipcfd, | 106 ipcfd, |
107 #endif | 107 #endif |
108 cmd_line)); | 108 cmd_line)); |
109 } | 109 } |
110 | 110 |
111 #if defined(OS_ANDROID) | 111 #if defined(OS_ANDROID) |
112 static void OnSandboxedProcessStarted( | 112 static void OnChildProcessStarted( |
113 // |this_object| is NOT thread safe. Only use it to post a task back. | 113 // |this_object| is NOT thread safe. Only use it to post a task back. |
114 scoped_refptr<Context> this_object, | 114 scoped_refptr<Context> this_object, |
115 BrowserThread::ID client_thread_id, | 115 BrowserThread::ID client_thread_id, |
116 const base::TimeTicks begin_launch_time, | 116 const base::TimeTicks begin_launch_time, |
117 base::ProcessHandle handle) { | 117 base::ProcessHandle handle) { |
118 RecordHistograms(begin_launch_time); | 118 RecordHistograms(begin_launch_time); |
119 if (BrowserThread::CurrentlyOn(client_thread_id)) { | 119 if (BrowserThread::CurrentlyOn(client_thread_id)) { |
120 // This is always invoked on the UI thread which is commonly the | 120 // This is always invoked on the UI thread which is commonly the |
121 // |client_thread_id| so we can shortcut one PostTask. | 121 // |client_thread_id| so we can shortcut one PostTask. |
122 this_object->Notify(handle); | 122 this_object->Notify(handle); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 203 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
204 std::vector<FileDescriptorInfo> files_to_register; | 204 std::vector<FileDescriptorInfo> files_to_register; |
205 files_to_register.push_back( | 205 files_to_register.push_back( |
206 FileDescriptorInfo(kPrimaryIPCChannel, | 206 FileDescriptorInfo(kPrimaryIPCChannel, |
207 base::FileDescriptor(ipcfd, false))); | 207 base::FileDescriptor(ipcfd, false))); |
208 | 208 |
209 GetContentClient()->browser()-> | 209 GetContentClient()->browser()-> |
210 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, | 210 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, |
211 &files_to_register); | 211 &files_to_register); |
212 | 212 |
213 StartSandboxedProcess(cmd_line->argv(), files_to_register, | 213 StartChildProcess(cmd_line->argv(), files_to_register, |
214 base::Bind(&ChildProcessLauncher::Context::OnSandboxedProcessStarted, | 214 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, |
215 this_object, client_thread_id, begin_launch_time)); | 215 this_object, client_thread_id, begin_launch_time)); |
216 | 216 |
217 #elif defined(OS_POSIX) | 217 #elif defined(OS_POSIX) |
218 base::ProcessHandle handle = base::kNullProcessHandle; | 218 base::ProcessHandle handle = base::kNullProcessHandle; |
219 // We need to close the client end of the IPC channel to reliably detect | 219 // We need to close the client end of the IPC channel to reliably detect |
220 // child termination. | 220 // child termination. |
221 file_util::ScopedFD ipcfd_closer(&ipcfd); | 221 file_util::ScopedFD ipcfd_closer(&ipcfd); |
222 | 222 |
223 std::string process_type = | 223 std::string process_type = |
224 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 224 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 process.SetProcessBackgrounded(background); | 359 process.SetProcessBackgrounded(background); |
360 } | 360 } |
361 | 361 |
362 static void TerminateInternal( | 362 static void TerminateInternal( |
363 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 363 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
364 bool zygote, | 364 bool zygote, |
365 #endif | 365 #endif |
366 base::ProcessHandle handle) { | 366 base::ProcessHandle handle) { |
367 #if defined(OS_ANDROID) | 367 #if defined(OS_ANDROID) |
368 LOG(INFO) << "ChromeProcess: Stopping process with handle " << handle; | 368 LOG(INFO) << "ChromeProcess: Stopping process with handle " << handle; |
369 StopSandboxedProcess(handle); | 369 StopChildProcess(handle); |
370 #else | 370 #else |
371 base::Process process(handle); | 371 base::Process process(handle); |
372 // Client has gone away, so just kill the process. Using exit code 0 | 372 // Client has gone away, so just kill the process. Using exit code 0 |
373 // means that UMA won't treat this as a crash. | 373 // means that UMA won't treat this as a crash. |
374 process.Terminate(RESULT_CODE_NORMAL_EXIT); | 374 process.Terminate(RESULT_CODE_NORMAL_EXIT); |
375 // On POSIX, we must additionally reap the child. | 375 // On POSIX, we must additionally reap the child. |
376 #if defined(OS_POSIX) | 376 #if defined(OS_POSIX) |
377 #if !defined(OS_MACOSX) | 377 #if !defined(OS_MACOSX) |
378 if (zygote) { | 378 if (zygote) { |
379 // If the renderer was created via a zygote, we have to proxy the reaping | 379 // If the renderer was created via a zygote, we have to proxy the reaping |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 GetHandle(), background)); | 491 GetHandle(), background)); |
492 } | 492 } |
493 | 493 |
494 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 494 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
495 bool terminate_on_shutdown) { | 495 bool terminate_on_shutdown) { |
496 if (context_) | 496 if (context_) |
497 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 497 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
498 } | 498 } |
499 | 499 |
500 } // namespace content | 500 } // namespace content |
OLD | NEW |