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 #include "mojo/edk/system/proxy_message_pipe_endpoint.h" | 5 #include "mojo/edk/system/proxy_message_pipe_endpoint.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "mojo/edk/system/channel_endpoint.h" | 10 #include "mojo/edk/system/channel_endpoint.h" |
11 #include "mojo/edk/system/local_message_pipe_endpoint.h" | 11 #include "mojo/edk/system/local_message_pipe_endpoint.h" |
12 #include "mojo/edk/system/message_pipe_dispatcher.h" | 12 #include "mojo/edk/system/message_pipe_dispatcher.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 namespace system { | 15 namespace system { |
16 | 16 |
17 ProxyMessagePipeEndpoint::ProxyMessagePipeEndpoint( | 17 ProxyMessagePipeEndpoint::ProxyMessagePipeEndpoint( |
18 ChannelEndpoint* channel_endpoint) | 18 ChannelEndpoint* channel_endpoint) |
19 : channel_endpoint_(channel_endpoint) { | 19 : channel_endpoint_(channel_endpoint) { |
20 } | 20 } |
21 | 21 |
22 ProxyMessagePipeEndpoint::~ProxyMessagePipeEndpoint() { | 22 ProxyMessagePipeEndpoint::~ProxyMessagePipeEndpoint() { |
23 DCHECK(!channel_endpoint_.get()); | 23 DCHECK(!channel_endpoint_); |
| 24 } |
| 25 |
| 26 scoped_refptr<ChannelEndpoint> |
| 27 ProxyMessagePipeEndpoint::ReleaseChannelEndpoint() { |
| 28 DCHECK(channel_endpoint_); |
| 29 scoped_refptr<ChannelEndpoint> rv; |
| 30 rv.swap(channel_endpoint_); |
| 31 return rv; |
24 } | 32 } |
25 | 33 |
26 MessagePipeEndpoint::Type ProxyMessagePipeEndpoint::GetType() const { | 34 MessagePipeEndpoint::Type ProxyMessagePipeEndpoint::GetType() const { |
27 return kTypeProxy; | 35 return kTypeProxy; |
28 } | 36 } |
29 | 37 |
30 bool ProxyMessagePipeEndpoint::OnPeerClose() { | 38 bool ProxyMessagePipeEndpoint::OnPeerClose() { |
31 DetachIfNecessary(); | 39 DetachIfNecessary(); |
32 return false; | 40 return false; |
33 } | 41 } |
34 | 42 |
35 // Note: We may have to enqueue messages even when our (local) peer isn't open | 43 // Note: We may have to enqueue messages even when our (local) peer isn't open |
36 // -- it may have been written to and closed immediately, before we were ready. | 44 // -- it may have been written to and closed immediately, before we were ready. |
37 // This case is handled in |Run()| (which will call us). | 45 // This case is handled in |Run()| (which will call us). |
38 void ProxyMessagePipeEndpoint::EnqueueMessage( | 46 void ProxyMessagePipeEndpoint::EnqueueMessage( |
39 scoped_ptr<MessageInTransit> message) { | 47 scoped_ptr<MessageInTransit> message) { |
40 DCHECK(channel_endpoint_.get()); | 48 DCHECK(channel_endpoint_); |
41 LOG_IF(WARNING, !channel_endpoint_->EnqueueMessage(message.Pass())) | 49 LOG_IF(WARNING, !channel_endpoint_->EnqueueMessage(message.Pass())) |
42 << "Failed to write enqueue message to channel"; | 50 << "Failed to write enqueue message to channel"; |
43 } | 51 } |
44 | 52 |
45 void ProxyMessagePipeEndpoint::Close() { | 53 void ProxyMessagePipeEndpoint::Close() { |
46 DetachIfNecessary(); | 54 DetachIfNecessary(); |
47 } | 55 } |
48 | 56 |
49 void ProxyMessagePipeEndpoint::DetachIfNecessary() { | 57 void ProxyMessagePipeEndpoint::DetachIfNecessary() { |
50 if (channel_endpoint_.get()) { | 58 if (channel_endpoint_) { |
51 channel_endpoint_->DetachFromClient(); | 59 channel_endpoint_->DetachFromClient(); |
52 channel_endpoint_ = nullptr; | 60 channel_endpoint_ = nullptr; |
53 } | 61 } |
54 } | 62 } |
55 | 63 |
56 } // namespace system | 64 } // namespace system |
57 } // namespace mojo | 65 } // namespace mojo |
OLD | NEW |