summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-03 20:28:04 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-03 20:28:04 +0000
commitf457849d72a7a4f63c137cea037428e69b3903e2 (patch)
tree668dac2de65d90700bb3a2881cddbede8f1777b0 /mojo
parent065ed0a0cfa65bddbc090e1a6b14825630feb625 (diff)
downloadchromium_src-f457849d72a7a4f63c137cea037428e69b3903e2.zip
chromium_src-f457849d72a7a4f63c137cea037428e69b3903e2.tar.gz
chromium_src-f457849d72a7a4f63c137cea037428e69b3903e2.tar.bz2
Mojo: Add a GetType() to MessagePipeEndpoint.
This isn't absolutely required, but it's useful (and will soon be even more useful) for assertions. R=darin@chromium.org Review URL: https://codereview.chromium.org/176863006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r--mojo/system/channel.cc5
-rw-r--r--mojo/system/local_message_pipe_endpoint.cc4
-rw-r--r--mojo/system/local_message_pipe_endpoint.h1
-rw-r--r--mojo/system/message_pipe.cc7
-rw-r--r--mojo/system/message_pipe.h5
-rw-r--r--mojo/system/message_pipe_endpoint.h6
-rw-r--r--mojo/system/proxy_message_pipe_endpoint.cc4
-rw-r--r--mojo/system/proxy_message_pipe_endpoint.h1
8 files changed, 31 insertions, 2 deletions
diff --git a/mojo/system/channel.cc b/mojo/system/channel.cc
index 1c5d336..804e4d7 100644
--- a/mojo/system/channel.cc
+++ b/mojo/system/channel.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/stringprintf.h"
+#include "mojo/system/message_pipe_endpoint.h"
namespace mojo {
namespace system {
@@ -70,6 +71,10 @@ void Channel::Shutdown() {
MessageInTransit::EndpointId Channel::AttachMessagePipeEndpoint(
scoped_refptr<MessagePipe> message_pipe, unsigned port) {
+ DCHECK(port == 0 || port == 1);
+ // Note: This assertion must *not* be done under |lock_|.
+ DCHECK_EQ(message_pipe->GetType(port), MessagePipeEndpoint::kTypeProxy);
+
MessageInTransit::EndpointId local_id;
{
base::AutoLock locker(lock_);
diff --git a/mojo/system/local_message_pipe_endpoint.cc b/mojo/system/local_message_pipe_endpoint.cc
index 6fdec6d7..19f0761 100644
--- a/mojo/system/local_message_pipe_endpoint.cc
+++ b/mojo/system/local_message_pipe_endpoint.cc
@@ -24,6 +24,10 @@ LocalMessagePipeEndpoint::~LocalMessagePipeEndpoint() {
DCHECK(message_queue_.empty()); // Should be implied by not being open.
}
+MessagePipeEndpoint::Type LocalMessagePipeEndpoint::GetType() const {
+ return kTypeLocal;
+}
+
void LocalMessagePipeEndpoint::Close() {
DCHECK(is_open_);
is_open_ = false;
diff --git a/mojo/system/local_message_pipe_endpoint.h b/mojo/system/local_message_pipe_endpoint.h
index e9c8502..27de317 100644
--- a/mojo/system/local_message_pipe_endpoint.h
+++ b/mojo/system/local_message_pipe_endpoint.h
@@ -25,6 +25,7 @@ class MOJO_SYSTEM_IMPL_EXPORT LocalMessagePipeEndpoint
virtual ~LocalMessagePipeEndpoint();
// |MessagePipeEndpoint| implementation:
+ virtual Type GetType() const OVERRIDE;
virtual void Close() OVERRIDE;
virtual void OnPeerClose() OVERRIDE;
virtual void EnqueueMessage(scoped_ptr<MessageInTransit> message) OVERRIDE;
diff --git a/mojo/system/message_pipe.cc b/mojo/system/message_pipe.cc
index 0092abd..b18fb75 100644
--- a/mojo/system/message_pipe.cc
+++ b/mojo/system/message_pipe.cc
@@ -32,6 +32,12 @@ unsigned MessagePipe::GetPeerPort(unsigned port) {
return port ^ 1;
}
+MessagePipeEndpoint::Type MessagePipe::GetType(unsigned port) {
+ DCHECK(port == 0 || port == 1);
+ base::AutoLock locker(lock_);
+ return endpoints_[port]->GetType();
+}
+
void MessagePipe::CancelAllWaiters(unsigned port) {
DCHECK(port == 0 || port == 1);
@@ -54,7 +60,6 @@ void MessagePipe::Close(unsigned port) {
endpoints_[port].reset();
}
-// TODO(vtl): Support sending handles.
// TODO(vtl): Handle flags.
MojoResult MessagePipe::WriteMessage(
unsigned port,
diff --git a/mojo/system/message_pipe.h b/mojo/system/message_pipe.h
index 7bfffd1..33e49a1 100644
--- a/mojo/system/message_pipe.h
+++ b/mojo/system/message_pipe.h
@@ -14,13 +14,13 @@
#include "mojo/public/system/core.h"
#include "mojo/system/dispatcher.h"
#include "mojo/system/message_in_transit.h"
+#include "mojo/system/message_pipe_endpoint.h"
#include "mojo/system/system_impl_export.h"
namespace mojo {
namespace system {
class Channel;
-class MessagePipeEndpoint;
class Waiter;
// |MessagePipe| is the secondary object implementing a message pipe (see the
@@ -40,6 +40,9 @@ class MOJO_SYSTEM_IMPL_EXPORT MessagePipe :
// Gets the other port number (i.e., 0 -> 1, 1 -> 0).
static unsigned GetPeerPort(unsigned port);
+ // Gets the type of the endpoint (used for assertions, etc.).
+ MessagePipeEndpoint::Type GetType(unsigned port);
+
// These are called by the dispatcher to implement its methods of
// corresponding names. In all cases, the port |port| must be open.
void CancelAllWaiters(unsigned port);
diff --git a/mojo/system/message_pipe_endpoint.h b/mojo/system/message_pipe_endpoint.h
index bd9a206..2cd9c17 100644
--- a/mojo/system/message_pipe_endpoint.h
+++ b/mojo/system/message_pipe_endpoint.h
@@ -35,6 +35,12 @@ class MOJO_SYSTEM_IMPL_EXPORT MessagePipeEndpoint {
public:
virtual ~MessagePipeEndpoint() {}
+ enum Type {
+ kTypeLocal,
+ kTypeProxy
+ };
+ virtual Type GetType() const = 0;
+
// All implementations must implement these.
virtual void Close() = 0;
virtual void OnPeerClose() = 0;
diff --git a/mojo/system/proxy_message_pipe_endpoint.cc b/mojo/system/proxy_message_pipe_endpoint.cc
index 58c72da..ce4de56 100644
--- a/mojo/system/proxy_message_pipe_endpoint.cc
+++ b/mojo/system/proxy_message_pipe_endpoint.cc
@@ -29,6 +29,10 @@ ProxyMessagePipeEndpoint::~ProxyMessagePipeEndpoint() {
DCHECK(paused_message_queue_.empty());
}
+MessagePipeEndpoint::Type ProxyMessagePipeEndpoint::GetType() const {
+ return kTypeProxy;
+}
+
void ProxyMessagePipeEndpoint::Close() {
DCHECK(is_open_);
is_open_ = false;
diff --git a/mojo/system/proxy_message_pipe_endpoint.h b/mojo/system/proxy_message_pipe_endpoint.h
index 68f1d89..dd0ee03 100644
--- a/mojo/system/proxy_message_pipe_endpoint.h
+++ b/mojo/system/proxy_message_pipe_endpoint.h
@@ -45,6 +45,7 @@ class MOJO_SYSTEM_IMPL_EXPORT ProxyMessagePipeEndpoint
virtual ~ProxyMessagePipeEndpoint();
// |MessagePipeEndpoint| implementation:
+ virtual Type GetType() const OVERRIDE;
virtual void Close() OVERRIDE;
virtual void OnPeerClose() OVERRIDE;
virtual void EnqueueMessage(scoped_ptr<MessageInTransit> message) OVERRIDE;