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

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

Issue 1975993002: Change InterfaceFactory<I>::Create() to take a ConnectionContext instead of an ApplicationConnectio… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 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 unified diff | Download patch
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_SERVICE_PROVIDER_IMPL_H_ 5 #ifndef MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_
6 #define MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_ 6 #define MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_
7 7
8 #include <functional> 8 #include <functional>
9 #include <string> 9 #include <string>
10 10
(...skipping 19 matching lines...) Expand all
30 template <typename Interface> 30 template <typename Interface>
31 using InterfaceRequestHandler = 31 using InterfaceRequestHandler =
32 std::function<void(const ConnectionContext& connection_context, 32 std::function<void(const ConnectionContext& connection_context,
33 InterfaceRequest<Interface> interface_request)>; 33 InterfaceRequest<Interface> interface_request)>;
34 34
35 // Constructs this service provider implementation in an unbound state. 35 // Constructs this service provider implementation in an unbound state.
36 ServiceProviderImpl(); 36 ServiceProviderImpl();
37 37
38 // Constructs this service provider implementation, binding it to the given 38 // Constructs this service provider implementation, binding it to the given
39 // interface request. 39 // interface request.
40 // TODO(vtl): This should take a |ConnectionContext|, to provide
41 // |InterfaceRequestHandler<I>|s.
42 explicit ServiceProviderImpl( 40 explicit ServiceProviderImpl(
41 const ConnectionContext& connection_context,
43 InterfaceRequest<ServiceProvider> service_provider_request); 42 InterfaceRequest<ServiceProvider> service_provider_request);
44 43
45 ~ServiceProviderImpl() override; 44 ~ServiceProviderImpl() override;
46 45
47 // Binds this service provider implementation to the given interface request. 46 // Binds this service provider implementation to the given interface request.
48 // This may only be called if this object is unbound. 47 // This may only be called if this object is unbound.
49 // TODO(vtl): This should take a |ConnectionContext|, to provide 48 void Bind(const ConnectionContext& connection_context,
50 // |InterfaceRequestHandler<I>|s. 49 InterfaceRequest<ServiceProvider> service_provider_request);
51 void Bind(InterfaceRequest<ServiceProvider> service_provider_request);
52 50
53 // Disconnect this service provider implementation and put it in a state where 51 // Disconnect this service provider implementation and put it in a state where
54 // it can be rebound to a new request (i.e., restores this object to an 52 // it can be rebound to a new request (i.e., restores this object to an
55 // unbound state). This may be called even if this object is already unbound. 53 // unbound state). This may be called even if this object is already unbound.
56 void Close(); 54 void Close();
57 55
58 // TODO(vtl): Remove this. 56 // TODO(vtl): Remove this.
59 template <typename Interface> 57 template <typename Interface>
60 void AddService(InterfaceFactory<Interface>* factory, 58 void AddService(InterfaceFactory<Interface>* factory,
61 const std::string& interface_name = Interface::Name_) { 59 const std::string& interface_name = Interface::Name_) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // request (i.e., |ServiceConnector::ConnectToService()|) to the type-safe 101 // request (i.e., |ServiceConnector::ConnectToService()|) to the type-safe
104 // |InterfaceRequestHandler<Interface>|. 102 // |InterfaceRequestHandler<Interface>|.
105 template <typename Interface> 103 template <typename Interface>
106 class ServiceConnectorImpl : public ServiceConnector { 104 class ServiceConnectorImpl : public ServiceConnector {
107 public: 105 public:
108 explicit ServiceConnectorImpl( 106 explicit ServiceConnectorImpl(
109 InterfaceRequestHandler<Interface> interface_request_handler) 107 InterfaceRequestHandler<Interface> interface_request_handler)
110 : interface_request_handler_(std::move(interface_request_handler)) {} 108 : interface_request_handler_(std::move(interface_request_handler)) {}
111 ~ServiceConnectorImpl() override {} 109 ~ServiceConnectorImpl() override {}
112 110
113 void ConnectToService(ApplicationConnection* application_connection, 111 void ConnectToService(const mojo::ConnectionContext& connection_context,
114 const std::string& interface_name, 112 const std::string& interface_name,
115 ScopedMessagePipeHandle client_handle) override { 113 ScopedMessagePipeHandle client_handle) override {
116 // TODO(vtl): This should be given a |const ConnectionContext&|, instead
117 // of an |ApplicationConnection*| -- which may be null!
118 interface_request_handler_( 114 interface_request_handler_(
119 application_connection 115 connection_context,
120 ? application_connection->GetConnectionContext()
121 : ConnectionContext(),
122 InterfaceRequest<Interface>(client_handle.Pass())); 116 InterfaceRequest<Interface>(client_handle.Pass()));
123 } 117 }
124 118
125 private: 119 private:
126 const InterfaceRequestHandler<Interface> interface_request_handler_; 120 const InterfaceRequestHandler<Interface> interface_request_handler_;
127 121
128 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnectorImpl); 122 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnectorImpl);
129 }; 123 };
130 124
131 // Overridden from |ServiceProvider|: 125 // Overridden from |ServiceProvider|:
132 void ConnectToService(const String& service_name, 126 void ConnectToService(const String& service_name,
133 ScopedMessagePipeHandle client_handle) override; 127 ScopedMessagePipeHandle client_handle) override;
134 128
129 ConnectionContext connection_context_;
135 Binding<ServiceProvider> binding_; 130 Binding<ServiceProvider> binding_;
136 131
137 internal::ServiceConnectorRegistry service_connector_registry_; 132 internal::ServiceConnectorRegistry service_connector_registry_;
138 ServiceProvider* fallback_service_provider_; 133 ServiceProvider* fallback_service_provider_;
139 134
140 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceProviderImpl); 135 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceProviderImpl);
141 }; 136 };
142 137
143 } // namespace mojo 138 } // namespace mojo
144 139
145 #endif // MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_ 140 #endif // MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/service_connector.h ('k') | mojo/public/cpp/application/tests/service_provider_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698