Index: mojo/edk/system/incoming_endpoint.cc |
diff --git a/mojo/edk/system/incoming_endpoint.cc b/mojo/edk/system/incoming_endpoint.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..14f1a71816287e0a4e41dacece0838aac099b036 |
--- /dev/null |
+++ b/mojo/edk/system/incoming_endpoint.cc |
@@ -0,0 +1,59 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "mojo/edk/system/incoming_endpoint.h" |
+ |
+#include "base/logging.h" |
+#include "mojo/edk/system/channel_endpoint.h" |
+#include "mojo/edk/system/message_in_transit.h" |
+#include "mojo/edk/system/message_pipe.h" |
+ |
+namespace mojo { |
+namespace system { |
+ |
+IncomingEndpoint::IncomingEndpoint() { |
+} |
+ |
+scoped_refptr<ChannelEndpoint> IncomingEndpoint::Init() { |
+ endpoint_ = new ChannelEndpoint(this, 0); |
+ return endpoint_; |
+} |
+ |
+scoped_refptr<MessagePipe> IncomingEndpoint::ConvertToMessagePipe() { |
+ base::AutoLock locker(lock_); |
+ scoped_refptr<MessagePipe> message_pipe( |
+ MessagePipe::CreateLocalProxyFromExisting(&message_queue_, |
+ endpoint_.get())); |
+ DCHECK(message_queue_.IsEmpty()); |
+ endpoint_ = nullptr; |
+ return message_pipe; |
+} |
+ |
+void IncomingEndpoint::Close() { |
+ base::AutoLock locker(lock_); |
+ if (endpoint_) { |
+ endpoint_->DetachFromClient(); |
+ endpoint_ = nullptr; |
+ } |
+} |
+ |
+bool IncomingEndpoint::OnReadMessage(unsigned /*port*/, |
+ MessageInTransit* message) { |
+ base::AutoLock locker(lock_); |
+ if (!endpoint_) |
+ return false; |
+ |
+ message_queue_.AddMessage(make_scoped_ptr(message)); |
+ return true; |
+} |
+ |
+void IncomingEndpoint::OnDetachFromChannel(unsigned /*port*/) { |
+ Close(); |
+} |
+ |
+IncomingEndpoint::~IncomingEndpoint() { |
+} |
+ |
+} // namespace system |
+} // namespace mojo |