OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_EDK_SYSTEM_CONNECTION_MANAGER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_CONNECTION_MANAGER_H_ |
6 #define MOJO_EDK_SYSTEM_CONNECTION_MANAGER_H_ | 6 #define MOJO_EDK_SYSTEM_CONNECTION_MANAGER_H_ |
7 | 7 |
| 8 #include <ostream> |
| 9 |
8 #include "mojo/edk/system/connection_identifier.h" | 10 #include "mojo/edk/system/connection_identifier.h" |
9 #include "mojo/edk/system/process_identifier.h" | 11 #include "mojo/edk/system/process_identifier.h" |
10 #include "mojo/edk/system/system_impl_export.h" | 12 #include "mojo/edk/system/system_impl_export.h" |
| 13 #include "mojo/edk/system/thread_annotations.h" |
11 #include "mojo/public/cpp/system/macros.h" | 14 #include "mojo/public/cpp/system/macros.h" |
12 | 15 |
13 namespace mojo { | 16 namespace mojo { |
14 | 17 |
15 namespace embedder { | 18 namespace embedder { |
16 class PlatformSupport; | 19 class PlatformSupport; |
17 class ScopedPlatformHandle; | 20 class ScopedPlatformHandle; |
18 } // namespace embedder | 21 } // namespace embedder |
19 | 22 |
20 namespace system { | 23 namespace system { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // Implementation notes: We implement this using a "star topology", with a | 55 // Implementation notes: We implement this using a "star topology", with a |
53 // single trusted "master" (broker) process and an arbitrary number of untrusted | 56 // single trusted "master" (broker) process and an arbitrary number of untrusted |
54 // "slave" (client) processes. The former is implemented by | 57 // "slave" (client) processes. The former is implemented by |
55 // |MasterConnectionManager| (master_connection_manager.*) and the latter by | 58 // |MasterConnectionManager| (master_connection_manager.*) and the latter by |
56 // |SlaveConnectionManager| (slave_connection_manager.*). Each slave is | 59 // |SlaveConnectionManager| (slave_connection_manager.*). Each slave is |
57 // connected to the master by a special dedicated |RawChannel|, on which it does | 60 // connected to the master by a special dedicated |RawChannel|, on which it does |
58 // synchronous IPC (note, however, that the master should never block on any | 61 // synchronous IPC (note, however, that the master should never block on any |
59 // slave). | 62 // slave). |
60 class MOJO_SYSTEM_IMPL_EXPORT ConnectionManager { | 63 class MOJO_SYSTEM_IMPL_EXPORT ConnectionManager { |
61 public: | 64 public: |
| 65 enum class Result { |
| 66 FAILURE = 0, |
| 67 SUCCESS, |
| 68 // These results are used for |Connect()| (which also uses |FAILURE|, but |
| 69 // not |SUCCESS|). |
| 70 SUCCESS_CONNECT_SAME_PROCESS, |
| 71 SUCCESS_CONNECT_NEW_CONNECTION, |
| 72 SUCCESS_CONNECT_REUSE_CONNECTION |
| 73 }; |
| 74 |
62 virtual ~ConnectionManager() {} | 75 virtual ~ConnectionManager() {} |
63 | 76 |
64 ConnectionIdentifier GenerateConnectionIdentifier(); | 77 ConnectionIdentifier GenerateConnectionIdentifier(); |
65 | 78 |
66 // Shuts down this connection manager. No other methods may be called after | 79 // Shuts down this connection manager. No other methods may be called after |
67 // this is (or while it is being) called. | 80 // this is (or while it is being) called. |
68 virtual void Shutdown() = 0; | 81 virtual void Shutdown() MOJO_NOT_THREAD_SAFE = 0; |
69 | 82 |
70 // TODO(vtl): Add a "get my own process identifier" method? | 83 // TODO(vtl): Add a "get my own process identifier" method? |
71 | 84 |
72 // All of the methods below return true on success or false on failure. | 85 // All of the methods below return true on success or false on failure. |
73 // Failure is obviously fatal for the establishment of a particular | 86 // Failure is obviously fatal for the establishment of a particular |
74 // connection, but should not be treated as fatal to the process. Failure may, | 87 // connection, but should not be treated as fatal to the process. Failure may, |
75 // e.g., be caused by a misbehaving (malicious) untrusted peer process. | 88 // e.g., be caused by a misbehaving (malicious) untrusted peer process. |
76 | 89 |
77 // Allows a process who makes the identical call (with equal |connection_id|) | 90 // Allows a process who makes the identical call (with equal |connection_id|) |
78 // to connect to the calling process. (On success, there will be a "pending | 91 // to connect to the calling process. (On success, there will be a "pending |
79 // connection" for the given |connection_id| for the calling process.) | 92 // connection" for the given |connection_id| for the calling process.) |
80 virtual bool AllowConnect(const ConnectionIdentifier& connection_id) = 0; | 93 virtual bool AllowConnect(const ConnectionIdentifier& connection_id) = 0; |
81 | 94 |
82 // Cancels a pending connection for the calling process. (Note that this may | 95 // Cancels a pending connection for the calling process. (Note that this may |
83 // fail even if |AllowConnect()| succeeded; regardless, |Connect()| should not | 96 // fail even if |AllowConnect()| succeeded; regardless, |Connect()| should not |
84 // be called.) | 97 // be called.) |
85 virtual bool CancelConnect(const ConnectionIdentifier& connection_id) = 0; | 98 virtual bool CancelConnect(const ConnectionIdentifier& connection_id) = 0; |
86 | 99 |
87 // Connects a pending connection; to be called only after both parties have | 100 // Connects a pending connection; to be called only after both parties have |
88 // called |AllowConnect()|. On success, |peer_process_identifier| is set to an | 101 // called |AllowConnect()|. On success, |Result::SUCCESS_CONNECT_...| is |
89 // unique identifier for the peer process, and if the peer process is not the | 102 // returned and |peer_process_identifier| is set to an unique identifier for |
90 // same as the calling process then |*platform_handle| is set to a suitable | 103 // the peer process. In the case of |SUCCESS_CONNECT_SAME_PROCESS|, |
91 // native handle connecting the two parties (if the two parties are the same | 104 // |*platform_handle| is set to a suitable native handle connecting the two |
92 // process, then |*platform_handle| is reset to be invalid). | 105 // parties. |
93 virtual bool Connect(const ConnectionIdentifier& connection_id, | 106 virtual Result Connect(const ConnectionIdentifier& connection_id, |
94 ProcessIdentifier* peer_process_identifier, | 107 ProcessIdentifier* peer_process_identifier, |
95 embedder::ScopedPlatformHandle* platform_handle) = 0; | 108 embedder::ScopedPlatformHandle* platform_handle) = 0; |
96 | 109 |
97 protected: | 110 protected: |
98 // |platform_support| must be valid and remain alive until after |Shutdown()| | 111 // |platform_support| must be valid and remain alive until after |Shutdown()| |
99 // has completed. | 112 // has completed. |
100 explicit ConnectionManager(embedder::PlatformSupport* platform_support) | 113 explicit ConnectionManager(embedder::PlatformSupport* platform_support) |
101 : platform_support_(platform_support) {} | 114 : platform_support_(platform_support) {} |
102 | 115 |
103 private: | 116 private: |
104 embedder::PlatformSupport* const platform_support_; | 117 embedder::PlatformSupport* const platform_support_; |
105 | 118 |
106 MOJO_DISALLOW_COPY_AND_ASSIGN(ConnectionManager); | 119 MOJO_DISALLOW_COPY_AND_ASSIGN(ConnectionManager); |
107 }; | 120 }; |
108 | 121 |
| 122 // So logging macros and |DCHECK_EQ()|, etc. work. |
| 123 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<( |
| 124 std::ostream& out, |
| 125 ConnectionManager::Result result) { |
| 126 return out << static_cast<int>(result); |
| 127 } |
| 128 |
109 } // namespace system | 129 } // namespace system |
110 } // namespace mojo | 130 } // namespace mojo |
111 | 131 |
112 #endif // MOJO_EDK_SYSTEM_CONNECTION_MANAGER_H_ | 132 #endif // MOJO_EDK_SYSTEM_CONNECTION_MANAGER_H_ |
OLD | NEW |