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 "mojo/edk/system/incoming_endpoint.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "mojo/edk/system/channel_endpoint.h" |
| 9 #include "mojo/edk/system/message_in_transit.h" |
| 10 #include "mojo/edk/system/message_pipe.h" |
| 11 |
| 12 namespace mojo { |
| 13 namespace system { |
| 14 |
| 15 IncomingEndpoint::IncomingEndpoint() { |
| 16 } |
| 17 |
| 18 scoped_refptr<ChannelEndpoint> IncomingEndpoint::Init() { |
| 19 endpoint_ = new ChannelEndpoint(this, 0); |
| 20 return endpoint_; |
| 21 } |
| 22 |
| 23 scoped_refptr<MessagePipe> IncomingEndpoint::ConvertToMessagePipe() { |
| 24 base::AutoLock locker(lock_); |
| 25 scoped_refptr<MessagePipe> message_pipe( |
| 26 MessagePipe::CreateLocalProxyFromExisting(&message_queue_, |
| 27 endpoint_.get())); |
| 28 DCHECK(message_queue_.IsEmpty()); |
| 29 endpoint_ = nullptr; |
| 30 return message_pipe; |
| 31 } |
| 32 |
| 33 void IncomingEndpoint::Close() { |
| 34 base::AutoLock locker(lock_); |
| 35 if (endpoint_) { |
| 36 endpoint_->DetachFromClient(); |
| 37 endpoint_ = nullptr; |
| 38 } |
| 39 } |
| 40 |
| 41 bool IncomingEndpoint::OnReadMessage(unsigned /*port*/, |
| 42 MessageInTransit* message) { |
| 43 base::AutoLock locker(lock_); |
| 44 if (!endpoint_) |
| 45 return false; |
| 46 |
| 47 message_queue_.AddMessage(make_scoped_ptr(message)); |
| 48 return true; |
| 49 } |
| 50 |
| 51 void IncomingEndpoint::OnDetachFromChannel(unsigned /*port*/) { |
| 52 Close(); |
| 53 } |
| 54 |
| 55 IncomingEndpoint::~IncomingEndpoint() { |
| 56 } |
| 57 |
| 58 } // namespace system |
| 59 } // namespace mojo |
OLD | NEW |