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 10 matching lines...) Expand all Loading... |
21 #include "content/public/common/result_codes.h" | 21 #include "content/public/common/result_codes.h" |
22 | 22 |
23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
24 #include "base/files/file_path.h" | 24 #include "base/files/file_path.h" |
25 #include "content/common/sandbox_policy.h" | 25 #include "content/common/sandbox_policy.h" |
26 #include "content/public/common/sandbox_init.h" | 26 #include "content/public/common/sandbox_init.h" |
27 #elif defined(OS_MACOSX) | 27 #elif defined(OS_MACOSX) |
28 #include "content/browser/mach_broker_mac.h" | 28 #include "content/browser/mach_broker_mac.h" |
29 #elif defined(OS_ANDROID) | 29 #elif defined(OS_ANDROID) |
30 #include "base/android/jni_android.h" | 30 #include "base/android/jni_android.h" |
31 #include "content/browser/android/sandboxed_process_launcher.h" | 31 #include "content/browser/android/child_process_launcher.h" |
32 #elif defined(OS_POSIX) | 32 #elif defined(OS_POSIX) |
33 #include "base/memory/singleton.h" | 33 #include "base/memory/singleton.h" |
34 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 34 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
35 #include "content/browser/zygote_host/zygote_host_impl_linux.h" | 35 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
36 #endif | 36 #endif |
37 | 37 |
38 #if defined(OS_POSIX) | 38 #if defined(OS_POSIX) |
39 #include "base/posix/global_descriptors.h" | 39 #include "base/posix/global_descriptors.h" |
40 #endif | 40 #endif |
41 | 41 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 ipcfd, | 101 ipcfd, |
102 #elif defined(OS_POSIX) | 102 #elif defined(OS_POSIX) |
103 use_zygote, | 103 use_zygote, |
104 environ, | 104 environ, |
105 ipcfd, | 105 ipcfd, |
106 #endif | 106 #endif |
107 cmd_line)); | 107 cmd_line)); |
108 } | 108 } |
109 | 109 |
110 #if defined(OS_ANDROID) | 110 #if defined(OS_ANDROID) |
111 static void OnSandboxedProcessStarted( | 111 static void OnChildProcessStarted( |
112 // |this_object| is NOT thread safe. Only use it to post a task back. | 112 // |this_object| is NOT thread safe. Only use it to post a task back. |
113 scoped_refptr<Context> this_object, | 113 scoped_refptr<Context> this_object, |
114 BrowserThread::ID client_thread_id, | 114 BrowserThread::ID client_thread_id, |
115 base::ProcessHandle handle) { | 115 base::ProcessHandle handle) { |
116 if (BrowserThread::CurrentlyOn(client_thread_id)) { | 116 if (BrowserThread::CurrentlyOn(client_thread_id)) { |
117 // This is always invoked on the UI thread which is commonly the | 117 // This is always invoked on the UI thread which is commonly the |
118 // |client_thread_id| so we can shortcut one PostTask. | 118 // |client_thread_id| so we can shortcut one PostTask. |
119 this_object->Notify(handle); | 119 this_object->Notify(handle); |
120 } else { | 120 } else { |
121 BrowserThread::PostTask( | 121 BrowserThread::PostTask( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 175 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
176 std::vector<FileDescriptorInfo> files_to_register; | 176 std::vector<FileDescriptorInfo> files_to_register; |
177 files_to_register.push_back( | 177 files_to_register.push_back( |
178 FileDescriptorInfo(kPrimaryIPCChannel, | 178 FileDescriptorInfo(kPrimaryIPCChannel, |
179 base::FileDescriptor(ipcfd, false))); | 179 base::FileDescriptor(ipcfd, false))); |
180 | 180 |
181 GetContentClient()->browser()-> | 181 GetContentClient()->browser()-> |
182 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, | 182 GetAdditionalMappedFilesForChildProcess(*cmd_line, child_process_id, |
183 &files_to_register); | 183 &files_to_register); |
184 | 184 |
185 StartSandboxedProcess(cmd_line->argv(), files_to_register, | 185 StartChildProcess(cmd_line->argv(), files_to_register, |
186 base::Bind(&ChildProcessLauncher::Context::OnSandboxedProcessStarted, | 186 base::Bind(&ChildProcessLauncher::Context::OnChildProcessStarted, |
187 this_object, client_thread_id)); | 187 this_object, client_thread_id)); |
188 | 188 |
189 #elif defined(OS_POSIX) | 189 #elif defined(OS_POSIX) |
190 base::ProcessHandle handle = base::kNullProcessHandle; | 190 base::ProcessHandle handle = base::kNullProcessHandle; |
191 // We need to close the client end of the IPC channel to reliably detect | 191 // We need to close the client end of the IPC channel to reliably detect |
192 // child termination. | 192 // child termination. |
193 file_util::ScopedFD ipcfd_closer(&ipcfd); | 193 file_util::ScopedFD ipcfd_closer(&ipcfd); |
194 | 194 |
195 std::string process_type = | 195 std::string process_type = |
196 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 196 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 process.SetProcessBackgrounded(background); | 329 process.SetProcessBackgrounded(background); |
330 } | 330 } |
331 | 331 |
332 static void TerminateInternal( | 332 static void TerminateInternal( |
333 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 333 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
334 bool zygote, | 334 bool zygote, |
335 #endif | 335 #endif |
336 base::ProcessHandle handle) { | 336 base::ProcessHandle handle) { |
337 #if defined(OS_ANDROID) | 337 #if defined(OS_ANDROID) |
338 LOG(INFO) << "ChromeProcess: Stopping process with handle " << handle; | 338 LOG(INFO) << "ChromeProcess: Stopping process with handle " << handle; |
339 StopSandboxedProcess(handle); | 339 StopChildProcess(handle); |
340 #else | 340 #else |
341 base::Process process(handle); | 341 base::Process process(handle); |
342 // Client has gone away, so just kill the process. Using exit code 0 | 342 // Client has gone away, so just kill the process. Using exit code 0 |
343 // means that UMA won't treat this as a crash. | 343 // means that UMA won't treat this as a crash. |
344 process.Terminate(RESULT_CODE_NORMAL_EXIT); | 344 process.Terminate(RESULT_CODE_NORMAL_EXIT); |
345 // On POSIX, we must additionally reap the child. | 345 // On POSIX, we must additionally reap the child. |
346 #if defined(OS_POSIX) | 346 #if defined(OS_POSIX) |
347 #if !defined(OS_MACOSX) | 347 #if !defined(OS_MACOSX) |
348 if (zygote) { | 348 if (zygote) { |
349 // If the renderer was created via a zygote, we have to proxy the reaping | 349 // 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... |
461 GetHandle(), background)); | 461 GetHandle(), background)); |
462 } | 462 } |
463 | 463 |
464 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 464 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
465 bool terminate_on_shutdown) { | 465 bool terminate_on_shutdown) { |
466 if (context_) | 466 if (context_) |
467 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 467 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
468 } | 468 } |
469 | 469 |
470 } // namespace content | 470 } // namespace content |
OLD | NEW |