Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_PICKLE_BUFFER_H_ | |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_PICKLE_BUFFER_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/pickle.h" | |
| 11 #include "mojo/public/cpp/bindings/lib/buffer.h" | |
| 12 | |
| 13 namespace mojo { | |
| 14 namespace internal { | |
| 15 | |
| 16 // An implementation of Buffer which uses base::Pickle for its backing. Note | |
| 17 // that this does not use Pickle's header structure at all, instead storing | |
| 18 // the complete Message (including header) in the Pickle's payload. | |
| 19 class PickleBuffer : public Buffer { | |
| 20 public: | |
| 21 PickleBuffer(size_t num_bytes, bool zero_initialized); | |
| 22 ~PickleBuffer() override; | |
| 23 | |
| 24 const void* data() const; | |
| 25 | |
| 26 void* data() { | |
| 27 return const_cast<void*>(static_cast<const PickleBuffer*>(this)->data()); | |
| 28 } | |
| 29 | |
| 30 size_t data_num_bytes() const; | |
| 31 | |
| 32 base::Pickle* pickle() const; | |
| 33 | |
| 34 // Buffer: | |
| 35 PickleBuffer* AsPickleBuffer() override; | |
|
yzshen1
2015/12/16 00:29:28
nit: It seems nice to put this method and Allocate
| |
| 36 | |
| 37 private: | |
| 38 class Storage; | |
| 39 | |
| 40 // Buffer implementation. Note that this cannot grow the Pickle's capacity and | |
| 41 // it is an error to Allocate() more bytes in total than have been | |
| 42 // pre-allocated using ReserveCapacity() or ReserveUninitializedCapacity(). | |
| 43 // | |
| 44 // This guarantees that the returned data is aligned on an 8-byte boundary. | |
| 45 void* Allocate(size_t num_bytes) override; | |
| 46 | |
| 47 scoped_ptr<Storage> storage_; | |
| 48 | |
| 49 DISALLOW_COPY_AND_ASSIGN(PickleBuffer); | |
| 50 }; | |
| 51 | |
| 52 } // namespace internal | |
| 53 } // namespace mojo | |
| 54 | |
| 55 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_PICKLE_BUFFER_H_ | |
| OLD | NEW |