OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_LIB_MAP_SERIALIZATION_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ |
7 | 7 |
8 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 8 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
9 #include "mojo/public/cpp/bindings/lib/map_data_internal.h" | 9 #include "mojo/public/cpp/bindings/lib/map_data_internal.h" |
10 #include "mojo/public/cpp/bindings/lib/map_internal.h" | 10 #include "mojo/public/cpp/bindings/lib/map_internal.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 *output = result; | 155 *output = result; |
156 } else { | 156 } else { |
157 *output = nullptr; | 157 *output = nullptr; |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 template <typename MapKey, | 161 template <typename MapKey, |
162 typename MapValue, | 162 typename MapValue, |
163 typename DataKey, | 163 typename DataKey, |
164 typename DataValue> | 164 typename DataValue> |
165 inline void Deserialize_(internal::Map_Data<DataKey, DataValue>* input, | 165 inline bool Deserialize_(internal::Map_Data<DataKey, DataValue>* input, |
166 Map<MapKey, MapValue>* output, | 166 Map<MapKey, MapValue>* output, |
167 internal::SerializationContext* context) { | 167 internal::SerializationContext* context) { |
| 168 bool success = true; |
168 if (input) { | 169 if (input) { |
169 Array<MapKey> keys; | 170 Array<MapKey> keys; |
170 Array<MapValue> values; | 171 Array<MapValue> values; |
171 | 172 |
172 Deserialize_(input->keys.ptr, &keys, context); | 173 // Note that we rely on complete deserialization taking place in order to |
173 Deserialize_(input->values.ptr, &values, context); | 174 // transfer ownership of all encoded handles. Therefore we don't |
| 175 // short-circuit on failure here. |
| 176 if (!Deserialize_(input->keys.ptr, &keys, context)) |
| 177 success = false; |
| 178 if (!Deserialize_(input->values.ptr, &values, context)) |
| 179 success = false; |
174 | 180 |
175 *output = Map<MapKey, MapValue>(keys.Pass(), values.Pass()); | 181 *output = Map<MapKey, MapValue>(keys.Pass(), values.Pass()); |
176 } else { | 182 } else { |
177 output->reset(); | 183 output->reset(); |
178 } | 184 } |
| 185 return success; |
179 } | 186 } |
180 | 187 |
181 } // namespace mojo | 188 } // namespace mojo |
182 | 189 |
183 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ | 190 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ |
OLD | NEW |