OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chromeos/network/onc/onc_mapper.h" | 5 #include "chromeos/network/onc/onc_mapper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chromeos/network/onc/onc_signature.h" | 9 #include "chromeos/network/onc/onc_signature.h" |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 onc_value.GetAsList(&list); | 33 onc_value.GetAsList(&list); |
34 result_value = MapArray(signature, *list, error); | 34 result_value = MapArray(signature, *list, error); |
35 break; | 35 break; |
36 } | 36 } |
37 default: { | 37 default: { |
38 result_value = MapPrimitive(signature, onc_value, error); | 38 result_value = MapPrimitive(signature, onc_value, error); |
39 break; | 39 break; |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 return result_value.Pass(); | 43 return result_value; |
44 } | 44 } |
45 | 45 |
46 scoped_ptr<base::DictionaryValue> Mapper::MapObject( | 46 scoped_ptr<base::DictionaryValue> Mapper::MapObject( |
47 const OncValueSignature& signature, | 47 const OncValueSignature& signature, |
48 const base::DictionaryValue& onc_object, | 48 const base::DictionaryValue& onc_object, |
49 bool* error) { | 49 bool* error) { |
50 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); | 50 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
51 | 51 |
52 bool found_unknown_field = false; | 52 bool found_unknown_field = false; |
53 MapFields(signature, onc_object, &found_unknown_field, error, result.get()); | 53 MapFields(signature, onc_object, &found_unknown_field, error, result.get()); |
54 if (found_unknown_field) | 54 if (found_unknown_field) |
55 *error = true; | 55 *error = true; |
56 return result.Pass(); | 56 return result; |
57 } | 57 } |
58 | 58 |
59 scoped_ptr<base::Value> Mapper::MapPrimitive(const OncValueSignature& signature, | 59 scoped_ptr<base::Value> Mapper::MapPrimitive(const OncValueSignature& signature, |
60 const base::Value& onc_primitive, | 60 const base::Value& onc_primitive, |
61 bool* error) { | 61 bool* error) { |
62 return make_scoped_ptr(onc_primitive.DeepCopy()); | 62 return make_scoped_ptr(onc_primitive.DeepCopy()); |
63 } | 63 } |
64 | 64 |
65 void Mapper::MapFields(const OncValueSignature& object_signature, | 65 void Mapper::MapFields(const OncValueSignature& object_signature, |
66 const base::DictionaryValue& onc_object, | 66 const base::DictionaryValue& onc_object, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 scoped_ptr<base::Value> result_entry; | 122 scoped_ptr<base::Value> result_entry; |
123 result_entry = MapEntry(original_index, | 123 result_entry = MapEntry(original_index, |
124 *array_signature.onc_array_entry_signature, | 124 *array_signature.onc_array_entry_signature, |
125 *entry, | 125 *entry, |
126 nested_error); | 126 nested_error); |
127 if (result_entry.get() != NULL) | 127 if (result_entry.get() != NULL) |
128 result_array->Append(result_entry.release()); | 128 result_array->Append(result_entry.release()); |
129 else | 129 else |
130 DCHECK(*nested_error); | 130 DCHECK(*nested_error); |
131 } | 131 } |
132 return result_array.Pass(); | 132 return result_array; |
133 } | 133 } |
134 | 134 |
135 scoped_ptr<base::Value> Mapper::MapEntry(int index, | 135 scoped_ptr<base::Value> Mapper::MapEntry(int index, |
136 const OncValueSignature& signature, | 136 const OncValueSignature& signature, |
137 const base::Value& onc_value, | 137 const base::Value& onc_value, |
138 bool* error) { | 138 bool* error) { |
139 return MapValue(signature, onc_value, error); | 139 return MapValue(signature, onc_value, error); |
140 } | 140 } |
141 | 141 |
142 } // namespace onc | 142 } // namespace onc |
143 } // namespace chromeos | 143 } // namespace chromeos |
OLD | NEW |