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

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

Issue 1955123003: Mojo C++ bindings: switch the remaining callsites of the old serialization interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@24_union_and_others
Patch Set: Created 4 years, 7 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
Index: mojo/public/cpp/bindings/lib/serialization_context.h
diff --git a/mojo/public/cpp/bindings/lib/serialization_context.h b/mojo/public/cpp/bindings/lib/serialization_context.h
new file mode 100644
index 0000000000000000000000000000000000000000..48d37cf713af4dced20094f408cfe1987d3e538e
--- /dev/null
+++ b/mojo/public/cpp/bindings/lib/serialization_context.h
@@ -0,0 +1,75 @@
+// 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_LIB_BINDINGS_SERIALIZATION_CONTEXT_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_SERIALIZATION_CONTEXT_H_
+
+#include <stddef.h>
+
+#include <memory>
+#include <queue>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "mojo/public/cpp/bindings/lib/bindings_internal.h"
+#include "mojo/public/cpp/system/handle.h"
+
+namespace mojo {
+namespace internal {
+
+class MultiplexRouter;
+
+// A container for handles during serialization/deserialization.
+class SerializedHandleVector {
+ public:
+ SerializedHandleVector();
+ ~SerializedHandleVector();
+
+ size_t size() const { return handles_.size(); }
+
+ // Adds a handle to the handle list and returns its index for encoding.
+ Handle_Data AddHandle(mojo::Handle handle);
+
+ // Takes a handle from the list of serialized handle data.
+ mojo::Handle TakeHandle(const Handle_Data& encoded_handle);
+
+ // Takes a handle from the list of serialized handle data and returns it in
+ // |*out_handle| as a specific scoped handle type.
+ template <typename T>
+ ScopedHandleBase<T> TakeHandleAs(const Handle_Data& encoded_handle) {
+ return MakeScopedHandle(T(TakeHandle(encoded_handle).value()));
+ }
+
+ // Swaps all owned handles out with another Handle vector.
+ void Swap(std::vector<mojo::Handle>* other);
+
+ private:
+ // Handles are owned by this object.
+ std::vector<mojo::Handle> handles_;
+
+ DISALLOW_COPY_AND_ASSIGN(SerializedHandleVector);
+};
+
+// Context information for serialization/deserialization routines.
+struct SerializationContext {
+ SerializationContext();
+ explicit SerializationContext(scoped_refptr<MultiplexRouter> in_router);
+
+ ~SerializationContext();
+
+ // Used to serialize/deserialize associated interface pointers and requests.
+ scoped_refptr<MultiplexRouter> router;
+
+ // Opaque context pointers returned by StringTraits::SetUpContext().
+ std::unique_ptr<std::queue<void*>> custom_contexts;
+
+ // Stashes handles encoded in a message by index.
+ SerializedHandleVector handles;
+};
+
+} // namespace internal
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_SERIALIZATION_CONTEXT_H_
« no previous file with comments | « mojo/public/cpp/bindings/lib/pipe_control_message_proxy.cc ('k') | mojo/public/cpp/bindings/lib/serialization_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698