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 e454437fb8314781a70e470c1cd1df3a386616dd..102d34fea8d0dc8286fe7a1776e3eb70f4462372 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, |
@@ -271,14 +261,14 @@ MojoShellContext::MojoShellContext() { |
catalog_->TakeShellClient())); |
request = shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName); |
} |
- MojoShellConnection::SetForProcess( |
- MojoShellConnection::Create(std::move(request))); |
+ MojoShellConnection::SetForProcess(MojoShellConnection::Create( |
+ std::move(request), |
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
- std::unique_ptr<shell::Connector> io_connector = |
+ // 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(); |
- BrowserThread::PostTask( |
- BrowserThread::IO, FROM_HERE, |
- base::Bind(&SetConnectorOnIOThread, base::Passed(&io_connector))); |
ContentBrowserClient::StaticMojoApplicationMap apps; |
GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); |
@@ -339,7 +329,8 @@ void MojoShellContext::ConnectToApplication( |
// static |
shell::Connector* MojoShellContext::GetConnectorForIOThread() { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- return io_connector_tls_ptr.Pointer()->Get(); |
+ DCHECK(g_io_thread_connector.Get()); |
+ return g_io_thread_connector.Get().get(); |
} |
void MojoShellContext::ConnectToApplicationOnOwnThread( |