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/utility_process_host_impl.h" | 5 #include "content/browser/utility_process_host_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/process/process_handle.h" | 17 #include "base/process/process_handle.h" |
18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
19 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
23 #include "base/synchronization/waitable_event.h" | 23 #include "base/synchronization/waitable_event.h" |
24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
25 #include "content/browser/browser_child_process_host_impl.h" | 25 #include "content/browser/browser_child_process_host_impl.h" |
26 #include "content/browser/mojo/constants.h" | 26 #include "content/browser/mojo/constants.h" |
27 #include "content/browser/mojo/mojo_child_connection.h" | 27 #include "content/browser/mojo/mojo_child_connection.h" |
28 #include "content/browser/mojo/mojo_shell_context.h" | |
29 #include "content/browser/renderer_host/render_process_host_impl.h" | 28 #include "content/browser/renderer_host/render_process_host_impl.h" |
30 #include "content/common/child_process_host_impl.h" | 29 #include "content/common/child_process_host_impl.h" |
31 #include "content/common/in_process_child_thread_params.h" | 30 #include "content/common/in_process_child_thread_params.h" |
32 #include "content/common/utility_messages.h" | 31 #include "content/common/utility_messages.h" |
33 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/content_browser_client.h" | 33 #include "content/public/browser/content_browser_client.h" |
| 34 #include "content/public/browser/shell_context.h" |
35 #include "content/public/browser/utility_process_host_client.h" | 35 #include "content/public/browser/utility_process_host_client.h" |
36 #include "content/public/common/content_switches.h" | 36 #include "content/public/common/content_switches.h" |
37 #include "content/public/common/mojo_channel_switches.h" | 37 #include "content/public/common/mojo_channel_switches.h" |
38 #include "content/public/common/mojo_shell_connection.h" | 38 #include "content/public/common/mojo_shell_connection.h" |
39 #include "content/public/common/process_type.h" | 39 #include "content/public/common/process_type.h" |
40 #include "content/public/common/sandbox_type.h" | 40 #include "content/public/common/sandbox_type.h" |
41 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 41 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 42 #include "ipc/ipc.mojom.h" |
42 #include "ipc/ipc_switches.h" | 43 #include "ipc/ipc_switches.h" |
43 #include "mojo/edk/embedder/embedder.h" | 44 #include "mojo/edk/embedder/embedder.h" |
44 #include "services/shell/public/cpp/connection.h" | 45 #include "services/shell/public/cpp/connection.h" |
45 #include "services/shell/public/cpp/interface_provider.h" | 46 #include "services/shell/public/cpp/interface_provider.h" |
46 #include "services/shell/public/cpp/interface_registry.h" | 47 #include "services/shell/public/cpp/interface_registry.h" |
47 #include "ui/base/ui_base_switches.h" | 48 #include "ui/base/ui_base_switches.h" |
48 | 49 |
49 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 50 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
50 #include "content/public/browser/zygote_handle_linux.h" | 51 #include "content/public/browser/zygote_handle_linux.h" |
51 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 52 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 started_(false), | 168 started_(false), |
168 name_(base::ASCIIToUTF16("utility process")), | 169 name_(base::ASCIIToUTF16("utility process")), |
169 child_token_(mojo::edk::GenerateRandomToken()), | 170 child_token_(mojo::edk::GenerateRandomToken()), |
170 weak_ptr_factory_(this) { | 171 weak_ptr_factory_(this) { |
171 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this, | 172 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this, |
172 child_token_)); | 173 child_token_)); |
173 mojo_child_connection_.reset(new MojoChildConnection( | 174 mojo_child_connection_.reset(new MojoChildConnection( |
174 kUtilityMojoApplicationName, | 175 kUtilityMojoApplicationName, |
175 base::StringPrintf("%d_0", process_->GetData().id), | 176 base::StringPrintf("%d_0", process_->GetData().id), |
176 child_token_, | 177 child_token_, |
177 MojoShellContext::GetConnectorForIOThread())); | 178 ShellContext::GetConnectorForIOThread())); |
178 } | 179 } |
179 | 180 |
180 UtilityProcessHostImpl::~UtilityProcessHostImpl() { | 181 UtilityProcessHostImpl::~UtilityProcessHostImpl() { |
181 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 182 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
182 if (is_batch_mode_) | 183 if (is_batch_mode_) |
183 EndBatchMode(); | 184 EndBatchMode(); |
184 } | 185 } |
185 | 186 |
186 base::WeakPtr<UtilityProcessHost> UtilityProcessHostImpl::AsWeakPtr() { | 187 base::WeakPtr<UtilityProcessHost> UtilityProcessHostImpl::AsWeakPtr() { |
187 return weak_ptr_factory_.GetWeakPtr(); | 188 return weak_ptr_factory_.GetWeakPtr(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 bool UtilityProcessHostImpl::StartProcess() { | 262 bool UtilityProcessHostImpl::StartProcess() { |
262 if (started_) | 263 if (started_) |
263 return true; | 264 return true; |
264 started_ = true; | 265 started_ = true; |
265 | 266 |
266 if (is_batch_mode_) | 267 if (is_batch_mode_) |
267 return true; | 268 return true; |
268 | 269 |
269 process_->SetName(name_); | 270 process_->SetName(name_); |
270 | 271 |
271 std::string mojo_channel_token = | 272 IPC::mojom::BootstrapPtr bootstrap; |
272 process_->GetHost()->CreateChannelMojo(child_token_); | 273 mojo_child_connection_->connection()->GetInterface(&bootstrap); |
273 if (mojo_channel_token.empty()) { | 274 if (!process_->GetHost()->CreateChannelMojoWithBootstrap( |
| 275 bootstrap.PassInterface().PassHandle())) { |
274 NotifyAndDelete(LAUNCH_RESULT_FAILURE); | 276 NotifyAndDelete(LAUNCH_RESULT_FAILURE); |
275 return false; | 277 return false; |
276 } | 278 } |
277 | 279 |
278 if (RenderProcessHost::run_renderer_in_process()) { | 280 if (RenderProcessHost::run_renderer_in_process()) { |
279 DCHECK(g_utility_main_thread_factory); | 281 DCHECK(g_utility_main_thread_factory); |
280 // See comment in RenderProcessHostImpl::Init() for the background on why we | 282 // See comment in RenderProcessHostImpl::Init() for the background on why we |
281 // support single process mode this way. | 283 // support single process mode this way. |
282 in_process_thread_.reset( | 284 in_process_thread_.reset( |
283 g_utility_main_thread_factory(InProcessChildThreadParams( | 285 g_utility_main_thread_factory(InProcessChildThreadParams( |
284 std::string(), BrowserThread::UnsafeGetMessageLoopForThread( | 286 std::string(), BrowserThread::UnsafeGetMessageLoopForThread( |
285 BrowserThread::IO)->task_runner(), | 287 BrowserThread::IO)->task_runner(), |
286 mojo_channel_token, mojo_child_connection_->shell_client_token()))); | 288 std::string(), mojo_child_connection_->shell_client_token()))); |
287 in_process_thread_->Start(); | 289 in_process_thread_->Start(); |
288 } else { | 290 } else { |
289 const base::CommandLine& browser_command_line = | 291 const base::CommandLine& browser_command_line = |
290 *base::CommandLine::ForCurrentProcess(); | 292 *base::CommandLine::ForCurrentProcess(); |
291 | 293 |
292 bool has_cmd_prefix = browser_command_line.HasSwitch( | 294 bool has_cmd_prefix = browser_command_line.HasSwitch( |
293 switches::kUtilityCmdPrefix); | 295 switches::kUtilityCmdPrefix); |
294 | 296 |
295 #if defined(OS_ANDROID) | 297 #if defined(OS_ANDROID) |
296 // readlink("/prof/self/exe") sometimes fails on Android at startup. | 298 // readlink("/prof/self/exe") sometimes fails on Android at startup. |
(...skipping 16 matching lines...) Expand all Loading... |
313 if (exe_path.empty()) { | 315 if (exe_path.empty()) { |
314 NOTREACHED() << "Unable to get utility process binary name."; | 316 NOTREACHED() << "Unable to get utility process binary name."; |
315 return false; | 317 return false; |
316 } | 318 } |
317 | 319 |
318 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | 320 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
319 #endif | 321 #endif |
320 | 322 |
321 cmd_line->AppendSwitchASCII(switches::kProcessType, | 323 cmd_line->AppendSwitchASCII(switches::kProcessType, |
322 switches::kUtilityProcess); | 324 switches::kUtilityProcess); |
323 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, | |
324 mojo_channel_token); | |
325 std::string locale = GetContentClient()->browser()->GetApplicationLocale(); | 325 std::string locale = GetContentClient()->browser()->GetApplicationLocale(); |
326 cmd_line->AppendSwitchASCII(switches::kLang, locale); | 326 cmd_line->AppendSwitchASCII(switches::kLang, locale); |
327 | 327 |
328 #if defined(OS_WIN) | 328 #if defined(OS_WIN) |
329 cmd_line->AppendArg(switches::kPrefetchArgumentOther); | 329 cmd_line->AppendArg(switches::kPrefetchArgumentOther); |
330 #endif // defined(OS_WIN) | 330 #endif // defined(OS_WIN) |
331 | 331 |
332 if (no_sandbox_) | 332 if (no_sandbox_) |
333 cmd_line->AppendSwitch(switches::kNoSandbox); | 333 cmd_line->AppendSwitch(switches::kNoSandbox); |
334 | 334 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 base::WeakPtr<UtilityProcessHostImpl> host, | 424 base::WeakPtr<UtilityProcessHostImpl> host, |
425 int error_code) { | 425 int error_code) { |
426 if (!host) | 426 if (!host) |
427 return; | 427 return; |
428 | 428 |
429 host->OnProcessLaunchFailed(error_code); | 429 host->OnProcessLaunchFailed(error_code); |
430 delete host.get(); | 430 delete host.get(); |
431 } | 431 } |
432 | 432 |
433 } // namespace content | 433 } // namespace content |
OLD | NEW |