OLD | NEW |
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 MOJO_SHELL_PUBLIC_CPP_CONNECTOR_H_ | 5 #ifndef MOJO_SHELL_PUBLIC_CPP_CONNECTOR_H_ |
6 #define MOJO_SHELL_PUBLIC_CPP_CONNECTOR_H_ | 6 #define MOJO_SHELL_PUBLIC_CPP_CONNECTOR_H_ |
7 | 7 |
8 #include "mojo/shell/public/cpp/connection.h" | 8 #include "mojo/shell/public/cpp/connection.h" |
9 #include "mojo/shell/public/cpp/identity.h" | 9 #include "mojo/shell/public/cpp/identity.h" |
10 #include "mojo/shell/public/interfaces/connector.mojom.h" | 10 #include "mojo/shell/public/interfaces/connector.mojom.h" |
| 11 #include "mojo/shell/public/interfaces/shell.mojom.h" |
| 12 #include "mojo/shell/public/interfaces/shell_client_factory.mojom.h" |
11 | 13 |
12 namespace mojo { | 14 namespace mojo { |
13 | 15 |
14 // An interface that encapsulates the Mojo Shell's broker interface by which | 16 // An interface that encapsulates the Mojo Shell's broker interface by which |
15 // connections between applications are established. Once Connect() is called, | 17 // connections between applications are established. Once Connect() is called, |
16 // this class is bound to the thread the call was made on and it cannot be | 18 // this class is bound to the thread the call was made on and it cannot be |
17 // passed to another thread without calling Clone(). | 19 // passed to another thread without calling Clone(). |
18 // An instance of this class is created internally by ShellConnection for use | 20 // An instance of this class is created internally by ShellConnection for use |
19 // on the thread ShellConnection is instantiated on, and this interface is | 21 // on the thread ShellConnection is instantiated on, and this interface is |
20 // wrapped by the Shell interface. | 22 // wrapped by the Shell interface. |
21 // To use this interface on other threads, call Shell::CloneConnector() and | 23 // To use this interface on other threads, call Shell::CloneConnector() and |
22 // pass the result to another thread. To pass to subsequent threads, call | 24 // pass the result to another thread. To pass to subsequent threads, call |
23 // Clone() on instances of this object. | 25 // Clone() on instances of this object. |
24 // While instances of this object are owned by the caller, the underlying | 26 // While instances of this object are owned by the caller, the underlying |
25 // connection with the shell is bound to the lifetime of the instance that | 27 // connection with the shell is bound to the lifetime of the instance that |
26 // created it, i.e. when the application is terminated the Connector pipe is | 28 // created it, i.e. when the application is terminated the Connector pipe is |
27 // closed. | 29 // closed. |
28 class Connector { | 30 class Connector { |
29 public: | 31 public: |
30 virtual ~Connector() {} | 32 virtual ~Connector() {} |
31 | 33 |
32 class ConnectParams { | 34 class ConnectParams { |
33 public: | 35 public: |
34 explicit ConnectParams(const Identity& target); | 36 explicit ConnectParams(const Identity& target); |
35 explicit ConnectParams(const std::string& name); | 37 explicit ConnectParams(const std::string& name); |
36 ~ConnectParams(); | 38 ~ConnectParams(); |
37 | 39 |
38 const Identity& target() { return target_; } | 40 const Identity& target() { return target_; } |
39 void set_target(const Identity& target) { target_ = target; } | 41 void set_target(const Identity& target) { target_ = target; } |
| 42 void set_client_process_connection( |
| 43 shell::mojom::ShellClientFactoryPtr shell_client_factory, |
| 44 shell::mojom::PIDReceiverRequest pid_receiver_request) { |
| 45 shell_client_factory_ = std::move(shell_client_factory); |
| 46 pid_receiver_request_ = std::move(pid_receiver_request); |
| 47 } |
| 48 void TakeClientProcessConnection( |
| 49 shell::mojom::ShellClientFactoryPtr* shell_client_factory, |
| 50 shell::mojom::PIDReceiverRequest* pid_receiver_request) { |
| 51 *shell_client_factory = std::move(shell_client_factory_); |
| 52 *pid_receiver_request = std::move(pid_receiver_request_); |
| 53 } |
40 | 54 |
41 private: | 55 private: |
42 Identity target_; | 56 Identity target_; |
| 57 shell::mojom::ShellClientFactoryPtr shell_client_factory_; |
| 58 shell::mojom::PIDReceiverRequest pid_receiver_request_; |
43 | 59 |
44 DISALLOW_COPY_AND_ASSIGN(ConnectParams); | 60 DISALLOW_COPY_AND_ASSIGN(ConnectParams); |
45 }; | 61 }; |
46 | 62 |
47 // Requests a new connection to an application. Returns a pointer to the | 63 // Requests a new connection to an application. Returns a pointer to the |
48 // connection if the connection is permitted by this application's delegate, | 64 // connection if the connection is permitted by this application's delegate, |
49 // or nullptr otherwise. Caller takes ownership. | 65 // or nullptr otherwise. Caller takes ownership. |
50 // Once this method is called, this object is bound to the thread on which the | 66 // Once this method is called, this object is bound to the thread on which the |
51 // call took place. To pass to another thread, call Clone() and pass the | 67 // call took place. To pass to another thread, call Clone() and pass the |
52 // result. | 68 // result. |
(...skipping 23 matching lines...) Expand all Loading... |
76 | 92 |
77 // Creates a new instance of this class which may be passed to another thread. | 93 // Creates a new instance of this class which may be passed to another thread. |
78 // The returned object may be passed multiple times until Connect() is called, | 94 // The returned object may be passed multiple times until Connect() is called, |
79 // at which point this method must be called again to pass again. | 95 // at which point this method must be called again to pass again. |
80 virtual scoped_ptr<Connector> Clone() = 0; | 96 virtual scoped_ptr<Connector> Clone() = 0; |
81 }; | 97 }; |
82 | 98 |
83 } // namespace mojo | 99 } // namespace mojo |
84 | 100 |
85 #endif // MOJO_SHELL_PUBLIC_CPP_CONNECTOR_H_ | 101 #endif // MOJO_SHELL_PUBLIC_CPP_CONNECTOR_H_ |
OLD | NEW |