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

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

Issue 1031253002: Format ONC translation files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 9 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
« no previous file with comments | « chromeos/network/onc/onc_translator_onc_to_shill.cc ('k') | no next file » | 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 field_translation_table_ = GetFieldTranslationTable(onc_signature); 59 field_translation_table_ = GetFieldTranslationTable(onc_signature);
60 } 60 }
61 61
62 ShillToONCTranslator(const base::DictionaryValue& shill_dictionary, 62 ShillToONCTranslator(const base::DictionaryValue& shill_dictionary,
63 ::onc::ONCSource onc_source, 63 ::onc::ONCSource onc_source,
64 const OncValueSignature& onc_signature, 64 const OncValueSignature& onc_signature,
65 const FieldTranslationEntry* field_translation_table) 65 const FieldTranslationEntry* field_translation_table)
66 : shill_dictionary_(&shill_dictionary), 66 : shill_dictionary_(&shill_dictionary),
67 onc_source_(onc_source), 67 onc_source_(onc_source),
68 onc_signature_(&onc_signature), 68 onc_signature_(&onc_signature),
69 field_translation_table_(field_translation_table) { 69 field_translation_table_(field_translation_table) {}
70 }
71 70
72 // Translates the associated Shill dictionary and creates an ONC object of the 71 // Translates the associated Shill dictionary and creates an ONC object of the
73 // given signature. 72 // given signature.
74 scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject(); 73 scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject();
75 74
76 private: 75 private:
77 void TranslateEthernet(); 76 void TranslateEthernet();
78 void TranslateOpenVPN(); 77 void TranslateOpenVPN();
79 void TranslateIPsec(); 78 void TranslateIPsec();
80 void TranslateThirdPartyVPN(); 79 void TranslateThirdPartyVPN();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 if (onc_field_name == ::onc::openvpn::kRemoteCertKU || 214 if (onc_field_name == ::onc::openvpn::kRemoteCertKU ||
216 onc_field_name == ::onc::openvpn::kServerCAPEMs) { 215 onc_field_name == ::onc::openvpn::kServerCAPEMs) {
217 CopyProperty(field_signature); 216 CopyProperty(field_signature);
218 continue; 217 continue;
219 } 218 }
220 219
221 std::string shill_property_name; 220 std::string shill_property_name;
222 const base::Value* shill_value = NULL; 221 const base::Value* shill_value = NULL;
223 if (!field_translation_table_ || 222 if (!field_translation_table_ ||
224 !GetShillPropertyName(field_signature->onc_field_name, 223 !GetShillPropertyName(field_signature->onc_field_name,
225 field_translation_table_, 224 field_translation_table_, &shill_property_name) ||
226 &shill_property_name) ||
227 !shill_dictionary_->GetWithoutPathExpansion(shill_property_name, 225 !shill_dictionary_->GetWithoutPathExpansion(shill_property_name,
228 &shill_value)) { 226 &shill_value)) {
229 continue; 227 continue;
230 } 228 }
231 229
232 scoped_ptr<base::Value> translated; 230 scoped_ptr<base::Value> translated;
233 std::string shill_str; 231 std::string shill_str;
234 if (shill_value->GetAsString(&shill_str)) { 232 if (shill_value->GetAsString(&shill_str)) {
235 // Shill wants all Provider/VPN fields to be strings. Translates these 233 // Shill wants all Provider/VPN fields to be strings. Translates these
236 // strings back to the correct ONC type. 234 // strings back to the correct ONC type.
237 translated = ConvertStringToValue( 235 translated = ConvertStringToValue(
238 shill_str, 236 shill_str, field_signature->value_signature->onc_type);
239 field_signature->value_signature->onc_type);
240 237
241 if (translated.get() == NULL) { 238 if (translated.get() == NULL) {
242 LOG(ERROR) << "Shill property '" << shill_property_name 239 LOG(ERROR) << "Shill property '" << shill_property_name
243 << "' with value " << *shill_value 240 << "' with value " << *shill_value
244 << " couldn't be converted to base::Value::Type " 241 << " couldn't be converted to base::Value::Type "
245 << field_signature->value_signature->onc_type 242 << field_signature->value_signature->onc_type << ": "
246 << ": " << GetName(); 243 << GetName();
247 } else { 244 } else {
248 onc_object_->SetWithoutPathExpansion(onc_field_name, 245 onc_object_->SetWithoutPathExpansion(onc_field_name,
249 translated.release()); 246 translated.release());
250 } 247 }
251 } else { 248 } else {
252 LOG(ERROR) << "Shill property '" << shill_property_name 249 LOG(ERROR) << "Shill property '" << shill_property_name << "' has value "
253 << "' has value " << *shill_value 250 << *shill_value << ", but expected a string: " << GetName();
254 << ", but expected a string: " << GetName();
255 } 251 }
256 } 252 }
257 } 253 }
258 254
259 void ShillToONCTranslator::TranslateIPsec() { 255 void ShillToONCTranslator::TranslateIPsec() {
260 CopyPropertiesAccordingToSignature(); 256 CopyPropertiesAccordingToSignature();
261 if (shill_dictionary_->HasKey(shill::kL2tpIpsecXauthUserProperty)) 257 if (shill_dictionary_->HasKey(shill::kL2tpIpsecXauthUserProperty))
262 TranslateAndAddNestedObject(::onc::ipsec::kXAUTH); 258 TranslateAndAddNestedObject(::onc::ipsec::kXAUTH);
263 std::string client_cert_id; 259 std::string client_cert_id;
264 shill_dictionary_->GetStringWithoutPathExpansion( 260 shill_dictionary_->GetStringWithoutPathExpansion(
(...skipping 22 matching lines...) Expand all
287 // Parse Shill Provider dictionary. Note, this may not exist, e.g. if we are 283 // Parse Shill Provider dictionary. Note, this may not exist, e.g. if we are
288 // just translating network state in network_util::TranslateNetworkStateToONC. 284 // just translating network state in network_util::TranslateNetworkStateToONC.
289 const base::DictionaryValue* provider = NULL; 285 const base::DictionaryValue* provider = NULL;
290 if (!shill_dictionary_->GetDictionaryWithoutPathExpansion( 286 if (!shill_dictionary_->GetDictionaryWithoutPathExpansion(
291 shill::kProviderProperty, &provider)) { 287 shill::kProviderProperty, &provider)) {
292 return; 288 return;
293 } 289 }
294 std::string shill_provider_type, onc_provider_type; 290 std::string shill_provider_type, onc_provider_type;
295 provider->GetStringWithoutPathExpansion(shill::kTypeProperty, 291 provider->GetStringWithoutPathExpansion(shill::kTypeProperty,
296 &shill_provider_type); 292 &shill_provider_type);
297 if (!TranslateStringToONC( 293 if (!TranslateStringToONC(kVPNTypeTable, shill_provider_type,
298 kVPNTypeTable, shill_provider_type, &onc_provider_type)) { 294 &onc_provider_type)) {
299 return; 295 return;
300 } 296 }
301 onc_object_->SetStringWithoutPathExpansion(::onc::vpn::kType, 297 onc_object_->SetStringWithoutPathExpansion(::onc::vpn::kType,
302 onc_provider_type); 298 onc_provider_type);
303 std::string shill_provider_host; 299 std::string shill_provider_host;
304 if (onc_provider_type != ::onc::vpn::kThirdPartyVpn && 300 if (onc_provider_type != ::onc::vpn::kThirdPartyVpn &&
305 provider->GetStringWithoutPathExpansion(shill::kHostProperty, 301 provider->GetStringWithoutPathExpansion(shill::kHostProperty,
306 &shill_provider_host)) { 302 &shill_provider_host)) {
307 onc_object_->SetStringWithoutPathExpansion(::onc::vpn::kHost, 303 onc_object_->SetStringWithoutPathExpansion(::onc::vpn::kHost,
308 shill_provider_host); 304 shill_provider_host);
309 } 305 }
310 306
311 // Translate the nested dictionary. 307 // Translate the nested dictionary.
312 std::string provider_type_dictionary; 308 std::string provider_type_dictionary;
313 if (onc_provider_type == ::onc::vpn::kTypeL2TP_IPsec) { 309 if (onc_provider_type == ::onc::vpn::kTypeL2TP_IPsec) {
314 TranslateAndAddNestedObject(::onc::vpn::kIPsec, *provider); 310 TranslateAndAddNestedObject(::onc::vpn::kIPsec, *provider);
315 TranslateAndAddNestedObject(::onc::vpn::kL2TP, *provider); 311 TranslateAndAddNestedObject(::onc::vpn::kL2TP, *provider);
316 provider_type_dictionary = ::onc::vpn::kIPsec; 312 provider_type_dictionary = ::onc::vpn::kIPsec;
317 } else { 313 } else {
318 TranslateAndAddNestedObject(onc_provider_type, *provider); 314 TranslateAndAddNestedObject(onc_provider_type, *provider);
319 provider_type_dictionary = onc_provider_type; 315 provider_type_dictionary = onc_provider_type;
320 } 316 }
321 317
322 bool save_credentials; 318 bool save_credentials;
323 if (onc_provider_type != ::onc::vpn::kThirdPartyVpn && 319 if (onc_provider_type != ::onc::vpn::kThirdPartyVpn &&
324 shill_dictionary_->GetBooleanWithoutPathExpansion( 320 shill_dictionary_->GetBooleanWithoutPathExpansion(
325 shill::kSaveCredentialsProperty, &save_credentials)) { 321 shill::kSaveCredentialsProperty, &save_credentials)) {
326 SetNestedOncValue(provider_type_dictionary, 322 SetNestedOncValue(provider_type_dictionary, ::onc::vpn::kSaveCredentials,
327 ::onc::vpn::kSaveCredentials,
328 base::FundamentalValue(save_credentials)); 323 base::FundamentalValue(save_credentials));
329 } 324 }
330 } 325 }
331 326
332 void ShillToONCTranslator::TranslateWiFiWithState() { 327 void ShillToONCTranslator::TranslateWiFiWithState() {
333 TranslateWithTableAndSet(shill::kSecurityClassProperty, 328 TranslateWithTableAndSet(shill::kSecurityClassProperty, kWiFiSecurityTable,
334 kWiFiSecurityTable,
335 ::onc::wifi::kSecurity); 329 ::onc::wifi::kSecurity);
336 bool unknown_encoding = true; 330 bool unknown_encoding = true;
337 std::string ssid = shill_property_util::GetSSIDFromProperties( 331 std::string ssid = shill_property_util::GetSSIDFromProperties(
338 *shill_dictionary_, false /* verbose_logging */, &unknown_encoding); 332 *shill_dictionary_, false /* verbose_logging */, &unknown_encoding);
339 if (!unknown_encoding && !ssid.empty()) 333 if (!unknown_encoding && !ssid.empty())
340 onc_object_->SetStringWithoutPathExpansion(::onc::wifi::kSSID, ssid); 334 onc_object_->SetStringWithoutPathExpansion(::onc::wifi::kSSID, ssid);
341 335
342 bool link_monitor_disable; 336 bool link_monitor_disable;
343 if (shill_dictionary_->GetBooleanWithoutPathExpansion( 337 if (shill_dictionary_->GetBooleanWithoutPathExpansion(
344 shill::kLinkMonitorDisableProperty, &link_monitor_disable)) { 338 shill::kLinkMonitorDisableProperty, &link_monitor_disable)) {
(...skipping 10 matching lines...) Expand all
355 TranslateAndAddNestedObject(::onc::wimax::kEAP); 349 TranslateAndAddNestedObject(::onc::wimax::kEAP);
356 } 350 }
357 351
358 void ShillToONCTranslator::TranslateCellularWithState() { 352 void ShillToONCTranslator::TranslateCellularWithState() {
359 CopyPropertiesAccordingToSignature(); 353 CopyPropertiesAccordingToSignature();
360 TranslateWithTableAndSet(shill::kActivationStateProperty, 354 TranslateWithTableAndSet(shill::kActivationStateProperty,
361 kActivationStateTable, 355 kActivationStateTable,
362 ::onc::cellular::kActivationState); 356 ::onc::cellular::kActivationState);
363 const base::DictionaryValue* dictionary = NULL; 357 const base::DictionaryValue* dictionary = NULL;
364 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( 358 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
365 shill::kServingOperatorProperty, &dictionary)) { 359 shill::kServingOperatorProperty, &dictionary)) {
366 TranslateAndAddNestedObject(::onc::cellular::kServingOperator, *dictionary); 360 TranslateAndAddNestedObject(::onc::cellular::kServingOperator, *dictionary);
367 } 361 }
368 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( 362 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
369 shill::kCellularApnProperty, &dictionary)) { 363 shill::kCellularApnProperty, &dictionary)) {
370 TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary); 364 TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary);
371 } 365 }
372 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( 366 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
373 shill::kCellularLastGoodApnProperty, &dictionary)) { 367 shill::kCellularLastGoodApnProperty, &dictionary)) {
374 TranslateAndAddNestedObject(::onc::cellular::kLastGoodAPN, *dictionary); 368 TranslateAndAddNestedObject(::onc::cellular::kLastGoodAPN, *dictionary);
375 } 369 }
376 const base::DictionaryValue* device_dictionary = NULL; 370 const base::DictionaryValue* device_dictionary = NULL;
377 bool requires_roaming = false; 371 bool requires_roaming = false;
378 shill_dictionary_->GetDictionaryWithoutPathExpansion(shill::kDeviceProperty, 372 shill_dictionary_->GetDictionaryWithoutPathExpansion(shill::kDeviceProperty,
379 &device_dictionary); 373 &device_dictionary);
380 if (device_dictionary) { 374 if (device_dictionary) {
381 // Merge the Device dictionary with this one (Cellular) using the 375 // Merge the Device dictionary with this one (Cellular) using the
382 // CellularDevice signature. 376 // CellularDevice signature.
383 ShillToONCTranslator nested_translator(*device_dictionary, onc_source_, 377 ShillToONCTranslator nested_translator(*device_dictionary, onc_source_,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 423
430 void ShillToONCTranslator::TranslateNetworkWithState() { 424 void ShillToONCTranslator::TranslateNetworkWithState() {
431 CopyPropertiesAccordingToSignature(); 425 CopyPropertiesAccordingToSignature();
432 426
433 std::string shill_network_type; 427 std::string shill_network_type;
434 shill_dictionary_->GetStringWithoutPathExpansion(shill::kTypeProperty, 428 shill_dictionary_->GetStringWithoutPathExpansion(shill::kTypeProperty,
435 &shill_network_type); 429 &shill_network_type);
436 std::string onc_network_type = ::onc::network_type::kEthernet; 430 std::string onc_network_type = ::onc::network_type::kEthernet;
437 if (shill_network_type != shill::kTypeEthernet && 431 if (shill_network_type != shill::kTypeEthernet &&
438 shill_network_type != shill::kTypeEthernetEap) { 432 shill_network_type != shill::kTypeEthernetEap) {
439 TranslateStringToONC( 433 TranslateStringToONC(kNetworkTypeTable, shill_network_type,
440 kNetworkTypeTable, shill_network_type, &onc_network_type); 434 &onc_network_type);
441 } 435 }
442 // Translate nested Cellular, WiFi, etc. properties. 436 // Translate nested Cellular, WiFi, etc. properties.
443 if (!onc_network_type.empty()) { 437 if (!onc_network_type.empty()) {
444 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kType, 438 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kType,
445 onc_network_type); 439 onc_network_type);
446 TranslateAndAddNestedObject(onc_network_type); 440 TranslateAndAddNestedObject(onc_network_type);
447 } 441 }
448 442
449 // Since Name is a read only field in Shill unless it's a VPN, it is copied 443 // Since Name is a read only field in Shill unless it's a VPN, it is copied
450 // here, but not when going the other direction (if it's not a VPN). 444 // here, but not when going the other direction (if it's not a VPN).
(...skipping 29 matching lines...) Expand all
480 if (onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY) 474 if (onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY)
481 source = ::onc::network_config::kSourceDevicePolicy; 475 source = ::onc::network_config::kSourceDevicePolicy;
482 else if (onc_source_ == ::onc::ONC_SOURCE_USER_POLICY) 476 else if (onc_source_ == ::onc::ONC_SOURCE_USER_POLICY)
483 source = ::onc::network_config::kSourceUserPolicy; 477 source = ::onc::network_config::kSourceUserPolicy;
484 else if (profile_path == NetworkProfileHandler::GetSharedProfilePath()) 478 else if (profile_path == NetworkProfileHandler::GetSharedProfilePath())
485 source = ::onc::network_config::kSourceDevice; 479 source = ::onc::network_config::kSourceDevice;
486 else if (!profile_path.empty()) 480 else if (!profile_path.empty())
487 source = ::onc::network_config::kSourceUser; 481 source = ::onc::network_config::kSourceUser;
488 else 482 else
489 source = ::onc::network_config::kSourceNone; 483 source = ::onc::network_config::kSourceNone;
490 onc_object_->SetStringWithoutPathExpansion( 484 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kSource,
491 ::onc::network_config::kSource, source); 485 source);
492 } 486 }
493 487
494 // Use a human-readable aa:bb format for any hardware MAC address. Note: 488 // Use a human-readable aa:bb format for any hardware MAC address. Note:
495 // this property is provided by the caller but is not part of the Shill 489 // this property is provided by the caller but is not part of the Shill
496 // Service properties (it is copied from the Device properties). 490 // Service properties (it is copied from the Device properties).
497 std::string address; 491 std::string address;
498 if (shill_dictionary_->GetStringWithoutPathExpansion(shill::kAddressProperty, 492 if (shill_dictionary_->GetStringWithoutPathExpansion(shill::kAddressProperty,
499 &address)) { 493 &address)) {
500 onc_object_->SetStringWithoutPathExpansion( 494 onc_object_->SetStringWithoutPathExpansion(
501 ::onc::network_config::kMacAddress, 495 ::onc::network_config::kMacAddress,
502 network_util::FormattedMacAddress(address)); 496 network_util::FormattedMacAddress(address));
503 } 497 }
504 498
505 // Shill's Service has an IPConfig property (note the singular), not an 499 // Shill's Service has an IPConfig property (note the singular), not an
506 // IPConfigs property. However, we require the caller of the translation to 500 // IPConfigs property. However, we require the caller of the translation to
507 // patch the Shill dictionary before passing it to the translator. 501 // patch the Shill dictionary before passing it to the translator.
508 const base::ListValue* shill_ipconfigs = NULL; 502 const base::ListValue* shill_ipconfigs = NULL;
509 if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty, 503 if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty,
510 &shill_ipconfigs)) { 504 &shill_ipconfigs)) {
511 TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs, 505 TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs,
512 *shill_ipconfigs); 506 *shill_ipconfigs);
513 } 507 }
514 508
515 const base::DictionaryValue* saved_ipconfig = nullptr; 509 const base::DictionaryValue* saved_ipconfig = nullptr;
516 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( 510 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
517 shill::kSavedIPConfigProperty, &saved_ipconfig)) { 511 shill::kSavedIPConfigProperty, &saved_ipconfig)) {
518 TranslateAndAddNestedObject(::onc::network_config::kSavedIPConfig, 512 TranslateAndAddNestedObject(::onc::network_config::kSavedIPConfig,
519 *saved_ipconfig); 513 *saved_ipconfig);
520 } 514 }
521 515
522 // Translate the StaticIPConfig object and set the IP config types. 516 // Translate the StaticIPConfig object and set the IP config types.
523 const base::DictionaryValue* static_ipconfig = nullptr; 517 const base::DictionaryValue* static_ipconfig = nullptr;
524 if (shill_dictionary_->GetDictionaryWithoutPathExpansion( 518 if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
525 shill::kStaticIPConfigProperty, &static_ipconfig)) { 519 shill::kStaticIPConfigProperty, &static_ipconfig)) {
526 std::string ip_address; 520 std::string ip_address;
527 if (static_ipconfig->GetStringWithoutPathExpansion(shill::kAddressProperty, 521 if (static_ipconfig->GetStringWithoutPathExpansion(shill::kAddressProperty,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 585
592 void ShillToONCTranslator::TranslateAndAddNestedObject( 586 void ShillToONCTranslator::TranslateAndAddNestedObject(
593 const std::string& onc_field_name, 587 const std::string& onc_field_name,
594 const base::DictionaryValue& dictionary) { 588 const base::DictionaryValue& dictionary) {
595 const OncFieldSignature* field_signature = 589 const OncFieldSignature* field_signature =
596 GetFieldSignature(*onc_signature_, onc_field_name); 590 GetFieldSignature(*onc_signature_, onc_field_name);
597 if (!field_signature) { 591 if (!field_signature) {
598 NOTREACHED() << "Unable to find signature for field: " << onc_field_name; 592 NOTREACHED() << "Unable to find signature for field: " << onc_field_name;
599 return; 593 return;
600 } 594 }
601 ShillToONCTranslator nested_translator( 595 ShillToONCTranslator nested_translator(dictionary, onc_source_,
602 dictionary, onc_source_, *field_signature->value_signature); 596 *field_signature->value_signature);
603 scoped_ptr<base::DictionaryValue> nested_object = 597 scoped_ptr<base::DictionaryValue> nested_object =
604 nested_translator.CreateTranslatedONCObject(); 598 nested_translator.CreateTranslatedONCObject();
605 if (nested_object->empty()) 599 if (nested_object->empty())
606 return; 600 return;
607 onc_object_->SetWithoutPathExpansion(onc_field_name, nested_object.release()); 601 onc_object_->SetWithoutPathExpansion(onc_field_name, nested_object.release());
608 } 602 }
609 603
610 void ShillToONCTranslator::SetNestedOncValue( 604 void ShillToONCTranslator::SetNestedOncValue(
611 const std::string& onc_dictionary_name, 605 const std::string& onc_dictionary_name,
612 const std::string& onc_field_name, 606 const std::string& onc_field_name,
613 const base::Value& value) { 607 const base::Value& value) {
614 base::DictionaryValue* nested; 608 base::DictionaryValue* nested;
615 if (!onc_object_->GetDictionaryWithoutPathExpansion( 609 if (!onc_object_->GetDictionaryWithoutPathExpansion(onc_dictionary_name,
616 onc_dictionary_name, &nested)) { 610 &nested)) {
617 nested = new base::DictionaryValue; 611 nested = new base::DictionaryValue;
618 onc_object_->SetWithoutPathExpansion(onc_dictionary_name, nested); 612 onc_object_->SetWithoutPathExpansion(onc_dictionary_name, nested);
619 } 613 }
620 nested->SetWithoutPathExpansion(onc_field_name, value.DeepCopy()); 614 nested->SetWithoutPathExpansion(onc_field_name, value.DeepCopy());
621 } 615 }
622 616
623 void ShillToONCTranslator::TranslateAndAddListOfObjects( 617 void ShillToONCTranslator::TranslateAndAddListOfObjects(
624 const std::string& onc_field_name, 618 const std::string& onc_field_name,
625 const base::ListValue& list) { 619 const base::ListValue& list) {
626 const OncFieldSignature* field_signature = 620 const OncFieldSignature* field_signature =
627 GetFieldSignature(*onc_signature_, onc_field_name); 621 GetFieldSignature(*onc_signature_, onc_field_name);
628 if (field_signature->value_signature->onc_type != base::Value::TYPE_LIST) { 622 if (field_signature->value_signature->onc_type != base::Value::TYPE_LIST) {
629 LOG(ERROR) << "ONC Field name: '" << onc_field_name << "' has type '" 623 LOG(ERROR) << "ONC Field name: '" << onc_field_name << "' has type '"
630 << field_signature->value_signature->onc_type 624 << field_signature->value_signature->onc_type
631 << "', expected: base::Value::TYPE_LIST: " << GetName(); 625 << "', expected: base::Value::TYPE_LIST: " << GetName();
632 return; 626 return;
633 } 627 }
634 DCHECK(field_signature->value_signature->onc_array_entry_signature); 628 DCHECK(field_signature->value_signature->onc_array_entry_signature);
635 scoped_ptr<base::ListValue> result(new base::ListValue()); 629 scoped_ptr<base::ListValue> result(new base::ListValue());
636 for (base::ListValue::const_iterator it = list.begin(); 630 for (base::ListValue::const_iterator it = list.begin(); it != list.end();
637 it != list.end(); ++it) { 631 ++it) {
638 const base::DictionaryValue* shill_value = NULL; 632 const base::DictionaryValue* shill_value = NULL;
639 if (!(*it)->GetAsDictionary(&shill_value)) 633 if (!(*it)->GetAsDictionary(&shill_value))
640 continue; 634 continue;
641 ShillToONCTranslator nested_translator( 635 ShillToONCTranslator nested_translator(
642 *shill_value, 636 *shill_value, onc_source_,
643 onc_source_,
644 *field_signature->value_signature->onc_array_entry_signature); 637 *field_signature->value_signature->onc_array_entry_signature);
645 scoped_ptr<base::DictionaryValue> nested_object = 638 scoped_ptr<base::DictionaryValue> nested_object =
646 nested_translator.CreateTranslatedONCObject(); 639 nested_translator.CreateTranslatedONCObject();
647 // If the nested object couldn't be parsed, simply omit it. 640 // If the nested object couldn't be parsed, simply omit it.
648 if (nested_object->empty()) 641 if (nested_object->empty())
649 continue; 642 continue;
650 result->Append(nested_object.release()); 643 result->Append(nested_object.release());
651 } 644 }
652 // If there are no entries in the list, there is no need to expose this field. 645 // If there are no entries in the list, there is no need to expose this field.
653 if (result->empty()) 646 if (result->empty())
(...skipping 16 matching lines...) Expand all
670 CopyProperty(field_signature); 663 CopyProperty(field_signature);
671 } 664 }
672 } 665 }
673 666
674 void ShillToONCTranslator::CopyProperty( 667 void ShillToONCTranslator::CopyProperty(
675 const OncFieldSignature* field_signature) { 668 const OncFieldSignature* field_signature) {
676 std::string shill_property_name; 669 std::string shill_property_name;
677 const base::Value* shill_value = NULL; 670 const base::Value* shill_value = NULL;
678 if (!field_translation_table_ || 671 if (!field_translation_table_ ||
679 !GetShillPropertyName(field_signature->onc_field_name, 672 !GetShillPropertyName(field_signature->onc_field_name,
680 field_translation_table_, 673 field_translation_table_, &shill_property_name) ||
681 &shill_property_name) ||
682 !shill_dictionary_->GetWithoutPathExpansion(shill_property_name, 674 !shill_dictionary_->GetWithoutPathExpansion(shill_property_name,
683 &shill_value)) { 675 &shill_value)) {
684 return; 676 return;
685 } 677 }
686 678
687 if (shill_value->GetType() != field_signature->value_signature->onc_type) { 679 if (shill_value->GetType() != field_signature->value_signature->onc_type) {
688 LOG(ERROR) << "Shill property '" << shill_property_name 680 LOG(ERROR) << "Shill property '" << shill_property_name << "' with value "
689 << "' with value " << *shill_value 681 << *shill_value << " has base::Value::Type "
690 << " has base::Value::Type " << shill_value->GetType() 682 << shill_value->GetType() << " but ONC field '"
691 << " but ONC field '" << field_signature->onc_field_name 683 << field_signature->onc_field_name << "' requires type "
692 << "' requires type " 684 << field_signature->value_signature->onc_type << ": "
693 << field_signature->value_signature->onc_type 685 << GetName();
694 << ": " << GetName();
695 return; 686 return;
696 } 687 }
697 688
698 onc_object_->SetWithoutPathExpansion(field_signature->onc_field_name, 689 onc_object_->SetWithoutPathExpansion(field_signature->onc_field_name,
699 shill_value->DeepCopy()); 690 shill_value->DeepCopy());
700 } 691 }
701 692
702 void ShillToONCTranslator::TranslateWithTableAndSet( 693 void ShillToONCTranslator::TranslateWithTableAndSet(
703 const std::string& shill_property_name, 694 const std::string& shill_property_name,
704 const StringTranslationEntry table[], 695 const StringTranslationEntry table[],
(...skipping 26 matching lines...) Expand all
731 ::onc::ONCSource onc_source, 722 ::onc::ONCSource onc_source,
732 const OncValueSignature* onc_signature) { 723 const OncValueSignature* onc_signature) {
733 CHECK(onc_signature != NULL); 724 CHECK(onc_signature != NULL);
734 725
735 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature); 726 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature);
736 return translator.CreateTranslatedONCObject(); 727 return translator.CreateTranslatedONCObject();
737 } 728 }
738 729
739 } // namespace onc 730 } // namespace onc
740 } // namespace chromeos 731 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_translator_onc_to_shill.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698