Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(853)

Side by Side Diff: mojo/system/message_pipe.cc

Issue 147983009: Mojo: Refactor some message pipe stuff. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/system/message_pipe.h ('k') | mojo/system/message_pipe_endpoint.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_pipe.h" 5 #include "mojo/system/message_pipe.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "mojo/system/channel.h" 8 #include "mojo/system/channel.h"
9 #include "mojo/system/dispatcher.h" 9 #include "mojo/system/dispatcher.h"
10 #include "mojo/system/local_message_pipe_endpoint.h" 10 #include "mojo/system/local_message_pipe_endpoint.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 endpoints_[port]->RemoveWaiter(waiter); 108 endpoints_[port]->RemoveWaiter(waiter);
109 } 109 }
110 110
111 MojoResult MessagePipe::EnqueueMessage( 111 MojoResult MessagePipe::EnqueueMessage(
112 unsigned port, 112 unsigned port,
113 MessageInTransit* message, 113 MessageInTransit* message,
114 const std::vector<Dispatcher*>* dispatchers) { 114 const std::vector<Dispatcher*>* dispatchers) {
115 DCHECK(port == 0 || port == 1); 115 DCHECK(port == 0 || port == 1);
116 DCHECK(message); 116 DCHECK(message);
117 DCHECK(!dispatchers || !dispatchers->empty());
117 118
118 if (message->type() == MessageInTransit::kTypeMessagePipe) { 119 if (message->type() == MessageInTransit::kTypeMessagePipe) {
119 DCHECK(!dispatchers); 120 DCHECK(!dispatchers);
120 return HandleControlMessage(port, message); 121 return HandleControlMessage(port, message);
121 } 122 }
122 123
123 DCHECK_EQ(message->type(), MessageInTransit::kTypeMessagePipeEndpoint); 124 DCHECK_EQ(message->type(), MessageInTransit::kTypeMessagePipeEndpoint);
124 125
125 base::AutoLock locker(lock_); 126 base::AutoLock locker(lock_);
126 DCHECK(endpoints_[GetPeerPort(port)].get()); 127 DCHECK(endpoints_[GetPeerPort(port)].get());
127 128
128 // The destination port need not be open, unlike the source port. 129 // The destination port need not be open, unlike the source port.
129 if (!endpoints_[port].get()) { 130 if (!endpoints_[port].get()) {
130 message->Destroy(); 131 message->Destroy();
131 return MOJO_RESULT_FAILED_PRECONDITION; 132 return MOJO_RESULT_FAILED_PRECONDITION;
132 } 133 }
133 134
134 MojoResult result = endpoints_[port]->CanEnqueueMessage(message, dispatchers); 135 return endpoints_[port]->EnqueueMessage(message, dispatchers);
135 if (result != MOJO_RESULT_OK) {
136 message->Destroy();
137 return result;
138 }
139
140 if (dispatchers) {
141 DCHECK(!dispatchers->empty());
142
143 std::vector<scoped_refptr<Dispatcher> > replacement_dispatchers;
144 for (size_t i = 0; i < dispatchers->size(); i++) {
145 replacement_dispatchers.push_back(
146 (*dispatchers)[i]->CreateEquivalentDispatcherAndCloseNoLock());
147 }
148
149 endpoints_[port]->EnqueueMessage(message, &replacement_dispatchers);
150 } else {
151 endpoints_[port]->EnqueueMessage(message, NULL);
152 }
153
154 return MOJO_RESULT_OK;
155 } 136 }
156 137
157 void MessagePipe::Attach(unsigned port, 138 void MessagePipe::Attach(unsigned port,
158 scoped_refptr<Channel> channel, 139 scoped_refptr<Channel> channel,
159 MessageInTransit::EndpointId local_id) { 140 MessageInTransit::EndpointId local_id) {
160 DCHECK(port == 0 || port == 1); 141 DCHECK(port == 0 || port == 1);
161 DCHECK(channel.get()); 142 DCHECK(channel.get());
162 DCHECK_NE(local_id, MessageInTransit::kInvalidEndpointId); 143 DCHECK_NE(local_id, MessageInTransit::kInvalidEndpointId);
163 144
164 base::AutoLock locker(lock_); 145 base::AutoLock locker(lock_);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 rv = MOJO_RESULT_UNKNOWN; 192 rv = MOJO_RESULT_UNKNOWN;
212 break; 193 break;
213 } 194 }
214 195
215 message->Destroy(); 196 message->Destroy();
216 return rv; 197 return rv;
217 } 198 }
218 199
219 } // namespace system 200 } // namespace system
220 } // namespace mojo 201 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/message_pipe.h ('k') | mojo/system/message_pipe_endpoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698