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/core.h" | 5 #include "mojo/edk/system/core.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 if (!dispatcher) | 466 if (!dispatcher) |
467 return MOJO_RESULT_INVALID_ARGUMENT; | 467 return MOJO_RESULT_INVALID_ARGUMENT; |
468 return dispatcher->CancelWatch(context); | 468 return dispatcher->CancelWatch(context); |
469 } | 469 } |
470 | 470 |
471 MojoResult Core::AllocMessage(uint32_t num_bytes, | 471 MojoResult Core::AllocMessage(uint32_t num_bytes, |
472 const MojoHandle* handles, | 472 const MojoHandle* handles, |
473 uint32_t num_handles, | 473 uint32_t num_handles, |
474 MojoAllocMessageFlags flags, | 474 MojoAllocMessageFlags flags, |
475 MojoMessageHandle* message) { | 475 MojoMessageHandle* message) { |
476 if (!message) | 476 DCHECK(message); |
477 return MOJO_RESULT_INVALID_ARGUMENT; | |
478 | 477 |
479 if (num_handles == 0) { // Fast path: no handles. | 478 if (num_handles == 0) { // Fast path: no handles. |
480 std::unique_ptr<MessageForTransit> msg; | 479 std::unique_ptr<MessageForTransit> msg; |
481 MojoResult rv = MessageForTransit::Create(&msg, num_bytes, nullptr, 0); | 480 MojoResult rv = MessageForTransit::Create(&msg, num_bytes, nullptr, 0); |
482 if (rv != MOJO_RESULT_OK) | 481 DCHECK(rv == MOJO_RESULT_OK) << rv; |
483 return rv; | |
484 | 482 |
485 *message = reinterpret_cast<MojoMessageHandle>(msg.release()); | 483 *message = reinterpret_cast<MojoMessageHandle>(msg.release()); |
486 return MOJO_RESULT_OK; | 484 return MOJO_RESULT_OK; |
487 } | 485 } |
488 | 486 |
489 if (!handles) | 487 DCHECK(handles); |
490 return MOJO_RESULT_INVALID_ARGUMENT; | |
491 | 488 |
492 if (num_handles > kMaxHandlesPerMessage) | 489 if (num_handles > kMaxHandlesPerMessage) |
493 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 490 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
494 | 491 |
495 std::vector<Dispatcher::DispatcherInTransit> dispatchers; | 492 std::vector<Dispatcher::DispatcherInTransit> dispatchers; |
496 { | 493 { |
497 base::AutoLock lock(handles_lock_); | 494 base::AutoLock lock(handles_lock_); |
498 MojoResult rv = handles_.BeginTransit(handles, num_handles, &dispatchers); | 495 MojoResult rv = handles_.BeginTransit(handles, num_handles, &dispatchers); |
499 if (rv != MOJO_RESULT_OK) { | 496 DCHECK(rv == MOJO_RESULT_OK) << rv; |
500 handles_.CancelTransit(dispatchers); | |
501 return rv; | |
502 } | |
503 } | 497 } |
504 DCHECK_EQ(num_handles, dispatchers.size()); | 498 DCHECK_EQ(num_handles, dispatchers.size()); |
505 | 499 |
506 std::unique_ptr<MessageForTransit> msg; | 500 std::unique_ptr<MessageForTransit> msg; |
507 MojoResult rv = MessageForTransit::Create( | 501 MojoResult rv = MessageForTransit::Create( |
508 &msg, num_bytes, dispatchers.data(), num_handles); | 502 &msg, num_bytes, dispatchers.data(), num_handles); |
509 | 503 |
510 { | 504 { |
511 base::AutoLock lock(handles_lock_); | 505 base::AutoLock lock(handles_lock_); |
512 if (rv == MOJO_RESULT_OK) { | 506 if (rv == MOJO_RESULT_OK) { |
513 handles_.CompleteTransitAndClose(dispatchers); | 507 handles_.CompleteTransitAndClose(dispatchers); |
514 *message = reinterpret_cast<MojoMessageHandle>(msg.release()); | 508 *message = reinterpret_cast<MojoMessageHandle>(msg.release()); |
515 } else { | 509 } else { |
516 handles_.CancelTransit(dispatchers); | 510 handles_.CancelTransit(dispatchers); |
517 } | 511 } |
518 } | 512 } |
519 | 513 |
| 514 DCHECK(rv == MOJO_RESULT_OK) << rv; |
520 return rv; | 515 return rv; |
521 } | 516 } |
522 | 517 |
523 MojoResult Core::FreeMessage(MojoMessageHandle message) { | 518 MojoResult Core::FreeMessage(MojoMessageHandle message) { |
524 if (!message) | 519 if (!message) |
525 return MOJO_RESULT_INVALID_ARGUMENT; | 520 return MOJO_RESULT_INVALID_ARGUMENT; |
526 | 521 |
527 delete reinterpret_cast<MessageForTransit*>(message); | 522 delete reinterpret_cast<MessageForTransit*>(message); |
528 | 523 |
529 return MOJO_RESULT_OK; | 524 return MOJO_RESULT_OK; |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 std::unique_ptr<NodeController> node_controller) { | 1185 std::unique_ptr<NodeController> node_controller) { |
1191 // It's OK to leak this reference. At this point we know the IO loop is still | 1186 // It's OK to leak this reference. At this point we know the IO loop is still |
1192 // running, and we know the NodeController will observe its eventual | 1187 // running, and we know the NodeController will observe its eventual |
1193 // destruction. This tells the NodeController to delete itself when that | 1188 // destruction. This tells the NodeController to delete itself when that |
1194 // happens. | 1189 // happens. |
1195 node_controller.release()->DestroyOnIOThreadShutdown(); | 1190 node_controller.release()->DestroyOnIOThreadShutdown(); |
1196 } | 1191 } |
1197 | 1192 |
1198 } // namespace edk | 1193 } // namespace edk |
1199 } // namespace mojo | 1194 } // namespace mojo |
OLD | NEW |