| 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 23 matching lines...) Expand all Loading... |
| 34 #include "components/tracing/child/child_trace_message_filter.h" | 34 #include "components/tracing/child/child_trace_message_filter.h" |
| 35 #include "content/child/child_discardable_shared_memory_manager.h" | 35 #include "content/child/child_discardable_shared_memory_manager.h" |
| 36 #include "content/child/child_gpu_memory_buffer_manager.h" | 36 #include "content/child/child_gpu_memory_buffer_manager.h" |
| 37 #include "content/child/child_histogram_message_filter.h" | 37 #include "content/child/child_histogram_message_filter.h" |
| 38 #include "content/child/child_process.h" | 38 #include "content/child/child_process.h" |
| 39 #include "content/child/child_resource_message_filter.h" | 39 #include "content/child/child_resource_message_filter.h" |
| 40 #include "content/child/child_shared_bitmap_manager.h" | 40 #include "content/child/child_shared_bitmap_manager.h" |
| 41 #include "content/child/fileapi/file_system_dispatcher.h" | 41 #include "content/child/fileapi/file_system_dispatcher.h" |
| 42 #include "content/child/fileapi/webfilesystem_impl.h" | 42 #include "content/child/fileapi/webfilesystem_impl.h" |
| 43 #include "content/child/memory/child_memory_message_filter.h" | 43 #include "content/child/memory/child_memory_message_filter.h" |
| 44 #include "content/child/mojo/mojo_application.h" | |
| 45 #include "content/child/notifications/notification_dispatcher.h" | 44 #include "content/child/notifications/notification_dispatcher.h" |
| 46 #include "content/child/power_monitor_broadcast_source.h" | 45 #include "content/child/power_monitor_broadcast_source.h" |
| 47 #include "content/child/push_messaging/push_dispatcher.h" | 46 #include "content/child/push_messaging/push_dispatcher.h" |
| 48 #include "content/child/quota_dispatcher.h" | 47 #include "content/child/quota_dispatcher.h" |
| 49 #include "content/child/quota_message_filter.h" | 48 #include "content/child/quota_message_filter.h" |
| 50 #include "content/child/resource_dispatcher.h" | 49 #include "content/child/resource_dispatcher.h" |
| 51 #include "content/child/service_worker/service_worker_message_filter.h" | 50 #include "content/child/service_worker/service_worker_message_filter.h" |
| 52 #include "content/child/thread_safe_sender.h" | 51 #include "content/child/thread_safe_sender.h" |
| 53 #include "content/child/websocket_dispatcher.h" | 52 #include "content/child/websocket_dispatcher.h" |
| 54 #include "content/child/websocket_message_filter.h" | 53 #include "content/child/websocket_message_filter.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 return *this; | 297 return *this; |
| 299 } | 298 } |
| 300 | 299 |
| 301 ChildThreadImpl::Options::Builder& | 300 ChildThreadImpl::Options::Builder& |
| 302 ChildThreadImpl::Options::Builder::AddStartupFilter( | 301 ChildThreadImpl::Options::Builder::AddStartupFilter( |
| 303 IPC::MessageFilter* filter) { | 302 IPC::MessageFilter* filter) { |
| 304 options_.startup_filters.push_back(filter); | 303 options_.startup_filters.push_back(filter); |
| 305 return *this; | 304 return *this; |
| 306 } | 305 } |
| 307 | 306 |
| 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() { | 307 ChildThreadImpl::Options ChildThreadImpl::Options::Builder::Build() { |
| 316 return options_; | 308 return options_; |
| 317 } | 309 } |
| 318 | 310 |
| 319 ChildThreadImpl::ChildThreadMessageRouter::ChildThreadMessageRouter( | 311 ChildThreadImpl::ChildThreadMessageRouter::ChildThreadMessageRouter( |
| 320 IPC::Sender* sender) | 312 IPC::Sender* sender) |
| 321 : sender_(sender) {} | 313 : sender_(sender) {} |
| 322 | 314 |
| 323 bool ChildThreadImpl::ChildThreadMessageRouter::Send(IPC::Message* msg) { | 315 bool ChildThreadImpl::ChildThreadMessageRouter::Send(IPC::Message* msg) { |
| 324 return sender_->Send(msg); | 316 return sender_->Send(msg); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 create_pipe_now); | 367 create_pipe_now); |
| 376 return; | 368 return; |
| 377 } | 369 } |
| 378 | 370 |
| 379 VLOG(1) << "Mojo is disabled on child"; | 371 VLOG(1) << "Mojo is disabled on child"; |
| 380 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); | 372 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); |
| 381 } | 373 } |
| 382 | 374 |
| 383 void ChildThreadImpl::Init(const Options& options) { | 375 void ChildThreadImpl::Init(const Options& options) { |
| 384 channel_name_ = options.channel_name; | 376 channel_name_ = options.channel_name; |
| 385 use_mojo_shell_connection_ = options.use_mojo_shell_connection; | |
| 386 | 377 |
| 387 g_lazy_tls.Pointer()->Set(this); | 378 g_lazy_tls.Pointer()->Set(this); |
| 388 on_channel_error_called_ = false; | 379 on_channel_error_called_ = false; |
| 389 message_loop_ = base::MessageLoop::current(); | 380 message_loop_ = base::MessageLoop::current(); |
| 390 #ifdef IPC_MESSAGE_LOG_ENABLED | 381 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 391 // We must make sure to instantiate the IPC Logger *before* we create the | 382 // 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 | 383 // 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. | 384 // the logger, and the logger does not like being created on the IO thread. |
| 394 IPC::Logging::GetInstance(); | 385 IPC::Logging::GetInstance(); |
| 395 #endif | 386 #endif |
| (...skipping 14 matching lines...) Expand all Loading... |
| 410 InitializeMojoIPCChannel(); | 401 InitializeMojoIPCChannel(); |
| 411 } | 402 } |
| 412 std::string mojo_application_token; | 403 std::string mojo_application_token; |
| 413 if (!IsInBrowserProcess()) { | 404 if (!IsInBrowserProcess()) { |
| 414 mojo_application_token = | 405 mojo_application_token = |
| 415 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 406 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 416 switches::kMojoApplicationChannelToken); | 407 switches::kMojoApplicationChannelToken); |
| 417 } else { | 408 } else { |
| 418 mojo_application_token = options.in_process_application_token; | 409 mojo_application_token = options.in_process_application_token; |
| 419 } | 410 } |
| 420 if (use_mojo_shell_connection_) { | 411 if (!mojo_application_token.empty()) { |
| 421 mojo::ScopedMessagePipeHandle handle = | 412 mojo::ScopedMessagePipeHandle handle = |
| 422 mojo::edk::CreateChildMessagePipe(mojo_application_token); | 413 mojo::edk::CreateChildMessagePipe(mojo_application_token); |
| 423 DCHECK(handle.is_valid()); | 414 DCHECK(handle.is_valid()); |
| 424 mojo_shell_connection_ = MojoShellConnection::Create( | 415 mojo_shell_connection_ = MojoShellConnection::Create( |
| 425 mojo::MakeRequest<shell::mojom::ShellClient>(std::move(handle))); | 416 mojo::MakeRequest<shell::mojom::ShellClient>(std::move(handle))); |
| 426 mojo_shell_connection_->AddEmbeddedShellClient(this); | 417 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 } | 418 } |
| 419 |
| 432 sync_message_filter_ = channel_->CreateSyncMessageFilter(); | 420 sync_message_filter_ = channel_->CreateSyncMessageFilter(); |
| 433 thread_safe_sender_ = new ThreadSafeSender( | 421 thread_safe_sender_ = new ThreadSafeSender( |
| 434 message_loop_->task_runner(), sync_message_filter_.get()); | 422 message_loop_->task_runner(), sync_message_filter_.get()); |
| 435 | 423 |
| 436 resource_dispatcher_.reset(new ResourceDispatcher( | 424 resource_dispatcher_.reset(new ResourceDispatcher( |
| 437 this, message_loop()->task_runner())); | 425 this, message_loop()->task_runner())); |
| 438 websocket_dispatcher_.reset(new WebSocketDispatcher); | 426 websocket_dispatcher_.reset(new WebSocketDispatcher); |
| 439 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 427 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
| 440 | 428 |
| 441 histogram_message_filter_ = new ChildHistogramMessageFilter(); | 429 histogram_message_filter_ = new ChildHistogramMessageFilter(); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 | 590 |
| 603 void ChildThreadImpl::RecordComputedAction(const std::string& action) { | 591 void ChildThreadImpl::RecordComputedAction(const std::string& action) { |
| 604 NOTREACHED(); | 592 NOTREACHED(); |
| 605 } | 593 } |
| 606 | 594 |
| 607 MojoShellConnection* ChildThreadImpl::GetMojoShellConnection() { | 595 MojoShellConnection* ChildThreadImpl::GetMojoShellConnection() { |
| 608 return mojo_shell_connection_.get(); | 596 return mojo_shell_connection_.get(); |
| 609 } | 597 } |
| 610 | 598 |
| 611 shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistry() { | 599 shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistry() { |
| 612 if (use_mojo_shell_connection_) { | 600 if (!interface_registry_.get()) |
| 613 if (!interface_registry_.get()) | 601 interface_registry_.reset(new shell::InterfaceRegistry(nullptr)); |
| 614 interface_registry_.reset(new shell::InterfaceRegistry(nullptr)); | 602 return interface_registry_.get(); |
| 615 return interface_registry_.get(); | |
| 616 } | |
| 617 return mojo_application_->interface_registry(); | |
| 618 } | 603 } |
| 619 | 604 |
| 620 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { | 605 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { |
| 621 if (use_mojo_shell_connection_) { | 606 if (!remote_interfaces_.get()) |
| 622 if (!remote_interfaces_.get()) | 607 remote_interfaces_.reset(new shell::InterfaceProvider); |
| 623 remote_interfaces_.reset(new shell::InterfaceProvider); | 608 return remote_interfaces_.get(); |
| 624 return remote_interfaces_.get(); | |
| 625 } | |
| 626 return mojo_application_->remote_interfaces(); | |
| 627 } | 609 } |
| 628 | 610 |
| 629 shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistryForConnection() { | 611 shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistryForConnection() { |
| 630 return GetInterfaceRegistry(); | 612 return GetInterfaceRegistry(); |
| 631 } | 613 } |
| 632 | 614 |
| 633 shell::InterfaceProvider* ChildThreadImpl::GetInterfaceProviderForConnection() { | 615 shell::InterfaceProvider* ChildThreadImpl::GetInterfaceProviderForConnection() { |
| 634 return GetRemoteInterfaces(); | 616 return GetRemoteInterfaces(); |
| 635 } | 617 } |
| 636 | 618 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 void ChildThreadImpl::EnsureConnected() { | 766 void ChildThreadImpl::EnsureConnected() { |
| 785 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 767 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
| 786 base::Process::Current().Terminate(0, false); | 768 base::Process::Current().Terminate(0, false); |
| 787 } | 769 } |
| 788 | 770 |
| 789 bool ChildThreadImpl::IsInBrowserProcess() const { | 771 bool ChildThreadImpl::IsInBrowserProcess() const { |
| 790 return static_cast<bool>(browser_process_io_runner_); | 772 return static_cast<bool>(browser_process_io_runner_); |
| 791 } | 773 } |
| 792 | 774 |
| 793 } // namespace content | 775 } // namespace content |
| OLD | NEW |