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

Unified Diff: content/browser/mojo/mojo_shell_context.cc

Issue 2138263002: Revert of Move content's shell connections to the IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 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(
« 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