Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: chromeos/network/onc/onc_translator_shill_to_onc.cc

Issue 402953004: Correctly translate Cellular Device properties to ONC (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restore cellular_with_state signature, add nested ShillToONCTranslator constructor, update tests Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/onc/onc_translator.h" 5 #include "chromeos/network/onc/onc_translator.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // are translated. 48 // are translated.
49 class ShillToONCTranslator { 49 class ShillToONCTranslator {
50 public: 50 public:
51 ShillToONCTranslator(const base::DictionaryValue& shill_dictionary, 51 ShillToONCTranslator(const base::DictionaryValue& shill_dictionary,
52 const OncValueSignature& onc_signature) 52 const OncValueSignature& onc_signature)
53 : shill_dictionary_(&shill_dictionary), 53 : shill_dictionary_(&shill_dictionary),
54 onc_signature_(&onc_signature) { 54 onc_signature_(&onc_signature) {
55 field_translation_table_ = GetFieldTranslationTable(onc_signature); 55 field_translation_table_ = GetFieldTranslationTable(onc_signature);
56 } 56 }
57 57
58 ShillToONCTranslator(const base::DictionaryValue& shill_dictionary,
59 const OncValueSignature& onc_signature,
60 const FieldTranslationEntry* field_translation_table)
61 : shill_dictionary_(&shill_dictionary),
62 onc_signature_(&onc_signature),
63 field_translation_table_(field_translation_table) {
64 }
65
58 // Translates the associated Shill dictionary and creates an ONC object of the 66 // Translates the associated Shill dictionary and creates an ONC object of the
59 // given signature. 67 // given signature.
60 scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject(); 68 scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject();
61 69
62 private: 70 private:
63 void TranslateEthernet(); 71 void TranslateEthernet();
64 void TranslateOpenVPN(); 72 void TranslateOpenVPN();
65 void TranslateIPsec(); 73 void TranslateIPsec();
66 void TranslateVPN(); 74 void TranslateVPN();
67 void TranslateWiFiWithState(); 75 void TranslateWiFiWithState();
68 void TranslateCellularWithState(); 76 void TranslateCellularWithState();
77 void TranslateCellularDevice();
69 void TranslateNetworkWithState(); 78 void TranslateNetworkWithState();
70 void TranslateIPConfig(); 79 void TranslateIPConfig();
71 80
72 // Creates an ONC object from |dictionary| according to the signature 81 // Creates an ONC object from |dictionary| according to the signature
73 // associated to |onc_field_name| and adds it to |onc_object_| at 82 // associated to |onc_field_name| and adds it to |onc_object_| at
74 // |onc_field_name|. 83 // |onc_field_name|.
75 void TranslateAndAddNestedObject(const std::string& onc_field_name, 84 void TranslateAndAddNestedObject(const std::string& onc_field_name,
76 const base::DictionaryValue& dictionary); 85 const base::DictionaryValue& dictionary);
77 86
78 // Creates an ONC object from |shill_dictionary_| according to the signature 87 // Creates an ONC object from |shill_dictionary_| according to the signature
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 TranslateEthernet(); 134 TranslateEthernet();
126 } else if (onc_signature_ == &kVPNSignature) { 135 } else if (onc_signature_ == &kVPNSignature) {
127 TranslateVPN(); 136 TranslateVPN();
128 } else if (onc_signature_ == &kOpenVPNSignature) { 137 } else if (onc_signature_ == &kOpenVPNSignature) {
129 TranslateOpenVPN(); 138 TranslateOpenVPN();
130 } else if (onc_signature_ == &kIPsecSignature) { 139 } else if (onc_signature_ == &kIPsecSignature) {
131 TranslateIPsec(); 140 TranslateIPsec();
132 } else if (onc_signature_ == &kWiFiWithStateSignature) { 141 } else if (onc_signature_ == &kWiFiWithStateSignature) {
133 TranslateWiFiWithState(); 142 TranslateWiFiWithState();
134 } else if (onc_signature_ == &kCellularWithStateSignature) { 143 } else if (onc_signature_ == &kCellularWithStateSignature) {
135 TranslateCellularWithState(); 144 if (field_translation_table_ == kCellularDeviceTable)
pneubeck (no reviews) 2014/07/25 08:50:03 oh, I didn't foresee that one :-/ To avoid this, I
stevenjb 2014/07/25 17:00:54 Yeah, I'll be honest, I find these translation fun
145 TranslateCellularDevice();
146 else
147 TranslateCellularWithState();
136 } else if (onc_signature_ == &kIPConfigSignature) { 148 } else if (onc_signature_ == &kIPConfigSignature) {
137 TranslateIPConfig(); 149 TranslateIPConfig();
138 } else { 150 } else {
139 CopyPropertiesAccordingToSignature(); 151 CopyPropertiesAccordingToSignature();
140 } 152 }
141 return onc_object_.Pass(); 153 return onc_object_.Pass();
142 } 154 }
143 155
144 void ShillToONCTranslator::TranslateEthernet() { 156 void ShillToONCTranslator::TranslateEthernet() {
145 std::string shill_network_type; 157 std::string shill_network_type;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 CopyPropertiesAccordingToSignature(); 263 CopyPropertiesAccordingToSignature();
252 const base::DictionaryValue* dictionary = NULL; 264 const base::DictionaryValue* dictionary = NULL;
253 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( 265 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
254 shill::kServingOperatorProperty, &dictionary)) { 266 shill::kServingOperatorProperty, &dictionary)) {
255 TranslateAndAddNestedObject(::onc::cellular::kServingOperator, *dictionary); 267 TranslateAndAddNestedObject(::onc::cellular::kServingOperator, *dictionary);
256 } 268 }
257 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( 269 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
258 shill::kCellularApnProperty, &dictionary)) { 270 shill::kCellularApnProperty, &dictionary)) {
259 TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary); 271 TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary);
260 } 272 }
273 // Merge the Device dictionary with this one (Cellular) using the
274 // CellularDevice signature.
275 const base::DictionaryValue* device_dictionary = NULL;
276 if (!shill_dictionary_->GetDictionaryWithoutPathExpansion(
277 shill::kDeviceProperty, &device_dictionary)) {
278 return;
279 }
280 ShillToONCTranslator nested_translator(*device_dictionary,
281 kCellularWithStateSignature,
282 kCellularDeviceTable);
283 scoped_ptr<base::DictionaryValue> nested_object =
284 nested_translator.CreateTranslatedONCObject();
285 onc_object_->MergeDictionary(nested_object.get());
286 }
287
288 void ShillToONCTranslator::TranslateCellularDevice() {
289 CopyPropertiesAccordingToSignature();
290 const base::DictionaryValue* shill_sim_lock_status = NULL;
291 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
292 shill::kSIMLockStatusProperty, &shill_sim_lock_status)) {
293 TranslateAndAddNestedObject(::onc::cellular::kSIMLockStatus,
294 *shill_sim_lock_status);
295 }
261 const base::ListValue* shill_apns = NULL; 296 const base::ListValue* shill_apns = NULL;
262 if (shill_dictionary_->GetListWithoutPathExpansion( 297 if (shill_dictionary_->GetListWithoutPathExpansion(
263 shill::kCellularApnListProperty, &shill_apns)) { 298 shill::kCellularApnListProperty, &shill_apns)) {
264 TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *shill_apns); 299 TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *shill_apns);
265 } 300 }
266 301 const base::ListValue* shill_found_networks = NULL;
267 const base::DictionaryValue* device_dictionary = NULL; 302 if (shill_dictionary_->GetListWithoutPathExpansion(
268 if (!shill_dictionary_->GetDictionaryWithoutPathExpansion( 303 shill::kFoundNetworksProperty, &shill_found_networks)) {
269 shill::kDeviceProperty, &device_dictionary)) { 304 TranslateAndAddListOfObjects(::onc::cellular::kFoundNetworks,
270 return; 305 *shill_found_networks);
271 }
272
273 // Iterate through all fields of the CellularWithState signature and copy
274 // values from the device properties according to the separate
275 // CellularDeviceTable.
276 for (const OncFieldSignature* field_signature = onc_signature_->fields;
277 field_signature->onc_field_name != NULL; ++field_signature) {
278 const std::string& onc_field_name = field_signature->onc_field_name;
279
280 std::string shill_property_name;
281 const base::Value* shill_value = NULL;
282 if (!GetShillPropertyName(field_signature->onc_field_name,
283 kCellularDeviceTable,
284 &shill_property_name) ||
285 !device_dictionary->GetWithoutPathExpansion(shill_property_name,
286 &shill_value)) {
287 continue;
288 }
289 onc_object_->SetWithoutPathExpansion(onc_field_name,
290 shill_value->DeepCopy());
291 } 306 }
292 } 307 }
293 308
294 void ShillToONCTranslator::TranslateNetworkWithState() { 309 void ShillToONCTranslator::TranslateNetworkWithState() {
295 CopyPropertiesAccordingToSignature(); 310 CopyPropertiesAccordingToSignature();
296 311
297 std::string shill_network_type; 312 std::string shill_network_type;
298 shill_dictionary_->GetStringWithoutPathExpansion(shill::kTypeProperty, 313 shill_dictionary_->GetStringWithoutPathExpansion(shill::kTypeProperty,
299 &shill_network_type); 314 &shill_network_type);
300 std::string onc_network_type = ::onc::network_type::kEthernet; 315 std::string onc_network_type = ::onc::network_type::kEthernet;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 const base::DictionaryValue& shill_dictionary, 508 const base::DictionaryValue& shill_dictionary,
494 const OncValueSignature* onc_signature) { 509 const OncValueSignature* onc_signature) {
495 CHECK(onc_signature != NULL); 510 CHECK(onc_signature != NULL);
496 511
497 ShillToONCTranslator translator(shill_dictionary, *onc_signature); 512 ShillToONCTranslator translator(shill_dictionary, *onc_signature);
498 return translator.CreateTranslatedONCObject(); 513 return translator.CreateTranslatedONCObject();
499 } 514 }
500 515
501 } // namespace onc 516 } // namespace onc
502 } // namespace chromeos 517 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_translation_tables.cc ('k') | chromeos/test/data/network/shill_cellular_with_state.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698