Index: content/common/mojo/service_registry_impl.cc |
diff --git a/content/common/mojo/service_registry_impl.cc b/content/common/mojo/service_registry_impl.cc |
index a55864f92ea7066fe908327776bfdb5dd3dadc6a..5f0e4f4de3d5360a25afe71c982046aa826e5da1 100644 |
--- a/content/common/mojo/service_registry_impl.cc |
+++ b/content/common/mojo/service_registry_impl.cc |
@@ -39,9 +39,13 @@ void ServiceRegistryImpl::BindRemoteServiceProvider( |
} |
} |
-void ServiceRegistryImpl::AddService( |
- const std::string& service_name, |
- const base::Callback<void(mojo::ScopedMessagePipeHandle)> service_factory) { |
+void ServiceRegistryImpl::AddServiceOverride(const std::string& service_name, |
+ const ServiceFactory& factory) { |
+ service_overrides_[service_name] = factory; |
+} |
+ |
+void ServiceRegistryImpl::AddService(const std::string& service_name, |
+ const ServiceFactory service_factory) { |
service_factories_[service_name] = service_factory; |
} |
@@ -52,6 +56,12 @@ void ServiceRegistryImpl::RemoveService(const std::string& service_name) { |
void ServiceRegistryImpl::ConnectToRemoteService( |
const base::StringPiece& service_name, |
mojo::ScopedMessagePipeHandle handle) { |
+ auto override_it = service_overrides_.find(service_name.as_string()); |
+ if (override_it != service_overrides_.end()) { |
+ override_it->second.Run(std::move(handle)); |
+ return; |
+ } |
+ |
if (!remote_provider_) { |
pending_connects_.push( |
std::make_pair(service_name.as_string(), handle.release())); |
@@ -72,9 +82,7 @@ base::WeakPtr<ServiceRegistry> ServiceRegistryImpl::GetWeakPtr() { |
void ServiceRegistryImpl::ConnectToService( |
const mojo::String& name, |
mojo::ScopedMessagePipeHandle client_handle) { |
- std::map<std::string, |
- base::Callback<void(mojo::ScopedMessagePipeHandle)> >::iterator it = |
- service_factories_.find(name); |
+ auto it = service_factories_.find(name); |
if (it == service_factories_.end()) |
return; |