| 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 // This class implements a DeepCopy of base::Values for ONC objects that |
| 24 // iterates over both the ONC signature and the object hierarchy. DCHECKs if a |
| 25 // field signature without value signature or an array signature without entry |
| 26 // signature is reached. |
| 27 // |
| 28 // The general term "map" is used here, as this class is meant as base class and |
| 29 // the copy behavior can be adapted by overriding the methods. By comparing the |
| 30 // address of a signature object to the list of signatures in "onc_signature.h", |
| 31 // accurate signature-specific translations or validations can be applied in the |
| 32 // overriding methods. |
| 33 // |
| 34 // The ONC validator and normalizer derive from this class and adapt the default |
| 35 // copy behavior. |
| 36 class Mapper { |
| 37 public: |
| 38 Mapper(); |
| 39 virtual ~Mapper(); |
| 40 |
| 41 protected: |
| 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 |
| 44 // is returned. On error returns NULL. |
| 45 virtual scoped_ptr<base::Value> MapValue( |
| 46 const OncValueSignature& signature, |
| 47 const base::Value& onc_value); |
| 48 |
| 49 // Maps objects/dictionaries. By default calls |MapFields|, which recurses |
| 50 // into each field of |onc_object|, and aborts on unknown fields. Result of |
| 51 // the mapping is returned. On error returns NULL. |
| 52 virtual scoped_ptr<base::DictionaryValue> MapObject( |
| 53 const OncValueSignature& signature, |
| 54 const base::DictionaryValue& onc_object); |
| 55 |
| 56 // Maps primitive values like BinaryValue, StringValue, IntegerValue... (all |
| 57 // but dictionaries and lists). By default copies |onc_primitive|. Result of |
| 58 // the mapping is returned. On error returns NULL. |
| 59 virtual scoped_ptr<base::Value> MapPrimitive( |
| 60 const OncValueSignature& signature, |
| 61 const base::Value& onc_primitive); |
| 62 |
| 63 // Maps each field of the given |onc_object| according to |
| 64 // |object_signature|. Adds the mapping of each field to |result| using |
| 65 // |MapField| and drops unknown fields by default. Sets |
| 66 // |found_unknown_field| to true if this dictionary contains any unknown |
| 67 // fields. Set |nested_error_occured| to true if nested errors occured. |
| 68 virtual void MapFields( |
| 69 const OncValueSignature& object_signature, |
| 70 const base::DictionaryValue& onc_object, |
| 71 bool* found_unknown_field, |
| 72 bool* nested_error_occured, |
| 73 base::DictionaryValue* result); |
| 74 |
| 75 // Maps the value |onc_value| of field |field_name| according to its field |
| 76 // signature in |object_signature| using |MapValue|. Sets |
| 77 // |found_unknown_field| to true if |field_name| cannot be found in |
| 78 // |object_signature|, which by default is an error. Result of the mapping is |
| 79 // returned. On error returns NULL. |
| 80 virtual scoped_ptr<base::Value> MapField( |
| 81 const std::string& field_name, |
| 82 const OncValueSignature& object_signature, |
| 83 const base::Value& onc_value, |
| 84 bool* found_unknown_field); |
| 85 |
| 86 // 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 |
| 88 // the nested mappings failed, the flag |nested_error_occured| is set to true |
| 89 // and the entry is dropped from the result. The resulting array is |
| 90 // returned. On error returns NULL. |
| 91 virtual scoped_ptr<base::ListValue> MapArray( |
| 92 const OncValueSignature& array_signature, |
| 93 const base::ListValue& onc_array, |
| 94 bool* nested_error_occured); |
| 95 |
| 96 private: |
| 97 DISALLOW_COPY_AND_ASSIGN(Mapper); |
| 98 }; |
| 99 |
| 100 } // namespace onc |
| 101 } // namespace chromeos |
| 102 |
| 103 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_MAPPER_H_ |
| OLD | NEW |