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 #include "mojo/edk/system/remote_consumer_data_pipe_impl.h" | 5 #include "mojo/edk/system/remote_consumer_data_pipe_impl.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "mojo/edk/system/channel.h" | |
13 #include "mojo/edk/system/channel_endpoint.h" | 14 #include "mojo/edk/system/channel_endpoint.h" |
14 #include "mojo/edk/system/configuration.h" | 15 #include "mojo/edk/system/configuration.h" |
15 #include "mojo/edk/system/data_pipe.h" | 16 #include "mojo/edk/system/data_pipe.h" |
16 #include "mojo/edk/system/message_in_transit.h" | 17 #include "mojo/edk/system/message_in_transit.h" |
17 #include "mojo/edk/system/remote_data_pipe_ack.h" | 18 #include "mojo/edk/system/remote_data_pipe_ack.h" |
18 | 19 |
19 namespace mojo { | 20 namespace mojo { |
20 namespace system { | 21 namespace system { |
21 | 22 |
22 namespace { | 23 namespace { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 249 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
249 } | 250 } |
250 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 251 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
251 return rv; | 252 return rv; |
252 } | 253 } |
253 | 254 |
254 void RemoteConsumerDataPipeImpl::ProducerStartSerialize( | 255 void RemoteConsumerDataPipeImpl::ProducerStartSerialize( |
255 Channel* channel, | 256 Channel* channel, |
256 size_t* max_size, | 257 size_t* max_size, |
257 size_t* max_platform_handles) { | 258 size_t* max_platform_handles) { |
258 // TODO(vtl): Support serializing producer data pipe handles. | 259 *max_size = sizeof(SerializedDataPipeProducerDispatcher) + |
259 NOTIMPLEMENTED(); // FIXME | 260 channel->GetSerializedEndpointSize(); |
260 *max_size = 0; | |
261 *max_platform_handles = 0; | 261 *max_platform_handles = 0; |
262 } | 262 } |
263 | 263 |
264 bool RemoteConsumerDataPipeImpl::ProducerEndSerialize( | 264 bool RemoteConsumerDataPipeImpl::ProducerEndSerialize( |
265 Channel* channel, | 265 Channel* channel, |
266 void* destination, | 266 void* destination, |
267 size_t* actual_size, | 267 size_t* actual_size, |
268 embedder::PlatformHandleVector* platform_handles) { | 268 embedder::PlatformHandleVector* platform_handles) { |
269 // TODO(vtl): Support serializing producer data pipe handles. | 269 SerializedDataPipeProducerDispatcher* s = |
270 NOTIMPLEMENTED(); // FIXME | 270 static_cast<SerializedDataPipeProducerDispatcher*>(destination); |
271 owner()->ProducerCloseNoLock(); | 271 s->validated_options = validated_options(); |
272 return false; | 272 void* destination_for_endpoint = static_cast<char*>(destination) + |
273 sizeof(SerializedDataPipeProducerDispatcher); | |
274 | |
275 if (!consumer_open()) { | |
276 // Case 1: The consumer is closed. | |
277 s->consumer_num_bytes = static_cast<size_t>(-1); | |
278 *actual_size = sizeof(SerializedDataPipeProducerDispatcher); | |
279 return true; | |
280 } | |
281 | |
282 // Case 2: The consumer isn't closed. We pass |channel_endpoint| back to the | |
283 // |Channel|. There's no reason for us to continue to exist afterwards. | |
284 | |
285 s->consumer_num_bytes = consumer_num_bytes_; | |
286 // Note: We don't use |port|. | |
287 scoped_refptr<ChannelEndpoint> channel_endpoint; | |
288 channel_endpoint.swap(channel_endpoint_); | |
289 channel->SerializeEndpointWithRemotePeer(destination_for_endpoint, nullptr, | |
290 channel_endpoint); | |
291 owner()->SetConsumerClosedNoLock(); | |
Hajime Morrita
2015/03/03 03:00:38
This isn't directly related to this CL, but it'd b
viettrungluu
2015/03/03 05:17:45
Yeah, things aren't factored quite right (partly a
| |
292 | |
293 *actual_size = sizeof(SerializedDataPipeProducerDispatcher) + | |
294 channel->GetSerializedEndpointSize(); | |
295 return true; | |
273 } | 296 } |
274 | 297 |
275 void RemoteConsumerDataPipeImpl::ConsumerClose() { | 298 void RemoteConsumerDataPipeImpl::ConsumerClose() { |
276 NOTREACHED(); | 299 NOTREACHED(); |
277 } | 300 } |
278 | 301 |
279 MojoResult RemoteConsumerDataPipeImpl::ConsumerReadData( | 302 MojoResult RemoteConsumerDataPipeImpl::ConsumerReadData( |
280 UserPointer<void> /*elements*/, | 303 UserPointer<void> /*elements*/, |
281 UserPointer<uint32_t> /*num_bytes*/, | 304 UserPointer<uint32_t> /*num_bytes*/, |
282 uint32_t /*max_num_bytes_to_read*/, | 305 uint32_t /*max_num_bytes_to_read*/, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 DCHECK(consumer_open()); | 409 DCHECK(consumer_open()); |
387 DCHECK(channel_endpoint_); | 410 DCHECK(channel_endpoint_); |
388 owner()->SetConsumerClosedNoLock(); | 411 owner()->SetConsumerClosedNoLock(); |
389 channel_endpoint_->DetachFromClient(); | 412 channel_endpoint_->DetachFromClient(); |
390 channel_endpoint_ = nullptr; | 413 channel_endpoint_ = nullptr; |
391 DestroyBuffer(); | 414 DestroyBuffer(); |
392 } | 415 } |
393 | 416 |
394 } // namespace system | 417 } // namespace system |
395 } // namespace mojo | 418 } // namespace mojo |
OLD | NEW |