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

Unified Diff: mojo/system/local_message_pipe_endpoint.cc

Issue 147983009: Mojo: Refactor some message pipe stuff. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/system/local_message_pipe_endpoint.h ('k') | mojo/system/message_pipe.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/system/local_message_pipe_endpoint.cc
diff --git a/mojo/system/local_message_pipe_endpoint.cc b/mojo/system/local_message_pipe_endpoint.cc
index 92f64df0f0bd6df0dd46e5954f6bb13bb3503866..7f7b96dab68dbcb6b5c6140bc3c9b68477643a96 100644
--- a/mojo/system/local_message_pipe_endpoint.cc
+++ b/mojo/system/local_message_pipe_endpoint.cc
@@ -14,26 +14,52 @@ namespace mojo {
namespace system {
LocalMessagePipeEndpoint::MessageQueueEntry::MessageQueueEntry()
- : message(NULL) {
+ : message_(NULL) {
}
// See comment in header file.
LocalMessagePipeEndpoint::MessageQueueEntry::MessageQueueEntry(
const MessageQueueEntry& other)
- : message(NULL) {
- DCHECK(!other.message);
- DCHECK(other.dispatchers.empty());
+ : message_(NULL) {
+ DCHECK(!other.message_);
+ DCHECK(other.dispatchers_.empty());
}
LocalMessagePipeEndpoint::MessageQueueEntry::~MessageQueueEntry() {
- if (message)
- message->Destroy();
+ if (message_)
+ message_->Destroy();
// Close all the dispatchers.
- for (size_t i = 0; i < dispatchers.size(); i++) {
+ for (size_t i = 0; i < dispatchers_.size(); i++) {
// Note: Taking the |Dispatcher| locks is okay, since no one else should
// have a reference to the dispatchers (and the locks shouldn't be held).
- DCHECK(dispatchers[i]->HasOneRef());
- dispatchers[i]->Close();
+ DCHECK(dispatchers_[i]->HasOneRef());
+ dispatchers_[i]->Close();
+ }
+}
+
+void LocalMessagePipeEndpoint::MessageQueueEntry::Init(
+ MessageInTransit* message,
+ const std::vector<Dispatcher*>* dispatchers) {
+ DCHECK(message);
+ DCHECK(!dispatchers || !dispatchers->empty());
+ DCHECK(!message_);
+ DCHECK(dispatchers_.empty());
+
+ message_ = message;
+ if (dispatchers) {
+ dispatchers_.reserve(dispatchers->size());
+ for (size_t i = 0; i < dispatchers->size(); i++) {
+ dispatchers_.push_back(
+ (*dispatchers)[i]->CreateEquivalentDispatcherAndCloseNoLock());
+
+#ifndef NDEBUG
+ // It's important that we have "ownership" of these dispatchers. In
+ // particular, they must not be in the global handle table (i.e., have
+ // live handles referring to them). If we need to destroy any queued
+ // messages, we need to know that any handles in them should be closed.
+ DCHECK(dispatchers_[i]->HasOneRef());
+#endif
+ }
}
}
@@ -69,36 +95,24 @@ void LocalMessagePipeEndpoint::OnPeerClose() {
}
}
-MojoResult LocalMessagePipeEndpoint::CanEnqueueMessage(
- const MessageInTransit* /*message*/,
- const std::vector<Dispatcher*>* /*dispatchers*/) {
- return MOJO_RESULT_OK;
-}
-
-void LocalMessagePipeEndpoint::EnqueueMessage(
+MojoResult LocalMessagePipeEndpoint::EnqueueMessage(
MessageInTransit* message,
- std::vector<scoped_refptr<Dispatcher> >* dispatchers) {
+ const std::vector<Dispatcher*>* dispatchers) {
DCHECK(is_open_);
DCHECK(is_peer_open_);
+ DCHECK(!dispatchers || !dispatchers->empty());
bool was_empty = message_queue_.empty();
+ // TODO(vtl): Use |emplace_back()| (and a suitable constructor, instead of
+ // |Init()|) when that becomes available.
message_queue_.push_back(MessageQueueEntry());
- message_queue_.back().message = message;
- if (dispatchers) {
-#ifndef NDEBUG
- // It's important that we're taking "ownership" of the dispatchers. In
- // particular, they must not be in the global handle table (i.e., have live
- // handles referring to them). If we need to destroy any queued messages, we
- // need to know that any handles in them should be closed.
- for (size_t i = 0; i < dispatchers->size(); i++)
- DCHECK((*dispatchers)[i]->HasOneRef());
-#endif
- message_queue_.back().dispatchers.swap(*dispatchers);
- }
+ message_queue_.back().Init(message, dispatchers);
if (was_empty) {
waiter_list_.AwakeWaitersForStateChange(SatisfiedFlags(),
SatisfiableFlags());
}
+
+ return MOJO_RESULT_OK;
}
void LocalMessagePipeEndpoint::CancelAllWaiters() {
@@ -125,7 +139,7 @@ MojoResult LocalMessagePipeEndpoint::ReadMessage(
// TODO(vtl): If |flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD|, we could pop
// and release the lock immediately.
bool enough_space = true;
- const MessageInTransit* queued_message = message_queue_.front().message;
+ const MessageInTransit* queued_message = message_queue_.front().message();
if (num_bytes)
*num_bytes = queued_message->data_size();
if (queued_message->data_size() <= max_bytes)
@@ -134,7 +148,7 @@ MojoResult LocalMessagePipeEndpoint::ReadMessage(
enough_space = false;
std::vector<scoped_refptr<Dispatcher> >* queued_dispatchers =
- &message_queue_.front().dispatchers;
+ message_queue_.front().dispatchers();
if (num_dispatchers)
*num_dispatchers = static_cast<uint32_t>(queued_dispatchers->size());
if (enough_space) {
« no previous file with comments | « mojo/system/local_message_pipe_endpoint.h ('k') | mojo/system/message_pipe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698