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

Unified Diff: mojo/public/cpp/application/lib/service_connector.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/public/cpp/application/lib/mojo_main_standalone.cc ('k') | mojo/public/cpp/bindings/interface_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..aeb7de1728ddbcb88ae9b6e123d719093a43cd07 100644
--- a/mojo/public/cpp/application/lib/service_connector.h
+++ b/mojo/public/cpp/application/lib/service_connector.h
@@ -5,10 +5,8 @@
#ifndef MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_
#define MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_
-#include <assert.h>
-
-#include <vector>
-
+#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"
namespace mojo {
@@ -16,59 +14,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 +31,22 @@ 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!
- }
+ explicit InterfaceFactoryConnector(InterfaceFactory<Interface>* factory)
+ : ServiceConnectorBase(Interface::Name_), factory_(factory) {}
+ 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) {
+ factory_->Create(application_connection_,
+ MakeRequest<Interface>(client_handle.Pass()));
}
- 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
« no previous file with comments | « mojo/public/cpp/application/lib/mojo_main_standalone.cc ('k') | mojo/public/cpp/bindings/interface_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698