| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_LIB_MESSAGE_BUFFER_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_LIB_MESSAGE_BUFFER_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_LIB_MESSAGE_BUFFER_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_LIB_MESSAGE_BUFFER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | 8 #include <stdint.h> |
| 10 | 9 |
| 11 #include <utility> | 10 #include <utility> |
| 12 | 11 |
| 13 #include "base/macros.h" | 12 #include "base/macros.h" |
| 14 #include "mojo/public/cpp/bindings/lib/buffer.h" | 13 #include "mojo/public/cpp/bindings/lib/buffer.h" |
| 15 #include "mojo/public/cpp/system/message.h" | 14 #include "mojo/public/cpp/system/message.h" |
| 16 | 15 |
| 17 namespace mojo { | 16 namespace mojo { |
| 18 namespace internal { | 17 namespace internal { |
| 19 | 18 |
| 20 // A fixed-size Buffer implementation using a Mojo message object for storage. | 19 // A fixed-size Buffer using a Mojo message object for storage. |
| 21 class MessageBuffer : public Buffer { | 20 class MessageBuffer : public Buffer { |
| 22 public: | 21 public: |
| 23 // Initializes this buffer to carry a fixed byte capacity and no handles. | 22 // Initializes this buffer to carry a fixed byte capacity and no handles. |
| 24 MessageBuffer(size_t capacity, bool zero_initialized); | 23 MessageBuffer(size_t capacity, bool zero_initialized); |
| 25 | 24 |
| 26 // Initializes this buffer from an existing Mojo MessageHandle. | 25 // Initializes this buffer from an existing Mojo MessageHandle. |
| 27 MessageBuffer(ScopedMessageHandle message, uint32_t num_bytes); | 26 MessageBuffer(ScopedMessageHandle message, uint32_t num_bytes); |
| 28 | 27 |
| 29 ~MessageBuffer() override; | 28 ~MessageBuffer(); |
| 30 | |
| 31 void* data() const { return buffer_; } | |
| 32 uint32_t data_num_bytes() const { return data_num_bytes_; } | |
| 33 | |
| 34 // Buffer: | |
| 35 void* Allocate(size_t delta) override; | |
| 36 | 29 |
| 37 ScopedMessageHandle TakeMessage() { return std::move(message_); } | 30 ScopedMessageHandle TakeMessage() { return std::move(message_); } |
| 38 | 31 |
| 39 void NotifyBadMessage(const std::string& error); | 32 void NotifyBadMessage(const std::string& error); |
| 40 | 33 |
| 41 private: | 34 private: |
| 42 uint32_t data_num_bytes_ = 0; | |
| 43 ScopedMessageHandle message_; | 35 ScopedMessageHandle message_; |
| 44 void* buffer_; | |
| 45 | |
| 46 uint32_t bytes_claimed_ = 0; | |
| 47 | 36 |
| 48 DISALLOW_COPY_AND_ASSIGN(MessageBuffer); | 37 DISALLOW_COPY_AND_ASSIGN(MessageBuffer); |
| 49 }; | 38 }; |
| 50 | 39 |
| 51 } // namespace internal | 40 } // namespace internal |
| 52 } // namespace mojo | 41 } // namespace mojo |
| 53 | 42 |
| 54 #endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_LIB_MESSAGE_BUFFER_H_ | 43 #endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_LIB_MESSAGE_BUFFER_H_ |
| OLD | NEW |