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

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

Issue 304273004: Add name to services (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Get chrome to build 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
« no previous file with comments | « content/renderer/render_thread_impl.cc ('k') | mojo/public/cpp/application/connect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 to do any necessary initialization. There's no need to call 74 // Override this to do any necessary initialization. There's no need to call
75 // Application's implementation. 75 // Application's implementation.
76 // The service_provider will be bound to its pipe before this is called. 76 // The service_provider will be bound to its pipe before this is called.
77 virtual void Initialize(); 77 virtual void Initialize();
78 78
79 template <typename Impl, typename Context> 79 template <typename Impl, typename Context>
80 void AddService(Context* context) { 80 void AddService(Context* context) {
81 AddServiceConnector(new internal::ServiceConnector<Impl, Context>(context)); 81 AddServiceConnector(
82 new internal::ServiceConnector<Impl, Context>(Impl::Name_, context));
82 } 83 }
83 84
84 template <typename Impl> 85 template <typename Impl>
85 void AddService() { 86 void AddService() {
86 AddServiceConnector(new internal::ServiceConnector<Impl, void>(NULL)); 87 AddServiceConnector(
88 new internal::ServiceConnector<Impl, void>(Impl::Name_, NULL));
87 } 89 }
88 90
89 template <typename Interface> 91 template <typename Interface>
90 void ConnectTo(const std::string& url, 92 void ConnectTo(const std::string& url,
91 InterfacePtr<Interface>* ptr) { 93 InterfacePtr<Interface>* ptr) {
92 mojo::ConnectToService(service_provider(), url, ptr); 94 mojo::ConnectToService(service_provider(), url, ptr);
93 } 95 }
94 96
95 ServiceProvider* service_provider() { return service_provider_.get(); } 97 ServiceProvider* service_provider() { return service_provider_.get(); }
96 void BindServiceProvider(ScopedMessagePipeHandle service_provider_handle); 98 void BindServiceProvider(ScopedMessagePipeHandle service_provider_handle);
97 99
98 protected: 100 protected:
99 // ServiceProvider methods. 101 // ServiceProvider methods.
100 // Override this to dispatch to correct service when there's more than one. 102 // Override this to dispatch to correct service when there's more than one.
101 // TODO(davemoore): Augment this with name registration. 103 // TODO(davemoore): Augment this with name registration.
102 virtual void ConnectToService(const mojo::String& url, 104 virtual void ConnectToService(const mojo::String& url,
105 const mojo::String& name,
103 ScopedMessagePipeHandle client_handle) 106 ScopedMessagePipeHandle client_handle)
104 MOJO_OVERRIDE; 107 MOJO_OVERRIDE;
105 108
106 private: 109 private:
107 friend MojoResult (::MojoMain)(MojoHandle); 110 friend MojoResult (::MojoMain)(MojoHandle);
108 111
109 // Implement this method to create the specific subclass of Application. 112 // Implement this method to create the specific subclass of Application.
110 static Application* Create(); 113 static Application* Create();
111 114
112 // internal::ServiceConnectorBase::Owner methods. 115 // internal::ServiceConnectorBase::Owner methods.
113 // Takes ownership of |service_connector|. 116 // Takes ownership of |service_connector|.
114 virtual void AddServiceConnector( 117 virtual void AddServiceConnector(
115 internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE; 118 internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE;
116 virtual void RemoveServiceConnector( 119 virtual void RemoveServiceConnector(
117 internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE; 120 internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE;
118 121
119 typedef std::vector<internal::ServiceConnectorBase*> ServiceConnectorList; 122 typedef std::map<std::string, internal::ServiceConnectorBase*>
120 ServiceConnectorList service_connectors_; 123 NameToServiceConnectorMap;
124 NameToServiceConnectorMap name_to_service_connector_;
121 }; 125 };
122 126
123 } // namespace mojo 127 } // namespace mojo
124 128
125 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_H_ 129 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_H_
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.cc ('k') | mojo/public/cpp/application/connect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698