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

Unified Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 2245333005: Fix data races in MojoShellConnectionImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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
« no previous file with comments | « no previous file | content/common/mojo/mojo_shell_connection_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/render_process_host_impl.cc
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index 2beb2b18d3872cac26c28fbfd1f01179010aa1ac..8a5aa3eababbb4df374285a0f5c279930ae5742b 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -472,9 +472,17 @@ class RenderProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter {
std::unique_ptr<shell::InterfaceRegistry> registry)
: child_identity_(child_identity),
registry_(std::move(registry)),
- weak_factory_(this) {}
+ weak_factory_(this) {
+ // Registration of this filter may race with browser shutdown, in which case
+ // it's possible for this filter to be destroyed on the main thread. This
+ // is fine as long as the filter hasn't been used on the IO thread yet. We
+ // detach the ThreadChecker initially and the first use of the filter will
+ // bind it.
+ thread_checker_.DetachFromThread();
+ }
+
~ConnectionFilterImpl() override {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(thread_checker_.CalledOnValidThread());
}
private:
@@ -482,6 +490,8 @@ class RenderProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter {
bool OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry,
shell::Connector* connector) override {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
// We only fulfill connections from the renderer we host.
if (child_identity_.name() != remote_identity.name() ||
child_identity_.instance() != remote_identity.instance()) {
@@ -503,10 +513,13 @@ class RenderProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter {
void GetInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle handle) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
shell::mojom::InterfaceProvider* provider = registry_.get();
provider->GetInterface(interface_name, std::move(handle));
}
+ base::ThreadChecker thread_checker_;
shell::Identity child_identity_;
std::unique_ptr<shell::InterfaceRegistry> registry_;
base::WeakPtrFactory<ConnectionFilterImpl> weak_factory_;
« no previous file with comments | « no previous file | content/common/mojo/mojo_shell_connection_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698