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 #ifndef CHROMEOS_NETWORK_ONC_ONC_MAPPER_H_ | 5 #ifndef CHROMEOS_NETWORK_ONC_ONC_MAPPER_H_ |
6 #define CHROMEOS_NETWORK_ONC_ONC_MAPPER_H_ | 6 #define CHROMEOS_NETWORK_ONC_ONC_MAPPER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 // The ONC validator and normalizer derive from this class and adapt the default | 35 // The ONC validator and normalizer derive from this class and adapt the default |
36 // copy behavior. | 36 // copy behavior. |
37 class Mapper { | 37 class Mapper { |
38 public: | 38 public: |
39 Mapper(); | 39 Mapper(); |
40 virtual ~Mapper(); | 40 virtual ~Mapper(); |
41 | 41 |
42 protected: | 42 protected: |
43 // Calls |MapObject|, |MapArray| and |MapPrimitive| according to |onc_value|'s | 43 // Calls |MapObject|, |MapArray| and |MapPrimitive| according to |onc_value|'s |
44 // type, which always return an object of the according type. Result of the | 44 // type, which always return an object of the according type. Result of the |
45 // mapping is returned. On error sets |error| to true. | 45 // mapping is returned. Only on error sets |error| to true. |
46 virtual scoped_ptr<base::Value> MapValue(const OncValueSignature& signature, | 46 virtual scoped_ptr<base::Value> MapValue(const OncValueSignature& signature, |
47 const base::Value& onc_value, | 47 const base::Value& onc_value, |
48 bool* error); | 48 bool* error); |
49 | 49 |
50 // Maps objects/dictionaries. By default calls |MapFields|, which recurses | 50 // Maps objects/dictionaries. By default calls |MapFields|, which recurses |
51 // into each field of |onc_object|, and drops unknown fields. Result of the | 51 // into each field of |onc_object|, and drops unknown fields. Result of the |
52 // mapping is returned. On error sets |error| to true. In this implementation | 52 // mapping is returned. Only on error sets |error| to true. In this |
53 // only unknown fields are errors. | 53 // implementation only unknown fields are errors. |
54 virtual scoped_ptr<base::DictionaryValue> MapObject( | 54 virtual scoped_ptr<base::DictionaryValue> MapObject( |
55 const OncValueSignature& signature, | 55 const OncValueSignature& signature, |
56 const base::DictionaryValue& onc_object, | 56 const base::DictionaryValue& onc_object, |
57 bool* error); | 57 bool* error); |
58 | 58 |
59 // Maps primitive values like BinaryValue, StringValue, IntegerValue... (all | 59 // Maps primitive values like BinaryValue, StringValue, IntegerValue... (all |
60 // but dictionaries and lists). By default copies |onc_primitive|. Result of | 60 // but dictionaries and lists). By default copies |onc_primitive|. Result of |
61 // the mapping is returned. On error sets |error| to true. | 61 // the mapping is returned. Only on error sets |error| to true. |
62 virtual scoped_ptr<base::Value> MapPrimitive( | 62 virtual scoped_ptr<base::Value> MapPrimitive( |
63 const OncValueSignature& signature, | 63 const OncValueSignature& signature, |
64 const base::Value& onc_primitive, | 64 const base::Value& onc_primitive, |
65 bool* error); | 65 bool* error); |
66 | 66 |
67 // Maps each field of the given |onc_object| according to |object_signature|. | 67 // Maps each field of the given |onc_object| according to |object_signature|. |
68 // Adds the mapping of each field to |result| using |MapField| and drops | 68 // Adds the mapping of each field to |result| using |MapField| and drops |
69 // unknown fields by default. Sets |found_unknown_field| to true if this | 69 // unknown fields by default. Sets |found_unknown_field| to true if this |
70 // dictionary contains any unknown fields. Set |nested_error| to true if | 70 // dictionary contains any unknown fields. Set |nested_error| to true only if |
71 // nested errors occured. | 71 // nested errors occured. |
72 virtual void MapFields(const OncValueSignature& object_signature, | 72 virtual void MapFields(const OncValueSignature& object_signature, |
73 const base::DictionaryValue& onc_object, | 73 const base::DictionaryValue& onc_object, |
74 bool* found_unknown_field, | 74 bool* found_unknown_field, |
75 bool* nested_error, | 75 bool* nested_error, |
76 base::DictionaryValue* result); | 76 base::DictionaryValue* result); |
77 | 77 |
78 // Maps the value |onc_value| of field |field_name| according to its field | 78 // Maps the value |onc_value| of field |field_name| according to its field |
79 // signature in |object_signature| using |MapValue|. Sets | 79 // signature in |object_signature| using |MapValue|. Sets |
80 // |found_unknown_field| to true and returns NULL if |field_name| cannot be | 80 // |found_unknown_field| to true and returns NULL if |field_name| cannot be |
81 // found in |object_signature|. Otherwise returns the mapping of |onc_value|. | 81 // found in |object_signature|. Otherwise returns the mapping of |onc_value|. |
82 virtual scoped_ptr<base::Value> MapField( | 82 virtual scoped_ptr<base::Value> MapField( |
83 const std::string& field_name, | 83 const std::string& field_name, |
84 const OncValueSignature& object_signature, | 84 const OncValueSignature& object_signature, |
85 const base::Value& onc_value, | 85 const base::Value& onc_value, |
86 bool* found_unknown_field, | 86 bool* found_unknown_field, |
87 bool* error); | 87 bool* error); |
88 | 88 |
89 // Maps the array |onc_array| according to |array_signature|, which defines | 89 // Maps the array |onc_array| according to |array_signature|, which defines |
90 // the type of the entries. Maps each entry by calling |MapValue|. If any of | 90 // the type of the entries. Maps each entry by calling |MapValue|. If any of |
91 // the nested mappings failed, the flag |nested_error| is set to true and the | 91 // the nested mappings failed, the flag |nested_error| is set to true and the |
92 // entry is dropped from the result. The resulting array is returned. | 92 // entry is dropped from the result. Otherwise |nested_error| isn't |
| 93 // modified. The resulting array is returned. |
93 virtual scoped_ptr<base::ListValue> MapArray( | 94 virtual scoped_ptr<base::ListValue> MapArray( |
94 const OncValueSignature& array_signature, | 95 const OncValueSignature& array_signature, |
95 const base::ListValue& onc_array, | 96 const base::ListValue& onc_array, |
96 bool* nested_error); | 97 bool* nested_error); |
97 | 98 |
98 // Calls |MapValue| and returns its result. Called by |MapArray| for each | 99 // Calls |MapValue| and returns its result. Called by |MapArray| for each |
99 // entry and its index in the enclosing array. | 100 // entry and its index in the enclosing array. |
100 virtual scoped_ptr<base::Value> MapEntry(int index, | 101 virtual scoped_ptr<base::Value> MapEntry(int index, |
101 const OncValueSignature& signature, | 102 const OncValueSignature& signature, |
102 const base::Value& onc_value, | 103 const base::Value& onc_value, |
103 bool* error); | 104 bool* error); |
104 | 105 |
105 private: | 106 private: |
106 DISALLOW_COPY_AND_ASSIGN(Mapper); | 107 DISALLOW_COPY_AND_ASSIGN(Mapper); |
107 }; | 108 }; |
108 | 109 |
109 } // namespace onc | 110 } // namespace onc |
110 } // namespace chromeos | 111 } // namespace chromeos |
111 | 112 |
112 #endif // CHROMEOS_NETWORK_ONC_ONC_MAPPER_H_ | 113 #endif // CHROMEOS_NETWORK_ONC_ONC_MAPPER_H_ |
OLD | NEW |