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

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 signature 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
« no previous file with comments | « chromeos/network/onc/onc_translation_tables.cc ('k') | components/onc/onc_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
261 const base::ListValue* shill_apns = NULL; 264 const base::ListValue* shill_apns = NULL;
262 if (shill_dictionary_->GetListWithoutPathExpansion( 265 if (shill_dictionary_->GetListWithoutPathExpansion(
263 shill::kCellularApnListProperty, &shill_apns)) { 266 shill::kCellularApnListProperty, &shill_apns)) {
264 TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *shill_apns); 267 TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *shill_apns);
265 } 268 }
266 269
270 // Merge the Device dictionary with this one (Cellular) using the
271 // CellularDevice signiture.
267 const base::DictionaryValue* device_dictionary = NULL; 272 const base::DictionaryValue* device_dictionary = NULL;
268 if (!shill_dictionary_->GetDictionaryWithoutPathExpansion( 273 if (!shill_dictionary_->GetDictionaryWithoutPathExpansion(
269 shill::kDeviceProperty, &device_dictionary)) { 274 shill::kDeviceProperty, &device_dictionary)) {
270 return; 275 return;
271 } 276 }
277 ShillToONCTranslator nested_translator(*device_dictionary,
278 kCellularDeviceSignature);
279 scoped_ptr<base::DictionaryValue> nested_object =
280 nested_translator.CreateTranslatedONCObject();
281 onc_object_->MergeDictionary(nested_object.get());
282 }
272 283
273 // Iterate through all fields of the CellularWithState signature and copy 284 void ShillToONCTranslator::TranslateCellularDevice() {
274 // values from the device properties according to the separate 285 CopyPropertiesAccordingToSignature();
275 // CellularDeviceTable. 286 const base::DictionaryValue* dictionary = NULL;
276 for (const OncFieldSignature* field_signature = onc_signature_->fields; 287 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
277 field_signature->onc_field_name != NULL; ++field_signature) { 288 shill::kSIMLockStatusProperty, &dictionary)) {
278 const std::string& onc_field_name = field_signature->onc_field_name; 289 TranslateAndAddNestedObject(::onc::cellular::kSIMLockStatus, *dictionary);
armansito 2014/07/18 21:21:52 I wonder if we should just place all the nested fi
stevenjb 2014/07/18 21:31:50 Fortunately in JS, nested dictionaries are easy to
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 } 290 }
292 } 291 }
293 292
294 void ShillToONCTranslator::TranslateNetworkWithState() { 293 void ShillToONCTranslator::TranslateNetworkWithState() {
295 CopyPropertiesAccordingToSignature(); 294 CopyPropertiesAccordingToSignature();
296 295
297 std::string shill_network_type; 296 std::string shill_network_type;
298 shill_dictionary_->GetStringWithoutPathExpansion(shill::kTypeProperty, 297 shill_dictionary_->GetStringWithoutPathExpansion(shill::kTypeProperty,
299 &shill_network_type); 298 &shill_network_type);
300 std::string onc_network_type = ::onc::network_type::kEthernet; 299 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, 492 const base::DictionaryValue& shill_dictionary,
494 const OncValueSignature* onc_signature) { 493 const OncValueSignature* onc_signature) {
495 CHECK(onc_signature != NULL); 494 CHECK(onc_signature != NULL);
496 495
497 ShillToONCTranslator translator(shill_dictionary, *onc_signature); 496 ShillToONCTranslator translator(shill_dictionary, *onc_signature);
498 return translator.CreateTranslatedONCObject(); 497 return translator.CreateTranslatedONCObject();
499 } 498 }
500 499
501 } // namespace onc 500 } // namespace onc
502 } // namespace chromeos 501 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_translation_tables.cc ('k') | components/onc/onc_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698