Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chromeos/network/network_state.h" | 5 #include "chromeos/network/network_state.h" |
| 6 | 6 |
| 7 #include "base/i18n/icu_encoding_detection.h" | 7 #include "base/i18n/icu_encoding_detection.h" |
| 8 #include "base/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 } else { | 44 } else { |
| 45 const uint32 kReplacementChar = 0xFFFD; | 45 const uint32 kReplacementChar = 0xFFFD; |
| 46 // Puts kReplacementChar if character is a control character [0,0x20) | 46 // Puts kReplacementChar if character is a control character [0,0x20) |
| 47 // or is not readable UTF8. | 47 // or is not readable UTF8. |
| 48 base::WriteUnicodeCharacter(kReplacementChar, &result); | 48 base::WriteUnicodeCharacter(kReplacementChar, &result); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 return result; | 51 return result; |
| 52 } | 52 } |
| 53 | 53 |
| 54 // If |ui_data_value| is empty, returns true and does not set |ui_data|. | |
| 55 // 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
| |
| 56 // NetworkUIData dictionary string. | |
| 57 bool GetUIDataFromValue(const base::Value& ui_data_value, | |
| 58 scoped_ptr<chromeos::NetworkUIData>* ui_data) { | |
| 59 std::string ui_data_str; | |
| 60 if (!ui_data_value.GetAsString(&ui_data_str)) | |
| 61 return false; | |
| 62 if (ui_data_str.empty()) | |
| 63 return true; // Empty string is valid; |ui_data| is NULL. | |
| 64 | |
| 65 scoped_ptr<base::DictionaryValue> ui_data_dict( | |
| 66 chromeos::onc::ReadDictionaryFromJson(ui_data_str)); | |
| 67 if (!ui_data_dict) | |
| 68 return false; | |
| 69 ui_data->reset(new chromeos::NetworkUIData(*ui_data_dict)); | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 54 } // namespace | 73 } // namespace |
| 55 | 74 |
| 56 namespace chromeos { | 75 namespace chromeos { |
| 57 | 76 |
| 58 NetworkState::NetworkState(const std::string& path) | 77 NetworkState::NetworkState(const std::string& path) |
| 59 : ManagedState(MANAGED_TYPE_NETWORK, path), | 78 : ManagedState(MANAGED_TYPE_NETWORK, path), |
| 60 auto_connect_(false), | 79 auto_connect_(false), |
| 61 favorite_(false), | 80 favorite_(false), |
| 62 priority_(0), | 81 priority_(0), |
| 82 user_profile_required_(false), | |
| 63 onc_source_(onc::ONC_SOURCE_NONE), | 83 onc_source_(onc::ONC_SOURCE_NONE), |
| 64 prefix_length_(0), | 84 prefix_length_(0), |
| 65 signal_strength_(0), | 85 signal_strength_(0), |
| 66 connectable_(false), | 86 connectable_(false), |
| 67 passphrase_required_(false), | 87 passphrase_required_(false), |
| 68 activate_over_non_cellular_networks_(false), | 88 activate_over_non_cellular_networks_(false), |
| 69 cellular_out_of_credits_(false) { | 89 cellular_out_of_credits_(false) { |
| 70 } | 90 } |
| 71 | 91 |
| 72 NetworkState::~NetworkState() { | 92 NetworkState::~NetworkState() { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 NET_LOG_ERROR("Failed to parse " + key, path()); | 176 NET_LOG_ERROR("Failed to parse " + key, path()); |
| 157 } | 177 } |
| 158 return true; | 178 return true; |
| 159 } else if (key == flimflam::kUIDataProperty) { | 179 } else if (key == flimflam::kUIDataProperty) { |
| 160 if (!GetOncSource(value, &onc_source_)) { | 180 if (!GetOncSource(value, &onc_source_)) { |
| 161 NET_LOG_ERROR("Failed to parse " + key, path()); | 181 NET_LOG_ERROR("Failed to parse " + key, path()); |
| 162 return false; | 182 return false; |
| 163 } | 183 } |
| 164 return true; | 184 return true; |
| 165 } else if (key == flimflam::kNetworkTechnologyProperty) { | 185 } else if (key == flimflam::kNetworkTechnologyProperty) { |
| 166 return GetStringValue(key, value, &technology_); | 186 return GetStringValue(key, value, &network_technology_); |
| 167 } else if (key == flimflam::kDeviceProperty) { | 187 } else if (key == flimflam::kDeviceProperty) { |
| 168 return GetStringValue(key, value, &device_path_); | 188 return GetStringValue(key, value, &device_path_); |
| 169 } else if (key == flimflam::kGuidProperty) { | 189 } else if (key == flimflam::kGuidProperty) { |
| 170 return GetStringValue(key, value, &guid_); | 190 return GetStringValue(key, value, &guid_); |
| 171 } else if (key == flimflam::kProfileProperty) { | 191 } else if (key == flimflam::kProfileProperty) { |
| 172 return GetStringValue(key, value, &profile_path_); | 192 return GetStringValue(key, value, &profile_path_); |
| 173 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { | 193 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { |
| 174 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); | 194 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); |
| 175 } else if (key == shill::kOutOfCreditsProperty) { | 195 } else if (key == shill::kOutOfCreditsProperty) { |
| 176 return GetBooleanValue(key, value, &cellular_out_of_credits_); | 196 return GetBooleanValue(key, value, &cellular_out_of_credits_); |
| 177 } else if (key == flimflam::kUsageURLProperty) { | 197 } else if (key == flimflam::kUsageURLProperty) { |
| 178 return GetStringValue(key, value, &usage_url_); | 198 return GetStringValue(key, value, &usage_url_); |
| 179 } else if (key == flimflam::kPaymentPortalProperty) { | 199 } else if (key == flimflam::kPaymentPortalProperty) { |
| 180 const DictionaryValue* dict; | 200 const DictionaryValue* dict; |
| 181 if (!value.GetAsDictionary(&dict)) | 201 if (!value.GetAsDictionary(&dict)) |
| 182 return false; | 202 return false; |
| 183 if (!dict->GetStringWithoutPathExpansion( | 203 if (!dict->GetStringWithoutPathExpansion( |
| 184 flimflam::kPaymentPortalURL, &payment_url_) || | 204 flimflam::kPaymentPortalURL, &payment_url_) || |
| 185 !dict->GetStringWithoutPathExpansion( | 205 !dict->GetStringWithoutPathExpansion( |
| 186 flimflam::kPaymentPortalMethod, &post_method_) || | 206 flimflam::kPaymentPortalMethod, &post_method_) || |
| 187 !dict->GetStringWithoutPathExpansion( | 207 !dict->GetStringWithoutPathExpansion( |
| 188 flimflam::kPaymentPortalPostData, &post_data_)) { | 208 flimflam::kPaymentPortalPostData, &post_data_)) { |
| 189 return false; | 209 return false; |
| 190 } | 210 } |
| 191 return true; | 211 return true; |
| 192 } else if (key == flimflam::kWifiHexSsid) { | |
| 193 return GetStringValue(key, value, &hex_ssid_); | |
| 194 } else if (key == flimflam::kCountryProperty) { | |
| 195 // TODO(stevenjb): This is currently experimental. If we find a case where | |
| 196 // base::DetectEncoding() fails in UpdateName(), where country_code_ is | |
| 197 // set, figure out whether we can use country_code_ with ConvertToUtf8(). | |
| 198 // crbug.com/233267. | |
| 199 return GetStringValue(key, value, &country_code_); | |
| 200 } | 212 } |
| 201 return false; | 213 return false; |
| 202 } | 214 } |
| 203 | 215 |
| 204 void NetworkState::InitialPropertiesReceived() { | 216 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.
| |
| 205 UpdateName(); | 217 const base::DictionaryValue& properties) { |
| 218 UpdateName(properties); | |
| 219 UpdateUserProfileRequired(properties); | |
| 206 } | 220 } |
| 207 | 221 |
| 208 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { | 222 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { |
| 209 // Keep care that these properties are the same as in |PropertyChanged|. | 223 // Keep care that these properties are the same as in |PropertyChanged|. |
| 210 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); | 224 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); |
| 211 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); | 225 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); |
| 212 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, | 226 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, |
| 213 signal_strength_); | 227 signal_strength_); |
| 214 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, | 228 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, |
| 215 connection_state_); | 229 connection_state_); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 favorite_); | 273 favorite_); |
| 260 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, | 274 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, |
| 261 priority_); | 275 priority_); |
| 262 // Proxy config and ONC source are intentionally omitted: These properties are | 276 // Proxy config and ONC source are intentionally omitted: These properties are |
| 263 // placed in NetworkState to transition ProxyConfigServiceImpl from | 277 // placed in NetworkState to transition ProxyConfigServiceImpl from |
| 264 // NetworkLibrary to the new network stack. The networking extension API | 278 // NetworkLibrary to the new network stack. The networking extension API |
| 265 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler | 279 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler |
| 266 // is used instead of NetworkLibrary, we can remove them again. | 280 // is used instead of NetworkLibrary, we can remove them again. |
| 267 dictionary->SetStringWithoutPathExpansion( | 281 dictionary->SetStringWithoutPathExpansion( |
| 268 flimflam::kNetworkTechnologyProperty, | 282 flimflam::kNetworkTechnologyProperty, |
| 269 technology_); | 283 network_technology_); |
| 270 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, | 284 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
| 271 device_path_); | 285 device_path_); |
| 272 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); | 286 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); |
| 273 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, | 287 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, |
| 274 profile_path_); | 288 profile_path_); |
| 275 dictionary->SetBooleanWithoutPathExpansion( | 289 dictionary->SetBooleanWithoutPathExpansion( |
| 276 shill::kActivateOverNonCellularNetworkProperty, | 290 shill::kActivateOverNonCellularNetworkProperty, |
| 277 activate_over_non_cellular_networks_); | 291 activate_over_non_cellular_networks_); |
| 278 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, | 292 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, |
| 279 cellular_out_of_credits_); | 293 cellular_out_of_credits_); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 306 | 320 |
| 307 bool NetworkState::IsConnectingState() const { | 321 bool NetworkState::IsConnectingState() const { |
| 308 return StateIsConnecting(connection_state_); | 322 return StateIsConnecting(connection_state_); |
| 309 } | 323 } |
| 310 | 324 |
| 311 bool NetworkState::IsManaged() const { | 325 bool NetworkState::IsManaged() const { |
| 312 return onc_source_ == onc::ONC_SOURCE_DEVICE_POLICY || | 326 return onc_source_ == onc::ONC_SOURCE_DEVICE_POLICY || |
| 313 onc_source_ == onc::ONC_SOURCE_USER_POLICY; | 327 onc_source_ == onc::ONC_SOURCE_USER_POLICY; |
| 314 } | 328 } |
| 315 | 329 |
| 316 bool NetworkState::IsShared() const { | 330 bool NetworkState::IsPrivate() const { |
| 317 return profile_path_ == NetworkProfileHandler::kSharedProfilePath; | 331 return !profile_path_.empty() && |
| 332 profile_path_ != NetworkProfileHandler::kSharedProfilePath; | |
| 318 } | 333 } |
| 319 | 334 |
| 320 std::string NetworkState::GetDnsServersAsString() const { | 335 std::string NetworkState::GetDnsServersAsString() const { |
| 321 std::string result; | 336 std::string result; |
| 322 for (size_t i = 0; i < dns_servers_.size(); ++i) { | 337 for (size_t i = 0; i < dns_servers_.size(); ++i) { |
| 323 if (i != 0) | 338 if (i != 0) |
| 324 result += ","; | 339 result += ","; |
| 325 result += dns_servers_[i]; | 340 result += dns_servers_[i]; |
| 326 } | 341 } |
| 327 return result; | 342 return result; |
| 328 } | 343 } |
| 329 | 344 |
| 330 std::string NetworkState::GetNetmask() const { | 345 std::string NetworkState::GetNetmask() const { |
| 331 return network_util::PrefixLengthToNetmask(prefix_length_); | 346 return network_util::PrefixLengthToNetmask(prefix_length_); |
| 332 } | 347 } |
| 333 | 348 |
| 334 bool NetworkState::HasAuthenticationError() const { | 349 bool NetworkState::HasAuthenticationError() const { |
| 335 return (error_ == flimflam::kErrorBadPassphrase || | 350 return (error_ == flimflam::kErrorBadPassphrase || |
| 336 error_ == flimflam::kErrorBadWEPKey || | 351 error_ == flimflam::kErrorBadWEPKey || |
| 337 error_ == flimflam::kErrorPppAuthFailed || | 352 error_ == flimflam::kErrorPppAuthFailed || |
| 338 error_ == shill::kErrorEapLocalTlsFailed || | 353 error_ == shill::kErrorEapLocalTlsFailed || |
| 339 error_ == shill::kErrorEapRemoteTlsFailed || | 354 error_ == shill::kErrorEapRemoteTlsFailed || |
| 340 error_ == shill::kErrorEapAuthenticationFailed); | 355 error_ == shill::kErrorEapAuthenticationFailed); |
| 341 } | 356 } |
| 342 | 357 |
| 343 void NetworkState::UpdateName() { | 358 void NetworkState::UpdateName(const base::DictionaryValue& properties) { |
| 344 if (hex_ssid_.empty()) { | 359 std::string hex_ssid; |
| 360 properties.GetStringWithoutPathExpansion(flimflam::kWifiHexSsid, &hex_ssid); | |
| 361 if (hex_ssid.empty()) { | |
| 345 // Validate name for UTF8. | 362 // Validate name for UTF8. |
| 346 std::string valid_ssid = ValidateUTF8(name()); | 363 std::string valid_ssid = ValidateUTF8(name()); |
| 347 if (valid_ssid != name()) { | 364 if (valid_ssid != name()) { |
| 348 set_name(valid_ssid); | 365 set_name(valid_ssid); |
| 349 NET_LOG_DEBUG("UpdateName", base::StringPrintf( | 366 NET_LOG_DEBUG("UpdateName", base::StringPrintf( |
| 350 "%s: UTF8: %s", path().c_str(), name().c_str())); | 367 "%s: UTF8: %s", path().c_str(), name().c_str())); |
| 351 } | 368 } |
| 352 return; | 369 return; |
| 353 } | 370 } |
| 354 | 371 |
| 355 std::string ssid; | 372 std::string ssid; |
| 356 std::vector<uint8> raw_ssid_bytes; | 373 std::vector<uint8> raw_ssid_bytes; |
| 357 if (base::HexStringToBytes(hex_ssid_, &raw_ssid_bytes)) { | 374 if (base::HexStringToBytes(hex_ssid, &raw_ssid_bytes)) { |
| 358 ssid = std::string(raw_ssid_bytes.begin(), raw_ssid_bytes.end()); | 375 ssid = std::string(raw_ssid_bytes.begin(), raw_ssid_bytes.end()); |
| 359 } else { | 376 } else { |
| 360 std::string desc = base::StringPrintf("%s: Error processing: %s", | 377 std::string desc = base::StringPrintf("%s: Error processing: %s", |
| 361 path().c_str(), hex_ssid_.c_str()); | 378 path().c_str(), hex_ssid.c_str()); |
| 362 NET_LOG_DEBUG("UpdateName", desc); | 379 NET_LOG_DEBUG("UpdateName", desc); |
| 363 LOG(ERROR) << desc; | 380 LOG(ERROR) << desc; |
| 364 ssid = name(); | 381 ssid = name(); |
| 365 } | 382 } |
| 366 | 383 |
| 367 if (IsStringUTF8(ssid)) { | 384 if (IsStringUTF8(ssid)) { |
| 368 if (ssid != name()) { | 385 if (ssid != name()) { |
| 369 set_name(ssid); | 386 set_name(ssid); |
| 370 NET_LOG_DEBUG("UpdateName", base::StringPrintf( | 387 NET_LOG_DEBUG("UpdateName", base::StringPrintf( |
| 371 "%s: UTF8: %s", path().c_str(), name().c_str())); | 388 "%s: UTF8: %s", path().c_str(), name().c_str())); |
| 372 } | 389 } |
| 373 return; | 390 return; |
| 374 } | 391 } |
| 375 | 392 |
| 376 // Detect encoding and convert to UTF-8. | 393 // Detect encoding and convert to UTF-8. |
| 394 std::string country_code; | |
| 395 properties.GetStringWithoutPathExpansion( | |
| 396 flimflam::kCountryProperty, &country_code); | |
| 377 std::string encoding; | 397 std::string encoding; |
| 378 if (!base::DetectEncoding(ssid, &encoding)) { | 398 if (!base::DetectEncoding(ssid, &encoding)) { |
| 379 // TODO(stevenjb): Test this. See comment in PropertyChanged() under | 399 // TODO(stevenjb): This is currently experimental. If we find a case where |
| 380 // flimflam::kCountryProperty. | 400 // base::DetectEncoding() fails, we need to figure out whether we can use |
| 381 encoding = country_code_; | 401 // country_code with ConvertToUtf8(). crbug.com/233267. |
| 402 encoding = country_code; | |
| 382 } | 403 } |
| 383 if (!encoding.empty()) { | 404 if (!encoding.empty()) { |
| 384 std::string utf8_ssid; | 405 std::string utf8_ssid; |
| 385 if (base::ConvertToUtf8AndNormalize(ssid, encoding, &utf8_ssid)) { | 406 if (base::ConvertToUtf8AndNormalize(ssid, encoding, &utf8_ssid)) { |
| 386 set_name(utf8_ssid); | 407 set_name(utf8_ssid); |
| 387 NET_LOG_DEBUG("UpdateName", base::StringPrintf( | 408 NET_LOG_DEBUG("UpdateName", base::StringPrintf( |
| 388 "%s: Encoding=%s: %s", path().c_str(), | 409 "%s: Encoding=%s: %s", path().c_str(), |
| 389 encoding.c_str(), name().c_str())); | 410 encoding.c_str(), name().c_str())); |
| 390 return; | 411 return; |
| 391 } | 412 } |
| 392 } | 413 } |
| 393 | 414 |
| 394 // Unrecognized encoding. Only use raw bytes if name_ is empty. | 415 // Unrecognized encoding. Only use raw bytes if name_ is empty. |
| 395 if (name().empty()) | 416 if (name().empty()) |
| 396 set_name(ssid); | 417 set_name(ssid); |
| 397 NET_LOG_DEBUG("UpdateName", base::StringPrintf( | 418 NET_LOG_DEBUG("UpdateName", base::StringPrintf( |
| 398 "%s: Unrecognized Encoding=%s: %s", path().c_str(), | 419 "%s: Unrecognized Encoding=%s: %s", path().c_str(), |
| 399 encoding.c_str(), name().c_str())); | 420 encoding.c_str(), name().c_str())); |
| 400 } | 421 } |
| 401 | 422 |
| 423 void NetworkState::UpdateUserProfileRequired( | |
| 424 const base::DictionaryValue& properties) { | |
| 425 // VPN always requires a user profile. | |
| 426 if (type() == flimflam::kTypeVPN) { | |
| 427 user_profile_required_ = true; | |
| 428 return; | |
| 429 } | |
| 430 | |
| 431 // 8021x EAP-TLS wifi networks with a certificate or pattern set require a | |
| 432 // user profile. | |
| 433 if (type() == flimflam::kTypeWifi && | |
| 434 security() == flimflam::kSecurity8021x) { | |
| 435 std::string eap_method; | |
| 436 properties.GetStringWithoutPathExpansion( | |
| 437 flimflam::kEapMethodProperty, &eap_method); | |
| 438 if (eap_method != flimflam::kEapMethodTLS) | |
| 439 return; | |
| 440 | |
| 441 std::string eap_cert_id; | |
| 442 properties.GetStringWithoutPathExpansion( | |
| 443 flimflam::kEapCertIdProperty, &eap_cert_id); | |
| 444 if (!eap_cert_id.empty()) { | |
| 445 user_profile_required_ = true; | |
| 446 return; | |
| 447 } | |
| 448 | |
| 449 const base::Value* ui_data_value; | |
| 450 if (properties.GetWithoutPathExpansion( | |
| 451 flimflam::kUIDataProperty, &ui_data_value)) { | |
| 452 scoped_ptr<NetworkUIData> ui_data; | |
| 453 if (!GetUIDataFromValue(*ui_data_value, &ui_data) || !ui_data) | |
| 454 return; | |
| 455 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
| |
| 456 user_profile_required_ = true; | |
| 457 } | |
| 458 } | |
| 459 } | |
| 460 | |
| 402 // static | 461 // static |
| 403 bool NetworkState::StateIsConnected(const std::string& connection_state) { | 462 bool NetworkState::StateIsConnected(const std::string& connection_state) { |
| 404 return (connection_state == flimflam::kStateReady || | 463 return (connection_state == flimflam::kStateReady || |
| 405 connection_state == flimflam::kStateOnline || | 464 connection_state == flimflam::kStateOnline || |
| 406 connection_state == flimflam::kStatePortal); | 465 connection_state == flimflam::kStatePortal); |
| 407 } | 466 } |
| 408 | 467 |
| 409 // static | 468 // static |
| 410 bool NetworkState::StateIsConnecting(const std::string& connection_state) { | 469 bool NetworkState::StateIsConnecting(const std::string& connection_state) { |
| 411 return (connection_state == flimflam::kStateAssociation || | 470 return (connection_state == flimflam::kStateAssociation || |
| 412 connection_state == flimflam::kStateConfiguration || | 471 connection_state == flimflam::kStateConfiguration || |
| 413 connection_state == flimflam::kStateCarrier); | 472 connection_state == flimflam::kStateCarrier); |
| 414 } | 473 } |
| 415 | 474 |
| 416 // static | 475 // static |
| 417 std::string NetworkState::IPConfigProperty(const char* key) { | 476 std::string NetworkState::IPConfigProperty(const char* key) { |
| 418 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | 477 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
| 419 } | 478 } |
| 420 | 479 |
| 421 // static | 480 // static |
| 422 bool NetworkState::GetOncSource(const base::Value& value, | 481 bool NetworkState::GetOncSource(const base::Value& ui_data_value, |
| 423 onc::ONCSource* out) { | 482 onc::ONCSource* out) { |
| 424 std::string ui_data_str; | 483 scoped_ptr<NetworkUIData> ui_data; |
| 425 if (!value.GetAsString(&ui_data_str)) | 484 if (!GetUIDataFromValue(ui_data_value, &ui_data)) |
| 426 return false; | 485 return false; |
| 427 if (ui_data_str.empty()) { | 486 if (!ui_data) { |
| 428 *out = onc::ONC_SOURCE_NONE; | 487 *out = onc::ONC_SOURCE_NONE; |
| 429 return true; | 488 return true; |
| 430 } | 489 } |
| 431 scoped_ptr<base::DictionaryValue> ui_data_dict( | 490 *out = ui_data->onc_source(); |
| 432 onc::ReadDictionaryFromJson(ui_data_str)); | |
| 433 if (!ui_data_dict) | |
| 434 return false; | |
| 435 *out = NetworkUIData(*ui_data_dict).onc_source(); | |
| 436 return true; | 491 return true; |
| 437 } | 492 } |
| 438 | 493 |
| 439 } // namespace chromeos | 494 } // namespace chromeos |
| OLD | NEW |