OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CHANNEL_H_ | 5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_H_ |
6 #define MOJO_EDK_SYSTEM_CHANNEL_H_ | 6 #define MOJO_EDK_SYSTEM_CHANNEL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <unordered_map> | 11 #include <unordered_map> |
12 | 12 |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
15 #include "mojo/edk/embedder/scoped_platform_handle.h" | 14 #include "mojo/edk/embedder/scoped_platform_handle.h" |
16 #include "mojo/edk/system/channel_endpoint.h" | 15 #include "mojo/edk/system/channel_endpoint.h" |
17 #include "mojo/edk/system/channel_endpoint_id.h" | 16 #include "mojo/edk/system/channel_endpoint_id.h" |
18 #include "mojo/edk/system/incoming_endpoint.h" | 17 #include "mojo/edk/system/incoming_endpoint.h" |
19 #include "mojo/edk/system/message_in_transit.h" | 18 #include "mojo/edk/system/message_in_transit.h" |
20 #include "mojo/edk/system/mutex.h" | 19 #include "mojo/edk/system/mutex.h" |
21 #include "mojo/edk/system/raw_channel.h" | 20 #include "mojo/edk/system/raw_channel.h" |
22 #include "mojo/edk/system/ref_counted.h" | 21 #include "mojo/edk/system/ref_counted.h" |
23 #include "mojo/edk/system/ref_ptr.h" | 22 #include "mojo/edk/system/ref_ptr.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // Case 3: The endpoint's peer is remote (i.e., it has a peer | 145 // Case 3: The endpoint's peer is remote (i.e., it has a peer |
147 // |ChannelEndpoint|). (This has two subcases: the peer endpoint may be on | 146 // |ChannelEndpoint|). (This has two subcases: the peer endpoint may be on |
148 // this |Channel| or another |Channel|.) | 147 // this |Channel| or another |Channel|.) |
149 void SerializeEndpointWithClosedPeer(void* destination, | 148 void SerializeEndpointWithClosedPeer(void* destination, |
150 MessageInTransitQueue* message_queue); | 149 MessageInTransitQueue* message_queue); |
151 // This one returns the |ChannelEndpoint| for the serialized endpoint (which | 150 // This one returns the |ChannelEndpoint| for the serialized endpoint (which |
152 // can be used by, e.g., a |ProxyMessagePipeEndpoint|. | 151 // can be used by, e.g., a |ProxyMessagePipeEndpoint|. |
153 RefPtr<ChannelEndpoint> SerializeEndpointWithLocalPeer( | 152 RefPtr<ChannelEndpoint> SerializeEndpointWithLocalPeer( |
154 void* destination, | 153 void* destination, |
155 MessageInTransitQueue* message_queue, | 154 MessageInTransitQueue* message_queue, |
156 ChannelEndpointClient* endpoint_client, | 155 RefPtr<ChannelEndpointClient>&& endpoint_client, |
157 unsigned endpoint_client_port); | 156 unsigned endpoint_client_port); |
158 void SerializeEndpointWithRemotePeer(void* destination, | 157 void SerializeEndpointWithRemotePeer(void* destination, |
159 MessageInTransitQueue* message_queue, | 158 MessageInTransitQueue* message_queue, |
160 RefPtr<ChannelEndpoint>&& peer_endpoint); | 159 RefPtr<ChannelEndpoint>&& peer_endpoint); |
161 | 160 |
162 // Deserializes an endpoint that was sent from the peer |Channel| (using | 161 // Deserializes an endpoint that was sent from the peer |Channel| (using |
163 // |SerializeEndpoint...()|. |source| should be (a copy of) the data that | 162 // |SerializeEndpoint...()|. |source| should be (a copy of) the data that |
164 // |SerializeEndpoint...()| wrote, and must be (at least) | 163 // |SerializeEndpoint...()| wrote, and must be (at least) |
165 // |GetSerializedEndpointSize()| bytes. This returns the deserialized | 164 // |GetSerializedEndpointSize()| bytes. This returns the deserialized |
166 // |IncomingEndpoint| (which can be converted into a |MessagePipe|) or null on | 165 // |IncomingEndpoint| (which can be converted into a |MessagePipe|) or null on |
167 // error. | 166 // error. |
168 scoped_refptr<IncomingEndpoint> DeserializeEndpoint(const void* source); | 167 RefPtr<IncomingEndpoint> DeserializeEndpoint(const void* source); |
169 | 168 |
170 // See |RawChannel::GetSerializedPlatformHandleSize()|. | 169 // See |RawChannel::GetSerializedPlatformHandleSize()|. |
171 size_t GetSerializedPlatformHandleSize() const; | 170 size_t GetSerializedPlatformHandleSize() const; |
172 | 171 |
173 embedder::PlatformSupport* platform_support() const { | 172 embedder::PlatformSupport* platform_support() const { |
174 return platform_support_; | 173 return platform_support_; |
175 } | 174 } |
176 | 175 |
177 private: | 176 private: |
178 FRIEND_REF_COUNTED_THREAD_SAFE(Channel); | 177 FRIEND_REF_COUNTED_THREAD_SAFE(Channel); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 258 |
260 using IdToEndpointMap = | 259 using IdToEndpointMap = |
261 std::unordered_map<ChannelEndpointId, RefPtr<ChannelEndpoint>>; | 260 std::unordered_map<ChannelEndpointId, RefPtr<ChannelEndpoint>>; |
262 // Map from local IDs to endpoints. If the endpoint is null, this means that | 261 // Map from local IDs to endpoints. If the endpoint is null, this means that |
263 // we're just waiting for the remove ack before removing the entry. | 262 // we're just waiting for the remove ack before removing the entry. |
264 IdToEndpointMap local_id_to_endpoint_map_ MOJO_GUARDED_BY(mutex_); | 263 IdToEndpointMap local_id_to_endpoint_map_ MOJO_GUARDED_BY(mutex_); |
265 // Note: The IDs generated by this should be checked for existence before use. | 264 // Note: The IDs generated by this should be checked for existence before use. |
266 LocalChannelEndpointIdGenerator local_id_generator_ MOJO_GUARDED_BY(mutex_); | 265 LocalChannelEndpointIdGenerator local_id_generator_ MOJO_GUARDED_BY(mutex_); |
267 | 266 |
268 using IdToIncomingEndpointMap = | 267 using IdToIncomingEndpointMap = |
269 std::unordered_map<ChannelEndpointId, scoped_refptr<IncomingEndpoint>>; | 268 std::unordered_map<ChannelEndpointId, RefPtr<IncomingEndpoint>>; |
270 // Map from local IDs to incoming endpoints (i.e., those received inside other | 269 // Map from local IDs to incoming endpoints (i.e., those received inside other |
271 // messages, but not yet claimed via |DeserializeEndpoint()|). | 270 // messages, but not yet claimed via |DeserializeEndpoint()|). |
272 IdToIncomingEndpointMap incoming_endpoints_ MOJO_GUARDED_BY(mutex_); | 271 IdToIncomingEndpointMap incoming_endpoints_ MOJO_GUARDED_BY(mutex_); |
273 // TODO(vtl): We need to keep track of remote IDs (so that we don't collide | 272 // TODO(vtl): We need to keep track of remote IDs (so that we don't collide |
274 // if/when we wrap). | 273 // if/when we wrap). |
275 RemoteChannelEndpointIdGenerator remote_id_generator_ MOJO_GUARDED_BY(mutex_); | 274 RemoteChannelEndpointIdGenerator remote_id_generator_ MOJO_GUARDED_BY(mutex_); |
276 | 275 |
277 MOJO_DISALLOW_COPY_AND_ASSIGN(Channel); | 276 MOJO_DISALLOW_COPY_AND_ASSIGN(Channel); |
278 }; | 277 }; |
279 | 278 |
280 } // namespace system | 279 } // namespace system |
281 } // namespace mojo | 280 } // namespace mojo |
282 | 281 |
283 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ | 282 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ |
OLD | NEW |