| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_LIB_FIXED_BUFFER_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_FIXED_BUFFER_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_FIXED_BUFFER_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_FIXED_BUFFER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // |size| should be aligned using internal::Align. | 44 // |size| should be aligned using internal::Align. |
| 45 void Initialize(void* memory, size_t size); | 45 void Initialize(void* memory, size_t size); |
| 46 | 46 |
| 47 size_t size() const { return size_; } | 47 size_t size() const { return size_; } |
| 48 | 48 |
| 49 // Grows the buffer by |num_bytes| and returns a pointer to the start of the | 49 // Grows the buffer by |num_bytes| and returns a pointer to the start of the |
| 50 // addition. The resulting address is 8-byte aligned, and the content of the | 50 // addition. The resulting address is 8-byte aligned, and the content of the |
| 51 // memory is zero-filled. | 51 // memory is zero-filled. |
| 52 void* Allocate(size_t num_bytes) override; | 52 void* Allocate(size_t num_bytes) override; |
| 53 | 53 |
| 54 PickleBuffer* AsPickleBuffer() override; | |
| 55 | |
| 56 protected: | 54 protected: |
| 57 char* ptr_; | 55 char* ptr_; |
| 58 size_t cursor_; | 56 size_t cursor_; |
| 59 size_t size_; | 57 size_t size_; |
| 60 | 58 |
| 61 DISALLOW_COPY_AND_ASSIGN(FixedBuffer); | 59 DISALLOW_COPY_AND_ASSIGN(FixedBuffer); |
| 62 }; | 60 }; |
| 63 | 61 |
| 64 class FixedBufferForTesting : public FixedBuffer { | 62 class FixedBufferForTesting : public FixedBuffer { |
| 65 public: | 63 public: |
| 66 explicit FixedBufferForTesting(size_t size); | 64 explicit FixedBufferForTesting(size_t size); |
| 67 ~FixedBufferForTesting() override; | 65 ~FixedBufferForTesting() override; |
| 68 | 66 |
| 69 // Returns the internal memory owned by the Buffer to the caller. The Buffer | 67 // Returns the internal memory owned by the Buffer to the caller. The Buffer |
| 70 // relinquishes its pointer, effectively resetting the state of the Buffer | 68 // relinquishes its pointer, effectively resetting the state of the Buffer |
| 71 // and leaving the caller responsible for freeing the returned memory address | 69 // and leaving the caller responsible for freeing the returned memory address |
| 72 // when no longer needed. | 70 // when no longer needed. |
| 73 void* Leak(); | 71 void* Leak(); |
| 74 | 72 |
| 75 private: | 73 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(FixedBufferForTesting); | 74 DISALLOW_COPY_AND_ASSIGN(FixedBufferForTesting); |
| 77 }; | 75 }; |
| 78 | 76 |
| 79 } // namespace internal | 77 } // namespace internal |
| 80 } // namespace mojo | 78 } // namespace mojo |
| 81 | 79 |
| 82 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_FIXED_BUFFER_H_ | 80 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_FIXED_BUFFER_H_ |
| OLD | NEW |