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

Side by Side Diff: mojo/public/cpp/application/application.h

Issue 337533002: Introduce internal::ServiceRegistry to prepare for ServiceProvider split. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review concerns Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_H_ 5 #ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_H_
6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_H_ 6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_H_
7 #include <vector> 7 #include <vector>
8 8
9 #include "mojo/public/cpp/application/connect.h" 9 #include "mojo/public/cpp/application/connect.h"
10 #include "mojo/public/cpp/application/lib/service_connector.h" 10 #include "mojo/public/cpp/application/lib/service_connector.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // 57 //
58 // Create an Application instance that collects any service implementations. 58 // Create an Application instance that collects any service implementations.
59 // 59 //
60 // Application app(service_provider_handle); 60 // Application app(service_provider_handle);
61 // app.AddService<FooImpl>(); 61 // app.AddService<FooImpl>();
62 // 62 //
63 // BarContext context; 63 // BarContext context;
64 // app.AddService<BarImpl>(&context); 64 // app.AddService<BarImpl>(&context);
65 // 65 //
66 // 66 //
67 class Application : public internal::ServiceConnectorBase::Owner { 67 class Application {
68 public: 68 public:
69 Application(); 69 Application();
70 explicit Application(ScopedMessagePipeHandle service_provider_handle); 70 explicit Application(ScopedMessagePipeHandle service_provider_handle);
71 explicit Application(MojoHandle service_provider_handle); 71 explicit Application(MojoHandle service_provider_handle);
72 virtual ~Application(); 72 virtual ~Application();
73 73
74 // Override this method to control what urls are allowed to connect to a
75 // service.
76 virtual bool AllowIncomingConnection(const mojo::String& service_name,
77 const mojo::String& requestor_url);
78
79 template <typename Impl, typename Context>
80 void AddService(Context* context) {
81 service_registry_.AddServiceConnector(
82 new internal::ServiceConnector<Impl, Context>(Impl::Name_, context));
83 }
84
85 template <typename Impl>
86 void AddService() {
87 service_registry_.AddServiceConnector(
88 new internal::ServiceConnector<Impl, void>(Impl::Name_, NULL));
89 }
90
91 template <typename Interface>
92 void ConnectTo(const std::string& url, InterfacePtr<Interface>* ptr) {
93 mojo::ConnectToService(service_provider(), url, ptr);
94 }
95
96 ServiceProvider* service_provider() {
97 return service_registry_.remote_service_provider();
98 }
99
100 void BindServiceProvider(ScopedMessagePipeHandle service_provider_handle);
101
102 protected:
74 // Override this to do any necessary initialization. There's no need to call 103 // Override this to do any necessary initialization. There's no need to call
75 // Application's implementation. 104 // Application's implementation.
76 // The service_provider will be bound to its pipe before this is called. 105 // The service_provider will be bound to its pipe before this is called.
77 virtual void Initialize(); 106 virtual void Initialize();
78 107
79 template <typename Impl, typename Context>
80 void AddService(Context* context) {
81 AddServiceConnector(
82 new internal::ServiceConnector<Impl, Context>(Impl::Name_, context));
83 }
84
85 template <typename Impl>
86 void AddService() {
87 AddServiceConnector(
88 new internal::ServiceConnector<Impl, void>(Impl::Name_, NULL));
89 }
90
91 template <typename Interface>
92 void ConnectTo(const std::string& url,
93 InterfacePtr<Interface>* ptr) {
94 mojo::ConnectToService(service_provider(), url, ptr);
95 }
96
97 ServiceProvider* service_provider() { return service_provider_.get(); }
98 void BindServiceProvider(ScopedMessagePipeHandle service_provider_handle);
99
100 protected:
101 // ServiceProvider methods.
102 // Override this to dispatch to correct service when there's more than one.
103 virtual void ConnectToService(const mojo::String& service_url,
104 const mojo::String& service_name,
105 ScopedMessagePipeHandle client_handle,
106 const mojo::String& requestor_url)
107 MOJO_OVERRIDE;
108
109 private: 108 private:
110 friend MojoResult (::MojoMain)(MojoHandle); 109 friend MojoResult (::MojoMain)(MojoHandle);
111 110
112 // Implement this method to create the specific subclass of Application. 111 // Implement this method to create the specific subclass of Application.
113 static Application* Create(); 112 static Application* Create();
114 113
115 // internal::ServiceConnectorBase::Owner methods. 114 internal::ServiceRegistry service_registry_;
116 // Takes ownership of |service_connector|.
117 virtual void AddServiceConnector(
118 internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE;
119 virtual void RemoveServiceConnector(
120 internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE;
121 115
122 typedef std::map<std::string, internal::ServiceConnectorBase*> 116 MOJO_DISALLOW_COPY_AND_ASSIGN(Application);
123 NameToServiceConnectorMap;
124 NameToServiceConnectorMap name_to_service_connector_;
125 }; 117 };
126 118
127 } // namespace mojo 119 } // namespace mojo
128 120
129 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_H_ 121 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698