summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-04 21:06:31 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-04 21:06:31 +0000
commit73a7a8a02721baddefb25c4a6952760c006f3277 (patch)
tree7dcb66aa7a1ef989bd1adfe7179ecd4d343f5cba /mojo
parent97189c2a8169f67adec8797abf832b7cdd064d62 (diff)
downloadchromium_src-73a7a8a02721baddefb25c4a6952760c006f3277.zip
chromium_src-73a7a8a02721baddefb25c4a6952760c006f3277.tar.gz
chromium_src-73a7a8a02721baddefb25c4a6952760c006f3277.tar.bz2
Mojo: Add the ability to attach PlatformHandles to MessageInTransits.
But not yet the ability to actually transmit those anywhere (nor anything that actually attaches PlatformHandles). (I want to do some separate RawChannel refactoring first....) R=davemoore@chromium.org Review URL: https://codereview.chromium.org/226203003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261870 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r--mojo/system/message_in_transit.cc31
-rw-r--r--mojo/system/message_in_transit.h21
-rw-r--r--mojo/system/raw_channel.cc8
3 files changed, 47 insertions, 13 deletions
diff --git a/mojo/system/message_in_transit.cc b/mojo/system/message_in_transit.cc
index c56f4f3..6e2047f 100644
--- a/mojo/system/message_in_transit.cc
+++ b/mojo/system/message_in_transit.cc
@@ -148,14 +148,8 @@ MessageInTransit::MessageInTransit(const View& message_view)
MessageInTransit::~MessageInTransit() {
base::AlignedFree(main_buffer_);
base::AlignedFree(secondary_buffer_); // Okay if null.
-#ifndef NDEBUG
- main_buffer_size_ = 0;
- main_buffer_ = NULL;
- secondary_buffer_size_ = 0;
- secondary_buffer_ = NULL;
-#endif
- if (dispatchers_.get()) {
+ if (dispatchers_) {
for (size_t i = 0; i < dispatchers_->size(); i++) {
if (!(*dispatchers_)[i])
continue;
@@ -163,8 +157,21 @@ MessageInTransit::~MessageInTransit() {
DCHECK((*dispatchers_)[i]->HasOneRef());
(*dispatchers_)[i]->Close();
}
- dispatchers_.reset();
}
+
+ if (platform_handles_) {
+ for (size_t i = 0; i < platform_handles_->size(); i++)
+ (*platform_handles_)[i].CloseIfNecessary();
+ }
+
+#ifndef NDEBUG
+ main_buffer_size_ = 0;
+ main_buffer_ = NULL;
+ secondary_buffer_size_ = 0;
+ secondary_buffer_ = NULL;
+ dispatchers_.reset();
+ platform_handles_.reset();
+#endif
}
// static
@@ -189,8 +196,8 @@ bool MessageInTransit::GetNextMessageSize(const void* buffer,
void MessageInTransit::SetDispatchers(
scoped_ptr<std::vector<scoped_refptr<Dispatcher> > > dispatchers) {
- DCHECK(dispatchers.get());
- DCHECK(!dispatchers_.get());
+ DCHECK(dispatchers);
+ DCHECK(!dispatchers_);
dispatchers_ = dispatchers.Pass();
#ifndef NDEBUG
@@ -203,7 +210,7 @@ void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) {
DCHECK(channel);
DCHECK(!secondary_buffer_);
CHECK_EQ(num_handles(),
- dispatchers_.get() ? dispatchers_->size() : static_cast<size_t>(0));
+ dispatchers_ ? dispatchers_->size() : static_cast<size_t>(0));
if (!num_handles())
return;
@@ -263,7 +270,7 @@ void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) {
}
void MessageInTransit::DeserializeDispatchers(Channel* channel) {
- DCHECK(!dispatchers_.get());
+ DCHECK(!dispatchers_);
// This should have been checked by calling |IsValid()| on the |View| first.
DCHECK_LE(num_handles(), kMaxMessageNumHandles);
diff --git a/mojo/system/message_in_transit.h b/mojo/system/message_in_transit.h
index 966f84b..a4974cd 100644
--- a/mojo/system/message_in_transit.h
+++ b/mojo/system/message_in_transit.h
@@ -11,6 +11,7 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
+#include "mojo/embedder/platform_handle.h"
#include "mojo/system/dispatcher.h"
#include "mojo/system/system_impl_export.h"
@@ -211,7 +212,19 @@ class MOJO_SYSTEM_IMPL_EXPORT MessageInTransit {
// Returns true if this message has dispatchers attached.
bool has_dispatchers() const {
- return dispatchers_.get() && !dispatchers_->empty();
+ return dispatchers_ && !dispatchers_->empty();
+ }
+
+ // Gets the platform-specific handles attached to this message; this may
+ // return null if there are none. Note that the caller may mutate the set of
+ // platform-specific handles.
+ std::vector<embedder::PlatformHandle>* platform_handles() {
+ return platform_handles_.get();
+ }
+
+ // Returns true if this message has platform-specific handles attached.
+ bool has_platform_handles() const {
+ return platform_handles_ && !platform_handles_->empty();
}
// Rounds |n| up to a multiple of |kMessageAlignment|.
@@ -278,6 +291,12 @@ class MOJO_SYSTEM_IMPL_EXPORT MessageInTransit {
// some reason.)
scoped_ptr<std::vector<scoped_refptr<Dispatcher> > > dispatchers_;
+ // Any platform-specific handles attached to this message (for inter-process
+ // transport). The vector (if any) owns the handles that it contains (and is
+ // responsible for closing them).
+ // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandles|.
+ scoped_ptr<std::vector<embedder::PlatformHandle> > platform_handles_;
+
DISALLOW_COPY_AND_ASSIGN(MessageInTransit);
};
diff --git a/mojo/system/raw_channel.cc b/mojo/system/raw_channel.cc
index d19e5f7..80f2176 100644
--- a/mojo/system/raw_channel.cc
+++ b/mojo/system/raw_channel.cc
@@ -150,6 +150,14 @@ void RawChannel::Shutdown() {
// Reminder: This must be thread-safe.
bool RawChannel::WriteMessage(scoped_ptr<MessageInTransit> message) {
+ DCHECK(message);
+
+ // TODO(vtl)
+ if (message->has_platform_handles()) {
+ NOTIMPLEMENTED();
+ return false;
+ }
+
base::AutoLock locker(write_lock_);
if (write_stopped_)
return false;