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