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

Side by Side Diff: content/child/child_thread_impl.cc

Issue 1685183004: Bootstrap Mojo IPC independent of Chrome IPC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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/child/child_thread_impl.h ('k') | content/common/mojo/mojo_messages.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/child/child_thread_impl.h" 5 #include "content/child/child_thread_impl.h"
6 6
7 #include <signal.h> 7 #include <signal.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "content/child/power_monitor_broadcast_source.h" 45 #include "content/child/power_monitor_broadcast_source.h"
46 #include "content/child/push_messaging/push_dispatcher.h" 46 #include "content/child/push_messaging/push_dispatcher.h"
47 #include "content/child/quota_dispatcher.h" 47 #include "content/child/quota_dispatcher.h"
48 #include "content/child/quota_message_filter.h" 48 #include "content/child/quota_message_filter.h"
49 #include "content/child/resource_dispatcher.h" 49 #include "content/child/resource_dispatcher.h"
50 #include "content/child/service_worker/service_worker_message_filter.h" 50 #include "content/child/service_worker/service_worker_message_filter.h"
51 #include "content/child/thread_safe_sender.h" 51 #include "content/child/thread_safe_sender.h"
52 #include "content/child/websocket_dispatcher.h" 52 #include "content/child/websocket_dispatcher.h"
53 #include "content/common/child_process_messages.h" 53 #include "content/common/child_process_messages.h"
54 #include "content/common/in_process_child_thread_params.h" 54 #include "content/common/in_process_child_thread_params.h"
55 #include "content/common/mojo/mojo_messages.h"
56 #include "content/common/mojo/mojo_shell_connection_impl.h" 55 #include "content/common/mojo/mojo_shell_connection_impl.h"
57 #include "content/public/common/content_switches.h" 56 #include "content/public/common/content_switches.h"
58 #include "ipc/attachment_broker.h" 57 #include "ipc/attachment_broker.h"
59 #include "ipc/attachment_broker_unprivileged.h" 58 #include "ipc/attachment_broker_unprivileged.h"
59 #include "ipc/ipc_descriptors.h"
60 #include "ipc/ipc_logging.h" 60 #include "ipc/ipc_logging.h"
61 #include "ipc/ipc_platform_file.h" 61 #include "ipc/ipc_platform_file.h"
62 #include "ipc/ipc_switches.h" 62 #include "ipc/ipc_switches.h"
63 #include "ipc/ipc_sync_channel.h" 63 #include "ipc/ipc_sync_channel.h"
64 #include "ipc/ipc_sync_message_filter.h" 64 #include "ipc/ipc_sync_message_filter.h"
65 #include "ipc/mojo/ipc_channel_mojo.h" 65 #include "ipc/mojo/ipc_channel_mojo.h"
66 #include "mojo/edk/embedder/embedder.h" 66 #include "mojo/edk/embedder/embedder.h"
67 #include "mojo/edk/embedder/platform_channel_pair.h"
67 68
68 #if defined(USE_OZONE) 69 #if defined(USE_OZONE)
69 #include "ui/ozone/public/client_native_pixmap_factory.h" 70 #include "ui/ozone/public/client_native_pixmap_factory.h"
70 #endif 71 #endif
71 72
73 #if defined(OS_POSIX)
74 #include "base/posix/global_descriptors.h"
75 #endif
76
72 using tracked_objects::ThreadData; 77 using tracked_objects::ThreadData;
73 78
74 namespace content { 79 namespace content {
75 namespace { 80 namespace {
76 81
77 // How long to wait for a connection to the browser process before giving up. 82 // How long to wait for a connection to the browser process before giving up.
78 const int kConnectionTimeoutS = 15; 83 const int kConnectionTimeoutS = 15;
79 84
80 base::LazyInstance<base::ThreadLocalPointer<ChildThreadImpl> > g_lazy_tls = 85 base::LazyInstance<base::ThreadLocalPointer<ChildThreadImpl> > g_lazy_tls =
81 LAZY_INSTANCE_INITIALIZER; 86 LAZY_INSTANCE_INITIALIZER;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 base::AutoLock lock(lock_); 243 base::AutoLock lock(lock_);
239 while (closure_.is_null()) 244 while (closure_.is_null())
240 cond_var_.Wait(); 245 cond_var_.Wait();
241 246
242 closure_.Run(); 247 closure_.Run();
243 } 248 }
244 249
245 base::LazyInstance<QuitClosure> g_quit_closure = LAZY_INSTANCE_INITIALIZER; 250 base::LazyInstance<QuitClosure> g_quit_closure = LAZY_INSTANCE_INITIALIZER;
246 #endif 251 #endif
247 252
253 void InitializeMojoIPCChannel() {
254 mojo::edk::ScopedPlatformHandle platform_channel;
255 #if defined(OS_WIN)
256 platform_channel =
257 mojo::edk::PlatformChannelPair::PassClientHandleFromParentProcess(
258 *base::CommandLine::ForCurrentProcess());
259 #elif defined(OS_POSIX)
260 platform_channel.reset(mojo::edk::PlatformHandle(
261 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel)));
262 #endif
263 CHECK(platform_channel.is_valid());
264 mojo::edk::SetParentPipeHandle(std::move(platform_channel));
265 }
266
248 } // namespace 267 } // namespace
249 268
250 ChildThread* ChildThread::Get() { 269 ChildThread* ChildThread::Get() {
251 return ChildThreadImpl::current(); 270 return ChildThreadImpl::current();
252 } 271 }
253 272
254 ChildThreadImpl::Options::Options() 273 ChildThreadImpl::Options::Options()
255 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 274 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
256 switches::kProcessChannelID)), 275 switches::kProcessChannelID)),
257 use_mojo_channel(false) { 276 use_mojo_channel(false) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), 391 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(),
373 ChildProcess::current()->GetShutDownEvent()); 392 ChildProcess::current()->GetShutDownEvent());
374 #ifdef IPC_MESSAGE_LOG_ENABLED 393 #ifdef IPC_MESSAGE_LOG_ENABLED
375 if (!IsInBrowserProcess()) 394 if (!IsInBrowserProcess())
376 IPC::Logging::GetInstance()->SetIPCSender(this); 395 IPC::Logging::GetInstance()->SetIPCSender(this);
377 #endif 396 #endif
378 397
379 if (!IsInBrowserProcess()) { 398 if (!IsInBrowserProcess()) {
380 // Don't double-initialize IPC support in single-process mode. 399 // Don't double-initialize IPC support in single-process mode.
381 mojo_ipc_support_.reset(new IPC::ScopedIPCSupport(GetIOTaskRunner())); 400 mojo_ipc_support_.reset(new IPC::ScopedIPCSupport(GetIOTaskRunner()));
401
402 InitializeMojoIPCChannel();
403 }
404
405 // If this process was launched with a primordial pipe token, we exchange it
406 // for a pipe to connect to the shell.
407 std::string pipe_token =
408 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
409 switches::kMojoPrimordialPipeToken);
410 if (!pipe_token.empty() && MojoShellConnectionImpl::Get()) {
411 mojo::ScopedMessagePipeHandle pipe =
412 mojo::edk::CreateChildMessagePipe(pipe_token);
413 MojoShellConnectionImpl::Get()->BindToMessagePipe(std::move(pipe));
382 } 414 }
383 415
384 mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); 416 mojo_application_.reset(new MojoApplication(GetIOTaskRunner()));
385 417
386 sync_message_filter_ = channel_->CreateSyncMessageFilter(); 418 sync_message_filter_ = channel_->CreateSyncMessageFilter();
387 thread_safe_sender_ = new ThreadSafeSender( 419 thread_safe_sender_ = new ThreadSafeSender(
388 message_loop_->task_runner(), sync_message_filter_.get()); 420 message_loop_->task_runner(), sync_message_filter_.get());
389 421
390 resource_dispatcher_.reset(new ResourceDispatcher( 422 resource_dispatcher_.reset(new ResourceDispatcher(
391 this, message_loop()->task_runner())); 423 this, message_loop()->task_runner()));
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 OnSetIPCLoggingEnabled) 644 OnSetIPCLoggingEnabled)
613 #endif 645 #endif
614 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, 646 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus,
615 OnSetProfilerStatus) 647 OnSetProfilerStatus)
616 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData, 648 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData,
617 OnGetChildProfilerData) 649 OnGetChildProfilerData)
618 IPC_MESSAGE_HANDLER(ChildProcessMsg_ProfilingPhaseCompleted, 650 IPC_MESSAGE_HANDLER(ChildProcessMsg_ProfilingPhaseCompleted,
619 OnProfilingPhaseCompleted) 651 OnProfilingPhaseCompleted)
620 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProcessBackgrounded, 652 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProcessBackgrounded,
621 OnProcessBackgrounded) 653 OnProcessBackgrounded)
622 IPC_MESSAGE_HANDLER(MojoMsg_BindExternalMojoShellHandle,
623 OnBindExternalMojoShellHandle)
624 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetMojoParentPipeHandle,
625 OnSetMojoParentPipeHandle)
626 IPC_MESSAGE_UNHANDLED(handled = false) 654 IPC_MESSAGE_UNHANDLED(handled = false)
627 IPC_END_MESSAGE_MAP() 655 IPC_END_MESSAGE_MAP()
628 656
629 if (handled) 657 if (handled)
630 return true; 658 return true;
631 659
632 if (msg.routing_id() == MSG_ROUTING_CONTROL) 660 if (msg.routing_id() == MSG_ROUTING_CONTROL)
633 return OnControlMessageReceived(msg); 661 return OnControlMessageReceived(msg);
634 662
635 return router_.OnMessageReceived(msg); 663 return router_.OnMessageReceived(msg);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 ThreadData::Snapshot(current_profiling_phase, &process_data); 698 ThreadData::Snapshot(current_profiling_phase, &process_data);
671 699
672 Send( 700 Send(
673 new ChildProcessHostMsg_ChildProfilerData(sequence_number, process_data)); 701 new ChildProcessHostMsg_ChildProfilerData(sequence_number, process_data));
674 } 702 }
675 703
676 void ChildThreadImpl::OnProfilingPhaseCompleted(int profiling_phase) { 704 void ChildThreadImpl::OnProfilingPhaseCompleted(int profiling_phase) {
677 ThreadData::OnProfilingPhaseCompleted(profiling_phase); 705 ThreadData::OnProfilingPhaseCompleted(profiling_phase);
678 } 706 }
679 707
680 void ChildThreadImpl::OnBindExternalMojoShellHandle(
681 const IPC::PlatformFileForTransit& file) {
682 if (!MojoShellConnectionImpl::Get())
683 return;
684 #if defined(OS_POSIX)
685 base::PlatformFile handle = file.fd;
686 #elif defined(OS_WIN)
687 base::PlatformFile handle = file;
688 #endif
689 mojo::ScopedMessagePipeHandle pipe =
690 mojo_shell_channel_init_.Init(handle, GetIOTaskRunner());
691 MojoShellConnectionImpl::Get()->BindToMessagePipe(std::move(pipe));
692 }
693
694 void ChildThreadImpl::OnSetMojoParentPipeHandle(
695 const IPC::PlatformFileForTransit& file) {
696 mojo::edk::SetParentPipeHandle(
697 mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle(
698 IPC::PlatformFileForTransitToPlatformFile(file))));
699 }
700
701 ChildThreadImpl* ChildThreadImpl::current() { 708 ChildThreadImpl* ChildThreadImpl::current() {
702 return g_lazy_tls.Pointer()->Get(); 709 return g_lazy_tls.Pointer()->Get();
703 } 710 }
704 711
705 #if defined(OS_ANDROID) 712 #if defined(OS_ANDROID)
706 // The method must NOT be called on the child thread itself. 713 // The method must NOT be called on the child thread itself.
707 // It may block the child thread if so. 714 // It may block the child thread if so.
708 void ChildThreadImpl::ShutdownThread() { 715 void ChildThreadImpl::ShutdownThread() {
709 DCHECK(!ChildThreadImpl::current()) << 716 DCHECK(!ChildThreadImpl::current()) <<
710 "this method should NOT be called from child thread itself"; 717 "this method should NOT be called from child thread itself";
(...skipping 17 matching lines...) Expand all
728 void ChildThreadImpl::EnsureConnected() { 735 void ChildThreadImpl::EnsureConnected() {
729 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; 736 VLOG(0) << "ChildThreadImpl::EnsureConnected()";
730 base::Process::Current().Terminate(0, false); 737 base::Process::Current().Terminate(0, false);
731 } 738 }
732 739
733 bool ChildThreadImpl::IsInBrowserProcess() const { 740 bool ChildThreadImpl::IsInBrowserProcess() const {
734 return browser_process_io_runner_; 741 return browser_process_io_runner_;
735 } 742 }
736 743
737 } // namespace content 744 } // namespace content
OLDNEW
« no previous file with comments | « content/child/child_thread_impl.h ('k') | content/common/mojo/mojo_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698