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

Unified Diff: content/common/mojo/service_registry_impl.cc

Issue 1470153002: [mojo] Enable ServiceRegistryImpl to override remote services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usb-testing-3
Patch Set: Created 4 years, 11 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 | « content/common/mojo/service_registry_impl.h ('k') | content/renderer/mojo/service_registry_js_wrapper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d75f64d5d4163599215cbff86387dff5ce2f4c47 100644
--- a/content/common/mojo/service_registry_impl.cc
+++ b/content/common/mojo/service_registry_impl.cc
@@ -39,9 +39,14 @@ void ServiceRegistryImpl::BindRemoteServiceProvider(
}
}
-void ServiceRegistryImpl::AddService(
+void ServiceRegistryImpl::AddServiceOverrideForTesting(
const std::string& service_name,
- const base::Callback<void(mojo::ScopedMessagePipeHandle)> service_factory) {
+ 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 +57,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 +83,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;
« no previous file with comments | « content/common/mojo/service_registry_impl.h ('k') | content/renderer/mojo/service_registry_js_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698