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

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

Issue 1524613002: [mojo] Use base::Pickle for Message storage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: static_cast, initialization-is-allocation, and split out Pickle impl from PickleBuffer 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/lib/pickle_buffer.h
diff --git a/mojo/public/cpp/bindings/lib/pickle_buffer.h b/mojo/public/cpp/bindings/lib/pickle_buffer.h
new file mode 100644
index 0000000000000000000000000000000000000000..e9705c79b69829fb24b7d694182b36daecc5751f
--- /dev/null
+++ b/mojo/public/cpp/bindings/lib/pickle_buffer.h
@@ -0,0 +1,55 @@
+// Copyright 2015 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_LIB_PICKLE_BUFFER_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_LIB_PICKLE_BUFFER_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/pickle.h"
+#include "mojo/public/cpp/bindings/lib/buffer.h"
+
+namespace mojo {
+namespace internal {
+
+// An implementation of Buffer which uses base::Pickle for its backing. Note
+// that this does not use Pickle's header structure at all, instead storing
+// the complete Message (including header) in the Pickle's payload.
+class PickleBuffer : public Buffer {
+ public:
+ PickleBuffer(size_t num_bytes, bool zero_initialized);
+ ~PickleBuffer() override;
+
+ const void* data() const;
+
+ void* data() {
+ return const_cast<void*>(static_cast<const PickleBuffer*>(this)->data());
+ }
+
+ size_t data_num_bytes() const;
+
+ base::Pickle* pickle() const;
+
+ // Buffer:
+ PickleBuffer* AsPickleBuffer() override;
yzshen1 2015/12/16 00:29:28 nit: It seems nice to put this method and Allocate
+
+ private:
+ class Storage;
+
+ // Buffer implementation. Note that this cannot grow the Pickle's capacity and
+ // it is an error to Allocate() more bytes in total than have been
+ // pre-allocated using ReserveCapacity() or ReserveUninitializedCapacity().
+ //
+ // This guarantees that the returned data is aligned on an 8-byte boundary.
+ void* Allocate(size_t num_bytes) override;
+
+ scoped_ptr<Storage> storage_;
+
+ DISALLOW_COPY_AND_ASSIGN(PickleBuffer);
+};
+
+} // namespace internal
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_PICKLE_BUFFER_H_

Powered by Google App Engine
This is Rietveld 408576698