Chromium Code Reviews| Index: chrome/browser/chromeos/cros/native_network_parser.cc |
| =================================================================== |
| --- chrome/browser/chromeos/cros/native_network_parser.cc (revision 112004) |
| +++ chrome/browser/chromeos/cros/native_network_parser.cc (working copy) |
| @@ -139,6 +139,41 @@ |
| { flimflam::kWifiPhyMode, PROPERTY_INDEX_WIFI_PHY_MODE }, |
| }; |
| +EnumMapper<ConnectionType>::Pair type_table[] = { |
| + { flimflam::kTypeEthernet, TYPE_ETHERNET }, |
| + { flimflam::kTypeWifi, TYPE_WIFI }, |
| + { flimflam::kTypeWimax, TYPE_WIMAX }, |
| + { flimflam::kTypeBluetooth, TYPE_BLUETOOTH }, |
| + { flimflam::kTypeCellular, TYPE_CELLULAR }, |
| + { flimflam::kTypeVPN, TYPE_VPN }, |
| +}; |
| + |
| +EnumMapper<ConnectionSecurity>::Pair security_table[] = { |
| + { flimflam::kSecurityNone, SECURITY_NONE }, |
| + { flimflam::kSecurityWep, SECURITY_WEP }, |
| + { flimflam::kSecurityWpa, SECURITY_WPA }, |
| + { flimflam::kSecurityRsn, SECURITY_RSN }, |
| + { flimflam::kSecurityPsk, SECURITY_PSK }, |
| + { flimflam::kSecurity8021x, SECURITY_8021X }, |
| +}; |
| + |
| +EnumMapper<EAPMethod>::Pair eap_method_table[] = { |
| + { flimflam::kEapMethodPEAP, EAP_METHOD_PEAP }, |
| + { flimflam::kEapMethodTLS, EAP_METHOD_TLS }, |
| + { flimflam::kEapMethodTTLS, EAP_METHOD_TTLS }, |
| + { flimflam::kEapMethodLEAP, EAP_METHOD_LEAP }, |
| +}; |
| + |
| +EnumMapper<EAPPhase2Auth>::Pair eap_auth_table[] = { |
| + { flimflam::kEapPhase2AuthPEAPMD5, EAP_PHASE_2_AUTH_MD5 }, |
| + { flimflam::kEapPhase2AuthPEAPMSCHAPV2, EAP_PHASE_2_AUTH_MSCHAPV2 }, |
| + { flimflam::kEapPhase2AuthTTLSMD5, EAP_PHASE_2_AUTH_MD5 }, |
| + { flimflam::kEapPhase2AuthTTLSMSCHAPV2, EAP_PHASE_2_AUTH_MSCHAPV2 }, |
| + { flimflam::kEapPhase2AuthTTLSMSCHAP, EAP_PHASE_2_AUTH_MSCHAP }, |
| + { flimflam::kEapPhase2AuthTTLSPAP, EAP_PHASE_2_AUTH_PAP }, |
| + { flimflam::kEapPhase2AuthTTLSCHAP, EAP_PHASE_2_AUTH_CHAP }, |
| +}; |
| + |
| // Serve the singleton mapper instance. |
| const EnumMapper<PropertyIndex>* get_native_mapper() { |
| CR_DEFINE_STATIC_LOCAL(EnumMapper<PropertyIndex>, mapper, |
| @@ -148,20 +183,6 @@ |
| return &mapper; |
| } |
| -ConnectionType ParseNetworkType(const std::string& type) { |
| - static EnumMapper<ConnectionType>::Pair table[] = { |
| - { flimflam::kTypeEthernet, TYPE_ETHERNET }, |
| - { flimflam::kTypeWifi, TYPE_WIFI }, |
| - { flimflam::kTypeWimax, TYPE_WIMAX }, |
| - { flimflam::kTypeBluetooth, TYPE_BLUETOOTH }, |
| - { flimflam::kTypeCellular, TYPE_CELLULAR }, |
| - { flimflam::kTypeVPN, TYPE_VPN }, |
| - }; |
| - CR_DEFINE_STATIC_LOCAL(EnumMapper<ConnectionType>, parser, |
| - (table, arraysize(table), TYPE_UNKNOWN)); |
| - return parser.Get(type); |
| -} |
| - |
| } // namespace |
| // -------------------- NativeNetworkDeviceParser -------------------- |
| @@ -391,7 +412,7 @@ |
| } |
| ConnectionType NativeNetworkDeviceParser::ParseType(const std::string& type) { |
| - return ParseNetworkType(type); |
| + return NativeNetworkParser::type_mapper()->Get(type); |
| } |
| bool NativeNetworkDeviceParser::ParseApnList(const ListValue& list, |
| @@ -505,9 +526,37 @@ |
| return get_native_mapper(); |
| } |
| +// static |
| +const EnumMapper<ConnectionType>* NativeNetworkParser::type_mapper() { |
| + CR_DEFINE_STATIC_LOCAL(EnumMapper<ConnectionType>, type_mapper, |
| + (type_table, arraysize(type_table), TYPE_UNKNOWN)); |
| + return &type_mapper; |
|
stevenjb
2011/11/30 17:36:20
nit: "type_mapper" and "type_table" sound like gen
Charlie Lee
2011/11/30 18:01:21
Done.
|
| +} |
| + |
| +// static |
| +const EnumMapper<ConnectionSecurity>* NativeNetworkParser::security_mapper() { |
| + CR_DEFINE_STATIC_LOCAL(EnumMapper<ConnectionSecurity>, security_mapper, |
| + (security_table, arraysize(security_table), SECURITY_UNKNOWN)); |
| + return &security_mapper; |
| +} |
| + |
| +// static |
| +const EnumMapper<EAPMethod>* NativeNetworkParser::eap_method_mapper() { |
| + CR_DEFINE_STATIC_LOCAL(EnumMapper<EAPMethod>, eap_method_mapper, |
| + (eap_method_table, arraysize(eap_method_table), EAP_METHOD_UNKNOWN)); |
| + return &eap_method_mapper; |
| +} |
| + |
| +// static |
| +const EnumMapper<EAPPhase2Auth>* NativeNetworkParser::eap_auth_mapper() { |
| + CR_DEFINE_STATIC_LOCAL(EnumMapper<EAPPhase2Auth>, eap_auth_mapper, |
| + (eap_auth_table, arraysize(eap_auth_table), EAP_PHASE_2_AUTH_AUTO)); |
| + return &eap_auth_mapper; |
| +} |
| + |
| const ConnectionType NativeNetworkParser::ParseConnectionType( |
| const std::string& connection_type) { |
| - return ParseNetworkType(connection_type); |
| + return type_mapper()->Get(connection_type); |
| } |
| Network* NativeNetworkParser::CreateNewNetwork( |
| @@ -612,7 +661,7 @@ |
| } |
| ConnectionType NativeNetworkParser::ParseType(const std::string& type) { |
| - return ParseNetworkType(type); |
| + return type_mapper()->Get(type); |
| } |
| ConnectionType NativeNetworkParser::ParseTypeFromDictionary( |
| @@ -1034,45 +1083,16 @@ |
| ConnectionSecurity NativeWifiNetworkParser::ParseSecurity( |
| const std::string& security) { |
| - static EnumMapper<ConnectionSecurity>::Pair table[] = { |
| - { flimflam::kSecurityNone, SECURITY_NONE }, |
| - { flimflam::kSecurityWep, SECURITY_WEP }, |
| - { flimflam::kSecurityWpa, SECURITY_WPA }, |
| - { flimflam::kSecurityRsn, SECURITY_RSN }, |
| - { flimflam::kSecurityPsk, SECURITY_PSK }, |
| - { flimflam::kSecurity8021x, SECURITY_8021X }, |
| - }; |
| - CR_DEFINE_STATIC_LOCAL(EnumMapper<ConnectionSecurity>, parser, |
| - (table, arraysize(table), SECURITY_UNKNOWN)); |
| - return parser.Get(security); |
| + return security_mapper()->Get(security); |
| } |
| EAPMethod NativeWifiNetworkParser::ParseEAPMethod(const std::string& method) { |
| - static EnumMapper<EAPMethod>::Pair table[] = { |
| - { flimflam::kEapMethodPEAP, EAP_METHOD_PEAP }, |
| - { flimflam::kEapMethodTLS, EAP_METHOD_TLS }, |
| - { flimflam::kEapMethodTTLS, EAP_METHOD_TTLS }, |
| - { flimflam::kEapMethodLEAP, EAP_METHOD_LEAP }, |
| - }; |
| - CR_DEFINE_STATIC_LOCAL(EnumMapper<EAPMethod>, parser, |
| - (table, arraysize(table), EAP_METHOD_UNKNOWN)); |
| - return parser.Get(method); |
| + return eap_method_mapper()->Get(method); |
| } |
| EAPPhase2Auth NativeWifiNetworkParser::ParseEAPPhase2Auth( |
| const std::string& auth) { |
| - static EnumMapper<EAPPhase2Auth>::Pair table[] = { |
| - { flimflam::kEapPhase2AuthPEAPMD5, EAP_PHASE_2_AUTH_MD5 }, |
| - { flimflam::kEapPhase2AuthPEAPMSCHAPV2, EAP_PHASE_2_AUTH_MSCHAPV2 }, |
| - { flimflam::kEapPhase2AuthTTLSMD5, EAP_PHASE_2_AUTH_MD5 }, |
| - { flimflam::kEapPhase2AuthTTLSMSCHAPV2, EAP_PHASE_2_AUTH_MSCHAPV2 }, |
| - { flimflam::kEapPhase2AuthTTLSMSCHAP, EAP_PHASE_2_AUTH_MSCHAP }, |
| - { flimflam::kEapPhase2AuthTTLSPAP, EAP_PHASE_2_AUTH_PAP }, |
| - { flimflam::kEapPhase2AuthTTLSCHAP, EAP_PHASE_2_AUTH_CHAP }, |
| - }; |
| - CR_DEFINE_STATIC_LOCAL(EnumMapper<EAPPhase2Auth>, parser, |
| - (table, arraysize(table), EAP_PHASE_2_AUTH_AUTO)); |
| - return parser.Get(auth); |
| + return eap_auth_mapper()->Get(auth); |
| } |
| // -------------------- NativeVirtualNetworkParser -------------------- |