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/message_pipe.h" | 5 #include "mojo/edk/system/message_pipe.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/edk/system/channel.h" | 8 #include "mojo/edk/system/channel.h" |
9 #include "mojo/edk/system/channel_endpoint.h" | 9 #include "mojo/edk/system/channel_endpoint.h" |
10 #include "mojo/edk/system/channel_endpoint_id.h" | 10 #include "mojo/edk/system/channel_endpoint_id.h" |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 // You're not allowed to send either handle to a message pipe over the message | 345 // You're not allowed to send either handle to a message pipe over the message |
346 // pipe, so check for this. (The case of trying to write a handle to itself is | 346 // pipe, so check for this. (The case of trying to write a handle to itself is |
347 // taken care of by |Core|. That case kind of makes sense, but leads to | 347 // taken care of by |Core|. That case kind of makes sense, but leads to |
348 // complications if, e.g., both sides try to do the same thing with their | 348 // complications if, e.g., both sides try to do the same thing with their |
349 // respective handles simultaneously. The other case, of trying to write the | 349 // respective handles simultaneously. The other case, of trying to write the |
350 // peer handle to a handle, doesn't make sense -- since no handle will be | 350 // peer handle to a handle, doesn't make sense -- since no handle will be |
351 // available to read the message from.) | 351 // available to read the message from.) |
352 for (size_t i = 0; i < transports->size(); i++) { | 352 for (size_t i = 0; i < transports->size(); i++) { |
353 if (!(*transports)[i].is_valid()) | 353 if (!(*transports)[i].is_valid()) |
354 continue; | 354 continue; |
355 if ((*transports)[i].GetType() == Dispatcher::kTypeMessagePipe) { | 355 if ((*transports)[i].GetType() == Dispatcher::Type::MESSAGE_PIPE) { |
356 MessagePipeDispatcherTransport mp_transport((*transports)[i]); | 356 MessagePipeDispatcherTransport mp_transport((*transports)[i]); |
357 if (mp_transport.GetMessagePipe() == this) { | 357 if (mp_transport.GetMessagePipe() == this) { |
358 // The other case should have been disallowed by |Core|. (Note: |port| | 358 // The other case should have been disallowed by |Core|. (Note: |port| |
359 // is the peer port of the handle given to |WriteMessage()|.) | 359 // is the peer port of the handle given to |WriteMessage()|.) |
360 DCHECK_EQ(mp_transport.GetPort(), port); | 360 DCHECK_EQ(mp_transport.GetPort(), port); |
361 return MOJO_RESULT_INVALID_ARGUMENT; | 361 return MOJO_RESULT_INVALID_ARGUMENT; |
362 } | 362 } |
363 } | 363 } |
364 } | 364 } |
365 | 365 |
366 // Clone the dispatchers and attach them to the message. (This must be done as | 366 // Clone the dispatchers and attach them to the message. (This must be done as |
367 // a separate loop, since we want to leave the dispatchers alone on failure.) | 367 // a separate loop, since we want to leave the dispatchers alone on failure.) |
368 scoped_ptr<DispatcherVector> dispatchers(new DispatcherVector()); | 368 scoped_ptr<DispatcherVector> dispatchers(new DispatcherVector()); |
369 dispatchers->reserve(transports->size()); | 369 dispatchers->reserve(transports->size()); |
370 for (size_t i = 0; i < transports->size(); i++) { | 370 for (size_t i = 0; i < transports->size(); i++) { |
371 if ((*transports)[i].is_valid()) { | 371 if ((*transports)[i].is_valid()) { |
372 dispatchers->push_back( | 372 dispatchers->push_back( |
373 (*transports)[i].CreateEquivalentDispatcherAndClose()); | 373 (*transports)[i].CreateEquivalentDispatcherAndClose()); |
374 } else { | 374 } else { |
375 LOG(WARNING) << "Enqueueing null dispatcher"; | 375 LOG(WARNING) << "Enqueueing null dispatcher"; |
376 dispatchers->push_back(nullptr); | 376 dispatchers->push_back(nullptr); |
377 } | 377 } |
378 } | 378 } |
379 message->SetDispatchers(dispatchers.Pass()); | 379 message->SetDispatchers(dispatchers.Pass()); |
380 return MOJO_RESULT_OK; | 380 return MOJO_RESULT_OK; |
381 } | 381 } |
382 | 382 |
383 } // namespace system | 383 } // namespace system |
384 } // namespace mojo | 384 } // namespace mojo |
OLD | NEW |