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/system/proxy_message_pipe_endpoint.h" | 5 #include "mojo/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/system/channel_endpoint.h" | 10 #include "mojo/system/channel_endpoint.h" |
11 #include "mojo/system/local_message_pipe_endpoint.h" | 11 #include "mojo/system/local_message_pipe_endpoint.h" |
12 #include "mojo/system/message_pipe_dispatcher.h" | 12 #include "mojo/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(!is_attached()); | 23 channel_endpoint_->DetachFromMessagePipe(); |
24 } | 24 } |
25 | 25 |
26 MessagePipeEndpoint::Type ProxyMessagePipeEndpoint::GetType() const { | 26 MessagePipeEndpoint::Type ProxyMessagePipeEndpoint::GetType() const { |
27 return kTypeProxy; | 27 return kTypeProxy; |
28 } | 28 } |
29 | 29 |
30 bool ProxyMessagePipeEndpoint::OnPeerClose() { | 30 bool ProxyMessagePipeEndpoint::OnPeerClose() { |
31 if (is_attached()) | |
32 Detach(); | |
33 | |
34 return false; | 31 return false; |
35 } | 32 } |
36 | 33 |
37 // Note: We may have to enqueue messages even when our (local) peer isn't open | 34 // Note: We may have to enqueue messages even when our (local) peer isn't open |
38 // -- it may have been written to and closed immediately, before we were ready. | 35 // -- it may have been written to and closed immediately, before we were ready. |
39 // This case is handled in |Run()| (which will call us). | 36 // This case is handled in |Run()| (which will call us). |
40 void ProxyMessagePipeEndpoint::EnqueueMessage( | 37 void ProxyMessagePipeEndpoint::EnqueueMessage( |
41 scoped_ptr<MessageInTransit> message) { | 38 scoped_ptr<MessageInTransit> message) { |
42 DCHECK(channel_endpoint_.get()); | 39 DCHECK(channel_endpoint_.get()); |
43 LOG_IF(WARNING, !channel_endpoint_->EnqueueMessage(message.Pass())) | 40 LOG_IF(WARNING, !channel_endpoint_->EnqueueMessage(message.Pass())) |
44 << "Failed to write enqueue message to channel"; | 41 << "Failed to write enqueue message to channel"; |
45 } | 42 } |
46 | 43 |
47 void ProxyMessagePipeEndpoint::OnRemove() { | |
48 Detach(); | |
49 } | |
50 | |
51 void ProxyMessagePipeEndpoint::Detach() { | |
52 DCHECK(is_attached()); | |
53 | |
54 channel_endpoint_->DetachFromMessagePipe(); | |
55 channel_endpoint_ = nullptr; | |
56 } | |
57 | |
58 } // namespace system | 44 } // namespace system |
59 } // namespace mojo | 45 } // namespace mojo |
OLD | NEW |