Chromium Code Reviews| Index: mojo/public/cpp/application/lib/service_connector.h |
| diff --git a/mojo/public/cpp/application/lib/service_connector.h b/mojo/public/cpp/application/lib/service_connector.h |
| index d2de48b9b357b26518e51b15ca7626ed828273ea..32cb70369f2d634a163ca1a7fec1a968bde66a98 100644 |
| --- a/mojo/public/cpp/application/lib/service_connector.h |
| +++ b/mojo/public/cpp/application/lib/service_connector.h |
| @@ -9,6 +9,7 @@ |
| #include <vector> |
| +#include "mojo/public/cpp/application/interface_factory.h" |
| #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| namespace mojo { |
| @@ -16,59 +17,6 @@ class ApplicationConnection; |
| namespace internal { |
| -template <class ServiceImpl, typename Context> |
| -class ServiceConnector; |
| - |
| -// Specialization of ServiceConnection. |
| -// ServiceImpl: Subclass of InterfaceImpl<...>. |
| -// Context: Type of shared context. |
| -template <class ServiceImpl, typename Context> |
| -class ServiceConnection : public ServiceImpl { |
| - public: |
| - explicit ServiceConnection(ApplicationConnection* connection) |
| - : ServiceImpl(connection) {} |
| - ServiceConnection(ApplicationConnection* connection, |
| - Context* context) : ServiceImpl(connection, context) {} |
| - |
| - virtual void OnConnectionError() MOJO_OVERRIDE { |
| - service_connector_->RemoveConnection(static_cast<ServiceImpl*>(this)); |
| - ServiceImpl::OnConnectionError(); |
| - } |
| - |
| -private: |
| - friend class ServiceConnector<ServiceImpl, Context>; |
| - |
| - // Called shortly after this class is instantiated. |
| - void set_service_connector( |
| - ServiceConnector<ServiceImpl, Context>* connector) { |
| - service_connector_ = connector; |
| - } |
| - |
| - ServiceConnector<ServiceImpl, Context>* service_connector_; |
| - |
| - MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnection); |
| -}; |
| - |
| -template <typename ServiceImpl, typename Context> |
| -struct ServiceConstructor { |
| - static ServiceConnection<ServiceImpl, Context>* New( |
| - ApplicationConnection* connection, |
| - Context* context) { |
| - return new ServiceConnection<ServiceImpl, Context>( |
| - connection, context); |
| - } |
| -}; |
| - |
| -template <typename ServiceImpl> |
| -struct ServiceConstructor<ServiceImpl, void> { |
| - public: |
| - static ServiceConnection<ServiceImpl, void>* New( |
| - ApplicationConnection* connection, |
| - void* context) { |
| - return new ServiceConnection<ServiceImpl, void>(connection); |
| - } |
| -}; |
| - |
| class ServiceConnectorBase { |
| public: |
| ServiceConnectorBase(const std::string& name); |
| @@ -86,53 +34,23 @@ class ServiceConnectorBase { |
| MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnectorBase); |
| }; |
| -template <class ServiceImpl, typename Context=void> |
| -class ServiceConnector : public internal::ServiceConnectorBase { |
| +template <typename Interface> |
| +class InterfaceFactoryConnector : public ServiceConnectorBase { |
| public: |
| - ServiceConnector(const std::string& name, Context* context = NULL) |
| - : ServiceConnectorBase(name), context_(context) {} |
| - |
| - virtual ~ServiceConnector() { |
| - ConnectionList doomed; |
| - doomed.swap(connections_); |
| - for (typename ConnectionList::iterator it = doomed.begin(); |
| - it != doomed.end(); ++it) { |
| - delete *it; |
| - } |
| - assert(connections_.empty()); // No one should have added more! |
| - } |
| + InterfaceFactoryConnector(InterfaceFactory<Interface>* provider) |
| + : ServiceConnectorBase(Interface::Name_), factory_(provider) {} |
| + virtual ~InterfaceFactoryConnector() {} |
| virtual void ConnectToService(const std::string& name, |
| - ScopedMessagePipeHandle handle) MOJO_OVERRIDE { |
| - ServiceConnection<ServiceImpl, Context>* impl = |
| - ServiceConstructor<ServiceImpl, Context>::New(application_connection_, |
| - context_); |
| - impl->set_service_connector(this); |
| - BindToPipe(impl, handle.Pass()); |
| - |
| - connections_.push_back(impl); |
| - } |
| - |
| - void RemoveConnection(ServiceImpl* impl) { |
| - // Called from ~ServiceImpl, in response to a connection error. |
| - for (typename ConnectionList::iterator it = connections_.begin(); |
| - it != connections_.end(); ++it) { |
| - if (*it == impl) { |
| - delete impl; |
| - connections_.erase(it); |
| - return; |
| - } |
| - } |
| + ScopedMessagePipeHandle client_handle) { |
| + InterfaceRequest<Interface> request; |
| + request.Bind(client_handle.Pass()); |
| + factory_->Create(application_connection_, request.Pass()); |
|
darin (slow to review)
2014/07/15 06:10:38
note: you can also use MakeRequest<Interface>(clie
|
| } |
| - Context* context() const { return context_; } |
| - |
| private: |
| - typedef std::vector<ServiceImpl*> ConnectionList; |
| - ConnectionList connections_; |
| - Context* context_; |
| - |
| - MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnector); |
| + InterfaceFactory<Interface>* factory_; |
| + MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceFactoryConnector); |
| }; |
| } // namespace internal |