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

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: 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
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..ba7f21b8395d17bbb5fc2043a2206d79be9855d5 100644
--- a/mojo/public/cpp/bindings/lib/message.cc
+++ b/mojo/public/cpp/bindings/lib/message.cc
@@ -17,36 +17,31 @@ Message::Message() {
}
Message::~Message() {
- FreeDataAndCloseHandles();
+ CloseHandles();
}
void Message::Reset() {
- FreeDataAndCloseHandles();
+ CloseHandles();
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));
+ buffer_->AllocData(num_bytes);
}
void Message::AllocUninitializedData(uint32_t num_bytes) {
- MOJO_DCHECK(!data_);
- data_num_bytes_ = num_bytes;
- data_ = static_cast<internal::MessageData*>(malloc(num_bytes));
+ buffer_->AllocUninitializedData(num_bytes);
}
void Message::MoveTo(Message* destination) {
MOJO_DCHECK(this != destination);
yzshen1 2015/12/15 19:07:02 Please consider removing line 41 and 47-48, and re
- destination->FreeDataAndCloseHandles();
+ destination->CloseHandles();
// No copy needed.
- destination->data_num_bytes_ = data_num_bytes_;
- destination->data_ = data_;
+ std::swap(destination->buffer_, buffer_);
std::swap(destination->handles_, handles_);
handles_.clear();
@@ -54,13 +49,10 @@ void Message::MoveTo(Message* destination) {
}
void Message::Initialize() {
- data_num_bytes_ = 0;
- data_ = nullptr;
+ buffer_.reset(new internal::PickleBuffer);
}
-void Message::FreeDataAndCloseHandles() {
- free(data_);
-
+void Message::CloseHandles() {
for (std::vector<Handle>::iterator it = handles_.begin();
it != handles_.end(); ++it) {
if (it->is_valid())
@@ -85,15 +77,16 @@ MojoResult ReadAndDispatchMessage(MessagePipeHandle handle,
Message message;
message.AllocUninitializedData(num_bytes);
+ void* mutable_data = message.buffer()->Allocate(num_bytes);
yzshen1 2015/12/15 19:07:02 It seems fairly confusing to require two allocate
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)

Powered by Google App Engine
This is Rietveld 408576698