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

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

Issue 275363002: Internalize ServiceConnector<> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 6 years, 7 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
Index: mojo/public/cpp/shell/application.h
diff --git a/mojo/public/cpp/shell/application.h b/mojo/public/cpp/shell/application.h
index 933077bfdc9e4a01751e587530afc1d4a0cbfc33..e9788caeb02b073169d112f2feb915c0e5aa270d 100644
--- a/mojo/public/cpp/shell/application.h
+++ b/mojo/public/cpp/shell/application.h
@@ -7,24 +7,56 @@
#include <vector>
-#include "mojo/public/cpp/shell/service.h"
+#include "mojo/public/cpp/shell/connect.h"
+#include "mojo/public/cpp/shell/lib/service_connector.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
namespace mojo {
+// Utility class for creating ShellClients that vend service instances.
+// To use define a class that implements your specific server api, e.g. FooImpl
+// 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 defined an empty
darin (slow to review) 2014/05/12 22:04:52 nit: otherwise defined -> otherwise define
DaveMoore 2014/05/14 16:50:31 Done.
+// constructor.
+//
+// class FooImpl : public InterfaceImpl<Foo> {
+// public:
+// FooImpl() {}
+// };
+//
+// or
+//
+// class BarImpl : public InterfaceImpl<Bar> {
+// public:
+// BarImpl(BarContext* context) : context_(context) {}
+// private:
+// BarContext* context;
+// };
darin (slow to review) 2014/05/12 22:04:52 You might want to indicate that the BarContext poi
DaveMoore 2014/05/14 16:50:31 Done.
+//
+// Create an Application instance that collects any service implementations.
+//
+// Application app(shell_handle);
+// app.AddService<FooImpl>();
+//
+// BarContext context;
+// app.AddService<BarImpl>(&context);
+// app.AddService<FooImpl>();
+//
+//
class Application : public internal::ServiceConnectorBase::Owner {
public:
explicit Application(ScopedMessagePipeHandle shell_handle);
explicit Application(MojoHandle shell_handle);
virtual ~Application();
- // internal::ServiceConnectorBase::Owner methods.
- // Takes ownership of |service_connector|.
- virtual void AddServiceConnector(
- internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE;
- virtual void RemoveServiceConnector(
- internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE;
+ template <typename Impl, typename Context=void>
+ void AddService(Context* context = NULL) {
+ AddServiceConnector(new internal::ServiceConnector<Impl, Context>(context));
+ }
template <typename Interface>
void ConnectTo(const std::string& url, InterfacePtr<Interface>* ptr) {
@@ -33,11 +65,20 @@ class Application : public internal::ServiceConnectorBase::Owner {
protected:
// ShellClient methods.
+ // Override this to dispatch to correct service when there's more than one.
+ // TODO(davemoore): Augment this with name registration.
virtual void AcceptConnection(const mojo::String& url,
ScopedMessagePipeHandle client_handle)
MOJO_OVERRIDE;
private:
+ // internal::ServiceConnectorBase::Owner methods.
+ // Takes ownership of |service_connector|.
+ virtual void AddServiceConnector(
+ internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE;
+ virtual void RemoveServiceConnector(
+ internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE;
+
typedef std::vector<internal::ServiceConnectorBase*> ServiceConnectorList;
ServiceConnectorList service_connectors_;
};

Powered by Google App Engine
This is Rietveld 408576698