Chromium Code Reviews| Index: components/wifi_sync/wifi_credential.cc |
| diff --git a/components/wifi_sync/wifi_credential.cc b/components/wifi_sync/wifi_credential.cc |
| index 73fbaf27f96b34281b4f6606c4f959bde6d58305..c3effd69962a8bc6fd6afaac1d18904a4cd44884 100644 |
| --- a/components/wifi_sync/wifi_credential.cc |
| +++ b/components/wifi_sync/wifi_credential.cc |
| @@ -7,9 +7,13 @@ |
| #include <limits> |
| #include <string> |
|
erikwright (departed)
2015/01/08 19:27:07
not required (included in header)
mukesh agrawal
2015/01/09 02:00:18
Done.
Also removed limits, since it's also unnece
|
| +#include "base/i18n/streaming_utf8_validator.h" |
| #include "base/logging.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/stringprintf.h" |
| +#include "base/values.h" |
| +#include "components/onc/onc_constants.h" |
| +#include "components/wifi_sync/wifi_security_class.h" |
|
erikwright (departed)
2015/01/08 19:27:07
not required (included in header)
mukesh agrawal
2015/01/09 02:00:18
Done.
|
| namespace wifi_sync { |
| @@ -25,6 +29,36 @@ WifiCredential::WifiCredential( |
| WifiCredential::~WifiCredential() { |
| } |
| +bool WifiCredential::ToOncProperties(base::DictionaryValue* onc_properties) |
| + const { |
| + const std::string ssid_utf8(ssid().begin(), ssid().end()); |
| + if (!base::StreamingUtf8Validator::Validate(ssid_utf8)) { |
| + LOG(ERROR) << "SSID is not valid UTF-8"; |
| + return false; |
| + } |
| + |
| + std::string onc_security; |
| + if (!WifiSecurityClassToOncSecurityString(security_class(), &onc_security)) { |
|
erikwright (departed)
2015/01/08 19:27:07
Assuming that security_class() is not ..._INVALID
mukesh agrawal
2015/01/09 02:00:18
Done.
I've left in the check that the SecurityCla
erikwright (departed)
2015/01/09 14:58:20
The NOTREACHED is good, but I would remove the NUL
|
| + LOG(ERROR) << "Error converting SecurityClass with value " |
| + << security_class(); |
| + return false; |
| + } |
| + |
| + onc_properties->Set(onc::toplevel_config::kType, |
| + new base::StringValue(onc::network_type::kWiFi)); |
| + // TODO(quiche): Switch to the HexSSID property, once ONC fully supports it. |
| + onc_properties->Set(onc::network_config::WifiProperty(onc::wifi::kSSID), |
| + new base::StringValue(ssid_utf8)); |
| + onc_properties->Set(onc::network_config::WifiProperty(onc::wifi::kSecurity), |
| + new base::StringValue(onc_security)); |
| + if (WifiSecurityClassSupportsPassphrases(security_class())) { |
| + onc_properties->Set( |
| + onc::network_config::WifiProperty(onc::wifi::kPassphrase), |
| + new base::StringValue(passphrase())); |
| + } |
| + return true; |
| +} |
| + |
| std::string WifiCredential::ToString() const { |
| return base::StringPrintf( |
| "[SSID (hex): %s, SecurityClass: %d]", |
| @@ -45,4 +79,10 @@ WifiCredential::CredentialSet WifiCredential::MakeSet() { |
| return CredentialSet(WifiCredential::IsLessThan); |
| } |
| +// static |
| +WifiCredential::SsidBytes WifiCredential::MakeSsidBytes( |
| + const std::string& ssid) { |
| + return SsidBytes(ssid.begin(), ssid.end()); |
| +} |
| + |
| } // namespace wifi_sync |