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