OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/child_process_launcher.h" | 5 #include "chrome/browser/child_process_launcher.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/thread.h" | 10 #include "base/thread.h" |
11 #include "chrome/browser/chrome_thread.h" | 11 #include "chrome/browser/chrome_thread.h" |
12 #include "chrome/common/chrome_descriptors.h" | 12 #include "chrome/common/chrome_descriptors.h" |
13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/process_watcher.h" | 14 #include "chrome/common/process_watcher.h" |
15 #include "chrome/common/result_codes.h" | 15 #include "chrome/common/result_codes.h" |
16 | 16 |
17 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
18 #include "chrome/browser/sandbox_policy.h" | 18 #include "chrome/browser/sandbox_policy.h" |
19 #elif defined(OS_LINUX) | 19 #elif defined(OS_LINUX) |
20 #include "base/singleton.h" | 20 #include "base/singleton.h" |
21 #include "chrome/browser/crash_handler_host_linux.h" | 21 #include "chrome/browser/crash_handler_host_linux.h" |
22 #include "chrome/browser/zygote_host_linux.h" | 22 #include "chrome/browser/zygote_host_linux.h" |
23 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" | 23 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" |
24 #endif | 24 #endif |
25 | 25 |
| 26 #if defined(OS_MACOSX) |
| 27 #include "chrome/browser/mach_broker_mac.h" |
| 28 #endif |
| 29 |
26 #if defined(OS_POSIX) | 30 #if defined(OS_POSIX) |
27 #include "base/global_descriptors_posix.h" | 31 #include "base/global_descriptors_posix.h" |
28 #endif | 32 #endif |
29 | 33 |
30 // Having the functionality of ChildProcessLauncher be in an internal | 34 // Having the functionality of ChildProcessLauncher be in an internal |
31 // ref counted object allows us to automatically terminate the process when the | 35 // ref counted object allows us to automatically terminate the process when the |
32 // parent class destructs, while still holding on to state that we need. | 36 // parent class destructs, while still holding on to state that we need. |
33 class ChildProcessLauncher::Context | 37 class ChildProcessLauncher::Context |
34 : public base::RefCountedThreadSafe<ChildProcessLauncher::Context> { | 38 : public base::RefCountedThreadSafe<ChildProcessLauncher::Context> { |
35 public: | 39 public: |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (is_renderer) { | 158 if (is_renderer) { |
155 const int sandbox_fd = | 159 const int sandbox_fd = |
156 Singleton<RenderSandboxHostLinux>()->GetRendererSocket(); | 160 Singleton<RenderSandboxHostLinux>()->GetRendererSocket(); |
157 fds_to_map.push_back(std::make_pair( | 161 fds_to_map.push_back(std::make_pair( |
158 sandbox_fd, | 162 sandbox_fd, |
159 kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 163 kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
160 } | 164 } |
161 #endif // defined(OS_LINUX) | 165 #endif // defined(OS_LINUX) |
162 | 166 |
163 // Actually launch the app. | 167 // Actually launch the app. |
164 if (!base::LaunchApp(cmd_line->argv(), env, fds_to_map, false, &handle)) | 168 bool launched; |
| 169 #if defined(OS_MACOSX) |
| 170 task_t child_task; |
| 171 launched = base::LaunchAppAndGetTask( |
| 172 cmd_line->argv(), env, fds_to_map, false, &child_task, &handle); |
| 173 if (launched && child_task != MACH_PORT_NULL) { |
| 174 MachBroker::instance()->RegisterPid( |
| 175 handle, |
| 176 MachBroker::MachInfo().SetTask(child_task)); |
| 177 } |
| 178 #else |
| 179 launched = base::LaunchApp(cmd_line->argv(), env, fds_to_map, |
| 180 /* wait= */false, &handle); |
| 181 #endif |
| 182 if (!launched) |
165 handle = base::kNullProcessHandle; | 183 handle = base::kNullProcessHandle; |
166 } | 184 } |
167 #endif | 185 #endif // else defined(OS_POSIX) |
168 | 186 |
169 ChromeThread::PostTask( | 187 ChromeThread::PostTask( |
170 client_thread_id_, FROM_HERE, | 188 client_thread_id_, FROM_HERE, |
171 NewRunnableMethod( | 189 NewRunnableMethod( |
172 this, | 190 this, |
173 &ChildProcessLauncher::Context::Notify, | 191 &ChildProcessLauncher::Context::Notify, |
174 #if defined(OS_LINUX) | 192 #if defined(OS_LINUX) |
175 zygote, | 193 zygote, |
176 #endif | 194 #endif |
177 handle)); | 195 handle)); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 if (child_exited) | 321 if (child_exited) |
304 context_->process_.Close(); | 322 context_->process_.Close(); |
305 | 323 |
306 return did_crash; | 324 return did_crash; |
307 } | 325 } |
308 | 326 |
309 void ChildProcessLauncher::SetProcessBackgrounded(bool background) { | 327 void ChildProcessLauncher::SetProcessBackgrounded(bool background) { |
310 DCHECK(!context_->starting_); | 328 DCHECK(!context_->starting_); |
311 context_->process_.SetProcessBackgrounded(background); | 329 context_->process_.SetProcessBackgrounded(background); |
312 } | 330 } |
OLD | NEW |