| 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 "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool ProxyMessagePipeEndpoint::OnPeerClose() { | 49 bool ProxyMessagePipeEndpoint::OnPeerClose() { |
| 50 DCHECK(is_open_); | 50 DCHECK(is_open_); |
| 51 DCHECK(is_peer_open_); | 51 DCHECK(is_peer_open_); |
| 52 | 52 |
| 53 is_peer_open_ = false; | 53 is_peer_open_ = false; |
| 54 if (EnqueueMessage(MessageInTransit::Create( | 54 if (EnqueueMessage(MessageInTransit::Create( |
| 55 MessageInTransit::kTypeMessagePipe, | 55 MessageInTransit::kTypeMessagePipe, |
| 56 MessageInTransit::kSubtypeMessagePipePeerClosed, | 56 MessageInTransit::kSubtypeMessagePipePeerClosed, |
| 57 NULL, 0)) != MOJO_RESULT_OK) { | 57 NULL, 0), NULL) != MOJO_RESULT_OK) { |
| 58 // TODO(vtl): Do something more sensible on error here? | 58 // TODO(vtl): Do something more sensible on error here? |
| 59 LOG(WARNING) << "Failed to send peer closed control message"; | 59 LOG(WARNING) << "Failed to send peer closed control message"; |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Return false -- to indicate that we should be destroyed -- if no messages | 62 // Return false -- to indicate that we should be destroyed -- if no messages |
| 63 // are still enqueued. (Messages may still be enqueued if we're not running | 63 // are still enqueued. (Messages may still be enqueued if we're not running |
| 64 // yet, but our peer was closed.) | 64 // yet, but our peer was closed.) |
| 65 return !paused_message_queue_.empty(); | 65 return !paused_message_queue_.empty(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 MojoResult ProxyMessagePipeEndpoint::EnqueueMessage(MessageInTransit* message) { | 68 MojoResult ProxyMessagePipeEndpoint::EnqueueMessage( |
| 69 MessageInTransit* message, |
| 70 const std::vector<Dispatcher*>* dispatchers) { |
| 69 DCHECK(is_open_); | 71 DCHECK(is_open_); |
| 70 // If our (local) peer isn't open, we should only be enqueueing our own | 72 // If our (local) peer isn't open, we should only be enqueueing our own |
| 71 // control messages. | 73 // control messages. |
| 72 DCHECK(is_peer_open_ || | 74 DCHECK(is_peer_open_ || |
| 73 (message->type() == MessageInTransit::kTypeMessagePipe)); | 75 (message->type() == MessageInTransit::kTypeMessagePipe)); |
| 74 | 76 |
| 77 // TODO(vtl): Support sending handles over OS pipes. |
| 78 if (dispatchers) { |
| 79 message->Destroy(); |
| 80 NOTIMPLEMENTED(); |
| 81 return MOJO_RESULT_UNIMPLEMENTED; |
| 82 } |
| 83 |
| 75 MojoResult rv = MOJO_RESULT_OK; | 84 MojoResult rv = MOJO_RESULT_OK; |
| 76 | 85 |
| 77 if (is_running()) { | 86 if (is_running()) { |
| 78 message->set_source_id(local_id_); | 87 message->set_source_id(local_id_); |
| 79 message->set_destination_id(remote_id_); | 88 message->set_destination_id(remote_id_); |
| 80 if (!channel_->WriteMessage(message)) | 89 if (!channel_->WriteMessage(message)) |
| 81 rv = MOJO_RESULT_FAILED_PRECONDITION; | 90 rv = MOJO_RESULT_FAILED_PRECONDITION; |
| 82 } else { | 91 } else { |
| 83 paused_message_queue_.push_back(message); | 92 paused_message_queue_.push_back(message); |
| 84 } | 93 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 109 | 118 |
| 110 AssertConsistentState(); | 119 AssertConsistentState(); |
| 111 remote_id_ = remote_id; | 120 remote_id_ = remote_id; |
| 112 AssertConsistentState(); | 121 AssertConsistentState(); |
| 113 | 122 |
| 114 MojoResult result = MOJO_RESULT_OK; | 123 MojoResult result = MOJO_RESULT_OK; |
| 115 for (std::deque<MessageInTransit*>::iterator it = | 124 for (std::deque<MessageInTransit*>::iterator it = |
| 116 paused_message_queue_.begin(); | 125 paused_message_queue_.begin(); |
| 117 it != paused_message_queue_.end(); | 126 it != paused_message_queue_.end(); |
| 118 ++it) { | 127 ++it) { |
| 119 result = EnqueueMessage(*it); | 128 result = EnqueueMessage(*it, NULL); |
| 120 if (result != MOJO_RESULT_OK) { | 129 if (result != MOJO_RESULT_OK) { |
| 121 // TODO(vtl): Do something more sensible on error here? | 130 // TODO(vtl): Do something more sensible on error here? |
| 122 LOG(WARNING) << "Failed to send message"; | 131 LOG(WARNING) << "Failed to send message"; |
| 123 } | 132 } |
| 124 } | 133 } |
| 125 paused_message_queue_.clear(); | 134 paused_message_queue_.clear(); |
| 126 | 135 |
| 127 // If the peer is not open, we should return false since we should be | 136 // If the peer is not open, we should return false since we should be |
| 128 // destroyed. | 137 // destroyed. |
| 129 return is_peer_open_; | 138 return is_peer_open_; |
| 130 } | 139 } |
| 131 | 140 |
| 132 #ifndef NDEBUG | 141 #ifndef NDEBUG |
| 133 void ProxyMessagePipeEndpoint::AssertConsistentState() const { | 142 void ProxyMessagePipeEndpoint::AssertConsistentState() const { |
| 134 if (is_attached()) { | 143 if (is_attached()) { |
| 135 DCHECK_NE(local_id_, MessageInTransit::kInvalidEndpointId); | 144 DCHECK_NE(local_id_, MessageInTransit::kInvalidEndpointId); |
| 136 } else { // Not attached. | 145 } else { // Not attached. |
| 137 DCHECK_EQ(local_id_, MessageInTransit::kInvalidEndpointId); | 146 DCHECK_EQ(local_id_, MessageInTransit::kInvalidEndpointId); |
| 138 DCHECK_EQ(remote_id_, MessageInTransit::kInvalidEndpointId); | 147 DCHECK_EQ(remote_id_, MessageInTransit::kInvalidEndpointId); |
| 139 } | 148 } |
| 140 } | 149 } |
| 141 #endif | 150 #endif |
| 142 | 151 |
| 143 } // namespace system | 152 } // namespace system |
| 144 } // namespace mojo | 153 } // namespace mojo |
| OLD | NEW |