Chromium Code Reviews| Index: chrome/browser/chromeos/cros/onc_network_parser.h |
| =================================================================== |
| --- chrome/browser/chromeos/cros/onc_network_parser.h (revision 112277) |
| +++ chrome/browser/chromeos/cros/onc_network_parser.h (working copy) |
| @@ -10,6 +10,7 @@ |
| #include "base/compiler_specific.h" // for OVERRIDE |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/values.h" |
| #include "chrome/browser/chromeos/cros/network_parser.h" |
| namespace base { |
| @@ -20,6 +21,17 @@ |
| namespace chromeos { |
| +// This is a simple representation of the signature of an ONC typed |
| +// field, used in validation and translation. It could be extended |
| +// to include more complex rules of when the field is required/optional, |
| +// as well as to handle "enum" types, which are strings with a small |
| +// static set of possible values. |
| +struct OncValueSignature { |
| + const char* field; |
| + PropertyIndex index; |
| + base::Value::Type type; |
| +}; |
| + |
| // This is the network parser that parses the data from an Open Network |
| // Configuration (ONC) file. ONC files are in JSON format that describes |
| // networks. We will use this parser to parse the ONC JSON blob. |
| @@ -28,6 +40,11 @@ |
| // chromiumos-design-docs/open-network-configuration |
| class OncNetworkParser : public NetworkParser { |
| public: |
| + typedef bool (*ParserPointer)(OncNetworkParser*, |
| + PropertyIndex, |
| + const base::Value&, |
| + Network*); |
| + |
| explicit OncNetworkParser(const std::string& onc_blob); |
| virtual ~OncNetworkParser(); |
| static const EnumMapper<PropertyIndex>* property_mapper(); |
| @@ -49,6 +66,15 @@ |
| virtual Network* CreateNetworkFromInfo(const std::string& service_path, |
| const base::DictionaryValue& info) OVERRIDE; |
| + // Parses a nested ONC object with the given mapper and parser function. |
| + // If Value is not the proper type or there is an error in parsing |
| + // any individual field, VLOGs diagnostics, and returns false. |
| + bool ParseNestedObject(Network* network, |
| + const std::string& onc_type, |
| + const base::Value& value, |
| + OncValueSignature* signature, |
| + ParserPointer parser); |
| + |
| const std::string& parse_error() const { return parse_error_; } |
| protected: |
| @@ -66,6 +92,12 @@ |
| // Returns the GUID string from the dictionary of network values. |
| std::string GetGuidFromDictionary(const base::DictionaryValue& info); |
| + // Parse a field's value in the NetworkConfiguration object. |
| + static bool ParseNetworkConfigurationValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* network); |
| + |
| private: |
| bool ParseServerOrCaCertificate( |
| int cert_index, |
| @@ -90,9 +122,6 @@ |
| public: |
| OncWirelessNetworkParser(); |
| virtual ~OncWirelessNetworkParser(); |
| - virtual bool ParseValue(PropertyIndex index, |
| - const base::Value& value, |
| - Network* network) OVERRIDE; |
| private: |
| DISALLOW_COPY_AND_ASSIGN(OncWirelessNetworkParser); |
| }; |
| @@ -101,34 +130,59 @@ |
| public: |
| OncWifiNetworkParser(); |
| virtual ~OncWifiNetworkParser(); |
| - virtual bool ParseValue(PropertyIndex index, |
| - const base::Value& value, |
| - Network* network) OVERRIDE; |
| + static bool ParseWifiValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* wifi_network); |
|
Mattias Nissler (ping if slow)
2011/12/02 12:23:30
nit: as far as my experience goes, we mostly put n
kmixter1
2011/12/03 00:20:34
Done.
|
| protected: |
| - bool ParseEAPValue(PropertyIndex index, |
| - const base::Value& value, |
| - WifiNetwork* wifi_network); |
| - ConnectionSecurity ParseSecurity(const std::string& security); |
| - EAPMethod ParseEAPMethod(const std::string& method); |
| - EAPPhase2Auth ParseEAPPhase2Auth(const std::string& auth); |
| + static bool ParseEAPValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* wifi_network); |
| + static ConnectionSecurity ParseSecurity(const std::string& security); |
| + static EAPMethod ParseEAPMethod(const std::string& method); |
| + static EAPPhase2Auth ParseEAPPhase2Auth(const std::string& auth); |
| private: |
| DISALLOW_COPY_AND_ASSIGN(OncWifiNetworkParser); |
| }; |
| +// Base for virtual private networks. |
|
Mattias Nissler (ping if slow)
2011/12/02 12:23:30
nit: Is it really a base class?
kmixter1
2011/12/03 00:20:34
Done.
|
| class OncVirtualNetworkParser : public OncNetworkParser { |
| public: |
| OncVirtualNetworkParser(); |
| virtual ~OncVirtualNetworkParser(); |
| - virtual bool ParseValue(PropertyIndex index, |
| - const base::Value& value, |
| - Network* network) OVERRIDE; |
| virtual bool UpdateNetworkFromInfo( |
| const base::DictionaryValue& info, Network* network) OVERRIDE; |
| + static bool ParseVPNValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* network); |
|
Mattias Nissler (ping if slow)
2011/12/02 12:23:30
newline before start of comment
kmixter1
2011/12/03 00:20:34
Done.
|
| + // network_library combines provider type and authentication type |
| + // (L2TP-IPsec with PSK vs with Certificates). This function |
| + // takes a provider type and adds an authentication type to return |
| + // the updated provider type. |
| + static ProviderType UpdateProviderTypeWithAuthType( |
| + ProviderType provider, |
| + const std::string& auth_type); |
|
Mattias Nissler (ping if slow)
2011/12/02 12:23:30
ditto
kmixter1
2011/12/03 00:20:34
Done.
|
| + // This function takes a provider type (which includes authentication |
| + // type) and returns the canonical provider type from it. For instance |
| + // for L2TP-IPsec, the PSK provider type is the canonical one. |
| + static ProviderType GetCanonicalProviderType(ProviderType provider_type); |
| + |
| + static ProviderType ParseProviderType(const std::string& type); |
| protected: |
| - bool ParseProviderValue(PropertyIndex index, |
| - const base::Value& value, |
| - VirtualNetwork* network); |
| - ProviderType ParseProviderType(const std::string& type); |
| + static bool ParseIPsecValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* network); |
| + static bool ParseL2TPValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* network); |
| + static bool ParseOpenVPNValue(OncNetworkParser* parser, |
| + PropertyIndex index, |
| + const base::Value& value, |
| + Network* network); |
| private: |
| DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser); |
| }; |