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

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

Issue 380413003: Mojo: Use InterfaceFactory<Interface> for service registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix network_service_loader Created 6 years, 5 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 | « mojo/mojo_services.gypi ('k') | mojo/public/cpp/application/interface_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/application/application_connection.h
diff --git a/mojo/public/cpp/application/application_connection.h b/mojo/public/cpp/application/application_connection.h
index 2044af10a5a86cd935438839d92dc5a939abb25e..c0e348042b635cc88662494913e2cfeffe30b606 100644
--- a/mojo/public/cpp/application/application_connection.h
+++ b/mojo/public/cpp/application/application_connection.h
@@ -21,51 +21,26 @@ namespace mojo {
// to implement a service named Foo.
// That class must subclass an InterfaceImpl specialization.
//
-// If there is context that is to be shared amongst all instances, define a
-// constructor with that class as its only argument, otherwise define an empty
-// constructor.
+// Then implement an InterfaceFactory<Foo> that binds instances of FooImpl to
+// InterfaceRequest<Foo>s and register that on the connection.
//
-// class FooImpl : public InterfaceImpl<Foo> {
-// public:
-// explicit FooImpl(ApplicationConnnection* connection) {}
-// };
+// connection->AddService(&factory);
//
-// or
+// Or if you have multiple factories implemented by the same type, explicitly
+// specify the interface to register the factory for:
//
-// class BarImpl : public InterfaceImpl<Bar> {
-// public:
-// // contexts will remain valid for the lifetime of BarImpl.
-// BarImpl(ApplicationConnnection* connection, BarContext* service_context)
-// : connection_(connection), servicecontext_(context) {}
+// connection->AddService<Foo>(&my_foo_and_bar_factory_);
+// connection->AddService<Bar>(&my_foo_and_bar_factory_);
//
-// Create an ApplicationDelegate instance and pass it to the constructor
-// of an ApplicationImpl. The delegate will be called when new connections are
-// made to other applications.
-//
-// connection->AddService<FooImpl>();
-//
-// BarContext context;
-// connection->AddService<BarImpl>(&context);
+// The InterfaceFactory must outlive the ApplicationConnection.
class ApplicationConnection {
public:
virtual ~ApplicationConnection();
- // Impl’s constructor will receive two arguments:
- // Impl::Impl(Application::Context* app_context,
- // ServiceContext* svc_context)
- template <typename Impl, typename ServiceContext>
- void AddService(ServiceContext* context) {
- AddServiceConnector(
- new internal::ServiceConnector<Impl, ServiceContext>(Impl::Name_,
- context));
- }
-
- // Impl’s constructor will receive one argument:
- // Impl::Impl(Application::Context* app_context)
- template <typename Impl>
- void AddService() {
+ template <typename Interface>
+ void AddService(InterfaceFactory<Interface>* factory) {
AddServiceConnector(
- new internal::ServiceConnector<Impl, void>(Impl::Name_, NULL));
+ new internal::InterfaceFactoryConnector<Interface>(factory));
}
// Connect to the service implementing |Interface|.
@@ -96,8 +71,8 @@ class ApplicationConnection {
// Raw ServiceProvider interface to remote application.
virtual ServiceProvider* GetServiceProvider() = 0;
-private:
- virtual void AddServiceConnector(
+ private:
+ virtual void AddServiceConnector(
internal::ServiceConnectorBase* service_connector) = 0;
};
« no previous file with comments | « mojo/mojo_services.gypi ('k') | mojo/public/cpp/application/interface_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698