| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_CROS_ONC_NETWORK_PARSER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" // for OVERRIDE | 11 #include "base/compiler_specific.h" // for OVERRIDE |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/chromeos/cros/network_parser.h" | 14 #include "chrome/browser/chromeos/cros/network_parser.h" |
| 15 #include "chrome/browser/chromeos/cros/network_ui_data.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class DictionaryValue; | 18 class DictionaryValue; |
| 18 class ListValue; | 19 class ListValue; |
| 19 class Value; | 20 class Value; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace chromeos { | 23 namespace chromeos { |
| 23 | 24 |
| 24 // This is a simple representation of the signature of an ONC typed | 25 // This is a simple representation of the signature of an ONC typed |
| 25 // field, used in validation and translation. It could be extended | 26 // field, used in validation and translation. It could be extended |
| 26 // to include more complex rules of when the field is required/optional, | 27 // to include more complex rules of when the field is required/optional, |
| 27 // as well as to handle "enum" types, which are strings with a small | 28 // as well as to handle "enum" types, which are strings with a small |
| 28 // static set of possible values. | 29 // static set of possible values. |
| 29 struct OncValueSignature { | 30 struct OncValueSignature { |
| 30 const char* field; | 31 const char* field; |
| 31 PropertyIndex index; | 32 PropertyIndex index; |
| 32 base::Value::Type type; | 33 base::Value::Type type; |
| 34 const char* ui_data_key; |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 // This is the network parser that parses the data from an Open Network | 37 // This is the network parser that parses the data from an Open Network |
| 36 // Configuration (ONC) file. ONC files are in JSON format that describes | 38 // Configuration (ONC) file. ONC files are in JSON format that describes |
| 37 // networks. We will use this parser to parse the ONC JSON blob. | 39 // networks. We will use this parser to parse the ONC JSON blob. |
| 38 // | 40 // |
| 39 // For ONC file format, see: http://dev.chromium.org/chromium-os/ | 41 // For ONC file format, see: http://dev.chromium.org/chromium-os/ |
| 40 // chromiumos-design-docs/open-network-configuration | 42 // chromiumos-design-docs/open-network-configuration |
| 41 class OncNetworkParser : public NetworkParser { | 43 class OncNetworkParser : public NetworkParser { |
| 42 public: | 44 public: |
| 43 typedef bool (*ParserPointer)(OncNetworkParser*, | 45 typedef bool (*ParserPointer)(OncNetworkParser*, |
| 44 PropertyIndex, | 46 PropertyIndex, |
| 45 const base::Value&, | 47 const base::Value&, |
| 46 Network*); | 48 Network*); |
| 47 | 49 |
| 48 explicit OncNetworkParser(const std::string& onc_blob); | 50 OncNetworkParser(const std::string& onc_blob, |
| 51 NetworkUIData::ONCSource onc_source); |
| 49 virtual ~OncNetworkParser(); | 52 virtual ~OncNetworkParser(); |
| 50 static const EnumMapper<PropertyIndex>* property_mapper(); | 53 static const EnumMapper<PropertyIndex>* property_mapper(); |
| 51 | 54 |
| 52 // Returns the number of networks in the "NetworkConfigs" list. | 55 // Returns the number of networks in the "NetworkConfigs" list. |
| 53 int GetNetworkConfigsSize() const; | 56 int GetNetworkConfigsSize() const; |
| 54 | 57 |
| 55 // Returns the number of certificates in the "Certificates" list. | 58 // Returns the number of certificates in the "Certificates" list. |
| 56 int GetCertificatesSize() const; | 59 int GetCertificatesSize() const; |
| 57 | 60 |
| 58 // Call to create the network by parsing network config in the nth position. | 61 // Call to create the network by parsing network config in the nth position. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 120 |
| 118 private: | 121 private: |
| 119 bool ParseServerOrCaCertificate( | 122 bool ParseServerOrCaCertificate( |
| 120 int cert_index, | 123 int cert_index, |
| 121 const std::string& cert_type, | 124 const std::string& cert_type, |
| 122 base::DictionaryValue* certificate); | 125 base::DictionaryValue* certificate); |
| 123 bool ParseClientCertificate( | 126 bool ParseClientCertificate( |
| 124 int cert_index, | 127 int cert_index, |
| 125 base::DictionaryValue* certificate); | 128 base::DictionaryValue* certificate); |
| 126 | 129 |
| 130 // Fills in |network->ui_data()| for the properties in |signature|. |
| 131 void ParseUIData(Network* network, |
| 132 const base::DictionaryValue* dict, |
| 133 OncValueSignature* signature) const; |
| 134 |
| 127 // Error message from the JSON parser, if applicable. | 135 // Error message from the JSON parser, if applicable. |
| 128 std::string parse_error_; | 136 std::string parse_error_; |
| 129 | 137 |
| 138 // Where the ONC blob comes from. |
| 139 NetworkUIData::ONCSource onc_source_; |
| 140 |
| 130 scoped_ptr<base::DictionaryValue> root_dict_; | 141 scoped_ptr<base::DictionaryValue> root_dict_; |
| 131 base::ListValue* network_configs_; | 142 base::ListValue* network_configs_; |
| 132 base::ListValue* certificates_; | 143 base::ListValue* certificates_; |
| 133 | 144 |
| 134 DISALLOW_COPY_AND_ASSIGN(OncNetworkParser); | 145 DISALLOW_COPY_AND_ASSIGN(OncNetworkParser); |
| 135 }; | 146 }; |
| 136 | 147 |
| 137 // Base for wireless networks. | 148 // Base for wireless networks. |
| 138 class OncWirelessNetworkParser : public OncNetworkParser { | 149 class OncWirelessNetworkParser : public OncNetworkParser { |
| 139 public: | 150 public: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 const base::Value& value, | 219 const base::Value& value, |
| 209 Network* network); | 220 Network* network); |
| 210 | 221 |
| 211 private: | 222 private: |
| 212 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser); | 223 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser); |
| 213 }; | 224 }; |
| 214 | 225 |
| 215 } // namespace chromeos | 226 } // namespace chromeos |
| 216 | 227 |
| 217 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ | 228 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ |
| OLD | NEW |