diff options
author | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-15 02:55:28 +0000 |
---|---|---|
committer | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-15 02:55:28 +0000 |
commit | a722df12000a716024874982273921617e6efa53 (patch) | |
tree | 5a927392150b07ef194fbc562ad027610dad1551 /chromeos | |
parent | 172328d3b4fca5765177b75f0ff57382d98cde6e (diff) | |
download | chromium_src-a722df12000a716024874982273921617e6efa53.zip chromium_src-a722df12000a716024874982273921617e6efa53.tar.gz chromium_src-a722df12000a716024874982273921617e6efa53.tar.bz2 |
onc: Handle translation of Cellular.APNList property.
This CL adds code to onc_translator_shill_to_onc.cc that handles a list of
nested objects and uses it to translate the Cellular.APNList property.
BUG=280359
Review URL: https://codereview.chromium.org/24248005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228602 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
4 files changed, 94 insertions, 3 deletions
diff --git a/chromeos/network/onc/onc_signature.cc b/chromeos/network/onc/onc_signature.cc index f5589d1..fc7bf2f 100644 --- a/chromeos/network/onc/onc_signature.cc +++ b/chromeos/network/onc/onc_signature.cc @@ -31,6 +31,9 @@ const OncValueSignature kIntegerListSignature = { const OncValueSignature kIPConfigListSignature = { Value::TYPE_LIST, NULL, &kIPConfigSignature }; +const OncValueSignature kCellularApnListSignature = { + Value::TYPE_LIST, NULL, &kCellularApnSignature +}; const OncFieldSignature issuer_subject_pattern_fields[] = { { ::onc::certificate::kCommonName, &kStringSignature}, @@ -201,7 +204,8 @@ const OncFieldSignature cellular_apn_fields[] = { const OncFieldSignature cellular_fields[] = { { ::onc::kRecommended, &kRecommendedSignature}, - { ::onc::cellular::kAPN, &kCellularApnSignature}, {NULL}}; + { ::onc::cellular::kAPN, &kCellularApnSignature }, + { ::onc::cellular::kAPNList, &kCellularApnListSignature}, {NULL}}; const OncFieldSignature cellular_with_state_fields[] = { { ::onc::cellular::kActivateOverNonCellularNetwork, &kBoolSignature}, diff --git a/chromeos/network/onc/onc_translator_shill_to_onc.cc b/chromeos/network/onc/onc_translator_shill_to_onc.cc index bc14913..dbd5bcd 100644 --- a/chromeos/network/onc/onc_translator_shill_to_onc.cc +++ b/chromeos/network/onc/onc_translator_shill_to_onc.cc @@ -77,6 +77,13 @@ class ShillToONCTranslator { // |onc_field_name|. void TranslateAndAddNestedObject(const std::string& onc_field_name); + // Translates a list of nested objects and adds the list to |onc_object_| at + // |onc_field_name|. If there are errors while parsing individual objects or + // if the resulting list contains no entries, the result will not be added to + // |onc_object_|. + void TranslateAndAddListOfObjects(const std::string& onc_field_name, + const base::ListValue& list); + // Applies function CopyProperty to each field of |value_signature| and its // base signatures. void CopyPropertiesAccordingToSignature( @@ -235,6 +242,11 @@ void ShillToONCTranslator::TranslateCellularWithState() { shill::kCellularApnProperty, &dictionary)) { TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary); } + const base::ListValue* list = NULL; + if (shill_dictionary_->GetListWithoutPathExpansion( + shill::kCellularApnListProperty, &list)) { + TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *list); + } } void ShillToONCTranslator::TranslateNetworkWithState() { @@ -296,6 +308,41 @@ void ShillToONCTranslator::TranslateAndAddNestedObject( onc_object_->SetWithoutPathExpansion(onc_field_name, nested_object.release()); } +void ShillToONCTranslator::TranslateAndAddListOfObjects( + const std::string& onc_field_name, + const base::ListValue& list) { + const OncFieldSignature* field_signature = + GetFieldSignature(*onc_signature_, onc_field_name); + if (field_signature->value_signature->onc_type != Value::TYPE_LIST) { + LOG(ERROR) << "ONC Field name: '" << onc_field_name << "' has type '" + << field_signature->value_signature->onc_type + << "', expected: base::Value::TYPE_LIST."; + return; + } + DCHECK(field_signature->value_signature->onc_array_entry_signature); + scoped_ptr<base::ListValue> result(new base::ListValue()); + for (base::ListValue::const_iterator it = list.begin(); + it != list.end(); ++it) { + const base::DictionaryValue* shill_value = NULL; + if (!(*it)->GetAsDictionary(&shill_value)) + continue; + ShillToONCTranslator nested_translator( + *shill_value, + *field_signature->value_signature->onc_array_entry_signature); + scoped_ptr<base::DictionaryValue> nested_object = + nested_translator.CreateTranslatedONCObject(); + if (nested_object->empty()) + // The nested object couldn't be parsed, so simply omit it. + continue; + result->Append(nested_object.release()); + } + if (result->empty()) + // There are no entries in the list, so there is no need to expose this + // field. + return; + onc_object_->SetWithoutPathExpansion(onc_field_name, result.release()); +} + void ShillToONCTranslator::CopyPropertiesAccordingToSignature() { CopyPropertiesAccordingToSignature(onc_signature_); } diff --git a/chromeos/test/data/network/shill_cellular_with_state.json b/chromeos/test/data/network/shill_cellular_with_state.json index 5573791..0df6822c 100644 --- a/chromeos/test/data/network/shill_cellular_with_state.json +++ b/chromeos/test/data/network/shill_cellular_with_state.json @@ -12,5 +12,27 @@ "apn": "test-apn", "username": "test-username", "password": "test-password" - } + }, + "Cellular.APNList": [ + { + "apn": "test-apn0", + "username": "test-username0", + "password": "test-password0" + }, + { + "apn": "test-apn1", + "username": "test-username1", + "password": "test-password1" + }, + { + "apn": "test-apn2", + "username": "test-username2", + "password": "test-password2" + }, + { + "apn": "test-apn3", + "username": "test-username3", + "password": "test-password3" + } + ] } diff --git a/chromeos/test/data/network/translation_of_shill_cellular_with_state.onc b/chromeos/test/data/network/translation_of_shill_cellular_with_state.onc index 7107062..56534c4 100644 --- a/chromeos/test/data/network/translation_of_shill_cellular_with_state.onc +++ b/chromeos/test/data/network/translation_of_shill_cellular_with_state.onc @@ -13,6 +13,24 @@ "Name": "test-apn", "Username": "test-username", "Password": "test-password" - } + }, + "APNList": [ { + "Name": "test-apn0", + "Password": "test-password0", + "Username": "test-username0" + }, { + "Name": "test-apn1", + "Password": "test-password1", + "Username": "test-username1" + }, { + "Name": "test-apn2", + "Password": "test-password2", + "Username": "test-username2" + }, { + "Name": "test-apn3", + "Password": "test-password3", + "Username": "test-username3" + } + ] } } |