Chromium Code Reviews| Index: chromeos/network/network_state.cc |
| diff --git a/chromeos/network/network_state.cc b/chromeos/network/network_state.cc |
| index 25407e2488ef86c365f456b21068e91019c7c0d8..30b17162b6251ec8be0853fae733813246fb61fc 100644 |
| --- a/chromeos/network/network_state.cc |
| +++ b/chromeos/network/network_state.cc |
| @@ -51,6 +51,25 @@ std::string ValidateUTF8(const std::string& str) { |
| return result; |
| } |
| +// If |ui_data_value| is empty, returns true and does not set |ui_data|. |
| +// Otherwise returns true and sets |ui_data| if |ui_data_value| is a valid |
|
pneubeck (no reviews)
2013/07/29 19:13:25
You can simplify this by setting ui_data to new Ne
stevenjb
2013/07/29 20:25:47
Done
|
| +// NetworkUIData dictionary string. |
| +bool GetUIDataFromValue(const base::Value& ui_data_value, |
| + scoped_ptr<chromeos::NetworkUIData>* ui_data) { |
| + std::string ui_data_str; |
| + if (!ui_data_value.GetAsString(&ui_data_str)) |
| + return false; |
| + if (ui_data_str.empty()) |
| + return true; // Empty string is valid; |ui_data| is NULL. |
| + |
| + scoped_ptr<base::DictionaryValue> ui_data_dict( |
| + chromeos::onc::ReadDictionaryFromJson(ui_data_str)); |
| + if (!ui_data_dict) |
| + return false; |
| + ui_data->reset(new chromeos::NetworkUIData(*ui_data_dict)); |
| + return true; |
| +} |
| + |
| } // namespace |
| namespace chromeos { |
| @@ -60,6 +79,7 @@ NetworkState::NetworkState(const std::string& path) |
| auto_connect_(false), |
| favorite_(false), |
| priority_(0), |
| + user_profile_required_(false), |
| onc_source_(onc::ONC_SOURCE_NONE), |
| prefix_length_(0), |
| signal_strength_(0), |
| @@ -163,7 +183,7 @@ bool NetworkState::PropertyChanged(const std::string& key, |
| } |
| return true; |
| } else if (key == flimflam::kNetworkTechnologyProperty) { |
| - return GetStringValue(key, value, &technology_); |
| + return GetStringValue(key, value, &network_technology_); |
| } else if (key == flimflam::kDeviceProperty) { |
| return GetStringValue(key, value, &device_path_); |
| } else if (key == flimflam::kGuidProperty) { |
| @@ -189,20 +209,14 @@ bool NetworkState::PropertyChanged(const std::string& key, |
| return false; |
| } |
| return true; |
| - } else if (key == flimflam::kWifiHexSsid) { |
| - return GetStringValue(key, value, &hex_ssid_); |
| - } else if (key == flimflam::kCountryProperty) { |
| - // TODO(stevenjb): This is currently experimental. If we find a case where |
| - // base::DetectEncoding() fails in UpdateName(), where country_code_ is |
| - // set, figure out whether we can use country_code_ with ConvertToUtf8(). |
| - // crbug.com/233267. |
| - return GetStringValue(key, value, &country_code_); |
| } |
| return false; |
| } |
| -void NetworkState::InitialPropertiesReceived() { |
| - UpdateName(); |
| +void NetworkState::InitialPropertiesReceived( |
|
pneubeck (no reviews)
2013/07/29 19:13:25
I'm missing a return value that indicates if a pro
stevenjb
2013/07/29 20:25:47
Hmm, I guess that's theoretically possible. Fixed.
|
| + const base::DictionaryValue& properties) { |
| + UpdateName(properties); |
| + UpdateUserProfileRequired(properties); |
| } |
| void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { |
| @@ -266,7 +280,7 @@ void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { |
| // is used instead of NetworkLibrary, we can remove them again. |
| dictionary->SetStringWithoutPathExpansion( |
| flimflam::kNetworkTechnologyProperty, |
| - technology_); |
| + network_technology_); |
| dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
| device_path_); |
| dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); |
| @@ -313,8 +327,9 @@ bool NetworkState::IsManaged() const { |
| onc_source_ == onc::ONC_SOURCE_USER_POLICY; |
| } |
| -bool NetworkState::IsShared() const { |
| - return profile_path_ == NetworkProfileHandler::kSharedProfilePath; |
| +bool NetworkState::IsPrivate() const { |
| + return !profile_path_.empty() && |
| + profile_path_ != NetworkProfileHandler::kSharedProfilePath; |
| } |
| std::string NetworkState::GetDnsServersAsString() const { |
| @@ -340,8 +355,10 @@ bool NetworkState::HasAuthenticationError() const { |
| error_ == shill::kErrorEapAuthenticationFailed); |
| } |
| -void NetworkState::UpdateName() { |
| - if (hex_ssid_.empty()) { |
| +void NetworkState::UpdateName(const base::DictionaryValue& properties) { |
| + std::string hex_ssid; |
| + properties.GetStringWithoutPathExpansion(flimflam::kWifiHexSsid, &hex_ssid); |
| + if (hex_ssid.empty()) { |
| // Validate name for UTF8. |
| std::string valid_ssid = ValidateUTF8(name()); |
| if (valid_ssid != name()) { |
| @@ -354,11 +371,11 @@ void NetworkState::UpdateName() { |
| std::string ssid; |
| std::vector<uint8> raw_ssid_bytes; |
| - if (base::HexStringToBytes(hex_ssid_, &raw_ssid_bytes)) { |
| + if (base::HexStringToBytes(hex_ssid, &raw_ssid_bytes)) { |
| ssid = std::string(raw_ssid_bytes.begin(), raw_ssid_bytes.end()); |
| } else { |
| std::string desc = base::StringPrintf("%s: Error processing: %s", |
| - path().c_str(), hex_ssid_.c_str()); |
| + path().c_str(), hex_ssid.c_str()); |
| NET_LOG_DEBUG("UpdateName", desc); |
| LOG(ERROR) << desc; |
| ssid = name(); |
| @@ -374,11 +391,15 @@ void NetworkState::UpdateName() { |
| } |
| // Detect encoding and convert to UTF-8. |
| + std::string country_code; |
| + properties.GetStringWithoutPathExpansion( |
| + flimflam::kCountryProperty, &country_code); |
| std::string encoding; |
| if (!base::DetectEncoding(ssid, &encoding)) { |
| - // TODO(stevenjb): Test this. See comment in PropertyChanged() under |
| - // flimflam::kCountryProperty. |
| - encoding = country_code_; |
| + // TODO(stevenjb): This is currently experimental. If we find a case where |
| + // base::DetectEncoding() fails, we need to figure out whether we can use |
| + // country_code with ConvertToUtf8(). crbug.com/233267. |
| + encoding = country_code; |
| } |
| if (!encoding.empty()) { |
| std::string utf8_ssid; |
| @@ -399,6 +420,44 @@ void NetworkState::UpdateName() { |
| encoding.c_str(), name().c_str())); |
| } |
| +void NetworkState::UpdateUserProfileRequired( |
| + const base::DictionaryValue& properties) { |
| + // VPN always requires a user profile. |
| + if (type() == flimflam::kTypeVPN) { |
| + user_profile_required_ = true; |
| + return; |
| + } |
| + |
| + // 8021x EAP-TLS wifi networks with a certificate or pattern set require a |
| + // user profile. |
| + if (type() == flimflam::kTypeWifi && |
| + security() == flimflam::kSecurity8021x) { |
| + std::string eap_method; |
| + properties.GetStringWithoutPathExpansion( |
| + flimflam::kEapMethodProperty, &eap_method); |
| + if (eap_method != flimflam::kEapMethodTLS) |
| + return; |
| + |
| + std::string eap_cert_id; |
| + properties.GetStringWithoutPathExpansion( |
| + flimflam::kEapCertIdProperty, &eap_cert_id); |
| + if (!eap_cert_id.empty()) { |
| + user_profile_required_ = true; |
| + return; |
| + } |
| + |
| + const base::Value* ui_data_value; |
| + if (properties.GetWithoutPathExpansion( |
| + flimflam::kUIDataProperty, &ui_data_value)) { |
| + scoped_ptr<NetworkUIData> ui_data; |
| + if (!GetUIDataFromValue(*ui_data_value, &ui_data) || !ui_data) |
| + return; |
| + if (ui_data->certificate_type() == CLIENT_CERT_TYPE_PATTERN) |
|
pneubeck (no reviews)
2013/07/29 19:13:25
ClientCertPatterns can currently only be set by us
stevenjb
2013/07/29 20:25:47
A PSK network that is Private can be shared.
A net
|
| + user_profile_required_ = true; |
| + } |
| + } |
| +} |
| + |
| // static |
| bool NetworkState::StateIsConnected(const std::string& connection_state) { |
| return (connection_state == flimflam::kStateReady || |
| @@ -419,20 +478,16 @@ std::string NetworkState::IPConfigProperty(const char* key) { |
| } |
| // static |
| -bool NetworkState::GetOncSource(const base::Value& value, |
| +bool NetworkState::GetOncSource(const base::Value& ui_data_value, |
| onc::ONCSource* out) { |
| - std::string ui_data_str; |
| - if (!value.GetAsString(&ui_data_str)) |
| + scoped_ptr<NetworkUIData> ui_data; |
| + if (!GetUIDataFromValue(ui_data_value, &ui_data)) |
| return false; |
| - if (ui_data_str.empty()) { |
| + if (!ui_data) { |
| *out = onc::ONC_SOURCE_NONE; |
| return true; |
| } |
| - scoped_ptr<base::DictionaryValue> ui_data_dict( |
| - onc::ReadDictionaryFromJson(ui_data_str)); |
| - if (!ui_data_dict) |
| - return false; |
| - *out = NetworkUIData(*ui_data_dict).onc_source(); |
| + *out = ui_data->onc_source(); |
| return true; |
| } |