| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/cros/native_network_parser.h" | 5 #include "chrome/browser/chromeos/cros/native_network_parser.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "chrome/browser/chromeos/cros/native_network_constants.h" | 8 #include "chrome/browser/chromeos/cros/native_network_constants.h" |
| 9 #include "chrome/browser/chromeos/cros/network_library.h" | 9 #include "chrome/browser/chromeos/cros/network_library.h" |
| 10 #include "chrome/browser/chromeos/login/user_manager.h" | 10 #include "chrome/browser/chromeos/login/user_manager.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 return true; | 187 return true; |
| 188 } | 188 } |
| 189 case PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING: { | 189 case PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING: { |
| 190 bool data_roaming_allowed; | 190 bool data_roaming_allowed; |
| 191 if (!value.GetAsBoolean(&data_roaming_allowed)) | 191 if (!value.GetAsBoolean(&data_roaming_allowed)) |
| 192 return false; | 192 return false; |
| 193 device->set_data_roaming_allowed(data_roaming_allowed); | 193 device->set_data_roaming_allowed(data_roaming_allowed); |
| 194 return true; | 194 return true; |
| 195 } | 195 } |
| 196 case PROPERTY_INDEX_CELLULAR_APN_LIST: | 196 case PROPERTY_INDEX_CELLULAR_APN_LIST: |
| 197 if (value.IsType(Value::TYPE_LIST)) { | 197 if (value.IsList()) { |
| 198 CellularApnList provider_apn_list; | 198 CellularApnList provider_apn_list; |
| 199 if (!ParseApnList(static_cast<const ListValue&>(value), | 199 if (!ParseApnList(static_cast<const ListValue&>(value), |
| 200 &provider_apn_list)) | 200 &provider_apn_list)) |
| 201 return false; | 201 return false; |
| 202 device->set_provider_apn_list(provider_apn_list); | 202 device->set_provider_apn_list(provider_apn_list); |
| 203 return true; | 203 return true; |
| 204 } | 204 } |
| 205 break; | 205 break; |
| 206 case PROPERTY_INDEX_NETWORKS: | 206 case PROPERTY_INDEX_NETWORKS: |
| 207 if (value.IsType(Value::TYPE_LIST)) { | 207 if (value.IsList()) { |
| 208 // Ignored. | 208 // Ignored. |
| 209 return true; | 209 return true; |
| 210 } | 210 } |
| 211 break; | 211 break; |
| 212 case PROPERTY_INDEX_FOUND_NETWORKS: | 212 case PROPERTY_INDEX_FOUND_NETWORKS: |
| 213 if (value.IsType(Value::TYPE_LIST)) { | 213 if (value.IsList()) { |
| 214 CellularNetworkList found_cellular_networks; | 214 CellularNetworkList found_cellular_networks; |
| 215 if (!ParseFoundNetworksFromList( | 215 if (!ParseFoundNetworksFromList( |
| 216 static_cast<const ListValue&>(value), | 216 static_cast<const ListValue&>(value), |
| 217 &found_cellular_networks)) | 217 &found_cellular_networks)) |
| 218 return false; | 218 return false; |
| 219 device->set_found_cellular_networks(found_cellular_networks); | 219 device->set_found_cellular_networks(found_cellular_networks); |
| 220 return true; | 220 return true; |
| 221 } | 221 } |
| 222 break; | 222 break; |
| 223 case PROPERTY_INDEX_HOME_PROVIDER: { | 223 case PROPERTY_INDEX_HOME_PROVIDER: { |
| 224 if (value.IsType(Value::TYPE_DICTIONARY)) { | 224 if (value.IsDictionary()) { |
| 225 const DictionaryValue& dict = | 225 const DictionaryValue& dict = |
| 226 static_cast<const DictionaryValue&>(value); | 226 static_cast<const DictionaryValue&>(value); |
| 227 std::string home_provider_code; | 227 std::string home_provider_code; |
| 228 std::string home_provider_country; | 228 std::string home_provider_country; |
| 229 std::string home_provider_name; | 229 std::string home_provider_name; |
| 230 dict.GetStringWithoutPathExpansion(kOperatorCodeKey, | 230 dict.GetStringWithoutPathExpansion(kOperatorCodeKey, |
| 231 &home_provider_code); | 231 &home_provider_code); |
| 232 dict.GetStringWithoutPathExpansion(kOperatorCountryKey, | 232 dict.GetStringWithoutPathExpansion(kOperatorCountryKey, |
| 233 &home_provider_country); | 233 &home_provider_country); |
| 234 dict.GetStringWithoutPathExpansion(kOperatorNameKey, | 234 dict.GetStringWithoutPathExpansion(kOperatorNameKey, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 break; | 298 break; |
| 299 case PROPERTY_INDEX_SELECTED_NETWORK: | 299 case PROPERTY_INDEX_SELECTED_NETWORK: |
| 300 device->set_selected_cellular_network(item); | 300 device->set_selected_cellular_network(item); |
| 301 break; | 301 break; |
| 302 default: | 302 default: |
| 303 break; | 303 break; |
| 304 } | 304 } |
| 305 return true; | 305 return true; |
| 306 } | 306 } |
| 307 case PROPERTY_INDEX_SIM_LOCK: | 307 case PROPERTY_INDEX_SIM_LOCK: |
| 308 if (value.IsType(Value::TYPE_DICTIONARY)) { | 308 if (value.IsDictionary()) { |
| 309 SimLockState sim_lock_state; | 309 SimLockState sim_lock_state; |
| 310 int sim_retries_left; | 310 int sim_retries_left; |
| 311 if (!ParseSimLockStateFromDictionary( | 311 if (!ParseSimLockStateFromDictionary( |
| 312 static_cast<const DictionaryValue&>(value), | 312 static_cast<const DictionaryValue&>(value), |
| 313 &sim_lock_state, | 313 &sim_lock_state, |
| 314 &sim_retries_left)) | 314 &sim_retries_left)) |
| 315 return false; | 315 return false; |
| 316 device->set_sim_lock_state(sim_lock_state); | 316 device->set_sim_lock_state(sim_lock_state); |
| 317 device->set_sim_retries_left(sim_retries_left); | 317 device->set_sim_retries_left(sim_retries_left); |
| 318 // Initialize PinRequired value only once. | 318 // Initialize PinRequired value only once. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 362 |
| 363 ConnectionType NativeNetworkDeviceParser::ParseType(const std::string& type) { | 363 ConnectionType NativeNetworkDeviceParser::ParseType(const std::string& type) { |
| 364 return ParseNetworkType(type); | 364 return ParseNetworkType(type); |
| 365 } | 365 } |
| 366 | 366 |
| 367 bool NativeNetworkDeviceParser::ParseApnList(const ListValue& list, | 367 bool NativeNetworkDeviceParser::ParseApnList(const ListValue& list, |
| 368 CellularApnList* apn_list) { | 368 CellularApnList* apn_list) { |
| 369 apn_list->clear(); | 369 apn_list->clear(); |
| 370 apn_list->reserve(list.GetSize()); | 370 apn_list->reserve(list.GetSize()); |
| 371 for (ListValue::const_iterator it = list.begin(); it != list.end(); ++it) { | 371 for (ListValue::const_iterator it = list.begin(); it != list.end(); ++it) { |
| 372 if ((*it)->IsType(Value::TYPE_DICTIONARY)) { | 372 if ((*it)->IsDictionary()) { |
| 373 apn_list->resize(apn_list->size() + 1); | 373 apn_list->resize(apn_list->size() + 1); |
| 374 const DictionaryValue* dict = static_cast<const DictionaryValue*>(*it); | 374 const DictionaryValue* dict = static_cast<const DictionaryValue*>(*it); |
| 375 dict->GetStringWithoutPathExpansion( | 375 dict->GetStringWithoutPathExpansion( |
| 376 kApnProperty, &apn_list->back().apn); | 376 kApnProperty, &apn_list->back().apn); |
| 377 dict->GetStringWithoutPathExpansion( | 377 dict->GetStringWithoutPathExpansion( |
| 378 kApnNetworkIdProperty, &apn_list->back().network_id); | 378 kApnNetworkIdProperty, &apn_list->back().network_id); |
| 379 dict->GetStringWithoutPathExpansion( | 379 dict->GetStringWithoutPathExpansion( |
| 380 kApnUsernameProperty, &apn_list->back().username); | 380 kApnUsernameProperty, &apn_list->back().username); |
| 381 dict->GetStringWithoutPathExpansion( | 381 dict->GetStringWithoutPathExpansion( |
| 382 kApnPasswordProperty, &apn_list->back().password); | 382 kApnPasswordProperty, &apn_list->back().password); |
| 383 dict->GetStringWithoutPathExpansion( | 383 dict->GetStringWithoutPathExpansion( |
| 384 kApnNameProperty, &apn_list->back().name); | 384 kApnNameProperty, &apn_list->back().name); |
| 385 dict->GetStringWithoutPathExpansion( | 385 dict->GetStringWithoutPathExpansion( |
| 386 kApnLocalizedNameProperty, &apn_list->back().localized_name); | 386 kApnLocalizedNameProperty, &apn_list->back().localized_name); |
| 387 dict->GetStringWithoutPathExpansion( | 387 dict->GetStringWithoutPathExpansion( |
| 388 kApnLanguageProperty, &apn_list->back().language); | 388 kApnLanguageProperty, &apn_list->back().language); |
| 389 } else { | 389 } else { |
| 390 return false; | 390 return false; |
| 391 } | 391 } |
| 392 } | 392 } |
| 393 return true; | 393 return true; |
| 394 } | 394 } |
| 395 | 395 |
| 396 bool NativeNetworkDeviceParser::ParseFoundNetworksFromList( | 396 bool NativeNetworkDeviceParser::ParseFoundNetworksFromList( |
| 397 const ListValue& list, | 397 const ListValue& list, |
| 398 CellularNetworkList* found_networks) { | 398 CellularNetworkList* found_networks) { |
| 399 found_networks->clear(); | 399 found_networks->clear(); |
| 400 found_networks->reserve(list.GetSize()); | 400 found_networks->reserve(list.GetSize()); |
| 401 for (ListValue::const_iterator it = list.begin(); it != list.end(); ++it) { | 401 for (ListValue::const_iterator it = list.begin(); it != list.end(); ++it) { |
| 402 if ((*it)->IsType(Value::TYPE_DICTIONARY)) { | 402 if ((*it)->IsDictionary()) { |
| 403 found_networks->resize(found_networks->size() + 1); | 403 found_networks->resize(found_networks->size() + 1); |
| 404 const DictionaryValue* dict = static_cast<const DictionaryValue*>(*it); | 404 const DictionaryValue* dict = static_cast<const DictionaryValue*>(*it); |
| 405 dict->GetStringWithoutPathExpansion( | 405 dict->GetStringWithoutPathExpansion( |
| 406 kStatusProperty, &found_networks->back().status); | 406 kStatusProperty, &found_networks->back().status); |
| 407 dict->GetStringWithoutPathExpansion( | 407 dict->GetStringWithoutPathExpansion( |
| 408 kNetworkIdProperty, &found_networks->back().network_id); | 408 kNetworkIdProperty, &found_networks->back().network_id); |
| 409 dict->GetStringWithoutPathExpansion( | 409 dict->GetStringWithoutPathExpansion( |
| 410 kShortNameProperty, &found_networks->back().short_name); | 410 kShortNameProperty, &found_networks->back().short_name); |
| 411 dict->GetStringWithoutPathExpansion( | 411 dict->GetStringWithoutPathExpansion( |
| 412 kLongNameProperty, &found_networks->back().long_name); | 412 kLongNameProperty, &found_networks->back().long_name); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 ActivationState prev_state = cellular_network->activation_state(); | 690 ActivationState prev_state = cellular_network->activation_state(); |
| 691 cellular_network->set_activation_state( | 691 cellular_network->set_activation_state( |
| 692 ParseActivationState(activation_state_string)); | 692 ParseActivationState(activation_state_string)); |
| 693 if (cellular_network->activation_state() != prev_state) | 693 if (cellular_network->activation_state() != prev_state) |
| 694 cellular_network->RefreshDataPlansIfNeeded(); | 694 cellular_network->RefreshDataPlansIfNeeded(); |
| 695 return true; | 695 return true; |
| 696 } | 696 } |
| 697 break; | 697 break; |
| 698 } | 698 } |
| 699 case PROPERTY_INDEX_CELLULAR_APN: { | 699 case PROPERTY_INDEX_CELLULAR_APN: { |
| 700 if (value.IsType(Value::TYPE_DICTIONARY)) { | 700 if (value.IsDictionary()) { |
| 701 cellular_network->set_apn(static_cast<const DictionaryValue&>(value)); | 701 cellular_network->set_apn(static_cast<const DictionaryValue&>(value)); |
| 702 return true; | 702 return true; |
| 703 } | 703 } |
| 704 break; | 704 break; |
| 705 } | 705 } |
| 706 case PROPERTY_INDEX_CELLULAR_LAST_GOOD_APN: { | 706 case PROPERTY_INDEX_CELLULAR_LAST_GOOD_APN: { |
| 707 if (value.IsType(Value::TYPE_DICTIONARY)) { | 707 if (value.IsDictionary()) { |
| 708 cellular_network->set_last_good_apn( | 708 cellular_network->set_last_good_apn( |
| 709 static_cast<const DictionaryValue&>(value)); | 709 static_cast<const DictionaryValue&>(value)); |
| 710 return true; | 710 return true; |
| 711 } | 711 } |
| 712 break; | 712 break; |
| 713 } | 713 } |
| 714 case PROPERTY_INDEX_NETWORK_TECHNOLOGY: { | 714 case PROPERTY_INDEX_NETWORK_TECHNOLOGY: { |
| 715 std::string network_technology_string; | 715 std::string network_technology_string; |
| 716 if (value.GetAsString(&network_technology_string)) { | 716 if (value.GetAsString(&network_technology_string)) { |
| 717 cellular_network->set_network_technology( | 717 cellular_network->set_network_technology( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 737 return true; | 737 return true; |
| 738 } | 738 } |
| 739 case PROPERTY_INDEX_OPERATOR_CODE: { | 739 case PROPERTY_INDEX_OPERATOR_CODE: { |
| 740 std::string value_str; | 740 std::string value_str; |
| 741 if (!value.GetAsString(&value_str)) | 741 if (!value.GetAsString(&value_str)) |
| 742 break; | 742 break; |
| 743 cellular_network->set_operator_code(value_str); | 743 cellular_network->set_operator_code(value_str); |
| 744 return true; | 744 return true; |
| 745 } | 745 } |
| 746 case PROPERTY_INDEX_SERVING_OPERATOR: { | 746 case PROPERTY_INDEX_SERVING_OPERATOR: { |
| 747 if (value.IsType(Value::TYPE_DICTIONARY)) { | 747 if (value.IsDictionary()) { |
| 748 const DictionaryValue& dict = | 748 const DictionaryValue& dict = |
| 749 static_cast<const DictionaryValue&>(value); | 749 static_cast<const DictionaryValue&>(value); |
| 750 std::string value_str; | 750 std::string value_str; |
| 751 dict.GetStringWithoutPathExpansion(kOperatorNameKey, &value_str); | 751 dict.GetStringWithoutPathExpansion(kOperatorNameKey, &value_str); |
| 752 cellular_network->set_operator_name(value_str); | 752 cellular_network->set_operator_name(value_str); |
| 753 value_str.clear(); | 753 value_str.clear(); |
| 754 dict.GetStringWithoutPathExpansion(kOperatorCodeKey, &value_str); | 754 dict.GetStringWithoutPathExpansion(kOperatorCodeKey, &value_str); |
| 755 cellular_network->set_operator_code(value_str); | 755 cellular_network->set_operator_code(value_str); |
| 756 value_str.clear(); | 756 value_str.clear(); |
| 757 dict.GetStringWithoutPathExpansion(kOperatorCountryKey, &value_str); | 757 dict.GetStringWithoutPathExpansion(kOperatorCountryKey, &value_str); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 static EnumMapper<ProviderType>::Pair table[] = { | 1149 static EnumMapper<ProviderType>::Pair table[] = { |
| 1150 { kProviderL2tpIpsec, PROVIDER_TYPE_L2TP_IPSEC_PSK }, | 1150 { kProviderL2tpIpsec, PROVIDER_TYPE_L2TP_IPSEC_PSK }, |
| 1151 { kProviderOpenVpn, PROVIDER_TYPE_OPEN_VPN }, | 1151 { kProviderOpenVpn, PROVIDER_TYPE_OPEN_VPN }, |
| 1152 }; | 1152 }; |
| 1153 static EnumMapper<ProviderType> parser( | 1153 static EnumMapper<ProviderType> parser( |
| 1154 table, arraysize(table), PROVIDER_TYPE_MAX); | 1154 table, arraysize(table), PROVIDER_TYPE_MAX); |
| 1155 return parser.Get(type); | 1155 return parser.Get(type); |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 } // namespace chromeos | 1158 } // namespace chromeos |
| OLD | NEW |