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

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

Issue 1442893002: Move Shell connection to content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@i2
Patch Set: . Created 5 years, 1 month 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/child_process_launcher.h ('k') | content/common/BUILD.gn » ('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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/i18n/icu_util.h" 10 #include "base/i18n/icu_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/process/process.h" 14 #include "base/process/process.h"
15 #include "base/profiler/scoped_tracker.h" 15 #include "base/profiler/scoped_tracker.h"
16 #include "base/strings/string_number_conversions.h"
16 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
17 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
18 #include "content/public/browser/content_browser_client.h" 19 #include "content/public/browser/content_browser_client.h"
19 #include "content/public/common/content_descriptors.h" 20 #include "content/public/common/content_descriptors.h"
20 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
21 #include "content/public/common/result_codes.h" 22 #include "content/public/common/result_codes.h"
22 #include "content/public/common/sandboxed_process_launcher_delegate.h" 23 #include "content/public/common/sandboxed_process_launcher_delegate.h"
23 24
24 #if defined(OS_WIN) 25 #if defined(OS_WIN)
25 #include "base/files/file_path.h" 26 #include "base/files/file_path.h"
(...skipping 14 matching lines...) Expand all
40 #include "content/browser/zygote_host/zygote_host_impl_linux.h" 41 #include "content/browser/zygote_host/zygote_host_impl_linux.h"
41 #include "content/common/child_process_sandbox_support_impl_linux.h" 42 #include "content/common/child_process_sandbox_support_impl_linux.h"
42 #endif 43 #endif
43 44
44 #if defined(OS_POSIX) 45 #if defined(OS_POSIX)
45 #include "base/posix/global_descriptors.h" 46 #include "base/posix/global_descriptors.h"
46 #include "content/browser/file_descriptor_info_impl.h" 47 #include "content/browser/file_descriptor_info_impl.h"
47 #include "gin/v8_initializer.h" 48 #include "gin/v8_initializer.h"
48 #endif 49 #endif
49 50
51 #if defined(MOJO_SHELL_CLIENT)
52 #include "content/public/common/mojo_shell_connection.h"
53 #include "mojo/application/public/cpp/application_impl.h"
54 #include "mojo/converters/network/network_type_converters.h"
55 #include "mojo/shell/application_manager.mojom.h"
56 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
57 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h"
58 #include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h"
59 #endif
60
50 namespace content { 61 namespace content {
51 62
52 namespace { 63 namespace {
53 64
54 typedef base::Callback<void(bool, 65 typedef base::Callback<void(bool,
55 #if defined(OS_ANDROID) 66 #if defined(OS_ANDROID)
56 base::ScopedFD, 67 base::ScopedFD,
57 #endif 68 #endif
58 base::Process)> NotifyCallback; 69 base::Process)> NotifyCallback;
59 70
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 bool background) { 325 bool background) {
315 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); 326 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
316 if (process.CanBackgroundProcesses()) { 327 if (process.CanBackgroundProcesses()) {
317 process.SetProcessBackgrounded(background); 328 process.SetProcessBackgrounded(background);
318 } 329 }
319 #if defined(OS_ANDROID) 330 #if defined(OS_ANDROID)
320 SetChildProcessInForeground(process.Handle(), !background); 331 SetChildProcessInForeground(process.Handle(), !background);
321 #endif 332 #endif
322 } 333 }
323 334
324 } // anonymous namespace 335 #if defined(MOJO_SHELL_CLIENT)
336 void DidCreateChannel(mojo::embedder::ChannelInfo* info) {}
337 #endif
338
339 } // namespace
325 340
326 ChildProcessLauncher::ChildProcessLauncher( 341 ChildProcessLauncher::ChildProcessLauncher(
327 SandboxedProcessLauncherDelegate* delegate, 342 SandboxedProcessLauncherDelegate* delegate,
328 base::CommandLine* cmd_line, 343 base::CommandLine* cmd_line,
329 int child_process_id, 344 int child_process_id,
330 Client* client, 345 Client* client,
331 bool terminate_on_shutdown) 346 bool terminate_on_shutdown)
332 : client_(client), 347 : client_(client),
333 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), 348 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION),
334 exit_code_(RESULT_CODE_NORMAL_EXIT), 349 exit_code_(RESULT_CODE_NORMAL_EXIT),
(...skipping 22 matching lines...) Expand all
357 base::Passed(&process_))); 372 base::Passed(&process_)));
358 } 373 }
359 } 374 }
360 375
361 void ChildProcessLauncher::Launch( 376 void ChildProcessLauncher::Launch(
362 SandboxedProcessLauncherDelegate* delegate, 377 SandboxedProcessLauncherDelegate* delegate,
363 base::CommandLine* cmd_line, 378 base::CommandLine* cmd_line,
364 int child_process_id) { 379 int child_process_id) {
365 DCHECK(CalledOnValidThread()); 380 DCHECK(CalledOnValidThread());
366 381
382 #if defined(MOJO_SHELL_CLIENT)
383 CreateMojoShellChannel(cmd_line);
384 #endif
385
367 #if defined(OS_ANDROID) 386 #if defined(OS_ANDROID)
368 // Android only supports renderer, sandboxed utility and gpu. 387 // Android only supports renderer, sandboxed utility and gpu.
369 std::string process_type = 388 std::string process_type =
370 cmd_line->GetSwitchValueASCII(switches::kProcessType); 389 cmd_line->GetSwitchValueASCII(switches::kProcessType);
371 CHECK(process_type == switches::kGpuProcess || 390 CHECK(process_type == switches::kGpuProcess ||
372 process_type == switches::kRendererProcess || 391 process_type == switches::kRendererProcess ||
373 #if defined(ENABLE_PLUGINS) 392 #if defined(ENABLE_PLUGINS)
374 process_type == switches::kPpapiPluginProcess || 393 process_type == switches::kPpapiPluginProcess ||
375 #endif 394 #endif
376 process_type == switches::kUtilityProcess) 395 process_type == switches::kUtilityProcess)
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/465841 515 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/465841
497 // is fixed. 516 // is fixed.
498 tracked_objects::ScopedTracker tracking_profile3( 517 tracked_objects::ScopedTracker tracking_profile3(
499 FROM_HERE_WITH_EXPLICIT_FUNCTION( 518 FROM_HERE_WITH_EXPLICIT_FUNCTION(
500 "465841 ChildProcessLauncher::Context::Notify::ProcessFailed")); 519 "465841 ChildProcessLauncher::Context::Notify::ProcessFailed"));
501 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; 520 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED;
502 client_->OnProcessLaunchFailed(); 521 client_->OnProcessLaunchFailed();
503 } 522 }
504 } 523 }
505 524
525 #if defined(MOJO_SHELL_CLIENT)
526 void ChildProcessLauncher::CreateMojoShellChannel(
527 base::CommandLine* command_line) {
528 DCHECK(MojoShellConnection::Get());
529
530 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk"))
531 command_line->AppendSwitch("use-new-edk");
jam 2015/11/13 23:28:10 are you sure this is needed? https://code.google.c
532
533 mojo::embedder::HandlePassingInformation handle_passing_info;
534
535 // Create the channel to be shared with the target process.
536 mojo::embedder::PlatformChannelPair platform_channel_pair;
537 // Give one end to the shell so that it can create an instance.
538 mojo::embedder::ScopedPlatformHandle platform_channel =
539 platform_channel_pair.PassServerHandle();
540
541 mojo::ScopedMessagePipeHandle handle(mojo::embedder::CreateChannel(
542 platform_channel.Pass(), base::Bind(&DidCreateChannel),
543 base::ThreadTaskRunnerHandle::Get()));
544
545 mojo::shell::mojom::ApplicationManagerPtr application_manager;
546 MojoShellConnection::Get()->GetApplication()->ConnectToService(
547 mojo::URLRequest::From(std::string("mojo:shell")),
548 &application_manager);
549 // The content of the URL/qualifier we pass is actually meaningless, it's only
550 // important that they're unique per process.
551 // TODO(beng): We need to specify a restrictive CapabilityFilter here that
552 // matches the needs of the target process. Figure out where that
553 // specification is best determined (not here, this is a common
554 // chokepoint for all process types) and how to wire it through.
555 // http://crbug.com/555393
556 application_manager->CreateInstanceForHandle(
557 mojo::ScopedHandle(mojo::Handle(handle.release().value())),
558 "exe:chrome_renderer", // See above about how this string is meaningless.
559 base::IntToString(child_process_id));
560 // Put the other end on the command line used to launch the target.
561 platform_channel_pair.PrepareToPassClientHandleToChildProcess(
562 command_line, &handle_passing_info);
563 }
564 #endif // defined(MOJO_SHELL_CLIENT)
565
506 bool ChildProcessLauncher::IsStarting() { 566 bool ChildProcessLauncher::IsStarting() {
507 // TODO(crbug.com/469248): This fails in some tests. 567 // TODO(crbug.com/469248): This fails in some tests.
508 // DCHECK(CalledOnValidThread()); 568 // DCHECK(CalledOnValidThread());
509 return starting_; 569 return starting_;
510 } 570 }
511 571
512 const base::Process& ChildProcessLauncher::GetProcess() const { 572 const base::Process& ChildProcessLauncher::GetProcess() const {
513 // TODO(crbug.com/469248): This fails in some tests. 573 // TODO(crbug.com/469248): This fails in some tests.
514 // DCHECK(CalledOnValidThread()); 574 // DCHECK(CalledOnValidThread());
515 return process_; 575 return process_;
(...skipping 27 matching lines...) Expand all
543 } 603 }
544 604
545 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( 605 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest(
546 Client* client) { 606 Client* client) {
547 Client* ret = client_; 607 Client* ret = client_;
548 client_ = client; 608 client_ = client;
549 return ret; 609 return ret;
550 } 610 }
551 611
552 } // namespace content 612 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/child_process_launcher.h ('k') | content/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698