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

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

Issue 1932083002: Mojo: Use new message APIs to reduce copying (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 8 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.cc ('k') | mojo/public/cpp/bindings/lib/message_buffer.cc » ('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.h
diff --git a/mojo/public/cpp/bindings/lib/message_buffer.h b/mojo/public/cpp/bindings/lib/message_buffer.h
new file mode 100644
index 0000000000000000000000000000000000000000..47ffea015144953ad0e396c65204638a6f583305
--- /dev/null
+++ b/mojo/public/cpp/bindings/lib/message_buffer.h
@@ -0,0 +1,52 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_LIB_MESSAGE_BUFFER_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_LIB_MESSAGE_BUFFER_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <utility>
+
+#include "base/macros.h"
+#include "mojo/public/cpp/bindings/lib/buffer.h"
+#include "mojo/public/cpp/system/message.h"
+
+namespace mojo {
+namespace internal {
+
+// A fixed-size Buffer implementation using a Mojo message object for storage.
+class MessageBuffer : public Buffer {
+ public:
+ // Initializes this buffer to carry a fixed byte capacity and no handles.
+ MessageBuffer(size_t capacity, bool zero_initialized);
+
+ // Initializes this buffer from an existing Mojo MessageHandle.
+ MessageBuffer(ScopedMessageHandle message, uint32_t num_bytes);
+
+ ~MessageBuffer() override;
+
+ void* data() const { return buffer_; }
+ uint32_t data_num_bytes() const { return data_num_bytes_; }
+
+ // Buffer:
+ void* Allocate(size_t delta) override;
+
+ ScopedMessageHandle TakeMessage() { return std::move(message_); }
+
+ private:
+ uint32_t data_num_bytes_ = 0;
+ ScopedMessageHandle message_;
+ void* buffer_;
+
+ uint32_t bytes_claimed_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(MessageBuffer);
+};
+
+} // namespace internal
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_LIB_MESSAGE_BUFFER_H_
« no previous file with comments | « mojo/public/cpp/bindings/lib/message.cc ('k') | mojo/public/cpp/bindings/lib/message_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698