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

Side by Side Diff: mojo/public/cpp/bindings/lib/map_serialization.h

Issue 1520153002: [mojo] Allow value deserialization to fail (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bindings-3-misc-support
Patch Set: 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 unified diff | Download patch
OLDNEW
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
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 if (input) { 168 if (input) {
169 Array<MapKey> keys; 169 Array<MapKey> keys;
170 Array<MapValue> values; 170 Array<MapValue> values;
171 171
172 Deserialize_(input->keys.ptr, &keys, context); 172 if (!Deserialize_(input->keys.ptr, &keys, context))
173 Deserialize_(input->values.ptr, &values, context); 173 return false;
174 if (!Deserialize_(input->values.ptr, &values, context))
175 return false;
174 176
175 *output = Map<MapKey, MapValue>(keys.Pass(), values.Pass()); 177 *output = Map<MapKey, MapValue>(keys.Pass(), values.Pass());
176 } else { 178 } else {
177 output->reset(); 179 output->reset();
178 } 180 }
181 return true;
179 } 182 }
180 183
181 } // namespace mojo 184 } // namespace mojo
182 185
183 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ 186 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698