| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 , zygote_(false) | 54 , zygote_(false) |
| 55 #endif | 55 #endif |
| 56 { | 56 { |
| 57 } | 57 } |
| 58 | 58 |
| 59 void Launch( | 59 void Launch( |
| 60 #if defined(OS_WIN) | 60 #if defined(OS_WIN) |
| 61 const FilePath& exposed_dir, | 61 const FilePath& exposed_dir, |
| 62 #elif defined(OS_POSIX) | 62 #elif defined(OS_POSIX) |
| 63 bool use_zygote, | 63 bool use_zygote, |
| 64 const base::environment_vector& environ, | 64 const base::EnvironmentVector& environ, |
| 65 int ipcfd, | 65 int ipcfd, |
| 66 #endif | 66 #endif |
| 67 CommandLine* cmd_line, | 67 CommandLine* cmd_line, |
| 68 Client* client) { | 68 Client* client) { |
| 69 client_ = client; | 69 client_ = client; |
| 70 | 70 |
| 71 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 71 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
| 72 | 72 |
| 73 BrowserThread::PostTask( | 73 BrowserThread::PostTask( |
| 74 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 74 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 106 } |
| 107 | 107 |
| 108 static void LaunchInternal( | 108 static void LaunchInternal( |
| 109 // |this_object| is NOT thread safe. Only use it to post a task back. | 109 // |this_object| is NOT thread safe. Only use it to post a task back. |
| 110 scoped_refptr<Context> this_object, | 110 scoped_refptr<Context> this_object, |
| 111 BrowserThread::ID client_thread_id, | 111 BrowserThread::ID client_thread_id, |
| 112 #if defined(OS_WIN) | 112 #if defined(OS_WIN) |
| 113 const FilePath& exposed_dir, | 113 const FilePath& exposed_dir, |
| 114 #elif defined(OS_POSIX) | 114 #elif defined(OS_POSIX) |
| 115 bool use_zygote, | 115 bool use_zygote, |
| 116 const base::environment_vector& env, | 116 const base::EnvironmentVector& env, |
| 117 int ipcfd, | 117 int ipcfd, |
| 118 #endif | 118 #endif |
| 119 CommandLine* cmd_line) { | 119 CommandLine* cmd_line) { |
| 120 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); | 120 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); |
| 121 | 121 |
| 122 base::ProcessHandle handle = base::kNullProcessHandle; | 122 base::ProcessHandle handle = base::kNullProcessHandle; |
| 123 #if defined(OS_WIN) | 123 #if defined(OS_WIN) |
| 124 handle = sandbox::StartProcessWithAccess(cmd_line, exposed_dir); | 124 handle = sandbox::StartProcessWithAccess(cmd_line, exposed_dir); |
| 125 #elif defined(OS_POSIX) | 125 #elif defined(OS_POSIX) |
| 126 // We need to close the client end of the IPC channel | 126 // We need to close the client end of the IPC channel |
| (...skipping 13 matching lines...) Expand all Loading... |
| 140 mapping.push_back(std::pair<uint32_t, int>(kCrashDumpSignal, | 140 mapping.push_back(std::pair<uint32_t, int>(kCrashDumpSignal, |
| 141 crash_signal_fd)); | 141 crash_signal_fd)); |
| 142 } | 142 } |
| 143 handle = ZygoteHost::GetInstance()->ForkRequest(cmd_line->argv(), | 143 handle = ZygoteHost::GetInstance()->ForkRequest(cmd_line->argv(), |
| 144 mapping, | 144 mapping, |
| 145 process_type); | 145 process_type); |
| 146 } else | 146 } else |
| 147 // Fall through to the normal posix case below when we're not zygoting. | 147 // Fall through to the normal posix case below when we're not zygoting. |
| 148 #endif | 148 #endif |
| 149 { | 149 { |
| 150 base::file_handle_mapping_vector fds_to_map; | 150 base::FileHandleMappingVector fds_to_map; |
| 151 fds_to_map.push_back(std::make_pair( | 151 fds_to_map.push_back(std::make_pair( |
| 152 ipcfd, | 152 ipcfd, |
| 153 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 153 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
| 154 | 154 |
| 155 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 155 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 156 if (crash_signal_fd >= 0) { | 156 if (crash_signal_fd >= 0) { |
| 157 fds_to_map.push_back(std::make_pair( | 157 fds_to_map.push_back(std::make_pair( |
| 158 crash_signal_fd, | 158 crash_signal_fd, |
| 159 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor)); | 159 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor)); |
| 160 } | 160 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 bool zygote_; | 300 bool zygote_; |
| 301 #endif | 301 #endif |
| 302 }; | 302 }; |
| 303 | 303 |
| 304 | 304 |
| 305 ChildProcessLauncher::ChildProcessLauncher( | 305 ChildProcessLauncher::ChildProcessLauncher( |
| 306 #if defined(OS_WIN) | 306 #if defined(OS_WIN) |
| 307 const FilePath& exposed_dir, | 307 const FilePath& exposed_dir, |
| 308 #elif defined(OS_POSIX) | 308 #elif defined(OS_POSIX) |
| 309 bool use_zygote, | 309 bool use_zygote, |
| 310 const base::environment_vector& environ, | 310 const base::EnvironmentVector& environ, |
| 311 int ipcfd, | 311 int ipcfd, |
| 312 #endif | 312 #endif |
| 313 CommandLine* cmd_line, | 313 CommandLine* cmd_line, |
| 314 Client* client) { | 314 Client* client) { |
| 315 context_ = new Context(); | 315 context_ = new Context(); |
| 316 context_->Launch( | 316 context_->Launch( |
| 317 #if defined(OS_WIN) | 317 #if defined(OS_WIN) |
| 318 exposed_dir, | 318 exposed_dir, |
| 319 #elif defined(OS_POSIX) | 319 #elif defined(OS_POSIX) |
| 320 use_zygote, | 320 use_zygote, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 base::Bind( | 379 base::Bind( |
| 380 &ChildProcessLauncher::Context::SetProcessBackgrounded, | 380 &ChildProcessLauncher::Context::SetProcessBackgrounded, |
| 381 GetHandle(), background)); | 381 GetHandle(), background)); |
| 382 } | 382 } |
| 383 | 383 |
| 384 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 384 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
| 385 bool terminate_on_shutdown) { | 385 bool terminate_on_shutdown) { |
| 386 if (context_) | 386 if (context_) |
| 387 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 387 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
| 388 } | 388 } |
| OLD | NEW |