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

Unified Diff: mojo/public/cpp/bindings/lib/message.cc

Issue 1524613002: [mojo] Use base::Pickle for Message storage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: happy compiler happy robots Created 5 years 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/public/cpp/bindings/lib/fixed_buffer.cc ('k') | mojo/public/cpp/bindings/lib/message_builder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/message.cc
diff --git a/mojo/public/cpp/bindings/lib/message.cc b/mojo/public/cpp/bindings/lib/message.cc
index 6b563e779aca7d196284726c0a899fe03ce2cdde..23ef162b40f69b36b0bc3f5a859b8b39d9e5acda 100644
--- a/mojo/public/cpp/bindings/lib/message.cc
+++ b/mojo/public/cpp/bindings/lib/message.cc
@@ -13,54 +13,30 @@
namespace mojo {
Message::Message() {
- Initialize();
}
Message::~Message() {
- FreeDataAndCloseHandles();
+ CloseHandles();
}
-void Message::Reset() {
- FreeDataAndCloseHandles();
-
- handles_.clear();
- Initialize();
-}
-
-void Message::AllocData(uint32_t num_bytes) {
- MOJO_DCHECK(!data_);
- data_num_bytes_ = num_bytes;
- data_ = static_cast<internal::MessageData*>(calloc(num_bytes, 1));
-}
-
-void Message::AllocUninitializedData(uint32_t num_bytes) {
- MOJO_DCHECK(!data_);
- data_num_bytes_ = num_bytes;
- data_ = static_cast<internal::MessageData*>(malloc(num_bytes));
+void Message::Initialize(size_t capacity, bool zero_initialized) {
+ DCHECK(!buffer_);
+ buffer_.reset(new internal::PickleBuffer(capacity, zero_initialized));
}
void Message::MoveTo(Message* destination) {
MOJO_DCHECK(this != destination);
- destination->FreeDataAndCloseHandles();
-
// No copy needed.
- destination->data_num_bytes_ = data_num_bytes_;
- destination->data_ = data_;
+ std::swap(destination->buffer_, buffer_);
std::swap(destination->handles_, handles_);
+ CloseHandles();
handles_.clear();
- Initialize();
-}
-
-void Message::Initialize() {
- data_num_bytes_ = 0;
- data_ = nullptr;
+ buffer_.reset();
}
-void Message::FreeDataAndCloseHandles() {
- free(data_);
-
+void Message::CloseHandles() {
for (std::vector<Handle>::iterator it = handles_.begin();
it != handles_.end(); ++it) {
if (it->is_valid())
@@ -84,16 +60,18 @@ MojoResult ReadAndDispatchMessage(MessagePipeHandle handle,
return rv;
Message message;
- message.AllocUninitializedData(num_bytes);
+ message.Initialize(num_bytes, false /* zero_initialized */);
+
+ void* mutable_data = message.buffer()->Allocate(num_bytes);
message.mutable_handles()->resize(num_handles);
rv = ReadMessageRaw(
handle,
- message.mutable_data(),
+ mutable_data,
&num_bytes,
message.mutable_handles()->empty()
? nullptr
- : reinterpret_cast<MojoHandle*>(&message.mutable_handles()->front()),
+ : reinterpret_cast<MojoHandle*>(message.mutable_handles()->data()),
&num_handles,
MOJO_READ_MESSAGE_FLAG_NONE);
if (receiver && rv == MOJO_RESULT_OK)
« no previous file with comments | « mojo/public/cpp/bindings/lib/fixed_buffer.cc ('k') | mojo/public/cpp/bindings/lib/message_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698