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

Unified Diff: content/browser/mojo/mojo_shell_context.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
Index: content/browser/mojo/mojo_shell_context.cc
diff --git a/content/browser/mojo/mojo_shell_context.cc b/content/browser/mojo/mojo_shell_context.cc
index 24e21ca8471d9e497dd5214a45a028d521becb2f..37b9e7011651132e7af28ddc1e70f69754d23e21 100644
--- a/content/browser/mojo/mojo_shell_context.cc
+++ b/content/browser/mojo/mojo_shell_context.cc
@@ -49,20 +49,10 @@ namespace content {
namespace {
-using ConnectorPtr = base::ThreadLocalPointer<shell::Connector>;
+base::LazyInstance<std::unique_ptr<shell::Connector>>::Leaky
+ g_io_thread_connector = LAZY_INSTANCE_INITIALIZER;
-base::LazyInstance<ConnectorPtr>::Leaky io_connector_tls_ptr =
- LAZY_INSTANCE_INITIALIZER;
-
-void SetConnectorOnIOThread(std::unique_ptr<shell::Connector> connector) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- io_connector_tls_ptr.Pointer()->Set(connector.release());
-}
-
-void DestroyConnectorOnIOThread() {
- delete MojoShellContext::GetConnectorForIOThread();
- io_connector_tls_ptr.Pointer()->Set(nullptr);
-}
+void DestroyConnectorOnIOThread() { g_io_thread_connector.Get().reset(); }
void StartUtilityProcessOnIOThread(
mojo::InterfaceRequest<mojom::ProcessControl> request,
@@ -272,14 +262,9 @@ MojoShellContext::MojoShellContext() {
request =
service_manager_->StartEmbedderService(kBrowserMojoApplicationName);
}
- MojoShellConnection::SetForProcess(
- MojoShellConnection::Create(std::move(request)));
-
- std::unique_ptr<shell::Connector> io_connector =
- MojoShellConnection::GetForProcess()->GetConnector()->Clone();
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&SetConnectorOnIOThread, base::Passed(&io_connector)));
+ MojoShellConnection::SetForProcess(MojoShellConnection::Create(
+ std::move(request),
+ BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)));
ContentBrowserClient::StaticMojoApplicationMap apps;
GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps);
@@ -288,6 +273,13 @@ MojoShellContext::MojoShellContext() {
entry.second);
}
+ // This is safe to assign directly from any thread, because MojoShellContext
+ // must be constructed before anyone can call GetConnectorForIOThread().
+ g_io_thread_connector.Get() =
+ MojoShellConnection::GetForProcess()->GetConnector()->Clone();
+
+ MojoShellConnection::GetForProcess()->Start();
+
ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps;
GetContentClient()
->browser()
@@ -340,7 +332,7 @@ void MojoShellContext::ConnectToApplication(
// static
shell::Connector* MojoShellContext::GetConnectorForIOThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- return io_connector_tls_ptr.Pointer()->Get();
+ return g_io_thread_connector.Get().get();
}
void MojoShellContext::ConnectToApplicationOnOwnThread(
« no previous file with comments | « content/browser/mojo/mojo_child_connection.cc ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698