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

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

Issue 2207763003: Make mojo::internal::Buffer a non-virtual class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@85_3_inline_validation_context
Patch Set: Created 4 years, 4 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/public/cpp/bindings/lib/message_buffer.h ('k') | mojo/public/cpp/bindings/lib/serialization.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_buffer.cc
diff --git a/mojo/public/cpp/bindings/lib/message_buffer.cc b/mojo/public/cpp/bindings/lib/message_buffer.cc
index af79cfd251354ba919f1734acf7edfea22ecadef..cc12ef6e31c9145f97768371834f4e2a494065dd 100644
--- a/mojo/public/cpp/bindings/lib/message_buffer.cc
+++ b/mojo/public/cpp/bindings/lib/message_buffer.cc
@@ -13,54 +13,35 @@ namespace internal {
MessageBuffer::MessageBuffer(size_t capacity, bool zero_initialized) {
DCHECK_LE(capacity, std::numeric_limits<uint32_t>::max());
- data_num_bytes_ = static_cast<uint32_t>(capacity);
MojoResult rv = AllocMessage(capacity, nullptr, 0,
MOJO_ALLOC_MESSAGE_FLAG_NONE, &message_);
CHECK_EQ(rv, MOJO_RESULT_OK);
- if (capacity == 0) {
- buffer_ = nullptr;
- } else {
- rv = GetMessageBuffer(message_.get(), &buffer_);
+ void* buffer = nullptr;
+ if (capacity != 0) {
+ rv = GetMessageBuffer(message_.get(), &buffer);
CHECK_EQ(rv, MOJO_RESULT_OK);
if (zero_initialized)
- memset(buffer_, 0, capacity);
+ memset(buffer, 0, capacity);
}
+ Initialize(buffer, capacity);
}
MessageBuffer::MessageBuffer(ScopedMessageHandle message, uint32_t num_bytes) {
message_ = std::move(message);
- data_num_bytes_ = num_bytes;
- if (num_bytes == 0) {
- buffer_ = nullptr;
- } else {
- MojoResult rv = GetMessageBuffer(message_.get(), &buffer_);
+ void* buffer = nullptr;
+ if (num_bytes != 0) {
+ MojoResult rv = GetMessageBuffer(message_.get(), &buffer);
CHECK_EQ(rv, MOJO_RESULT_OK);
}
+ Initialize(buffer, num_bytes);
}
MessageBuffer::~MessageBuffer() {}
-void* MessageBuffer::Allocate(size_t delta) {
- delta = internal::Align(delta);
-
- DCHECK_LE(delta, static_cast<size_t>(data_num_bytes_));
- DCHECK_GT(bytes_claimed_ + static_cast<uint32_t>(delta), bytes_claimed_);
-
- uint32_t new_bytes_claimed = bytes_claimed_ + static_cast<uint32_t>(delta);
- if (new_bytes_claimed > data_num_bytes_) {
- NOTREACHED();
- return nullptr;
- }
-
- char* start = static_cast<char*>(buffer_) + bytes_claimed_;
- bytes_claimed_ = new_bytes_claimed;
- return static_cast<void*>(start);
-}
-
void MessageBuffer::NotifyBadMessage(const std::string& error) {
DCHECK(message_.is_valid());
MojoResult result = mojo::NotifyBadMessage(message_.get(), error);
« no previous file with comments | « mojo/public/cpp/bindings/lib/message_buffer.h ('k') | mojo/public/cpp/bindings/lib/serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698