| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "third_party/mojo/src/mojo/edk/system/incoming_endpoint.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "third_party/mojo/src/mojo/edk/system/channel_endpoint.h" | |
| 9 #include "third_party/mojo/src/mojo/edk/system/data_pipe.h" | |
| 10 #include "third_party/mojo/src/mojo/edk/system/message_in_transit.h" | |
| 11 #include "third_party/mojo/src/mojo/edk/system/message_pipe.h" | |
| 12 #include "third_party/mojo/src/mojo/edk/system/remote_producer_data_pipe_impl.h" | |
| 13 | |
| 14 namespace mojo { | |
| 15 namespace system { | |
| 16 | |
| 17 IncomingEndpoint::IncomingEndpoint() { | |
| 18 } | |
| 19 | |
| 20 scoped_refptr<ChannelEndpoint> IncomingEndpoint::Init() { | |
| 21 endpoint_ = new ChannelEndpoint(this, 0); | |
| 22 return endpoint_; | |
| 23 } | |
| 24 | |
| 25 scoped_refptr<MessagePipe> IncomingEndpoint::ConvertToMessagePipe() { | |
| 26 MutexLocker locker(&mutex_); | |
| 27 scoped_refptr<MessagePipe> message_pipe( | |
| 28 MessagePipe::CreateLocalProxyFromExisting(&message_queue_, | |
| 29 endpoint_.get())); | |
| 30 DCHECK(message_queue_.IsEmpty()); | |
| 31 endpoint_ = nullptr; | |
| 32 return message_pipe; | |
| 33 } | |
| 34 | |
| 35 scoped_refptr<DataPipe> IncomingEndpoint::ConvertToDataPipeProducer( | |
| 36 const MojoCreateDataPipeOptions& validated_options, | |
| 37 size_t consumer_num_bytes) { | |
| 38 MutexLocker locker(&mutex_); | |
| 39 scoped_refptr<DataPipe> data_pipe(DataPipe::CreateRemoteConsumerFromExisting( | |
| 40 validated_options, consumer_num_bytes, &message_queue_, endpoint_.get())); | |
| 41 DCHECK(message_queue_.IsEmpty()); | |
| 42 endpoint_ = nullptr; | |
| 43 return data_pipe; | |
| 44 } | |
| 45 | |
| 46 scoped_refptr<DataPipe> IncomingEndpoint::ConvertToDataPipeConsumer( | |
| 47 const MojoCreateDataPipeOptions& validated_options) { | |
| 48 MutexLocker locker(&mutex_); | |
| 49 scoped_refptr<DataPipe> data_pipe(DataPipe::CreateRemoteProducerFromExisting( | |
| 50 validated_options, &message_queue_, endpoint_.get())); | |
| 51 DCHECK(message_queue_.IsEmpty()); | |
| 52 endpoint_ = nullptr; | |
| 53 return data_pipe; | |
| 54 } | |
| 55 | |
| 56 void IncomingEndpoint::Close() { | |
| 57 MutexLocker locker(&mutex_); | |
| 58 if (endpoint_) { | |
| 59 endpoint_->DetachFromClient(); | |
| 60 endpoint_ = nullptr; | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 bool IncomingEndpoint::OnReadMessage(unsigned /*port*/, | |
| 65 MessageInTransit* message) { | |
| 66 MutexLocker locker(&mutex_); | |
| 67 if (!endpoint_) | |
| 68 return false; | |
| 69 | |
| 70 message_queue_.AddMessage(make_scoped_ptr(message)); | |
| 71 return true; | |
| 72 } | |
| 73 | |
| 74 void IncomingEndpoint::OnDetachFromChannel(unsigned /*port*/) { | |
| 75 Close(); | |
| 76 } | |
| 77 | |
| 78 IncomingEndpoint::~IncomingEndpoint() { | |
| 79 } | |
| 80 | |
| 81 } // namespace system | |
| 82 } // namespace mojo | |
| OLD | NEW |