From ffdb373a3e3fd523e78890fa8ab4ac1e8b49090f Mon Sep 17 00:00:00 2001 From: "jamesr@chromium.org" Date: Thu, 24 Jul 2014 03:26:37 +0000 Subject: Mojo: Use InterfaceFactory for service registration This adds an InterfaceFactory type and allows registering a service through its provider. Using an InterfaceFactory allows the app to be in control of the lifetime of the implementation of the interface and hides all of the implementation details of the interface from the application library code (i.e. no subclassing impl classes or anything like that). The default binding behavior is to bind the lifetime of the impl to the lifetime of the pipe, but the application can also weakly bind to a service in cases where it needs to manage the lifetime explicitly. Review URL: https://codereview.chromium.org/380413003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285139 0039d316-1c4b-4281-b951-d872f2087c98 --- mojo/dbus/dbus_external_service.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'mojo/dbus') diff --git a/mojo/dbus/dbus_external_service.h b/mojo/dbus/dbus_external_service.h index 77e9e4b..ea4c602 100644 --- a/mojo/dbus/dbus_external_service.h +++ b/mojo/dbus/dbus_external_service.h @@ -11,6 +11,8 @@ #include "mojo/public/cpp/application/application_connection.h" #include "mojo/public/cpp/application/application_delegate.h" #include "mojo/public/cpp/application/application_impl.h" +#include "mojo/public/cpp/application/interface_factory.h" +#include "mojo/public/cpp/bindings/interface_request.h" #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" #include "mojo/shell/external_service.mojom.h" @@ -50,8 +52,10 @@ class DBusExternalServiceBase { }; template -class DBusExternalService : public DBusExternalServiceBase, - public ApplicationDelegate { +class DBusExternalService + : public DBusExternalServiceBase, + public ApplicationDelegate, + public InterfaceFactory { public: explicit DBusExternalService(const std::string& service_name) : DBusExternalServiceBase(service_name) { @@ -60,10 +64,17 @@ class DBusExternalService : public DBusExternalServiceBase, virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) MOJO_OVERRIDE { - connection->AddService(); + connection->AddService(this); return true; } + virtual void Create( + ApplicationConnection* connection, + InterfaceRequest request) + MOJO_OVERRIDE { + BindToRequest(new ServiceImpl, &request); + } + protected: virtual void Connect(ScopedMessagePipeHandle client_handle) OVERRIDE { external_service_.reset(BindToPipe(new Impl(this), client_handle.Pass())); -- cgit v1.1