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

Unified Diff: mojo/system/message_in_transit.cc

Issue 172953003: Mojo: Make MessageInTransit more opaque. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 10 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/raw_channel_posix.cc » ('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 89f1dad0777e2483db396551d183ae2ee6552d57..b7c536ebeb1e380d773e044450cc32cdca5bd895 100644
--- a/mojo/system/message_in_transit.cc
+++ b/mojo/system/message_in_transit.cc
@@ -51,21 +51,27 @@ MessageInTransit* MessageInTransit::Create(Type type,
const size_t data_size = num_bytes;
const size_t size_with_header = sizeof(MessageInTransit) + data_size;
- const size_t size_with_header_and_padding =
- RoundUpMessageAlignment(size_with_header);
+ const size_t buffer_size = RoundUpMessageAlignment(size_with_header);
- char* buffer = static_cast<char*>(
- base::AlignedAlloc(size_with_header_and_padding, kMessageAlignment));
+ char* buffer = static_cast<char*>(base::AlignedAlloc(buffer_size,
+ kMessageAlignment));
// The buffer consists of the header (a |MessageInTransit|, constructed using
// a placement new), followed by the data, followed by padding (of zeros).
MessageInTransit* rv = new (buffer) MessageInTransit(
static_cast<uint32_t>(data_size), type, subtype, num_bytes, num_handles);
memcpy(buffer + sizeof(MessageInTransit), bytes, num_bytes);
- memset(buffer + size_with_header, 0,
- size_with_header_and_padding - size_with_header);
+ memset(buffer + size_with_header, 0, buffer_size - size_with_header);
return rv;
}
+MessageInTransit* MessageInTransit::Clone() const {
+ size_t buffer_size = main_buffer_size();
+ char* buffer = static_cast<char*>(base::AlignedAlloc(buffer_size,
+ kMessageAlignment));
+ memcpy(buffer, main_buffer(), buffer_size);
+ return reinterpret_cast<MessageInTransit*>(buffer);
+}
+
void MessageInTransit::Destroy() {
// No need to call the destructor, since we're POD.
base::AlignedFree(this);
« no previous file with comments | « mojo/system/message_in_transit.h ('k') | mojo/system/raw_channel_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698