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

Unified Diff: mojo/system/message_in_transit.cc

Issue 419973005: Convert WriteMessage...() to use the new user pointer handling (see r285350). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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/message_in_transit.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/message_in_transit.cc
diff --git a/mojo/system/message_in_transit.cc b/mojo/system/message_in_transit.cc
index 944e12b19ae68b8613e30bb1020dc51f4915ff2e..5ac07547aac9c0c67336741dcb65b082a1808658 100644
--- a/mojo/system/message_in_transit.cc
+++ b/mojo/system/message_in_transit.cc
@@ -92,19 +92,7 @@ MessageInTransit::MessageInTransit(Type type,
: main_buffer_size_(RoundUpMessageAlignment(sizeof(Header) + num_bytes)),
main_buffer_(static_cast<char*>(base::AlignedAlloc(main_buffer_size_,
kMessageAlignment))) {
- DCHECK_LE(num_bytes, kMaxMessageNumBytes);
-
- // |total_size| is updated below, from the other values.
- header()->type = type;
- header()->subtype = subtype;
- header()->source_id = kInvalidEndpointId;
- header()->destination_id = kInvalidEndpointId;
- header()->num_bytes = num_bytes;
- header()->unused = 0;
- // Note: If dispatchers are subsequently attached, then |total_size| will have
- // to be adjusted.
- UpdateTotalSize();
-
+ ConstructorHelper(type, subtype, num_bytes);
if (bytes) {
memcpy(MessageInTransit::bytes(), bytes, num_bytes);
memset(static_cast<char*>(MessageInTransit::bytes()) + num_bytes, 0,
@@ -114,6 +102,17 @@ MessageInTransit::MessageInTransit(Type type,
}
}
+MessageInTransit::MessageInTransit(Type type,
+ Subtype subtype,
+ uint32_t num_bytes,
+ UserPointer<const void> bytes)
+ : main_buffer_size_(RoundUpMessageAlignment(sizeof(Header) + num_bytes)),
+ main_buffer_(static_cast<char*>(base::AlignedAlloc(main_buffer_size_,
+ kMessageAlignment))) {
+ ConstructorHelper(type, subtype, num_bytes);
+ bytes.GetArray(MessageInTransit::bytes(), num_bytes);
+}
+
MessageInTransit::MessageInTransit(const View& message_view)
: main_buffer_size_(message_view.main_buffer_size()),
main_buffer_(static_cast<char*>(base::AlignedAlloc(main_buffer_size_,
@@ -193,6 +192,23 @@ void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) {
UpdateTotalSize();
}
+void MessageInTransit::ConstructorHelper(Type type,
+ Subtype subtype,
+ uint32_t num_bytes) {
+ DCHECK_LE(num_bytes, kMaxMessageNumBytes);
+
+ // |total_size| is updated below, from the other values.
+ header()->type = type;
+ header()->subtype = subtype;
+ header()->source_id = kInvalidEndpointId;
+ header()->destination_id = kInvalidEndpointId;
+ header()->num_bytes = num_bytes;
+ header()->unused = 0;
+ // Note: If dispatchers are subsequently attached, then |total_size| will have
+ // to be adjusted.
+ UpdateTotalSize();
+}
+
void MessageInTransit::UpdateTotalSize() {
DCHECK_EQ(main_buffer_size_ % kMessageAlignment, 0u);
header()->total_size = static_cast<uint32_t>(main_buffer_size_);
« no previous file with comments | « mojo/system/message_in_transit.h ('k') | mojo/system/message_pipe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698