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

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

Issue 1882423004: Move shell service to toplevel shell namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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
« no previous file with comments | « services/shell/public/cpp/connection.h ('k') | services/shell/public/cpp/identity.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 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_SHELL_PUBLIC_CPP_CONNECTOR_H_ 5 #ifndef SERVICES_SHELL_PUBLIC_CPP_CONNECTOR_H_
6 #define SERVICES_SHELL_PUBLIC_CPP_CONNECTOR_H_ 6 #define SERVICES_SHELL_PUBLIC_CPP_CONNECTOR_H_
7 7
8 #include <memory>
9
8 #include "services/shell/public/cpp/connection.h" 10 #include "services/shell/public/cpp/connection.h"
9 #include "services/shell/public/cpp/identity.h" 11 #include "services/shell/public/cpp/identity.h"
10 #include "services/shell/public/interfaces/connector.mojom.h" 12 #include "services/shell/public/interfaces/connector.mojom.h"
11 #include "services/shell/public/interfaces/shell.mojom.h" 13 #include "services/shell/public/interfaces/shell.mojom.h"
12 #include "services/shell/public/interfaces/shell_client.mojom.h" 14 #include "services/shell/public/interfaces/shell_client.mojom.h"
13 15
14 namespace mojo { 16 namespace shell {
15 17
16 // An interface that encapsulates the Mojo Shell's broker interface by which 18 // An interface that encapsulates the Mojo Shell's broker interface by which
17 // connections between applications are established. Once Connect() is called, 19 // connections between applications are established. Once Connect() is called,
18 // this class is bound to the thread the call was made on and it cannot be 20 // this class is bound to the thread the call was made on and it cannot be
19 // passed to another thread without calling Clone(). 21 // passed to another thread without calling Clone().
20 // An instance of this class is created internally by ShellConnection for use 22 // An instance of this class is created internally by ShellConnection for use
21 // on the thread ShellConnection is instantiated on, and this interface is 23 // on the thread ShellConnection is instantiated on, and this interface is
22 // wrapped by the Shell interface. 24 // wrapped by the Shell interface.
23 // To use this interface on other threads, call Shell::CloneConnector() and 25 // To use this interface on other threads, call Shell::CloneConnector() and
24 // pass the result to another thread. To pass to subsequent threads, call 26 // pass the result to another thread. To pass to subsequent threads, call
25 // Clone() on instances of this object. 27 // Clone() on instances of this object.
26 // While instances of this object are owned by the caller, the underlying 28 // While instances of this object are owned by the caller, the underlying
27 // connection with the shell is bound to the lifetime of the instance that 29 // connection with the shell is bound to the lifetime of the instance that
28 // created it, i.e. when the application is terminated the Connector pipe is 30 // created it, i.e. when the application is terminated the Connector pipe is
29 // closed. 31 // closed.
30 class Connector { 32 class Connector {
31 public: 33 public:
32 virtual ~Connector() {} 34 virtual ~Connector() {}
33 35
34 class ConnectParams { 36 class ConnectParams {
35 public: 37 public:
36 explicit ConnectParams(const Identity& target); 38 explicit ConnectParams(const Identity& target);
37 explicit ConnectParams(const std::string& name); 39 explicit ConnectParams(const std::string& name);
38 ~ConnectParams(); 40 ~ConnectParams();
39 41
40 const Identity& target() { return target_; } 42 const Identity& target() { return target_; }
41 void set_target(const Identity& target) { target_ = target; } 43 void set_target(const Identity& target) { target_ = target; }
42 void set_client_process_connection( 44 void set_client_process_connection(
43 shell::mojom::ShellClientPtr shell_client, 45 mojom::ShellClientPtr shell_client,
44 shell::mojom::PIDReceiverRequest pid_receiver_request) { 46 mojom::PIDReceiverRequest pid_receiver_request) {
45 shell_client_ = std::move(shell_client); 47 shell_client_ = std::move(shell_client);
46 pid_receiver_request_ = std::move(pid_receiver_request); 48 pid_receiver_request_ = std::move(pid_receiver_request);
47 } 49 }
48 void TakeClientProcessConnection( 50 void TakeClientProcessConnection(
49 shell::mojom::ShellClientPtr* shell_client, 51 mojom::ShellClientPtr* shell_client,
50 shell::mojom::PIDReceiverRequest* pid_receiver_request) { 52 mojom::PIDReceiverRequest* pid_receiver_request) {
51 *shell_client = std::move(shell_client_); 53 *shell_client = std::move(shell_client_);
52 *pid_receiver_request = std::move(pid_receiver_request_); 54 *pid_receiver_request = std::move(pid_receiver_request_);
53 } 55 }
54 56
55 private: 57 private:
56 Identity target_; 58 Identity target_;
57 shell::mojom::ShellClientPtr shell_client_; 59 mojom::ShellClientPtr shell_client_;
58 shell::mojom::PIDReceiverRequest pid_receiver_request_; 60 mojom::PIDReceiverRequest pid_receiver_request_;
59 61
60 DISALLOW_COPY_AND_ASSIGN(ConnectParams); 62 DISALLOW_COPY_AND_ASSIGN(ConnectParams);
61 }; 63 };
62 64
63 // Requests a new connection to an application. Returns a pointer to the 65 // Requests a new connection to an application. Returns a pointer to the
64 // connection if the connection is permitted by this application's delegate, 66 // connection if the connection is permitted by this application's delegate,
65 // or nullptr otherwise. Caller takes ownership. 67 // or nullptr otherwise. Caller takes ownership.
66 // Once this method is called, this object is bound to the thread on which the 68 // Once this method is called, this object is bound to the thread on which the
67 // call took place. To pass to another thread, call Clone() and pass the 69 // call took place. To pass to another thread, call Clone() and pass the
68 // result. 70 // result.
69 virtual scoped_ptr<Connection> Connect(const std::string& name) = 0; 71 virtual std::unique_ptr<Connection> Connect(const std::string& name) = 0;
70 virtual scoped_ptr<Connection> Connect(ConnectParams* params) = 0; 72 virtual std::unique_ptr<Connection> Connect(ConnectParams* params) = 0;
71 73
72 // Connect to application identified by |request->name| and connect to the 74 // Connect to application identified by |request->name| and connect to the
73 // service implementation of the interface identified by |Interface|. 75 // service implementation of the interface identified by |Interface|.
74 template <typename Interface> 76 template <typename Interface>
75 void ConnectToInterface(ConnectParams* params, InterfacePtr<Interface>* ptr) { 77 void ConnectToInterface(ConnectParams* params,
76 scoped_ptr<Connection> connection = Connect(params); 78 mojo::InterfacePtr<Interface>* ptr) {
79 std::unique_ptr<Connection> connection = Connect(params);
77 if (connection) 80 if (connection)
78 connection->GetInterface(ptr); 81 connection->GetInterface(ptr);
79 } 82 }
80 template <typename Interface> 83 template <typename Interface>
81 void ConnectToInterface(const Identity& target, 84 void ConnectToInterface(const Identity& target,
82 InterfacePtr<Interface>* ptr) { 85 mojo::InterfacePtr<Interface>* ptr) {
83 ConnectParams params(target); 86 ConnectParams params(target);
84 return ConnectToInterface(&params, ptr); 87 return ConnectToInterface(&params, ptr);
85 } 88 }
86 template <typename Interface> 89 template <typename Interface>
87 void ConnectToInterface(const std::string& name, 90 void ConnectToInterface(const std::string& name,
88 InterfacePtr<Interface>* ptr) { 91 mojo::InterfacePtr<Interface>* ptr) {
89 ConnectParams params(name); 92 ConnectParams params(name);
90 return ConnectToInterface(&params, ptr); 93 return ConnectToInterface(&params, ptr);
91 } 94 }
92 95
93 // Creates a new instance of this class which may be passed to another thread. 96 // Creates a new instance of this class which may be passed to another thread.
94 // The returned object may be passed multiple times until Connect() is called, 97 // The returned object may be passed multiple times until Connect() is called,
95 // at which point this method must be called again to pass again. 98 // at which point this method must be called again to pass again.
96 virtual scoped_ptr<Connector> Clone() = 0; 99 virtual std::unique_ptr<Connector> Clone() = 0;
97 }; 100 };
98 101
99 } // namespace mojo 102 } // namespace shell
100 103
101 #endif // SERVICES_SHELL_PUBLIC_CPP_CONNECTOR_H_ 104 #endif // SERVICES_SHELL_PUBLIC_CPP_CONNECTOR_H_
OLDNEW
« no previous file with comments | « services/shell/public/cpp/connection.h ('k') | services/shell/public/cpp/identity.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698