| 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" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
| 20 #include "content/public/common/content_descriptors.h" | 20 #include "content/public/common/content_descriptors.h" |
| 21 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
| 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_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 #elif defined(OS_MACOSX) | 29 #elif defined(OS_MACOSX) |
| 29 #include "content/browser/mach_broker_mac.h" | 30 #include "content/browser/mach_broker_mac.h" |
| 30 #elif defined(OS_ANDROID) | 31 #elif defined(OS_ANDROID) |
| 31 #include "base/android/jni_android.h" | 32 #include "base/android/jni_android.h" |
| 32 #include "content/browser/android/sandboxed_process_launcher.h" | 33 #include "content/browser/android/sandboxed_process_launcher.h" |
| 33 #elif defined(OS_POSIX) | 34 #elif defined(OS_POSIX) |
| 34 #include "base/memory/singleton.h" | 35 #include "base/memory/singleton.h" |
| 35 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 36 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
| 36 #include "content/browser/zygote_host/zygote_host_impl_linux.h" | 37 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
| 37 #endif | 38 #endif |
| (...skipping 23 matching lines...) Expand all Loading... |
| 61 #if defined(OS_POSIX) | 62 #if defined(OS_POSIX) |
| 62 terminate_child_on_shutdown_ = !CommandLine::ForCurrentProcess()-> | 63 terminate_child_on_shutdown_ = !CommandLine::ForCurrentProcess()-> |
| 63 HasSwitch(switches::kChildCleanExit); | 64 HasSwitch(switches::kChildCleanExit); |
| 64 #else | 65 #else |
| 65 terminate_child_on_shutdown_ = true; | 66 terminate_child_on_shutdown_ = true; |
| 66 #endif | 67 #endif |
| 67 } | 68 } |
| 68 | 69 |
| 69 void Launch( | 70 void Launch( |
| 70 #if defined(OS_WIN) | 71 #if defined(OS_WIN) |
| 71 const base::FilePath& exposed_dir, | 72 SandboxedProcessLauncherDelegate* delegate, |
| 72 #elif defined(OS_ANDROID) | 73 #elif defined(OS_ANDROID) |
| 73 int ipcfd, | 74 int ipcfd, |
| 74 #elif defined(OS_POSIX) | 75 #elif defined(OS_POSIX) |
| 75 bool use_zygote, | 76 bool use_zygote, |
| 76 const base::EnvironmentVector& environ, | 77 const base::EnvironmentVector& environ, |
| 77 int ipcfd, | 78 int ipcfd, |
| 78 #endif | 79 #endif |
| 79 CommandLine* cmd_line, | 80 CommandLine* cmd_line, |
| 80 int child_process_id, | 81 int child_process_id, |
| 81 Client* client) { | 82 Client* client) { |
| 82 client_ = client; | 83 client_ = client; |
| 83 | 84 |
| 84 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 85 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
| 85 | 86 |
| 86 #if defined(OS_ANDROID) | 87 #if defined(OS_ANDROID) |
| 87 // We need to close the client end of the IPC channel to reliably detect | 88 // We need to close the client end of the IPC channel to reliably detect |
| 88 // child termination. We will close this fd after we create the child | 89 // child termination. We will close this fd after we create the child |
| 89 // process which is asynchronous on Android. | 90 // process which is asynchronous on Android. |
| 90 ipcfd_ = ipcfd; | 91 ipcfd_ = ipcfd; |
| 91 #endif | 92 #endif |
| 92 BrowserThread::PostTask( | 93 BrowserThread::PostTask( |
| 93 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 94 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| 94 base::Bind( | 95 base::Bind( |
| 95 &Context::LaunchInternal, | 96 &Context::LaunchInternal, |
| 96 make_scoped_refptr(this), | 97 make_scoped_refptr(this), |
| 97 client_thread_id_, | 98 client_thread_id_, |
| 98 child_process_id, | 99 child_process_id, |
| 99 #if defined(OS_WIN) | 100 #if defined(OS_WIN) |
| 100 exposed_dir, | 101 delegate, |
| 101 #elif defined(OS_ANDROID) | 102 #elif defined(OS_ANDROID) |
| 102 ipcfd, | 103 ipcfd, |
| 103 #elif defined(OS_POSIX) | 104 #elif defined(OS_POSIX) |
| 104 use_zygote, | 105 use_zygote, |
| 105 environ, | 106 environ, |
| 106 ipcfd, | 107 ipcfd, |
| 107 #endif | 108 #endif |
| 108 cmd_line)); | 109 cmd_line)); |
| 109 } | 110 } |
| 110 | 111 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 done_first_launch = true; | 174 done_first_launch = true; |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 | 177 |
| 177 static void LaunchInternal( | 178 static void LaunchInternal( |
| 178 // |this_object| is NOT thread safe. Only use it to post a task back. | 179 // |this_object| is NOT thread safe. Only use it to post a task back. |
| 179 scoped_refptr<Context> this_object, | 180 scoped_refptr<Context> this_object, |
| 180 BrowserThread::ID client_thread_id, | 181 BrowserThread::ID client_thread_id, |
| 181 int child_process_id, | 182 int child_process_id, |
| 182 #if defined(OS_WIN) | 183 #if defined(OS_WIN) |
| 183 const base::FilePath& exposed_dir, | 184 SandboxedProcessLauncherDelegate* delegate, |
| 184 #elif defined(OS_ANDROID) | 185 #elif defined(OS_ANDROID) |
| 185 int ipcfd, | 186 int ipcfd, |
| 186 #elif defined(OS_POSIX) | 187 #elif defined(OS_POSIX) |
| 187 bool use_zygote, | 188 bool use_zygote, |
| 188 const base::EnvironmentVector& env, | 189 const base::EnvironmentVector& env, |
| 189 int ipcfd, | 190 int ipcfd, |
| 190 #endif | 191 #endif |
| 191 CommandLine* cmd_line) { | 192 CommandLine* cmd_line) { |
| 192 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); | 193 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); |
| 193 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); | 194 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); |
| 194 | 195 |
| 195 #if defined(OS_WIN) | 196 #if defined(OS_WIN) |
| 196 base::ProcessHandle handle = StartProcessWithAccess(cmd_line, exposed_dir); | 197 scoped_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); |
| 198 base::ProcessHandle handle = StartSandboxedProcess(delegate, cmd_line); |
| 197 #elif defined(OS_ANDROID) | 199 #elif defined(OS_ANDROID) |
| 198 // Android WebView runs in single process, ensure that we never get here | 200 // Android WebView runs in single process, ensure that we never get here |
| 199 // when running in single process mode. | 201 // when running in single process mode. |
| 200 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); | 202 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); |
| 201 | 203 |
| 202 std::string process_type = | 204 std::string process_type = |
| 203 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 205 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
| 204 std::vector<FileDescriptorInfo> files_to_register; | 206 std::vector<FileDescriptorInfo> files_to_register; |
| 205 files_to_register.push_back( | 207 files_to_register.push_back( |
| 206 FileDescriptorInfo(kPrimaryIPCChannel, | 208 FileDescriptorInfo(kPrimaryIPCChannel, |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 // The fd to close after creating the process. | 404 // The fd to close after creating the process. |
| 403 int ipcfd_; | 405 int ipcfd_; |
| 404 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | 406 #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
| 405 bool zygote_; | 407 bool zygote_; |
| 406 #endif | 408 #endif |
| 407 }; | 409 }; |
| 408 | 410 |
| 409 | 411 |
| 410 ChildProcessLauncher::ChildProcessLauncher( | 412 ChildProcessLauncher::ChildProcessLauncher( |
| 411 #if defined(OS_WIN) | 413 #if defined(OS_WIN) |
| 412 const base::FilePath& exposed_dir, | 414 SandboxedProcessLauncherDelegate* delegate, |
| 413 #elif defined(OS_POSIX) | 415 #elif defined(OS_POSIX) |
| 414 bool use_zygote, | 416 bool use_zygote, |
| 415 const base::EnvironmentVector& environ, | 417 const base::EnvironmentVector& environ, |
| 416 int ipcfd, | 418 int ipcfd, |
| 417 #endif | 419 #endif |
| 418 CommandLine* cmd_line, | 420 CommandLine* cmd_line, |
| 419 int child_process_id, | 421 int child_process_id, |
| 420 Client* client) { | 422 Client* client) { |
| 421 context_ = new Context(); | 423 context_ = new Context(); |
| 422 context_->Launch( | 424 context_->Launch( |
| 423 #if defined(OS_WIN) | 425 #if defined(OS_WIN) |
| 424 exposed_dir, | 426 delegate, |
| 425 #elif defined(OS_ANDROID) | 427 #elif defined(OS_ANDROID) |
| 426 ipcfd, | 428 ipcfd, |
| 427 #elif defined(OS_POSIX) | 429 #elif defined(OS_POSIX) |
| 428 use_zygote, | 430 use_zygote, |
| 429 environ, | 431 environ, |
| 430 ipcfd, | 432 ipcfd, |
| 431 #endif | 433 #endif |
| 432 cmd_line, | 434 cmd_line, |
| 433 child_process_id, | 435 child_process_id, |
| 434 client); | 436 client); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 GetHandle(), background)); | 493 GetHandle(), background)); |
| 492 } | 494 } |
| 493 | 495 |
| 494 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 496 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
| 495 bool terminate_on_shutdown) { | 497 bool terminate_on_shutdown) { |
| 496 if (context_) | 498 if (context_) |
| 497 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 499 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
| 498 } | 500 } |
| 499 | 501 |
| 500 } // namespace content | 502 } // namespace content |
| OLD | NEW |