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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 terminate_child_on_shutdown_(true) | 69 terminate_child_on_shutdown_(true) |
70 #endif | 70 #endif |
71 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 71 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
72 , zygote_(false) | 72 , zygote_(false) |
73 #endif | 73 #endif |
74 { | 74 { |
75 } | 75 } |
76 | 76 |
77 void Launch( | 77 void Launch( |
78 SandboxedProcessLauncherDelegate* delegate, | 78 SandboxedProcessLauncherDelegate* delegate, |
79 CommandLine* cmd_line, | 79 base::CommandLine* cmd_line, |
80 int child_process_id, | 80 int child_process_id, |
81 Client* client) { | 81 Client* client) { |
82 client_ = client; | 82 client_ = client; |
83 | 83 |
84 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 84 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
85 | 85 |
86 #if defined(OS_ANDROID) | 86 #if defined(OS_ANDROID) |
87 // We need to close the client end of the IPC channel to reliably detect | 87 // 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 | 88 // child termination. We will close this fd after we create the child |
89 // process which is asynchronous on Android. | 89 // process which is asynchronous on Android. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 done_first_launch = true; | 165 done_first_launch = true; |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 static void LaunchInternal( | 169 static void LaunchInternal( |
170 // |this_object| is NOT thread safe. Only use it to post a task back. | 170 // |this_object| is NOT thread safe. Only use it to post a task back. |
171 scoped_refptr<Context> this_object, | 171 scoped_refptr<Context> this_object, |
172 BrowserThread::ID client_thread_id, | 172 BrowserThread::ID client_thread_id, |
173 int child_process_id, | 173 int child_process_id, |
174 SandboxedProcessLauncherDelegate* delegate, | 174 SandboxedProcessLauncherDelegate* delegate, |
175 CommandLine* cmd_line) { | 175 base::CommandLine* cmd_line) { |
176 scoped_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); | 176 scoped_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); |
177 #if defined(OS_WIN) | 177 #if defined(OS_WIN) |
178 bool launch_elevated = delegate->ShouldLaunchElevated(); | 178 bool launch_elevated = delegate->ShouldLaunchElevated(); |
179 #elif defined(OS_ANDROID) | 179 #elif defined(OS_ANDROID) |
180 int ipcfd = delegate->GetIpcFd(); | 180 int ipcfd = delegate->GetIpcFd(); |
181 #elif defined(OS_MACOSX) | 181 #elif defined(OS_MACOSX) |
182 base::EnvironmentMap env = delegate->GetEnvironment(); | 182 base::EnvironmentMap env = delegate->GetEnvironment(); |
183 int ipcfd = delegate->GetIpcFd(); | 183 int ipcfd = delegate->GetIpcFd(); |
184 #elif defined(OS_POSIX) | 184 #elif defined(OS_POSIX) |
185 bool use_zygote = delegate->ShouldUseZygote(); | 185 bool use_zygote = delegate->ShouldUseZygote(); |
186 base::EnvironmentMap env = delegate->GetEnvironment(); | 186 base::EnvironmentMap env = delegate->GetEnvironment(); |
187 int ipcfd = delegate->GetIpcFd(); | 187 int ipcfd = delegate->GetIpcFd(); |
188 #endif | 188 #endif |
189 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); | 189 scoped_ptr<base::CommandLine> cmd_line_deleter(cmd_line); |
190 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); | 190 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); |
191 | 191 |
192 #if defined(OS_WIN) | 192 #if defined(OS_WIN) |
193 base::ProcessHandle handle = base::kNullProcessHandle; | 193 base::ProcessHandle handle = base::kNullProcessHandle; |
194 if (launch_elevated) { | 194 if (launch_elevated) { |
195 base::LaunchOptions options; | 195 base::LaunchOptions options; |
196 options.start_hidden = true; | 196 options.start_hidden = true; |
197 base::LaunchElevatedProcess(*cmd_line, options, &handle); | 197 base::LaunchElevatedProcess(*cmd_line, options, &handle); |
198 } else { | 198 } else { |
199 handle = StartSandboxedProcess(delegate, cmd_line); | 199 handle = StartSandboxedProcess(delegate, cmd_line); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 // The fd to close after creating the process. | 429 // The fd to close after creating the process. |
430 int ipcfd_; | 430 int ipcfd_; |
431 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | 431 #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
432 bool zygote_; | 432 bool zygote_; |
433 #endif | 433 #endif |
434 }; | 434 }; |
435 | 435 |
436 | 436 |
437 ChildProcessLauncher::ChildProcessLauncher( | 437 ChildProcessLauncher::ChildProcessLauncher( |
438 SandboxedProcessLauncherDelegate* delegate, | 438 SandboxedProcessLauncherDelegate* delegate, |
439 CommandLine* cmd_line, | 439 base::CommandLine* cmd_line, |
440 int child_process_id, | 440 int child_process_id, |
441 Client* client) { | 441 Client* client) { |
442 context_ = new Context(); | 442 context_ = new Context(); |
443 context_->Launch( | 443 context_->Launch( |
444 delegate, | 444 delegate, |
445 cmd_line, | 445 cmd_line, |
446 child_process_id, | 446 child_process_id, |
447 client); | 447 client); |
448 } | 448 } |
449 | 449 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 GetHandle(), background)); | 517 GetHandle(), background)); |
518 } | 518 } |
519 | 519 |
520 void ChildProcessLauncher::SetTerminateChildOnShutdown( | 520 void ChildProcessLauncher::SetTerminateChildOnShutdown( |
521 bool terminate_on_shutdown) { | 521 bool terminate_on_shutdown) { |
522 if (context_.get()) | 522 if (context_.get()) |
523 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); | 523 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); |
524 } | 524 } |
525 | 525 |
526 } // namespace content | 526 } // namespace content |
OLD | NEW |