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

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

Issue 2610173003: Add RegisterService, split out of Connect(). (Closed)
Patch Set: . Created 3 years, 11 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 2016 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 <memory> 8 #include <memory>
9 9
10 #include "services/service_manager/public/cpp/connection.h" 10 #include "services/service_manager/public/cpp/connection.h"
(...skipping 18 matching lines...) Expand all
29 // 29 //
30 // While instances of this object are owned by the caller, the underlying 30 // While instances of this object are owned by the caller, the underlying
31 // connection with the service manager is bound to the lifetime of the instance 31 // connection with the service manager is bound to the lifetime of the instance
32 // that 32 // that
33 // created it, i.e. when the application is terminated the Connector pipe is 33 // created it, i.e. when the application is terminated the Connector pipe is
34 // closed. 34 // closed.
35 class Connector { 35 class Connector {
36 public: 36 public:
37 virtual ~Connector() {} 37 virtual ~Connector() {}
38 38
39 class ConnectParams {
40 public:
41 explicit ConnectParams(const Identity& target);
42 explicit ConnectParams(const std::string& name);
43 ~ConnectParams();
44
45 const Identity& target() { return target_; }
46 void set_target(const Identity& target) { target_ = target; }
47 void set_client_process_connection(
48 mojom::ServicePtr service,
49 mojom::PIDReceiverRequest pid_receiver_request) {
50 service_ = std::move(service);
51 pid_receiver_request_ = std::move(pid_receiver_request);
52 }
53 void TakeClientProcessConnection(
54 mojom::ServicePtr* service,
55 mojom::PIDReceiverRequest* pid_receiver_request) {
56 *service = std::move(service_);
57 *pid_receiver_request = std::move(pid_receiver_request_);
58 }
59 InterfaceProvider* remote_interfaces() { return remote_interfaces_; }
60 void set_remote_interfaces(InterfaceProvider* remote_interfaces) {
61 remote_interfaces_ = remote_interfaces;
62 }
63
64 private:
65 Identity target_;
66 mojom::ServicePtr service_;
67 mojom::PIDReceiverRequest pid_receiver_request_;
68 InterfaceProvider* remote_interfaces_ = nullptr;
69
70 DISALLOW_COPY_AND_ASSIGN(ConnectParams);
71 };
72
73 // Creates a new Connector instance and fills in |*request| with a request 39 // Creates a new Connector instance and fills in |*request| with a request
74 // for the other end the Connector's interface. 40 // for the other end the Connector's interface.
75 static std::unique_ptr<Connector> Create(mojom::ConnectorRequest* request); 41 static std::unique_ptr<Connector> Create(mojom::ConnectorRequest* request);
76 42
77 // Requests a new connection to an application. Returns a pointer to the 43 // Creates an instance of a service for |identity| in a process started by the
78 // connection if the connection is permitted by this application's delegate, 44 // client (or someone else). Must be called before Connect() may be called to
79 // or nullptr otherwise. Caller takes ownership. 45 // |identity|.
80 // Once this method is called, this object is bound to the thread on which the 46 virtual void Start(
81 // call took place. To pass to another thread, call Clone() and pass the 47 const Identity& identity,
82 // result. 48 mojom::ServicePtr service,
49 mojom::PIDReceiverRequest pid_receiver_request) = 0;
50
51 // Requests a new connection to a service. Returns a pointer to the
52 // connection if the connection is permitted by that service, nullptr
53 // otherwise. Once this method is called, this object is bound to the thread
54 // on which the call took place. To pass to another thread, call Clone() and
55 // pass the result.
83 virtual std::unique_ptr<Connection> Connect(const std::string& name) = 0; 56 virtual std::unique_ptr<Connection> Connect(const std::string& name) = 0;
84 virtual std::unique_ptr<Connection> Connect(ConnectParams* params) = 0; 57 virtual std::unique_ptr<Connection> Connect(const Identity& target) = 0;
85 58
86 // Connect to application identified by |request->name| and connect to the 59 // Connect to |target| & request to bind |Interface|. Does not retain a
87 // service implementation of the interface identified by |Interface|. 60 // connection to |target|.
88 template <typename Interface> 61 template <typename Interface>
89 void ConnectToInterface(ConnectParams* params, 62 void ConnectToInterface(const Identity& target,
90 mojo::InterfacePtr<Interface>* ptr) { 63 mojo::InterfacePtr<Interface>* ptr) {
91 std::unique_ptr<Connection> connection = Connect(params); 64 std::unique_ptr<Connection> connection = Connect(target);
92 if (connection) 65 if (connection)
93 connection->GetInterface(ptr); 66 connection->GetInterface(ptr);
94 } 67 }
95 template <typename Interface> 68 template <typename Interface>
96 void ConnectToInterface(const Identity& target,
97 mojo::InterfacePtr<Interface>* ptr) {
98 ConnectParams params(target);
99 return ConnectToInterface(&params, ptr);
100 }
101 template <typename Interface>
102 void ConnectToInterface(const std::string& name, 69 void ConnectToInterface(const std::string& name,
103 mojo::InterfacePtr<Interface>* ptr) { 70 mojo::InterfacePtr<Interface>* ptr) {
104 ConnectParams params(name); 71 return ConnectToInterface(Identity(name, mojom::kInheritUserID), ptr);
105 return ConnectToInterface(&params, ptr);
106 } 72 }
107 73
108 // Creates a new instance of this class which may be passed to another thread. 74 // Creates a new instance of this class which may be passed to another thread.
109 // The returned object may be passed multiple times until Connect() is called, 75 // The returned object may be passed multiple times until Connect() is called,
110 // at which point this method must be called again to pass again. 76 // at which point this method must be called again to pass again.
111 virtual std::unique_ptr<Connector> Clone() = 0; 77 virtual std::unique_ptr<Connector> Clone() = 0;
112 78
113 // Binds a Connector request to the other end of this Connector. 79 // Binds a Connector request to the other end of this Connector.
114 virtual void BindRequest(mojom::ConnectorRequest request) = 0; 80 virtual void BindRequest(mojom::ConnectorRequest request) = 0;
115 }; 81 };
116 82
117 } // namespace service_manager 83 } // namespace service_manager
118 84
119 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_ 85 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_
OLDNEW
« no previous file with comments | « services/service_manager/connect_params.h ('k') | services/service_manager/public/cpp/lib/connector_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698