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

Unified Diff: content/child/child_thread_impl.cc

Issue 2111353002: Move content's shell connections to the IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/child/child_thread_impl.h ('k') | content/common/mojo/mojo_shell_connection_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/child_thread_impl.cc
diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc
index 3bac8ae72e2deaecb0b63934a166125cc760b8af..bfd7c6b82b014a5139dbbec13c5289650b44413f 100644
--- a/content/child/child_thread_impl.cc
+++ b/content/child/child_thread_impl.cc
@@ -68,6 +68,8 @@
#include "mojo/edk/embedder/named_platform_channel_pair.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/edk/embedder/scoped_ipc_support.h"
+#include "services/shell/public/cpp/interface_provider.h"
+#include "services/shell/public/cpp/interface_registry.h"
#include "services/shell/runner/common/client_util.h"
#if defined(OS_POSIX)
@@ -263,7 +265,8 @@ ChildThreadImpl::Options::Options()
: channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID)),
use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kMojoChannelToken)) {
+ switches::kMojoChannelToken)),
+ auto_start_mojo_shell_connection(true) {
}
ChildThreadImpl::Options::Options(const Options& other) = default;
@@ -291,6 +294,13 @@ ChildThreadImpl::Options::Builder::UseMojoChannel(bool use_mojo_channel) {
}
ChildThreadImpl::Options::Builder&
+ChildThreadImpl::Options::Builder::AutoStartMojoShellConnection(
+ bool auto_start) {
+ options_.auto_start_mojo_shell_connection = auto_start;
+ return *this;
+}
+
+ChildThreadImpl::Options::Builder&
ChildThreadImpl::Options::Builder::WithChannelName(
const std::string& channel_name) {
options_.channel_name = channel_name;
@@ -331,14 +341,18 @@ bool ChildThreadImpl::ChildThreadMessageRouter::RouteMessage(
ChildThreadImpl::ChildThreadImpl()
: router_(this),
- channel_connected_factory_(this) {
+ channel_connected_factory_(
+ new base::WeakPtrFactory<ChildThreadImpl>(this)),
+ weak_factory_(this) {
Init(Options::Builder().Build());
}
ChildThreadImpl::ChildThreadImpl(const Options& options)
: router_(this),
browser_process_io_runner_(options.browser_process_io_runner),
- channel_connected_factory_(this) {
+ channel_connected_factory_(
+ new base::WeakPtrFactory<ChildThreadImpl>(this)),
+ weak_factory_(this) {
Init(options);
}
@@ -413,8 +427,18 @@ void ChildThreadImpl::Init(const Options& options) {
mojo::edk::CreateChildMessagePipe(mojo_application_token);
DCHECK(handle.is_valid());
mojo_shell_connection_ = MojoShellConnection::Create(
- mojo::MakeRequest<shell::mojom::Service>(std::move(handle)));
- mojo_shell_connection_->MergeService(this);
+ mojo::MakeRequest<shell::mojom::Service>(std::move(handle)),
+ GetIOTaskRunner());
+
+ // TODO(rockot): Remove this once all child-to-browser interface connections
+ // are made via a Connector rather than directly through an
+ // InterfaceProvider, and all exposed interfaces are exposed via a
+ // ConnectionFilter.
+ mojo_shell_connection_->SetupInterfaceRequestProxies(
+ GetInterfaceRegistry(), GetRemoteInterfaces());
+
+ if (options.auto_start_mojo_shell_connection)
+ StartMojoShellConnection();
}
sync_message_filter_ = channel_->CreateSyncMessageFilter();
@@ -499,7 +523,7 @@ void ChildThreadImpl::Init(const Options& options) {
message_loop_->task_runner()->PostDelayedTask(
FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected,
- channel_connected_factory_.GetWeakPtr()),
+ channel_connected_factory_->GetWeakPtr()),
base::TimeDelta::FromSeconds(connection_timeout));
#if defined(OS_ANDROID)
@@ -517,9 +541,6 @@ void ChildThreadImpl::Init(const Options& options) {
}
ChildThreadImpl::~ChildThreadImpl() {
- if (MojoShellConnection::GetForProcess())
- MojoShellConnection::DestroyForProcess();
-
#ifdef IPC_MESSAGE_LOG_ENABLED
IPC::Logging::GetInstance()->SetIPCSender(NULL);
#endif
@@ -556,7 +577,7 @@ void ChildThreadImpl::ShutdownDiscardableSharedMemoryManager() {
}
void ChildThreadImpl::OnChannelConnected(int32_t peer_pid) {
- channel_connected_factory_.InvalidateWeakPtrs();
+ channel_connected_factory_.reset();
}
void ChildThreadImpl::OnChannelError() {
@@ -608,14 +629,6 @@ shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() {
return remote_interfaces_.get();
}
-shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistryForConnection() {
- return GetInterfaceRegistry();
-}
-
-shell::InterfaceProvider* ChildThreadImpl::GetInterfaceProviderForConnection() {
- return GetRemoteInterfaces();
-}
-
IPC::MessageRouter* ChildThreadImpl::GetRouter() {
DCHECK(message_loop_->task_runner()->BelongsToCurrentThread());
return &router_;
@@ -691,6 +704,11 @@ bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) {
return router_.OnMessageReceived(msg);
}
+void ChildThreadImpl::StartMojoShellConnection() {
+ DCHECK(mojo_shell_connection_);
+ mojo_shell_connection_->Start();
+}
+
bool ChildThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
return false;
}
« no previous file with comments | « content/child/child_thread_impl.h ('k') | content/common/mojo/mojo_shell_connection_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698