| 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 cc0156117277031255772d84e7809b2c5d241491..7f4177fd456f1c56c8806746220f4cf0a87d07bb 100644
|
| --- a/content/browser/mojo/mojo_shell_context.cc
|
| +++ b/content/browser/mojo/mojo_shell_context.cc
|
| @@ -49,10 +49,20 @@
|
|
|
| namespace {
|
|
|
| -base::LazyInstance<std::unique_ptr<shell::Connector>>::Leaky
|
| - g_io_thread_connector = LAZY_INSTANCE_INITIALIZER;
|
| -
|
| -void DestroyConnectorOnIOThread() { g_io_thread_connector.Get().reset(); }
|
| +using ConnectorPtr = base::ThreadLocalPointer<shell::Connector>;
|
| +
|
| +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 StartUtilityProcessOnIOThread(
|
| mojo::InterfaceRequest<mojom::ProcessControl> request,
|
| @@ -263,9 +273,14 @@
|
| request = service_manager_->StartEmbedderService(
|
| kBrowserMojoApplicationName);
|
| }
|
| - MojoShellConnection::SetForProcess(MojoShellConnection::Create(
|
| - std::move(request),
|
| - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
|
| + 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)));
|
|
|
| ContentBrowserClient::StaticMojoApplicationMap apps;
|
| GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps);
|
| @@ -273,13 +288,6 @@
|
| MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first,
|
| 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()
|
| @@ -333,7 +341,7 @@
|
| // static
|
| shell::Connector* MojoShellContext::GetConnectorForIOThread() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - return g_io_thread_connector.Get().get();
|
| + return io_connector_tls_ptr.Pointer()->Get();
|
| }
|
|
|
| void MojoShellContext::ConnectToApplicationOnOwnThread(
|
|
|