OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_SERIALIZATION_CONTEXT_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_SERIALIZATION_CONTEXT_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 |
| 10 #include <memory> |
| 11 #include <queue> |
| 12 #include <vector> |
| 13 |
| 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" |
| 16 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
| 17 #include "mojo/public/cpp/system/handle.h" |
| 18 |
| 19 namespace mojo { |
| 20 namespace internal { |
| 21 |
| 22 class MultiplexRouter; |
| 23 |
| 24 // A container for handles during serialization/deserialization. |
| 25 class SerializedHandleVector { |
| 26 public: |
| 27 SerializedHandleVector(); |
| 28 ~SerializedHandleVector(); |
| 29 |
| 30 size_t size() const { return handles_.size(); } |
| 31 |
| 32 // Adds a handle to the handle list and returns its index for encoding. |
| 33 Handle_Data AddHandle(mojo::Handle handle); |
| 34 |
| 35 // Takes a handle from the list of serialized handle data. |
| 36 mojo::Handle TakeHandle(const Handle_Data& encoded_handle); |
| 37 |
| 38 // Takes a handle from the list of serialized handle data and returns it in |
| 39 // |*out_handle| as a specific scoped handle type. |
| 40 template <typename T> |
| 41 ScopedHandleBase<T> TakeHandleAs(const Handle_Data& encoded_handle) { |
| 42 return MakeScopedHandle(T(TakeHandle(encoded_handle).value())); |
| 43 } |
| 44 |
| 45 // Swaps all owned handles out with another Handle vector. |
| 46 void Swap(std::vector<mojo::Handle>* other); |
| 47 |
| 48 private: |
| 49 // Handles are owned by this object. |
| 50 std::vector<mojo::Handle> handles_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(SerializedHandleVector); |
| 53 }; |
| 54 |
| 55 // Context information for serialization/deserialization routines. |
| 56 struct SerializationContext { |
| 57 SerializationContext(); |
| 58 explicit SerializationContext(scoped_refptr<MultiplexRouter> in_router); |
| 59 |
| 60 ~SerializationContext(); |
| 61 |
| 62 // Used to serialize/deserialize associated interface pointers and requests. |
| 63 scoped_refptr<MultiplexRouter> router; |
| 64 |
| 65 // Opaque context pointers returned by StringTraits::SetUpContext(). |
| 66 std::unique_ptr<std::queue<void*>> custom_contexts; |
| 67 |
| 68 // Stashes handles encoded in a message by index. |
| 69 SerializedHandleVector handles; |
| 70 }; |
| 71 |
| 72 } // namespace internal |
| 73 } // namespace mojo |
| 74 |
| 75 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_SERIALIZATION_CONTEXT_H_ |
OLD | NEW |