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

Side by Side Diff: mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h

Issue 2130463002: Mojo C++ bindings: allow StructTraits to return handle or interface types as value. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 template <> 95 template <>
96 struct StructTraits<test::PassByValueStructWithTraits, 96 struct StructTraits<test::PassByValueStructWithTraits,
97 test::PassByValueStructWithTraitsImpl> { 97 test::PassByValueStructWithTraitsImpl> {
98 // Deserialization to test::PassByValueStructTraitsImpl. 98 // Deserialization to test::PassByValueStructTraitsImpl.
99 static bool Read(test::PassByValueStructWithTraits::DataView data, 99 static bool Read(test::PassByValueStructWithTraits::DataView data,
100 test::PassByValueStructWithTraitsImpl* out); 100 test::PassByValueStructWithTraitsImpl* out);
101 101
102 // Fields in test::PassByValueStructWithTraits. 102 // Fields in test::PassByValueStructWithTraits.
103 // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom. 103 // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.
104 static ScopedHandle& f_handle(test::PassByValueStructWithTraitsImpl& value) { 104 static ScopedHandle f_handle(test::PassByValueStructWithTraitsImpl& value) {
105 return value.get_mutable_handle(); 105 return std::move(value.get_mutable_handle());
Peng 2016/07/06 18:05:26 Yes. This is what I need.
106 } 106 }
107 }; 107 };
108 108
109 template <> 109 template <>
110 struct StructTraits<test::StructWithTraitsForUniquePtrTest, 110 struct StructTraits<test::StructWithTraitsForUniquePtrTest,
111 std::unique_ptr<int>> { 111 std::unique_ptr<int>> {
112 static int f_int32(const std::unique_ptr<int>& data) { return *data; } 112 static int f_int32(const std::unique_ptr<int>& data) { return *data; }
113 113
114 static bool Read(test::StructWithTraitsForUniquePtrTest::DataView data, 114 static bool Read(test::StructWithTraitsForUniquePtrTest::DataView data,
115 std::unique_ptr<int>* out) { 115 std::unique_ptr<int>* out) {
116 out->reset(new int(data.f_int32())); 116 out->reset(new int(data.f_int32()));
117 return true; 117 return true;
118 } 118 }
119 }; 119 };
120 120
121 } // namespace mojo 121 } // namespace mojo
122 122
123 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_ 123 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698