| 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 37b9e7011651132e7af28ddc1e70f69754d23e21..24e21ca8471d9e497dd5214a45a028d521becb2f 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,
|
| @@ -262,9 +272,14 @@
|
| request =
|
| service_manager_->StartEmbedderService(kBrowserMojoApplicationName);
|
| }
|
| - MojoShellConnection::SetForProcess(MojoShellConnection::Create(
|
| - std::move(request),
|
| - BrowserThread::GetTaskRunnerForThread(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);
|
| @@ -272,13 +287,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()
|
| @@ -332,7 +340,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(
|
|
|