diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-24 03:26:37 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-24 03:26:37 +0000 |
commit | ffdb373a3e3fd523e78890fa8ab4ac1e8b49090f (patch) | |
tree | eca69245cafdb225f7ee2cf62ce88c7308b1d022 /mojo/dbus | |
parent | 633c60c341bb4c430c60b54492b74d1bdcff22f4 (diff) | |
download | chromium_src-ffdb373a3e3fd523e78890fa8ab4ac1e8b49090f.zip chromium_src-ffdb373a3e3fd523e78890fa8ab4ac1e8b49090f.tar.gz chromium_src-ffdb373a3e3fd523e78890fa8ab4ac1e8b49090f.tar.bz2 |
Mojo: Use InterfaceFactory<Interface> for service registration
This adds an InterfaceFactory<Interface> 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
Diffstat (limited to 'mojo/dbus')
-rw-r--r-- | mojo/dbus/dbus_external_service.h | 17 |
1 files changed, 14 insertions, 3 deletions
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 ServiceImpl> -class DBusExternalService : public DBusExternalServiceBase, - public ApplicationDelegate { +class DBusExternalService + : public DBusExternalServiceBase, + public ApplicationDelegate, + public InterfaceFactory<typename ServiceImpl::ImplementedInterface> { 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<ServiceImpl>(); + connection->AddService(this); return true; } + virtual void Create( + ApplicationConnection* connection, + InterfaceRequest<typename ServiceImpl::ImplementedInterface> 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())); |