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/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 Loading... |
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" |
55 #include "content/common/mojo/mojo_shell_connection_impl.h" | 56 #include "content/common/mojo/mojo_shell_connection_impl.h" |
56 #include "content/public/common/content_switches.h" | 57 #include "content/public/common/content_switches.h" |
57 #include "ipc/attachment_broker.h" | 58 #include "ipc/attachment_broker.h" |
58 #include "ipc/attachment_broker_unprivileged.h" | 59 #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" | |
68 | 67 |
69 #if defined(USE_OZONE) | 68 #if defined(USE_OZONE) |
70 #include "ui/ozone/public/client_native_pixmap_factory.h" | 69 #include "ui/ozone/public/client_native_pixmap_factory.h" |
71 #endif | 70 #endif |
72 | 71 |
73 #if defined(OS_POSIX) | |
74 #include "base/posix/global_descriptors.h" | |
75 #endif | |
76 | |
77 using tracked_objects::ThreadData; | 72 using tracked_objects::ThreadData; |
78 | 73 |
79 namespace content { | 74 namespace content { |
80 namespace { | 75 namespace { |
81 | 76 |
82 // How long to wait for a connection to the browser process before giving up. | 77 // How long to wait for a connection to the browser process before giving up. |
83 const int kConnectionTimeoutS = 15; | 78 const int kConnectionTimeoutS = 15; |
84 | 79 |
85 base::LazyInstance<base::ThreadLocalPointer<ChildThreadImpl> > g_lazy_tls = | 80 base::LazyInstance<base::ThreadLocalPointer<ChildThreadImpl> > g_lazy_tls = |
86 LAZY_INSTANCE_INITIALIZER; | 81 LAZY_INSTANCE_INITIALIZER; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 base::AutoLock lock(lock_); | 238 base::AutoLock lock(lock_); |
244 while (closure_.is_null()) | 239 while (closure_.is_null()) |
245 cond_var_.Wait(); | 240 cond_var_.Wait(); |
246 | 241 |
247 closure_.Run(); | 242 closure_.Run(); |
248 } | 243 } |
249 | 244 |
250 base::LazyInstance<QuitClosure> g_quit_closure = LAZY_INSTANCE_INITIALIZER; | 245 base::LazyInstance<QuitClosure> g_quit_closure = LAZY_INSTANCE_INITIALIZER; |
251 #endif | 246 #endif |
252 | 247 |
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 | |
267 } // namespace | 248 } // namespace |
268 | 249 |
269 ChildThread* ChildThread::Get() { | 250 ChildThread* ChildThread::Get() { |
270 return ChildThreadImpl::current(); | 251 return ChildThreadImpl::current(); |
271 } | 252 } |
272 | 253 |
273 ChildThreadImpl::Options::Options() | 254 ChildThreadImpl::Options::Options() |
274 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 255 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
275 switches::kProcessChannelID)), | 256 switches::kProcessChannelID)), |
276 use_mojo_channel(false) { | 257 use_mojo_channel(false) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), | 372 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), |
392 ChildProcess::current()->GetShutDownEvent()); | 373 ChildProcess::current()->GetShutDownEvent()); |
393 #ifdef IPC_MESSAGE_LOG_ENABLED | 374 #ifdef IPC_MESSAGE_LOG_ENABLED |
394 if (!IsInBrowserProcess()) | 375 if (!IsInBrowserProcess()) |
395 IPC::Logging::GetInstance()->SetIPCSender(this); | 376 IPC::Logging::GetInstance()->SetIPCSender(this); |
396 #endif | 377 #endif |
397 | 378 |
398 if (!IsInBrowserProcess()) { | 379 if (!IsInBrowserProcess()) { |
399 // Don't double-initialize IPC support in single-process mode. | 380 // Don't double-initialize IPC support in single-process mode. |
400 mojo_ipc_support_.reset(new IPC::ScopedIPCSupport(GetIOTaskRunner())); | 381 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)); | |
414 } | 382 } |
415 | 383 |
416 mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); | 384 mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); |
417 | 385 |
418 sync_message_filter_ = channel_->CreateSyncMessageFilter(); | 386 sync_message_filter_ = channel_->CreateSyncMessageFilter(); |
419 thread_safe_sender_ = new ThreadSafeSender( | 387 thread_safe_sender_ = new ThreadSafeSender( |
420 message_loop_->task_runner(), sync_message_filter_.get()); | 388 message_loop_->task_runner(), sync_message_filter_.get()); |
421 | 389 |
422 resource_dispatcher_.reset(new ResourceDispatcher( | 390 resource_dispatcher_.reset(new ResourceDispatcher( |
423 this, message_loop()->task_runner())); | 391 this, message_loop()->task_runner())); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 OnSetIPCLoggingEnabled) | 612 OnSetIPCLoggingEnabled) |
645 #endif | 613 #endif |
646 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, | 614 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, |
647 OnSetProfilerStatus) | 615 OnSetProfilerStatus) |
648 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData, | 616 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData, |
649 OnGetChildProfilerData) | 617 OnGetChildProfilerData) |
650 IPC_MESSAGE_HANDLER(ChildProcessMsg_ProfilingPhaseCompleted, | 618 IPC_MESSAGE_HANDLER(ChildProcessMsg_ProfilingPhaseCompleted, |
651 OnProfilingPhaseCompleted) | 619 OnProfilingPhaseCompleted) |
652 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProcessBackgrounded, | 620 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProcessBackgrounded, |
653 OnProcessBackgrounded) | 621 OnProcessBackgrounded) |
| 622 IPC_MESSAGE_HANDLER(MojoMsg_BindExternalMojoShellHandle, |
| 623 OnBindExternalMojoShellHandle) |
| 624 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetMojoParentPipeHandle, |
| 625 OnSetMojoParentPipeHandle) |
654 IPC_MESSAGE_UNHANDLED(handled = false) | 626 IPC_MESSAGE_UNHANDLED(handled = false) |
655 IPC_END_MESSAGE_MAP() | 627 IPC_END_MESSAGE_MAP() |
656 | 628 |
657 if (handled) | 629 if (handled) |
658 return true; | 630 return true; |
659 | 631 |
660 if (msg.routing_id() == MSG_ROUTING_CONTROL) | 632 if (msg.routing_id() == MSG_ROUTING_CONTROL) |
661 return OnControlMessageReceived(msg); | 633 return OnControlMessageReceived(msg); |
662 | 634 |
663 return router_.OnMessageReceived(msg); | 635 return router_.OnMessageReceived(msg); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 ThreadData::Snapshot(current_profiling_phase, &process_data); | 670 ThreadData::Snapshot(current_profiling_phase, &process_data); |
699 | 671 |
700 Send( | 672 Send( |
701 new ChildProcessHostMsg_ChildProfilerData(sequence_number, process_data)); | 673 new ChildProcessHostMsg_ChildProfilerData(sequence_number, process_data)); |
702 } | 674 } |
703 | 675 |
704 void ChildThreadImpl::OnProfilingPhaseCompleted(int profiling_phase) { | 676 void ChildThreadImpl::OnProfilingPhaseCompleted(int profiling_phase) { |
705 ThreadData::OnProfilingPhaseCompleted(profiling_phase); | 677 ThreadData::OnProfilingPhaseCompleted(profiling_phase); |
706 } | 678 } |
707 | 679 |
| 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 |
708 ChildThreadImpl* ChildThreadImpl::current() { | 701 ChildThreadImpl* ChildThreadImpl::current() { |
709 return g_lazy_tls.Pointer()->Get(); | 702 return g_lazy_tls.Pointer()->Get(); |
710 } | 703 } |
711 | 704 |
712 #if defined(OS_ANDROID) | 705 #if defined(OS_ANDROID) |
713 // The method must NOT be called on the child thread itself. | 706 // The method must NOT be called on the child thread itself. |
714 // It may block the child thread if so. | 707 // It may block the child thread if so. |
715 void ChildThreadImpl::ShutdownThread() { | 708 void ChildThreadImpl::ShutdownThread() { |
716 DCHECK(!ChildThreadImpl::current()) << | 709 DCHECK(!ChildThreadImpl::current()) << |
717 "this method should NOT be called from child thread itself"; | 710 "this method should NOT be called from child thread itself"; |
(...skipping 17 matching lines...) Expand all Loading... |
735 void ChildThreadImpl::EnsureConnected() { | 728 void ChildThreadImpl::EnsureConnected() { |
736 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 729 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
737 base::Process::Current().Terminate(0, false); | 730 base::Process::Current().Terminate(0, false); |
738 } | 731 } |
739 | 732 |
740 bool ChildThreadImpl::IsInBrowserProcess() const { | 733 bool ChildThreadImpl::IsInBrowserProcess() const { |
741 return browser_process_io_runner_; | 734 return browser_process_io_runner_; |
742 } | 735 } |
743 | 736 |
744 } // namespace content | 737 } // namespace content |
OLD | NEW |