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

Unified Diff: mojo/public/cpp/application/service_provider_impl.h

Issue 1976063002: More work on ServiceProviderImpl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: sigh Created 4 years, 7 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 | « apps/moterm/moterm_view.cc ('k') | mojo/public/cpp/application/tests/service_provider_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/application/service_provider_impl.h
diff --git a/mojo/public/cpp/application/service_provider_impl.h b/mojo/public/cpp/application/service_provider_impl.h
index dd244723ef246e3f50d9ecc7ba0b69d42a36daad..54adac77bf41cfbb9bb78102f517a1eb0cbefaa9 100644
--- a/mojo/public/cpp/application/service_provider_impl.h
+++ b/mojo/public/cpp/application/service_provider_impl.h
@@ -7,10 +7,9 @@
#include <functional>
#include <string>
+#include <utility>
-#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/connection_context.h"
-#include "mojo/public/cpp/application/lib/interface_factory_connector.h"
#include "mojo/public/cpp/application/lib/service_connector_registry.h"
#include "mojo/public/cpp/application/service_connector.h"
#include "mojo/public/cpp/bindings/binding.h"
@@ -53,14 +52,12 @@ class ServiceProviderImpl : public ServiceProvider {
// unbound state). This may be called even if this object is already unbound.
void Close();
- // TODO(vtl): Remove this.
- template <typename Interface>
- void AddService(InterfaceFactory<Interface>* factory,
- const std::string& interface_name = Interface::Name_) {
+ // Adds a supported service with the given |name|, using the given
+ // |service_connector|.
+ void AddServiceForName(std::unique_ptr<ServiceConnector> service_connector,
+ const std::string& interface_name) {
service_connector_registry_.SetServiceConnectorForName(
- std::unique_ptr<ServiceConnector>(
- new internal::InterfaceFactoryConnector<Interface>(factory)),
- interface_name);
+ std::move(service_connector), interface_name);
}
// Adds a supported service with the given |name|, using the given
@@ -70,23 +67,34 @@ class ServiceProviderImpl : public ServiceProvider {
//
// A typical usage may be:
//
- // service_provider_impl_->AddServiceNew<Foobar>(
+ // service_provider_impl_->AddService<Foobar>(
// [](const ConnectionContext& connection_context,
// InterfaceRequest<FooBar> foobar_request) {
// // |FoobarImpl| owns itself.
// new FoobarImpl(std::move(foobar_request));
// });
- // TODO(vtl): Remove the AddService() above and rename this to AddService().
template <typename Interface>
- void AddServiceNew(
- InterfaceRequestHandler<Interface> interface_request_handler,
- const std::string& name = Interface::Name_) {
- service_connector_registry_.SetServiceConnectorForName(
+ void AddService(InterfaceRequestHandler<Interface> interface_request_handler,
+ const std::string& name = Interface::Name_) {
+ AddServiceForName(
std::unique_ptr<ServiceConnector>(new ServiceConnectorImpl<Interface>(
std::move(interface_request_handler))),
name);
}
+ // Removes support for the service with the given |name|.
+ void RemoveServiceForName(const std::string& name) {
+ service_connector_registry_.RemoveServiceConnectorForName(name);
+ }
+
+ // Like |RemoveServiceForName()| (above), but designed so that it can be used
+ // like |RemoveService<Interface>()| or even |RemoveService<Interface>(name)|
+ // (to parallel |AddService<Interface>()|).
+ template <typename Interface>
+ void RemoveService(const std::string& name = Interface::Name_) {
+ RemoveServiceForName(name);
+ }
+
// This uses the provided |fallback_service_provider| for connection requests
// for services that are not known (haven't been added). (Set it to null to
// not have any fallback.) A fallback must outlive this object (or until it is
@@ -96,6 +104,12 @@ class ServiceProviderImpl : public ServiceProvider {
fallback_service_provider_ = fallback_service_provider;
}
+ // Gets the context for the connection that this object is bound to (if not
+ // bound, the context is just a default-initialized |ConnectionContext|).
+ const ConnectionContext& connection_context() const {
+ return connection_context_;
+ }
+
private:
// Objects of this class are used to adapt a generic (untyped) connection
// request (i.e., |ServiceConnector::ConnectToService()|) to the type-safe
« no previous file with comments | « apps/moterm/moterm_view.cc ('k') | mojo/public/cpp/application/tests/service_provider_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698