Index: content/common/mojo/mojo_shell_connection_impl.cc |
diff --git a/content/common/mojo/mojo_shell_connection_impl.cc b/content/common/mojo/mojo_shell_connection_impl.cc |
index 1295ab60cc5d0889f9d4d35b0bdee2a10795d92d..47ff4f0c56f1e05bd9e469acb0ce39edc6703089 100644 |
--- a/content/common/mojo/mojo_shell_connection_impl.cc |
+++ b/content/common/mojo/mojo_shell_connection_impl.cc |
@@ -84,12 +84,26 @@ class MojoShellConnectionImpl::IOThreadContext |
DCHECK(posted); |
} |
- // Safe to call any time before Start() is called. |
+ // Safe to call any time before a message is received from a process. |
+ // i.e. can be called when starting the process but not afterwards. |
void AddConnectionFilter(std::unique_ptr<ConnectionFilter> filter) { |
- DCHECK(!started_); |
+ base::AutoLock lock(lock_); |
connection_filters_.emplace_back(std::move(filter)); |
} |
+ std::unique_ptr<ConnectionFilter> RemoveConnectionFilter( |
+ ConnectionFilter* filter) { |
+ for (auto it = connection_filters_.begin(); it != connection_filters_.end(); |
Ken Rockot(use gerrit already)
2016/07/29 23:20:47
This needs to hold lock_ too
|
+ ++it) { |
+ if (it->get() == filter) { |
+ std::unique_ptr<ConnectionFilter> taken = std::move(*it); |
+ connection_filters_.erase(it); |
+ return taken; |
+ } |
+ } |
+ return nullptr; |
+ } |
+ |
// Safe to call any time before Start() is called. |
void SetDefaultBinderForBrowserConnection( |
const shell::InterfaceRegistry::Binder& binder) { |
@@ -285,6 +299,8 @@ class MojoShellConnectionImpl::IOThreadContext |
mojo::BindingSet<shell::mojom::ServiceFactory> factory_bindings_; |
std::vector<std::unique_ptr<ConnectionFilter>> connection_filters_; |
+ base::Lock lock_; |
+ |
DISALLOW_COPY_AND_ASSIGN(IOThreadContext); |
}; |
@@ -388,10 +404,14 @@ void MojoShellConnectionImpl::SetupInterfaceRequestProxies( |
base::Bind(&MojoShellConnectionImpl::GetInterface, |
weak_factory_.GetWeakPtr(), registry)); |
+ if (!provider) |
+ return; |
+ |
// Forward all remote interface requests on |provider| to our IO-thread |
// context. This will ensure they're forwarded to the provider on the |
// incoming browser connection. |
- provider->Forward(base::Bind(&IOThreadContext::GetRemoteInterface, context_)); |
+ provider->Forward(base::Bind(&IOThreadContext::GetRemoteInterface, |
+ context_)); |
} |
void MojoShellConnectionImpl::AddConnectionFilter( |
@@ -399,6 +419,11 @@ void MojoShellConnectionImpl::AddConnectionFilter( |
context_->AddConnectionFilter(std::move(filter)); |
} |
+std::unique_ptr<ConnectionFilter> |
+MojoShellConnectionImpl::RemoveConnectionFilter(ConnectionFilter* filter) { |
+ return context_->RemoveConnectionFilter(filter); |
+} |
+ |
void MojoShellConnectionImpl::AddEmbeddedService( |
const std::string& name, |
const MojoApplicationInfo& info) { |