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

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: Fix APNList and FoundNetworks Created 6 years, 5 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // given signature. 59 // given signature.
60 scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject(); 60 scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject();
61 61
62 private: 62 private:
63 void TranslateEthernet(); 63 void TranslateEthernet();
64 void TranslateOpenVPN(); 64 void TranslateOpenVPN();
65 void TranslateIPsec(); 65 void TranslateIPsec();
66 void TranslateVPN(); 66 void TranslateVPN();
67 void TranslateWiFiWithState(); 67 void TranslateWiFiWithState();
68 void TranslateCellularWithState(); 68 void TranslateCellularWithState();
69 void TranslateCellularDevice();
69 void TranslateNetworkWithState(); 70 void TranslateNetworkWithState();
70 void TranslateIPConfig(); 71 void TranslateIPConfig();
71 72
72 // Creates an ONC object from |dictionary| according to the signature 73 // Creates an ONC object from |dictionary| according to the signature
73 // associated to |onc_field_name| and adds it to |onc_object_| at 74 // associated to |onc_field_name| and adds it to |onc_object_| at
74 // |onc_field_name|. 75 // |onc_field_name|.
75 void TranslateAndAddNestedObject(const std::string& onc_field_name, 76 void TranslateAndAddNestedObject(const std::string& onc_field_name,
76 const base::DictionaryValue& dictionary); 77 const base::DictionaryValue& dictionary);
77 78
78 // Creates an ONC object from |shill_dictionary_| according to the signature 79 // Creates an ONC object from |shill_dictionary_| according to the signature
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } else if (onc_signature_ == &kVPNSignature) { 127 } else if (onc_signature_ == &kVPNSignature) {
127 TranslateVPN(); 128 TranslateVPN();
128 } else if (onc_signature_ == &kOpenVPNSignature) { 129 } else if (onc_signature_ == &kOpenVPNSignature) {
129 TranslateOpenVPN(); 130 TranslateOpenVPN();
130 } else if (onc_signature_ == &kIPsecSignature) { 131 } else if (onc_signature_ == &kIPsecSignature) {
131 TranslateIPsec(); 132 TranslateIPsec();
132 } else if (onc_signature_ == &kWiFiWithStateSignature) { 133 } else if (onc_signature_ == &kWiFiWithStateSignature) {
133 TranslateWiFiWithState(); 134 TranslateWiFiWithState();
134 } else if (onc_signature_ == &kCellularWithStateSignature) { 135 } else if (onc_signature_ == &kCellularWithStateSignature) {
135 TranslateCellularWithState(); 136 TranslateCellularWithState();
137 } else if (onc_signature_ == &kCellularDeviceSignature) {
138 TranslateCellularDevice();
136 } else if (onc_signature_ == &kIPConfigSignature) { 139 } else if (onc_signature_ == &kIPConfigSignature) {
137 TranslateIPConfig(); 140 TranslateIPConfig();
138 } else { 141 } else {
139 CopyPropertiesAccordingToSignature(); 142 CopyPropertiesAccordingToSignature();
140 } 143 }
141 return onc_object_.Pass(); 144 return onc_object_.Pass();
142 } 145 }
143 146
144 void ShillToONCTranslator::TranslateEthernet() { 147 void ShillToONCTranslator::TranslateEthernet() {
145 std::string shill_network_type; 148 std::string shill_network_type;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 CopyPropertiesAccordingToSignature(); 254 CopyPropertiesAccordingToSignature();
252 const base::DictionaryValue* dictionary = NULL; 255 const base::DictionaryValue* dictionary = NULL;
253 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( 256 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
254 shill::kServingOperatorProperty, &dictionary)) { 257 shill::kServingOperatorProperty, &dictionary)) {
255 TranslateAndAddNestedObject(::onc::cellular::kServingOperator, *dictionary); 258 TranslateAndAddNestedObject(::onc::cellular::kServingOperator, *dictionary);
256 } 259 }
257 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( 260 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
258 shill::kCellularApnProperty, &dictionary)) { 261 shill::kCellularApnProperty, &dictionary)) {
259 TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary); 262 TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary);
260 } 263 }
264 // Merge the Device dictionary with this one (Cellular) using the
265 // CellularDevice signiture.
pneubeck (no reviews) 2014/07/21 08:21:53 typo: signiture -> signature
stevenjb 2014/07/22 18:29:33 Done.
266 const base::DictionaryValue* device_dictionary = NULL;
267 if (!shill_dictionary_->GetDictionaryWithoutPathExpansion(
268 shill::kDeviceProperty, &device_dictionary)) {
269 return;
270 }
271 ShillToONCTranslator nested_translator(*device_dictionary,
272 kCellularDeviceSignature);
pneubeck (no reviews) 2014/07/21 08:31:04 how about using kCellularWithStateSignature here a
stevenjb 2014/07/22 18:29:33 I'm not sure I follow.
273 scoped_ptr<base::DictionaryValue> nested_object =
274 nested_translator.CreateTranslatedONCObject();
275 onc_object_->MergeDictionary(nested_object.get());
276 }
277
278 void ShillToONCTranslator::TranslateCellularDevice() {
279 CopyPropertiesAccordingToSignature();
280 const base::DictionaryValue* dictionary = NULL;
pneubeck (no reviews) 2014/07/21 08:21:53 nit: dictionary -> shill_sim_lock
stevenjb 2014/07/22 18:29:33 Done.
281 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
282 shill::kSIMLockStatusProperty, &dictionary)) {
283 TranslateAndAddNestedObject(::onc::cellular::kSIMLockStatus, *dictionary);
284 }
261 const base::ListValue* shill_apns = NULL; 285 const base::ListValue* shill_apns = NULL;
262 if (shill_dictionary_->GetListWithoutPathExpansion( 286 if (shill_dictionary_->GetListWithoutPathExpansion(
263 shill::kCellularApnListProperty, &shill_apns)) { 287 shill::kCellularApnListProperty, &shill_apns)) {
264 TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *shill_apns); 288 TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *shill_apns);
265 } 289 }
266 290 const base::ListValue* shill_found_networks = NULL;
267 const base::DictionaryValue* device_dictionary = NULL; 291 if (shill_dictionary_->GetListWithoutPathExpansion(
268 if (!shill_dictionary_->GetDictionaryWithoutPathExpansion( 292 shill::kFoundNetworksProperty, &shill_found_networks)) {
269 shill::kDeviceProperty, &device_dictionary)) { 293 TranslateAndAddListOfObjects(::onc::cellular::kFoundNetworks,
270 return; 294 *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 } 295 }
292 } 296 }
293 297
294 void ShillToONCTranslator::TranslateNetworkWithState() { 298 void ShillToONCTranslator::TranslateNetworkWithState() {
295 CopyPropertiesAccordingToSignature(); 299 CopyPropertiesAccordingToSignature();
296 300
297 std::string shill_network_type; 301 std::string shill_network_type;
298 shill_dictionary_->GetStringWithoutPathExpansion(shill::kTypeProperty, 302 shill_dictionary_->GetStringWithoutPathExpansion(shill::kTypeProperty,
299 &shill_network_type); 303 &shill_network_type);
300 std::string onc_network_type = ::onc::network_type::kEthernet; 304 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, 497 const base::DictionaryValue& shill_dictionary,
494 const OncValueSignature* onc_signature) { 498 const OncValueSignature* onc_signature) {
495 CHECK(onc_signature != NULL); 499 CHECK(onc_signature != NULL);
496 500
497 ShillToONCTranslator translator(shill_dictionary, *onc_signature); 501 ShillToONCTranslator translator(shill_dictionary, *onc_signature);
498 return translator.CreateTranslatedONCObject(); 502 return translator.CreateTranslatedONCObject();
499 } 503 }
500 504
501 } // namespace onc 505 } // namespace onc
502 } // namespace chromeos 506 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698