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

Unified Diff: mojo/public/cpp/bindings/message.h

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/message.h
diff --git a/mojo/public/cpp/bindings/message.h b/mojo/public/cpp/bindings/message.h
index b0a403b3cdf9c64c0117cd03d692549dcac8cbcd..839544f896a02171bfe69c6a9ae8facd1b509a8b 100644
--- a/mojo/public/cpp/bindings/message.h
+++ b/mojo/public/cpp/bindings/message.h
@@ -7,7 +7,9 @@
#include <vector>
+#include "base/memory/scoped_ptr.h"
#include "mojo/public/cpp/bindings/lib/message_internal.h"
+#include "mojo/public/cpp/bindings/lib/pickle_buffer.h"
#include "mojo/public/cpp/environment/logging.h"
namespace mojo {
@@ -23,64 +25,73 @@ class Message {
void Reset();
+ // These methods preallocate capacity in underlying storage, but they *DO NOT*
+ // claim that space. Use the interface exposed by |buffer()| to claim bytes.
void AllocData(uint32_t num_bytes);
void AllocUninitializedData(uint32_t num_bytes);
// Transfers data and handles to |destination|.
void MoveTo(Message* destination);
- uint32_t data_num_bytes() const { return data_num_bytes_; }
+ uint32_t data_num_bytes() const { return buffer_->data_num_bytes(); }
// Access the raw bytes of the message.
const uint8_t* data() const {
- return reinterpret_cast<const uint8_t*>(data_);
+ return reinterpret_cast<const uint8_t*>(buffer_->data());
+ }
+ uint8_t* mutable_data() {
+ return reinterpret_cast<uint8_t*>(buffer_->data());
}
- uint8_t* mutable_data() { return reinterpret_cast<uint8_t*>(data_); }
// Access the header.
- const internal::MessageHeader* header() const { return &data_->header; }
+ const internal::MessageHeader* header() const {
+ return reinterpret_cast<const internal::MessageHeader*>(buffer_->data());
+ }
+
+ internal::MessageHeader* header() {
+ return const_cast<internal::MessageHeader*>(
+ static_cast<const Message*>(this)->header());
+ }
- uint32_t interface_id() const { return data_->header.interface_id; }
- void set_interface_id(uint32_t id) { data_->header.interface_id = id; }
+ uint32_t interface_id() const { return header()->interface_id; }
+ void set_interface_id(uint32_t id) { header()->interface_id = id; }
- uint32_t name() const { return data_->header.name; }
- bool has_flag(uint32_t flag) const { return !!(data_->header.flags & flag); }
+ uint32_t name() const { return header()->name; }
+ bool has_flag(uint32_t flag) const { return !!(header()->flags & flag); }
// Access the request_id field (if present).
- bool has_request_id() const { return data_->header.version >= 1; }
+ bool has_request_id() const { return header()->version >= 1; }
uint64_t request_id() const {
MOJO_DCHECK(has_request_id());
return static_cast<const internal::MessageHeaderWithRequestID*>(
- &data_->header)->request_id;
+ header())->request_id;
}
void set_request_id(uint64_t request_id) {
MOJO_DCHECK(has_request_id());
- static_cast<internal::MessageHeaderWithRequestID*>(&data_->header)
+ static_cast<internal::MessageHeaderWithRequestID*>(header())
->request_id = request_id;
}
// Access the payload.
- const uint8_t* payload() const {
- return reinterpret_cast<const uint8_t*>(data_) + data_->header.num_bytes;
- }
- uint8_t* mutable_payload() {
- return reinterpret_cast<uint8_t*>(data_) + data_->header.num_bytes;
- }
+ const uint8_t* payload() const { return data() + header()->num_bytes; }
+ uint8_t* mutable_payload() { return const_cast<uint8_t*>(payload()); }
uint32_t payload_num_bytes() const {
- MOJO_DCHECK(data_num_bytes_ >= data_->header.num_bytes);
- return data_num_bytes_ - data_->header.num_bytes;
+ MOJO_DCHECK(buffer_->data_num_bytes() >= header()->num_bytes);
+ return buffer_->data_num_bytes() - header()->num_bytes;
}
// Access the handles.
const std::vector<Handle>* handles() const { return &handles_; }
std::vector<Handle>* mutable_handles() { return &handles_; }
+ // Access the underlying Buffer interface.
+ internal::Buffer* buffer() { return buffer_.get(); }
+
private:
void Initialize();
- void FreeDataAndCloseHandles();
+ void CloseHandles();
- uint32_t data_num_bytes_;
- internal::MessageData* data_;
+ scoped_ptr<internal::PickleBuffer> buffer_;
std::vector<Handle> handles_;
MOJO_DISALLOW_COPY_AND_ASSIGN(Message);

Powered by Google App Engine
This is Rietveld 408576698