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 CHROMEOS_NETWORK_ONC_ONC_NORMALIZER_H_ 6 #define CHROMEOS_NETWORK_ONC_ONC_NORMALIZER_H_ 7 8 #include <memory> 9 10 #include "base/component_export.h" 11 #include "base/macros.h" 12 #include "chromeos/network/onc/onc_mapper.h" 13 14 namespace chromeos { 15 namespace onc { 16 17 struct OncValueSignature; 18 COMPONENT_EXPORT(CHROMEOS_NETWORK)19class COMPONENT_EXPORT(CHROMEOS_NETWORK) Normalizer : public Mapper { 20 public: 21 explicit Normalizer(bool remove_recommended_fields); 22 ~Normalizer() override; 23 24 // Removes all fields that are ignored/irrelevant because of the value of 25 // other fields. E.g. the "WiFi" field is irrelevant if the configurations 26 // type is "Ethernet". If |remove_recommended_fields| is true, kRecommended 27 // arrays are removed (the array itself and not the field names listed 28 // there). |object_signature| must point to one of the signatures in 29 // |onc_signature.h|. For configurations of type "WiFi", if the "SSID" field 30 // is set, but the field "HexSSID" is not, the contents of the "SSID" field is 31 // converted to UTF-8 encoding, a hex representation of the byte sequence is 32 // created and stored in the field "HexSSID". 33 std::unique_ptr<base::DictionaryValue> NormalizeObject( 34 const OncValueSignature* object_signature, 35 const base::Value& onc_object); 36 37 private: 38 // Dispatch to the right normalization function according to |signature|. 39 std::unique_ptr<base::DictionaryValue> MapObject( 40 const OncValueSignature& signature, 41 const base::Value& onc_object, 42 bool* error) override; 43 44 void NormalizeCertificate(base::DictionaryValue* cert); 45 void NormalizeEAP(base::DictionaryValue* eap); 46 void NormalizeEthernet(base::DictionaryValue* ethernet); 47 void NormalizeIPsec(base::DictionaryValue* ipsec); 48 void NormalizeNetworkConfiguration(base::DictionaryValue* network); 49 void NormalizeOpenVPN(base::DictionaryValue* openvpn); 50 void NormalizeProxySettings(base::DictionaryValue* proxy); 51 void NormalizeVPN(base::DictionaryValue* vpn); 52 void NormalizeWiFi(base::DictionaryValue* wifi); 53 void NormalizeStaticIPConfigForNetwork(base::DictionaryValue* network); 54 55 const bool remove_recommended_fields_; 56 57 DISALLOW_COPY_AND_ASSIGN(Normalizer); 58 }; 59 60 } // namespace onc 61 } // namespace chromeos 62 63 #endif // CHROMEOS_NETWORK_ONC_ONC_NORMALIZER_H_ 64