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

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

Issue 509643003: Use GetManagedProperties in InternetOptionsHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_279351_internet_options_8a
Patch Set: Created 6 years, 3 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
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 const OncValueSignature* value_signature); 108 const OncValueSignature* value_signature);
109 109
110 // Applies function CopyProperty to each field of |onc_signature_| and its 110 // Applies function CopyProperty to each field of |onc_signature_| and its
111 // base signatures. 111 // base signatures.
112 void CopyPropertiesAccordingToSignature(); 112 void CopyPropertiesAccordingToSignature();
113 113
114 // If |shill_property_name| is defined in |field_signature|, copies this 114 // If |shill_property_name| is defined in |field_signature|, copies this
115 // entry from |shill_dictionary_| to |onc_object_| if it exists. 115 // entry from |shill_dictionary_| to |onc_object_| if it exists.
116 void CopyProperty(const OncFieldSignature* field_signature); 116 void CopyProperty(const OncFieldSignature* field_signature);
117 117
118 // If |shill_property_name| exists in |shill_dictionary_|, copy it to
119 // |dictionary|.
pneubeck (no reviews) 2014/09/03 15:14:29 nit: mention that it copies to the key |onc_proper
stevenjb 2014/09/03 21:28:06 Done, and renamed -> onc_field_name for consistenc
120 void CopyPropertyToDictionary(const std::string& shill_property_name,
121 const std::string& onc_property_name,
122 base::DictionaryValue* dictionary);
123
118 // If existent, translates the entry at |shill_property_name| in 124 // If existent, translates the entry at |shill_property_name| in
119 // |shill_dictionary_| using |table|. It is an error if no matching table 125 // |shill_dictionary_| using |table|. It is an error if no matching table
120 // entry is found. Writes the result as entry at |onc_field_name| in 126 // entry is found. Writes the result as entry at |onc_field_name| in
121 // |onc_object_|. 127 // |onc_object_|.
122 void TranslateWithTableAndSet(const std::string& shill_property_name, 128 void TranslateWithTableAndSet(const std::string& shill_property_name,
123 const StringTranslationEntry table[], 129 const StringTranslationEntry table[],
124 const std::string& onc_field_name); 130 const std::string& onc_field_name);
125 131
126 // Returns the name of the Shill service provided in |shill_dictionary_| 132 // Returns the name of the Shill service provided in |shill_dictionary_|
127 // for debugging. 133 // for debugging.
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 // Translate nested Cellular, WiFi, etc. properties. 376 // Translate nested Cellular, WiFi, etc. properties.
371 if (!onc_network_type.empty()) { 377 if (!onc_network_type.empty()) {
372 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kType, 378 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kType,
373 onc_network_type); 379 onc_network_type);
374 TranslateAndAddNestedObject(onc_network_type); 380 TranslateAndAddNestedObject(onc_network_type);
375 } 381 }
376 382
377 // Since Name is a read only field in Shill unless it's a VPN, it is copied 383 // Since Name is a read only field in Shill unless it's a VPN, it is copied
378 // here, but not when going the other direction (if it's not a VPN). 384 // here, but not when going the other direction (if it's not a VPN).
379 std::string name; 385 std::string name;
380 shill_dictionary_->GetStringWithoutPathExpansion(shill::kNameProperty, 386 shill_dictionary_->GetStringWithoutPathExpansion(shill::kNameProperty, &name);
381 &name);
382 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kName, 387 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kName,
383 name); 388 name);
384 389
385 // Limit ONC state to "NotConnected", "Connected", or "Connecting". 390 // Limit ONC state to "NotConnected", "Connected", or "Connecting".
386 std::string state; 391 std::string state;
387 if (shill_dictionary_->GetStringWithoutPathExpansion(shill::kStateProperty, 392 if (shill_dictionary_->GetStringWithoutPathExpansion(shill::kStateProperty,
388 &state)) { 393 &state)) {
389 std::string onc_state = ::onc::connection_state::kNotConnected; 394 std::string onc_state = ::onc::connection_state::kNotConnected;
390 if (NetworkState::StateIsConnected(state)) { 395 if (NetworkState::StateIsConnected(state)) {
391 onc_state = ::onc::connection_state::kConnected; 396 onc_state = ::onc::connection_state::kConnected;
(...skipping 19 matching lines...) Expand all
411 416
412 // Shill's Service has an IPConfig property (note the singular), not an 417 // Shill's Service has an IPConfig property (note the singular), not an
413 // IPConfigs property. However, we require the caller of the translation to 418 // IPConfigs property. However, we require the caller of the translation to
414 // patch the Shill dictionary before passing it to the translator. 419 // patch the Shill dictionary before passing it to the translator.
415 const base::ListValue* shill_ipconfigs = NULL; 420 const base::ListValue* shill_ipconfigs = NULL;
416 if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty, 421 if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty,
417 &shill_ipconfigs)) { 422 &shill_ipconfigs)) {
418 TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs, 423 TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs,
419 *shill_ipconfigs); 424 *shill_ipconfigs);
420 } 425 }
426
427 // Convert StaticIP and SavedIP properties to dictionary format.
428 scoped_ptr<base::DictionaryValue> static_ip(new base::DictionaryValue);
pneubeck (no reviews) 2014/09/03 15:14:28 I think if you can save most of this code by suppo
stevenjb 2014/09/03 21:28:06 I'll... try doing this in a separate CL. I think I
pneubeck (no reviews) 2014/09/04 14:54:13 Thanks
429 CopyPropertyToDictionary(shill::kStaticIPAddressProperty,
430 ::onc::ipconfig::kIPAddress,
431 static_ip.get());
432 CopyPropertyToDictionary(shill::kStaticIPGatewayProperty,
433 ::onc::ipconfig::kGateway,
434 static_ip.get());
435 CopyPropertyToDictionary(shill::kStaticIPNameServersProperty,
436 ::onc::ipconfig::kNameServers,
437 static_ip.get());
438 CopyPropertyToDictionary(shill::kStaticIPPrefixlenProperty,
439 ::onc::ipconfig::kRoutingPrefix,
440 static_ip.get());
441 if (!static_ip->empty()) {
442 onc_object_->SetWithoutPathExpansion(::onc::network_config::kStaticIPConfig,
443 static_ip.release());
444 }
445
446 scoped_ptr<base::DictionaryValue> saved_ip(new base::DictionaryValue);
447 CopyPropertyToDictionary(shill::kSavedIPAddressProperty,
448 ::onc::ipconfig::kIPAddress,
449 saved_ip.get());
450 CopyPropertyToDictionary(shill::kSavedIPGatewayProperty,
451 ::onc::ipconfig::kGateway,
452 saved_ip.get());
453 CopyPropertyToDictionary(shill::kSavedIPNameServersProperty,
454 ::onc::ipconfig::kNameServers,
455 saved_ip.get());
456 CopyPropertyToDictionary(shill::kSavedIPPrefixlenProperty,
457 ::onc::ipconfig::kRoutingPrefix,
458 saved_ip.get());
459 if (!saved_ip->empty()) {
460 onc_object_->SetWithoutPathExpansion(::onc::network_config::kSavedIPConfig,
461 saved_ip.release());
462 }
421 } 463 }
422 464
423 void ShillToONCTranslator::TranslateIPConfig() { 465 void ShillToONCTranslator::TranslateIPConfig() {
424 CopyPropertiesAccordingToSignature(); 466 CopyPropertiesAccordingToSignature();
425 std::string shill_ip_method; 467 std::string shill_ip_method;
426 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty, 468 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty,
427 &shill_ip_method); 469 &shill_ip_method);
428 std::string type; 470 std::string type;
429 if (shill_ip_method == shill::kTypeIPv4 || 471 if (shill_ip_method == shill::kTypeIPv4 ||
430 shill_ip_method == shill::kTypeDHCP) { 472 shill_ip_method == shill::kTypeDHCP) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 << "' requires type " 586 << "' requires type "
545 << field_signature->value_signature->onc_type 587 << field_signature->value_signature->onc_type
546 << ": " << GetName(); 588 << ": " << GetName();
547 return; 589 return;
548 } 590 }
549 591
550 onc_object_->SetWithoutPathExpansion(field_signature->onc_field_name, 592 onc_object_->SetWithoutPathExpansion(field_signature->onc_field_name,
551 shill_value->DeepCopy()); 593 shill_value->DeepCopy());
552 } 594 }
553 595
596 void ShillToONCTranslator::CopyPropertyToDictionary(
597 const std::string& shill_property_name,
598 const std::string& onc_property_name,
599 base::DictionaryValue* dictionary) {
600 const base::Value* shill_value;
601 if (!shill_dictionary_->GetWithoutPathExpansion(shill_property_name,
602 &shill_value)) {
603 return;
604 }
605 dictionary->SetWithoutPathExpansion(onc_property_name,
606 shill_value->DeepCopy());
607 }
608
554 void ShillToONCTranslator::TranslateWithTableAndSet( 609 void ShillToONCTranslator::TranslateWithTableAndSet(
555 const std::string& shill_property_name, 610 const std::string& shill_property_name,
556 const StringTranslationEntry table[], 611 const StringTranslationEntry table[],
557 const std::string& onc_field_name) { 612 const std::string& onc_field_name) {
558 std::string shill_value; 613 std::string shill_value;
559 if (!shill_dictionary_->GetStringWithoutPathExpansion(shill_property_name, 614 if (!shill_dictionary_->GetStringWithoutPathExpansion(shill_property_name,
560 &shill_value)) { 615 &shill_value)) {
561 return; 616 return;
562 } 617 }
563 std::string onc_value; 618 std::string onc_value;
(...skipping 18 matching lines...) Expand all
582 const base::DictionaryValue& shill_dictionary, 637 const base::DictionaryValue& shill_dictionary,
583 const OncValueSignature* onc_signature) { 638 const OncValueSignature* onc_signature) {
584 CHECK(onc_signature != NULL); 639 CHECK(onc_signature != NULL);
585 640
586 ShillToONCTranslator translator(shill_dictionary, *onc_signature); 641 ShillToONCTranslator translator(shill_dictionary, *onc_signature);
587 return translator.CreateTranslatedONCObject(); 642 return translator.CreateTranslatedONCObject();
588 } 643 }
589 644
590 } // namespace onc 645 } // namespace onc
591 } // namespace chromeos 646 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698