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

Side by Side Diff: services/service_manager/public/cpp/connector.h

Issue 2857963004: Flatten Connector & ConnectorImpl (Closed)
Patch Set: . Created 3 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_ 5 #ifndef SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_
6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_ 6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_
7 7
8 #include <map>
8 #include <memory> 9 #include <memory>
9 10
11 #include "base/callback.h"
12 #include "base/threading/thread_checker.h"
10 #include "services/service_manager/public/cpp/identity.h" 13 #include "services/service_manager/public/cpp/identity.h"
11 #include "services/service_manager/public/interfaces/connector.mojom.h" 14 #include "services/service_manager/public/interfaces/connector.mojom.h"
12 #include "services/service_manager/public/interfaces/service.mojom.h" 15 #include "services/service_manager/public/interfaces/service.mojom.h"
13 #include "services/service_manager/public/interfaces/service_manager.mojom.h" 16 #include "services/service_manager/public/interfaces/service_manager.mojom.h"
14 17
15 namespace service_manager { 18 namespace service_manager {
16 19
17 // An interface that encapsulates the Service Manager's brokering interface, by 20 // An interface that encapsulates the Service Manager's brokering interface, by
18 // which 21 // which
19 // connections between services are established. Once either StartService() or 22 // connections between services are established. Once either StartService() or
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // service. This will be run in response to calls to StartService() or 60 // service. This will be run in response to calls to StartService() or
58 // BindInterface(). 61 // BindInterface().
59 void SetStartServiceCallback(const StartServiceCallback& callback) { 62 void SetStartServiceCallback(const StartServiceCallback& callback) {
60 connector_->SetStartServiceCallback(callback); 63 connector_->SetStartServiceCallback(callback);
61 } 64 }
62 65
63 private: 66 private:
64 Connector* connector_; 67 Connector* connector_;
65 }; 68 };
66 69
67 virtual ~Connector() {} 70 explicit Connector(mojom::ConnectorPtrInfo unbound_state);
71 explicit Connector(mojom::ConnectorPtr connector);
72 ~Connector();
68 73
69 // Creates a new Connector instance and fills in |*request| with a request 74 // Creates a new Connector instance and fills in |*request| with a request
70 // for the other end the Connector's interface. 75 // for the other end the Connector's interface.
71 static std::unique_ptr<Connector> Create(mojom::ConnectorRequest* request); 76 static std::unique_ptr<Connector> Create(mojom::ConnectorRequest* request);
72 77
73 // Creates an instance of a service for |identity|. 78 // Creates an instance of a service for |identity|.
74 virtual void StartService(const Identity& identity) = 0; 79 void StartService(const Identity& identity);
75 80
76 // Creates an instance of the service |name| inheriting the caller's identity. 81 // Creates an instance of the service |name| inheriting the caller's identity.
77 virtual void StartService(const std::string& name) = 0; 82 void StartService(const std::string& name);
78 83
79 // Creates an instance of a service for |identity| in a process started by the 84 // Creates an instance of a service for |identity| in a process started by the
80 // client (or someone else). Must be called before BindInterface() may be 85 // client (or someone else). Must be called before BindInterface() may be
81 // called to |identity|. 86 // called to |identity|.
82 virtual void StartService( 87 void StartService(const Identity& identity,
83 const Identity& identity, 88 mojom::ServicePtr service,
84 mojom::ServicePtr service, 89 mojom::PIDReceiverRequest pid_receiver_request);
85 mojom::PIDReceiverRequest pid_receiver_request) = 0;
86 90
87 // Connect to |target| & request to bind |Interface|. 91 // Connect to |target| & request to bind |Interface|.
88 template <typename Interface> 92 template <typename Interface>
89 void BindInterface(const Identity& target, 93 void BindInterface(const Identity& target,
90 mojo::InterfacePtr<Interface>* ptr) { 94 mojo::InterfacePtr<Interface>* ptr) {
91 mojo::MessagePipe pipe; 95 mojo::MessagePipe pipe;
92 ptr->Bind(mojo::InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u)); 96 ptr->Bind(mojo::InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u));
93 BindInterface(target, Interface::Name_, std::move(pipe.handle1)); 97 BindInterface(target, Interface::Name_, std::move(pipe.handle1));
94 } 98 }
95 template <typename Interface> 99 template <typename Interface>
96 void BindInterface(const std::string& name, 100 void BindInterface(const std::string& name,
97 mojo::InterfacePtr<Interface>* ptr) { 101 mojo::InterfacePtr<Interface>* ptr) {
98 return BindInterface(Identity(name, mojom::kInheritUserID), ptr); 102 return BindInterface(Identity(name, mojom::kInheritUserID), ptr);
99 } 103 }
100 template <typename Interface> 104 template <typename Interface>
101 void BindInterface(const std::string& name, 105 void BindInterface(const std::string& name,
102 mojo::InterfaceRequest<Interface> request) { 106 mojo::InterfaceRequest<Interface> request) {
103 return BindInterface(Identity(name, mojom::kInheritUserID), 107 return BindInterface(Identity(name, mojom::kInheritUserID),
104 Interface::Name_, request.PassMessagePipe()); 108 Interface::Name_, request.PassMessagePipe());
105 } 109 }
106 virtual void BindInterface(const Identity& target, 110 void BindInterface(const Identity& target,
107 const std::string& interface_name, 111 const std::string& interface_name,
108 mojo::ScopedMessagePipeHandle interface_pipe) = 0; 112 mojo::ScopedMessagePipeHandle interface_pipe);
109 113
110 // Creates a new instance of this class which may be passed to another thread. 114 // Creates a new instance of this class which may be passed to another thread.
111 // The returned object may be passed multiple times until StartService() or 115 // The returned object may be passed multiple times until StartService() or
112 // BindInterface() is called, at which point this method must be called again 116 // BindInterface() is called, at which point this method must be called again
113 // to pass again. 117 // to pass again.
114 virtual std::unique_ptr<Connector> Clone() = 0; 118 std::unique_ptr<Connector> Clone();
115 119
116 virtual void FilterInterfaces(const std::string& spec, 120 void FilterInterfaces(const std::string& spec,
117 const Identity& source_identity, 121 const Identity& source_identity,
118 mojom::InterfaceProviderRequest request, 122 mojom::InterfaceProviderRequest request,
119 mojom::InterfaceProviderPtr target) = 0; 123 mojom::InterfaceProviderPtr target);
120 124
121 // Binds a Connector request to the other end of this Connector. 125 // Binds a Connector request to the other end of this Connector.
122 virtual void BindConnectorRequest(mojom::ConnectorRequest request) = 0; 126 void BindConnectorRequest(mojom::ConnectorRequest request);
123 127
124 virtual base::WeakPtr<Connector> GetWeakPtr() = 0; 128 base::WeakPtr<Connector> GetWeakPtr();
125 129
126 protected: 130 private:
127 virtual void OverrideBinderForTesting(const std::string& service_name, 131 using BinderOverrideMap = std::map<std::string, TestApi::Binder>;
128 const std::string& interface_name, 132
129 const TestApi::Binder& binder) = 0; 133 void OnConnectionError();
130 virtual void ClearBinderOverrides() = 0; 134
131 virtual void SetStartServiceCallback( 135 void OverrideBinderForTesting(const std::string& service_name,
132 const StartServiceCallback& callback) = 0; 136 const std::string& interface_name,
133 virtual void ResetStartServiceCallback() = 0; 137 const TestApi::Binder& binder);
138 void ClearBinderOverrides();
139 void SetStartServiceCallback(const StartServiceCallback& callback);
140 void ResetStartServiceCallback();
141
142 bool BindConnectorIfNecessary();
143
144 // Callback passed to mojom methods StartService()/BindInterface().
145 void RunStartServiceCallback(mojom::ConnectResult result,
146 const Identity& user_id);
147
148 mojom::ConnectorPtrInfo unbound_state_;
149 mojom::ConnectorPtr connector_;
150
151 base::ThreadChecker thread_checker_;
152
153 std::map<std::string, BinderOverrideMap> local_binder_overrides_;
154 StartServiceCallback start_service_callback_;
155
156 base::WeakPtrFactory<Connector> weak_factory_;
157
158 DISALLOW_COPY_AND_ASSIGN(Connector);
134 }; 159 };
135 160
136 } // namespace service_manager 161 } // namespace service_manager
137 162
138 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_ 163 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/BUILD.gn ('k') | services/service_manager/public/cpp/connector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698