Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_MAPPER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_MAPPER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 | |
| 12 namespace base { | |
| 13 class Value; | |
| 14 class DictionaryValue; | |
| 15 class ListValue; | |
| 16 } | |
| 17 | |
| 18 namespace chromeos { | |
| 19 namespace onc { | |
| 20 | |
| 21 struct OncValueSignature; | |
| 22 | |
| 23 // Iterate over both a hierarchical onc signature and an onc value. By comparing | |
|
Mattias Nissler (ping if slow)
2012/11/02 10:10:00
nit: s/onc/ONC/g
pneubeck (no reviews)
2012/11/05 12:04:48
Done.
| |
| 24 // the address of a signature object to the list of signatures in | |
| 25 // "onc_signature.h", accurate signature-specific functions can be applied. It | |
|
Mattias Nissler (ping if slow)
2012/11/02 10:10:00
You should really explain what the term "map" mean
pneubeck (no reviews)
2012/11/05 12:04:48
Done.
| |
| 26 // is expected that the hierarchy of the signature is complete. | |
|
Mattias Nissler (ping if slow)
2012/11/02 10:10:00
what does this mean: "the hierarchy of the signatu
pneubeck (no reviews)
2012/11/05 12:04:48
Done.
| |
| 27 class Mapper { | |
| 28 public: | |
| 29 Mapper(); | |
| 30 virtual ~Mapper(); | |
| 31 | |
| 32 protected: | |
| 33 // Calls |MapObject|, |MapArray| and |MapPrimitive| according to |onc_value|'s | |
| 34 // type. By default aborts on nested errors in arrays. Result of the mapping | |
| 35 // is returned. On error returns NULL. | |
| 36 virtual scoped_ptr<base::Value> MapValue( | |
| 37 const OncValueSignature& signature, | |
| 38 const base::Value& onc_value); | |
| 39 | |
| 40 // Maps objects/dictionaries. By default calls |MapFields|, which recurses | |
| 41 // into each field of |onc_object|, and aborts on unknown fields. Result of | |
| 42 // the mapping is returned. On error returns NULL. | |
| 43 virtual scoped_ptr<base::DictionaryValue> MapObject( | |
| 44 const OncValueSignature& signature, | |
| 45 const base::DictionaryValue& onc_object); | |
| 46 | |
| 47 // Maps primitive values like BinaryValue, StringValue, IntegerValue... (all | |
| 48 // but dictionaries and lists). By default copies |onc_primitive|. Result of | |
| 49 // the mapping is returned. On error returns NULL. | |
| 50 virtual scoped_ptr<base::Value> MapPrimitive( | |
| 51 const OncValueSignature& signature, | |
| 52 const base::Value& onc_primitive); | |
| 53 | |
| 54 // Maps each field of the given |onc_object| according to | |
| 55 // |object_signature|. Adds the mapping of each field to |result| using | |
| 56 // |MapField| and drops unknown fields by default. Sets | |
| 57 // |found_unknown_field| to true if this dictionary contains any unknown | |
| 58 // fields. Set |nested_error_occured| to true if nested errors occured. | |
| 59 virtual void MapFields( | |
| 60 const OncValueSignature& object_signature, | |
| 61 const base::DictionaryValue& onc_object, | |
| 62 bool* found_unknown_field, | |
| 63 bool* nested_error_occured, | |
| 64 base::DictionaryValue* result); | |
| 65 | |
| 66 // Maps the value |onc_value| of field |field_name| according to its field | |
| 67 // signature in |object_signature| using |MapValue|. Sets | |
| 68 // |found_unknown_field| to true if |field_name| cannot be found in | |
| 69 // |object_signature|, which by default is an error. Result of the mapping is | |
| 70 // returned. On error returns NULL. | |
| 71 virtual scoped_ptr<base::Value> MapField( | |
| 72 const std::string& field_name, | |
| 73 const OncValueSignature& object_signature, | |
| 74 const base::Value& onc_value, | |
| 75 bool* found_unknown_field); | |
| 76 | |
| 77 // Maps the array |onc_array| according to |array_signature|, which defines | |
| 78 // the type of the entries. Maps each entry by calling |MapValue|. If any of | |
| 79 // the nested mappings failed, the flag |nested_error_occured| is set to true | |
| 80 // and the entry is dropped from the result. The resulting array is | |
| 81 // returned. On error returns NULL. | |
| 82 virtual scoped_ptr<base::ListValue> MapArray( | |
| 83 const OncValueSignature& array_signature, | |
| 84 const base::ListValue& onc_array, | |
| 85 bool* nested_error_occured); | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(Mapper); | |
| 88 }; | |
| 89 | |
| 90 } // namespace onc | |
| 91 } // namespace chromeos | |
| 92 | |
| 93 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_MAPPER_H_ | |
| OLD | NEW |