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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "content/child/push_messaging/push_dispatcher.h" | 47 #include "content/child/push_messaging/push_dispatcher.h" |
48 #include "content/child/quota_dispatcher.h" | 48 #include "content/child/quota_dispatcher.h" |
49 #include "content/child/quota_message_filter.h" | 49 #include "content/child/quota_message_filter.h" |
50 #include "content/child/resource_dispatcher.h" | 50 #include "content/child/resource_dispatcher.h" |
51 #include "content/child/service_worker/service_worker_message_filter.h" | 51 #include "content/child/service_worker/service_worker_message_filter.h" |
52 #include "content/child/thread_safe_sender.h" | 52 #include "content/child/thread_safe_sender.h" |
53 #include "content/child/websocket_dispatcher.h" | 53 #include "content/child/websocket_dispatcher.h" |
54 #include "content/child/websocket_message_filter.h" | 54 #include "content/child/websocket_message_filter.h" |
55 #include "content/common/child_process_messages.h" | 55 #include "content/common/child_process_messages.h" |
56 #include "content/common/in_process_child_thread_params.h" | 56 #include "content/common/in_process_child_thread_params.h" |
| 57 #include "content/common/mojo/mojo_shell_connection_impl.h" |
57 #include "content/public/common/content_switches.h" | 58 #include "content/public/common/content_switches.h" |
58 #include "content/public/common/mojo_channel_switches.h" | 59 #include "content/public/common/mojo_channel_switches.h" |
59 #include "content/public/common/mojo_shell_connection.h" | |
60 #include "ipc/attachment_broker.h" | 60 #include "ipc/attachment_broker.h" |
61 #include "ipc/attachment_broker_unprivileged.h" | 61 #include "ipc/attachment_broker_unprivileged.h" |
62 #include "ipc/ipc_channel_mojo.h" | 62 #include "ipc/ipc_channel_mojo.h" |
63 #include "ipc/ipc_logging.h" | 63 #include "ipc/ipc_logging.h" |
64 #include "ipc/ipc_platform_file.h" | 64 #include "ipc/ipc_platform_file.h" |
65 #include "ipc/ipc_switches.h" | 65 #include "ipc/ipc_switches.h" |
66 #include "ipc/ipc_sync_channel.h" | 66 #include "ipc/ipc_sync_channel.h" |
67 #include "ipc/ipc_sync_message_filter.h" | 67 #include "ipc/ipc_sync_message_filter.h" |
68 #include "mojo/edk/embedder/embedder.h" | 68 #include "mojo/edk/embedder/embedder.h" |
69 #include "mojo/edk/embedder/named_platform_channel_pair.h" | 69 #include "mojo/edk/embedder/named_platform_channel_pair.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 return *this; | 298 return *this; |
299 } | 299 } |
300 | 300 |
301 ChildThreadImpl::Options::Builder& | 301 ChildThreadImpl::Options::Builder& |
302 ChildThreadImpl::Options::Builder::AddStartupFilter( | 302 ChildThreadImpl::Options::Builder::AddStartupFilter( |
303 IPC::MessageFilter* filter) { | 303 IPC::MessageFilter* filter) { |
304 options_.startup_filters.push_back(filter); | 304 options_.startup_filters.push_back(filter); |
305 return *this; | 305 return *this; |
306 } | 306 } |
307 | 307 |
308 ChildThreadImpl::Options::Builder& | |
309 ChildThreadImpl::Options::Builder::UseMojoShellConnection( | |
310 bool use_mojo_shell_connection) { | |
311 options_.use_mojo_shell_connection = use_mojo_shell_connection; | |
312 return *this; | |
313 } | |
314 | |
315 ChildThreadImpl::Options ChildThreadImpl::Options::Builder::Build() { | 308 ChildThreadImpl::Options ChildThreadImpl::Options::Builder::Build() { |
316 return options_; | 309 return options_; |
317 } | 310 } |
318 | 311 |
319 ChildThreadImpl::ChildThreadMessageRouter::ChildThreadMessageRouter( | 312 ChildThreadImpl::ChildThreadMessageRouter::ChildThreadMessageRouter( |
320 IPC::Sender* sender) | 313 IPC::Sender* sender) |
321 : sender_(sender) {} | 314 : sender_(sender) {} |
322 | 315 |
323 bool ChildThreadImpl::ChildThreadMessageRouter::Send(IPC::Message* msg) { | 316 bool ChildThreadImpl::ChildThreadMessageRouter::Send(IPC::Message* msg) { |
324 return sender_->Send(msg); | 317 return sender_->Send(msg); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 create_pipe_now); | 368 create_pipe_now); |
376 return; | 369 return; |
377 } | 370 } |
378 | 371 |
379 VLOG(1) << "Mojo is disabled on child"; | 372 VLOG(1) << "Mojo is disabled on child"; |
380 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); | 373 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); |
381 } | 374 } |
382 | 375 |
383 void ChildThreadImpl::Init(const Options& options) { | 376 void ChildThreadImpl::Init(const Options& options) { |
384 channel_name_ = options.channel_name; | 377 channel_name_ = options.channel_name; |
385 use_mojo_shell_connection_ = options.use_mojo_shell_connection; | |
386 | 378 |
387 g_lazy_tls.Pointer()->Set(this); | 379 g_lazy_tls.Pointer()->Set(this); |
388 on_channel_error_called_ = false; | 380 on_channel_error_called_ = false; |
389 message_loop_ = base::MessageLoop::current(); | 381 message_loop_ = base::MessageLoop::current(); |
390 #ifdef IPC_MESSAGE_LOG_ENABLED | 382 #ifdef IPC_MESSAGE_LOG_ENABLED |
391 // We must make sure to instantiate the IPC Logger *before* we create the | 383 // We must make sure to instantiate the IPC Logger *before* we create the |
392 // channel, otherwise we can get a callback on the IO thread which creates | 384 // channel, otherwise we can get a callback on the IO thread which creates |
393 // the logger, and the logger does not like being created on the IO thread. | 385 // the logger, and the logger does not like being created on the IO thread. |
394 IPC::Logging::GetInstance(); | 386 IPC::Logging::GetInstance(); |
395 #endif | 387 #endif |
396 | 388 |
397 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); | 389 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); |
398 | 390 |
399 channel_ = | 391 channel_ = |
400 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), | 392 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), |
401 ChildProcess::current()->GetShutDownEvent()); | 393 ChildProcess::current()->GetShutDownEvent()); |
402 #ifdef IPC_MESSAGE_LOG_ENABLED | 394 #ifdef IPC_MESSAGE_LOG_ENABLED |
403 if (!IsInBrowserProcess()) | 395 if (!IsInBrowserProcess()) |
404 IPC::Logging::GetInstance()->SetIPCSender(this); | 396 IPC::Logging::GetInstance()->SetIPCSender(this); |
405 #endif | 397 #endif |
406 | 398 |
407 if (!IsInBrowserProcess()) { | 399 if (!IsInBrowserProcess()) { |
408 // Don't double-initialize IPC support in single-process mode. | 400 // Don't double-initialize IPC support in single-process mode. |
409 mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport(GetIOTaskRunner())); | 401 mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport(GetIOTaskRunner())); |
410 InitializeMojoIPCChannel(); | 402 InitializeMojoIPCChannel(); |
411 } | 403 } |
| 404 if (shell::ShellIsRemote()) { |
| 405 MojoShellConnection::SetForProcess( |
| 406 MojoShellConnection::Create( |
| 407 shell::GetShellClientRequestFromCommandLine())); |
| 408 } |
| 409 mojo_application_.reset(new MojoApplication()); |
412 std::string mojo_application_token; | 410 std::string mojo_application_token; |
413 if (!IsInBrowserProcess()) { | 411 if (!IsInBrowserProcess()) { |
414 mojo_application_token = | 412 mojo_application_token = |
415 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 413 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
416 switches::kMojoApplicationChannelToken); | 414 switches::kMojoApplicationChannelToken); |
417 } else { | 415 } else { |
418 mojo_application_token = options.in_process_application_token; | 416 mojo_application_token = options.in_process_application_token; |
419 } | 417 } |
420 if (use_mojo_shell_connection_) { | 418 if (!mojo_application_token.empty()) |
421 mojo::ScopedMessagePipeHandle handle = | 419 mojo_application_->InitWithToken(mojo_application_token); |
422 mojo::edk::CreateChildMessagePipe(mojo_application_token); | 420 |
423 DCHECK(handle.is_valid()); | |
424 mojo_shell_connection_ = MojoShellConnection::Create( | |
425 mojo::MakeRequest<shell::mojom::ShellClient>(std::move(handle))); | |
426 mojo_shell_connection_->AddEmbeddedShellClient(this); | |
427 } else { | |
428 mojo_application_.reset(new MojoApplication()); | |
429 if (!mojo_application_token.empty()) | |
430 mojo_application_->InitWithToken(mojo_application_token); | |
431 } | |
432 sync_message_filter_ = channel_->CreateSyncMessageFilter(); | 421 sync_message_filter_ = channel_->CreateSyncMessageFilter(); |
433 thread_safe_sender_ = new ThreadSafeSender( | 422 thread_safe_sender_ = new ThreadSafeSender( |
434 message_loop_->task_runner(), sync_message_filter_.get()); | 423 message_loop_->task_runner(), sync_message_filter_.get()); |
435 | 424 |
436 resource_dispatcher_.reset(new ResourceDispatcher( | 425 resource_dispatcher_.reset(new ResourceDispatcher( |
437 this, message_loop()->task_runner())); | 426 this, message_loop()->task_runner())); |
438 websocket_dispatcher_.reset(new WebSocketDispatcher); | 427 websocket_dispatcher_.reset(new WebSocketDispatcher); |
439 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 428 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
440 | 429 |
441 histogram_message_filter_ = new ChildHistogramMessageFilter(); | 430 histogram_message_filter_ = new ChildHistogramMessageFilter(); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 #endif | 586 #endif |
598 | 587 |
599 void ChildThreadImpl::RecordAction(const base::UserMetricsAction& action) { | 588 void ChildThreadImpl::RecordAction(const base::UserMetricsAction& action) { |
600 NOTREACHED(); | 589 NOTREACHED(); |
601 } | 590 } |
602 | 591 |
603 void ChildThreadImpl::RecordComputedAction(const std::string& action) { | 592 void ChildThreadImpl::RecordComputedAction(const std::string& action) { |
604 NOTREACHED(); | 593 NOTREACHED(); |
605 } | 594 } |
606 | 595 |
607 MojoShellConnection* ChildThreadImpl::GetMojoShellConnection() { | |
608 return mojo_shell_connection_.get(); | |
609 } | |
610 | |
611 shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistry() { | 596 shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistry() { |
612 if (use_mojo_shell_connection_) { | |
613 if (!interface_registry_.get()) | |
614 interface_registry_.reset(new shell::InterfaceRegistry(nullptr)); | |
615 return interface_registry_.get(); | |
616 } | |
617 return mojo_application_->interface_registry(); | 597 return mojo_application_->interface_registry(); |
618 } | 598 } |
619 | 599 |
620 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { | 600 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { |
621 if (use_mojo_shell_connection_) { | |
622 if (!remote_interfaces_.get()) | |
623 remote_interfaces_.reset(new shell::InterfaceProvider); | |
624 return remote_interfaces_.get(); | |
625 } | |
626 return mojo_application_->remote_interfaces(); | 601 return mojo_application_->remote_interfaces(); |
627 } | 602 } |
628 | 603 |
629 shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistryForConnection() { | |
630 return GetInterfaceRegistry(); | |
631 } | |
632 | |
633 shell::InterfaceProvider* ChildThreadImpl::GetInterfaceProviderForConnection() { | |
634 return GetRemoteInterfaces(); | |
635 } | |
636 | |
637 IPC::MessageRouter* ChildThreadImpl::GetRouter() { | 604 IPC::MessageRouter* ChildThreadImpl::GetRouter() { |
638 DCHECK(base::MessageLoop::current() == message_loop()); | 605 DCHECK(base::MessageLoop::current() == message_loop()); |
639 return &router_; | 606 return &router_; |
640 } | 607 } |
641 | 608 |
642 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( | 609 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( |
643 size_t buf_size) { | 610 size_t buf_size) { |
644 DCHECK(base::MessageLoop::current() == message_loop()); | 611 DCHECK(base::MessageLoop::current() == message_loop()); |
645 return AllocateSharedMemory(buf_size, this, nullptr); | 612 return AllocateSharedMemory(buf_size, this, nullptr); |
646 } | 613 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 void ChildThreadImpl::EnsureConnected() { | 751 void ChildThreadImpl::EnsureConnected() { |
785 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 752 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
786 base::Process::Current().Terminate(0, false); | 753 base::Process::Current().Terminate(0, false); |
787 } | 754 } |
788 | 755 |
789 bool ChildThreadImpl::IsInBrowserProcess() const { | 756 bool ChildThreadImpl::IsInBrowserProcess() const { |
790 return static_cast<bool>(browser_process_io_runner_); | 757 return static_cast<bool>(browser_process_io_runner_); |
791 } | 758 } |
792 | 759 |
793 } // namespace content | 760 } // namespace content |
OLD | NEW |