Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1031)

Side by Side Diff: content/browser/utility_process_host_impl.cc

Issue 1877743002: Use token-based initialisation for the utility process MojoApplication. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Always use token init. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/utility_process_host_impl.h ('k') | content/child/child_thread_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 13 matching lines...) Expand all
24 #include "content/browser/browser_child_process_host_impl.h" 24 #include "content/browser/browser_child_process_host_impl.h"
25 #include "content/browser/mojo/mojo_application_host.h" 25 #include "content/browser/mojo/mojo_application_host.h"
26 #include "content/browser/renderer_host/render_process_host_impl.h" 26 #include "content/browser/renderer_host/render_process_host_impl.h"
27 #include "content/common/child_process_host_impl.h" 27 #include "content/common/child_process_host_impl.h"
28 #include "content/common/in_process_child_thread_params.h" 28 #include "content/common/in_process_child_thread_params.h"
29 #include "content/common/utility_messages.h" 29 #include "content/common/utility_messages.h"
30 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/content_browser_client.h" 31 #include "content/public/browser/content_browser_client.h"
32 #include "content/public/browser/utility_process_host_client.h" 32 #include "content/public/browser/utility_process_host_client.h"
33 #include "content/public/common/content_switches.h" 33 #include "content/public/common/content_switches.h"
34 #include "content/public/common/mojo_channel_switches.h"
34 #include "content/public/common/process_type.h" 35 #include "content/public/common/process_type.h"
35 #include "content/public/common/sandbox_type.h" 36 #include "content/public/common/sandbox_type.h"
36 #include "content/public/common/sandboxed_process_launcher_delegate.h" 37 #include "content/public/common/sandboxed_process_launcher_delegate.h"
37 #include "ipc/ipc_switches.h" 38 #include "ipc/ipc_switches.h"
38 #include "ui/base/ui_base_switches.h" 39 #include "ui/base/ui_base_switches.h"
39 40
40 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 41 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
41 #include "content/public/browser/zygote_handle_linux.h" 42 #include "content/public/browser/zygote_handle_linux.h"
42 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 43 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
43 44
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 241 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
241 242
242 bool UtilityProcessHostImpl::StartProcess() { 243 bool UtilityProcessHostImpl::StartProcess() {
243 if (started_) 244 if (started_)
244 return true; 245 return true;
245 started_ = true; 246 started_ = true;
246 247
247 if (is_batch_mode_) 248 if (is_batch_mode_)
248 return true; 249 return true;
249 250
250 bool mojo_result = mojo_application_host_->Init();
251 if (!mojo_result) {
252 NotifyAndDelete();
253 return false;
254 }
255
256 // Name must be set or metrics_service will crash in any test which 251 // Name must be set or metrics_service will crash in any test which
257 // launches a UtilityProcessHost. 252 // launches a UtilityProcessHost.
258 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); 253 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this));
259 process_->SetName(name_); 254 process_->SetName(name_);
260 255
261 std::string channel_id = process_->GetHost()->CreateChannel(); 256 std::string channel_id = process_->GetHost()->CreateChannel();
262 if (channel_id.empty()) { 257 if (channel_id.empty()) {
263 NotifyAndDelete(); 258 NotifyAndDelete();
264 return false; 259 return false;
265 } 260 }
266 261
262 std::string mojo_token = mojo_application_host_->InitWithToken();
263
267 if (RenderProcessHost::run_renderer_in_process()) { 264 if (RenderProcessHost::run_renderer_in_process()) {
268 DCHECK(g_utility_main_thread_factory); 265 DCHECK(g_utility_main_thread_factory);
269 // See comment in RenderProcessHostImpl::Init() for the background on why we 266 // See comment in RenderProcessHostImpl::Init() for the background on why we
270 // support single process mode this way. 267 // support single process mode this way.
271 in_process_thread_.reset( 268 in_process_thread_.reset(
272 g_utility_main_thread_factory(InProcessChildThreadParams( 269 g_utility_main_thread_factory(InProcessChildThreadParams(
273 channel_id, BrowserThread::UnsafeGetMessageLoopForThread( 270 channel_id, BrowserThread::UnsafeGetMessageLoopForThread(
274 BrowserThread::IO)->task_runner()))); 271 BrowserThread::IO)->task_runner(),
272 mojo::MessagePipeHandle(), mojo_token)));
275 in_process_thread_->Start(); 273 in_process_thread_->Start();
276 OnProcessLaunched();
277 } else { 274 } else {
278 const base::CommandLine& browser_command_line = 275 const base::CommandLine& browser_command_line =
279 *base::CommandLine::ForCurrentProcess(); 276 *base::CommandLine::ForCurrentProcess();
280 277
281 bool has_cmd_prefix = browser_command_line.HasSwitch( 278 bool has_cmd_prefix = browser_command_line.HasSwitch(
282 switches::kUtilityCmdPrefix); 279 switches::kUtilityCmdPrefix);
283 280
284 #if defined(OS_ANDROID) 281 #if defined(OS_ANDROID)
285 // readlink("/prof/self/exe") sometimes fails on Android at startup. 282 // readlink("/prof/self/exe") sometimes fails on Android at startup.
286 // As a workaround skip calling it here, since the executable name is 283 // As a workaround skip calling it here, since the executable name is
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, 340 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir,
344 exposed_dir_); 341 exposed_dir_);
345 } 342 }
346 343
347 #if defined(OS_WIN) 344 #if defined(OS_WIN)
348 // Let the utility process know if it is intended to be elevated. 345 // Let the utility process know if it is intended to be elevated.
349 if (run_elevated_) 346 if (run_elevated_)
350 cmd_line->AppendSwitch(switches::kUtilityProcessRunningElevated); 347 cmd_line->AppendSwitch(switches::kUtilityProcessRunningElevated);
351 #endif 348 #endif
352 349
350 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken,
351 mojo_token);
352
353 process_->Launch( 353 process_->Launch(
354 new UtilitySandboxedProcessLauncherDelegate(exposed_dir_, 354 new UtilitySandboxedProcessLauncherDelegate(exposed_dir_,
355 run_elevated_, 355 run_elevated_,
356 no_sandbox_, env_, 356 no_sandbox_, env_,
357 process_->GetHost()), 357 process_->GetHost()),
358 cmd_line, 358 cmd_line,
359 true); 359 true);
360 } 360 }
361 361
362 return true; 362 return true;
(...skipping 26 matching lines...) Expand all
389 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { 389 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) {
390 if (!client_.get()) 390 if (!client_.get())
391 return; 391 return;
392 392
393 client_task_runner_->PostTask( 393 client_task_runner_->PostTask(
394 FROM_HERE, 394 FROM_HERE,
395 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), 395 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(),
396 exit_code)); 396 exit_code));
397 } 397 }
398 398
399 void UtilityProcessHostImpl::OnProcessLaunched() {
400 DCHECK(mojo_application_host_);
401 base::ProcessHandle handle;
402 if (RenderProcessHost::run_renderer_in_process())
403 handle = base::GetCurrentProcessHandle();
404 else
405 handle = process_->GetData().handle;
406
407 mojo_application_host_->Activate(this, handle);
408 }
409
410 void UtilityProcessHostImpl::NotifyAndDelete() { 399 void UtilityProcessHostImpl::NotifyAndDelete() {
411 BrowserThread::PostTask( 400 BrowserThread::PostTask(
412 BrowserThread::IO, FROM_HERE, 401 BrowserThread::IO, FROM_HERE,
413 base::Bind(&UtilityProcessHostImpl::NotifyLaunchFailedAndDelete, 402 base::Bind(&UtilityProcessHostImpl::NotifyLaunchFailedAndDelete,
414 weak_ptr_factory_.GetWeakPtr())); 403 weak_ptr_factory_.GetWeakPtr()));
415 } 404 }
416 405
417 // static 406 // static
418 void UtilityProcessHostImpl::NotifyLaunchFailedAndDelete( 407 void UtilityProcessHostImpl::NotifyLaunchFailedAndDelete(
419 base::WeakPtr<UtilityProcessHostImpl> host) { 408 base::WeakPtr<UtilityProcessHostImpl> host) {
420 if (!host) 409 if (!host)
421 return; 410 return;
422 411
423 host->OnProcessLaunchFailed(); 412 host->OnProcessLaunchFailed();
424 delete host.get(); 413 delete host.get();
425 } 414 }
426 415
427 } // namespace content 416 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/utility_process_host_impl.h ('k') | content/child/child_thread_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698