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

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

Issue 2884933002: Remove raw base::DictionaryValue::SetWithoutPathExpansion (Closed)
Patch Set: Include Created 3 years, 7 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 | « base/values.cc ('k') | components/policy/core/common/policy_test_utils.cc » ('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 <string> 5 #include <string>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chromeos/network/network_profile_handler.h" 15 #include "chromeos/network/network_profile_handler.h"
15 #include "chromeos/network/network_state.h" 16 #include "chromeos/network/network_state.h"
16 #include "chromeos/network/network_util.h" 17 #include "chromeos/network/network_util.h"
17 #include "chromeos/network/onc/onc_signature.h" 18 #include "chromeos/network/onc/onc_signature.h"
18 #include "chromeos/network/onc/onc_translation_tables.h" 19 #include "chromeos/network/onc/onc_translation_tables.h"
19 #include "chromeos/network/onc/onc_translator.h" 20 #include "chromeos/network/onc/onc_translator.h"
20 #include "chromeos/network/onc/onc_utils.h" 21 #include "chromeos/network/onc/onc_utils.h"
21 #include "chromeos/network/shill_property_util.h" 22 #include "chromeos/network/shill_property_util.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 TranslateAndAddNestedObject(::onc::openvpn::kVerifyX509); 206 TranslateAndAddNestedObject(::onc::openvpn::kVerifyX509);
206 207
207 // Shill supports only one RemoteCertKU but ONC requires a list. If existing, 208 // Shill supports only one RemoteCertKU but ONC requires a list. If existing,
208 // wraps the value into a list. 209 // wraps the value into a list.
209 std::string certKU; 210 std::string certKU;
210 if (shill_dictionary_->GetStringWithoutPathExpansion( 211 if (shill_dictionary_->GetStringWithoutPathExpansion(
211 shill::kOpenVPNRemoteCertKUProperty, &certKU)) { 212 shill::kOpenVPNRemoteCertKUProperty, &certKU)) {
212 std::unique_ptr<base::ListValue> certKUs(new base::ListValue); 213 std::unique_ptr<base::ListValue> certKUs(new base::ListValue);
213 certKUs->AppendString(certKU); 214 certKUs->AppendString(certKU);
214 onc_object_->SetWithoutPathExpansion(::onc::openvpn::kRemoteCertKU, 215 onc_object_->SetWithoutPathExpansion(::onc::openvpn::kRemoteCertKU,
215 certKUs.release()); 216 std::move(certKUs));
216 } 217 }
217 218
218 for (const OncFieldSignature* field_signature = onc_signature_->fields; 219 for (const OncFieldSignature* field_signature = onc_signature_->fields;
219 field_signature->onc_field_name != NULL; ++field_signature) { 220 field_signature->onc_field_name != NULL; ++field_signature) {
220 const std::string& onc_field_name = field_signature->onc_field_name; 221 const std::string& onc_field_name = field_signature->onc_field_name;
221 if (onc_field_name == ::onc::openvpn::kRemoteCertKU || 222 if (onc_field_name == ::onc::openvpn::kRemoteCertKU ||
222 onc_field_name == ::onc::openvpn::kServerCAPEMs) { 223 onc_field_name == ::onc::openvpn::kServerCAPEMs) {
223 CopyProperty(field_signature); 224 CopyProperty(field_signature);
224 continue; 225 continue;
225 } 226 }
(...skipping 17 matching lines...) Expand all
243 shill_str, field_signature->value_signature->onc_type); 244 shill_str, field_signature->value_signature->onc_type);
244 245
245 if (translated.get() == NULL) { 246 if (translated.get() == NULL) {
246 LOG(ERROR) << "Shill property '" << shill_property_name 247 LOG(ERROR) << "Shill property '" << shill_property_name
247 << "' with value " << *shill_value 248 << "' with value " << *shill_value
248 << " couldn't be converted to base::Value::Type " 249 << " couldn't be converted to base::Value::Type "
249 << field_signature->value_signature->onc_type << ": " 250 << field_signature->value_signature->onc_type << ": "
250 << GetName(); 251 << GetName();
251 } else { 252 } else {
252 onc_object_->SetWithoutPathExpansion(onc_field_name, 253 onc_object_->SetWithoutPathExpansion(onc_field_name,
253 translated.release()); 254 std::move(translated));
254 } 255 }
255 } else { 256 } else {
256 LOG(ERROR) << "Shill property '" << shill_property_name << "' has value " 257 LOG(ERROR) << "Shill property '" << shill_property_name << "' has value "
257 << *shill_value << ", but expected a string: " << GetName(); 258 << *shill_value << ", but expected a string: " << GetName();
258 } 259 }
259 } 260 }
260 } 261 }
261 262
262 void ShillToONCTranslator::TranslateIPsec() { 263 void ShillToONCTranslator::TranslateIPsec() {
263 CopyPropertiesAccordingToSignature(); 264 CopyPropertiesAccordingToSignature();
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 if (shill_dictionary_->GetStringWithoutPathExpansion( 583 if (shill_dictionary_->GetStringWithoutPathExpansion(
583 shill::kProxyConfigProperty, &proxy_config_str) && 584 shill::kProxyConfigProperty, &proxy_config_str) &&
584 !proxy_config_str.empty()) { 585 !proxy_config_str.empty()) {
585 std::unique_ptr<base::DictionaryValue> proxy_config_value( 586 std::unique_ptr<base::DictionaryValue> proxy_config_value(
586 ReadDictionaryFromJson(proxy_config_str)); 587 ReadDictionaryFromJson(proxy_config_str));
587 if (proxy_config_value) { 588 if (proxy_config_value) {
588 std::unique_ptr<base::DictionaryValue> proxy_settings = 589 std::unique_ptr<base::DictionaryValue> proxy_settings =
589 ConvertProxyConfigToOncProxySettings(std::move(proxy_config_value)); 590 ConvertProxyConfigToOncProxySettings(std::move(proxy_config_value));
590 if (proxy_settings) { 591 if (proxy_settings) {
591 onc_object_->SetWithoutPathExpansion( 592 onc_object_->SetWithoutPathExpansion(
592 ::onc::network_config::kProxySettings, proxy_settings.release()); 593 ::onc::network_config::kProxySettings, std::move(proxy_settings));
593 } 594 }
594 } 595 }
595 } 596 }
596 } 597 }
597 598
598 void ShillToONCTranslator::TranslateIPConfig() { 599 void ShillToONCTranslator::TranslateIPConfig() {
599 CopyPropertiesAccordingToSignature(); 600 CopyPropertiesAccordingToSignature();
600 std::string shill_ip_method; 601 std::string shill_ip_method;
601 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty, 602 shill_dictionary_->GetStringWithoutPathExpansion(shill::kMethodProperty,
602 &shill_ip_method); 603 &shill_ip_method);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 NOTREACHED() << "Unable to find signature for field: " << onc_field_name; 663 NOTREACHED() << "Unable to find signature for field: " << onc_field_name;
663 return; 664 return;
664 } 665 }
665 ShillToONCTranslator nested_translator(dictionary, onc_source_, 666 ShillToONCTranslator nested_translator(dictionary, onc_source_,
666 *field_signature->value_signature, 667 *field_signature->value_signature,
667 network_state_); 668 network_state_);
668 std::unique_ptr<base::DictionaryValue> nested_object = 669 std::unique_ptr<base::DictionaryValue> nested_object =
669 nested_translator.CreateTranslatedONCObject(); 670 nested_translator.CreateTranslatedONCObject();
670 if (nested_object->empty()) 671 if (nested_object->empty())
671 return; 672 return;
672 onc_object_->SetWithoutPathExpansion(onc_field_name, nested_object.release()); 673 onc_object_->SetWithoutPathExpansion(onc_field_name,
674 std::move(nested_object));
673 } 675 }
674 676
675 void ShillToONCTranslator::SetNestedOncValue( 677 void ShillToONCTranslator::SetNestedOncValue(
676 const std::string& onc_dictionary_name, 678 const std::string& onc_dictionary_name,
677 const std::string& onc_field_name, 679 const std::string& onc_field_name,
678 const base::Value& value) { 680 const base::Value& value) {
679 base::DictionaryValue* nested; 681 base::DictionaryValue* nested = nullptr;
680 if (!onc_object_->GetDictionaryWithoutPathExpansion(onc_dictionary_name, 682 if (!onc_object_->GetDictionaryWithoutPathExpansion(onc_dictionary_name,
681 &nested)) { 683 &nested)) {
682 nested = new base::DictionaryValue; 684 nested = onc_object_->SetDictionaryWithoutPathExpansion(
683 onc_object_->SetWithoutPathExpansion(onc_dictionary_name, nested); 685 onc_dictionary_name, base::MakeUnique<base::DictionaryValue>());
684 } 686 }
685 nested->SetWithoutPathExpansion(onc_field_name, value.DeepCopy()); 687 nested->SetWithoutPathExpansion(onc_field_name,
688 base::MakeUnique<base::Value>(value));
686 } 689 }
687 690
688 void ShillToONCTranslator::TranslateAndAddListOfObjects( 691 void ShillToONCTranslator::TranslateAndAddListOfObjects(
689 const std::string& onc_field_name, 692 const std::string& onc_field_name,
690 const base::ListValue& list) { 693 const base::ListValue& list) {
691 const OncFieldSignature* field_signature = 694 const OncFieldSignature* field_signature =
692 GetFieldSignature(*onc_signature_, onc_field_name); 695 GetFieldSignature(*onc_signature_, onc_field_name);
693 if (field_signature->value_signature->onc_type != base::Value::Type::LIST) { 696 if (field_signature->value_signature->onc_type != base::Value::Type::LIST) {
694 LOG(ERROR) << "ONC Field name: '" << onc_field_name << "' has type '" 697 LOG(ERROR) << "ONC Field name: '" << onc_field_name << "' has type '"
695 << field_signature->value_signature->onc_type 698 << field_signature->value_signature->onc_type
(...skipping 14 matching lines...) Expand all
710 std::unique_ptr<base::DictionaryValue> nested_object = 713 std::unique_ptr<base::DictionaryValue> nested_object =
711 nested_translator.CreateTranslatedONCObject(); 714 nested_translator.CreateTranslatedONCObject();
712 // If the nested object couldn't be parsed, simply omit it. 715 // If the nested object couldn't be parsed, simply omit it.
713 if (nested_object->empty()) 716 if (nested_object->empty())
714 continue; 717 continue;
715 result->Append(std::move(nested_object)); 718 result->Append(std::move(nested_object));
716 } 719 }
717 // If there are no entries in the list, there is no need to expose this field. 720 // If there are no entries in the list, there is no need to expose this field.
718 if (result->empty()) 721 if (result->empty())
719 return; 722 return;
720 onc_object_->SetWithoutPathExpansion(onc_field_name, result.release()); 723 onc_object_->SetWithoutPathExpansion(onc_field_name, std::move(result));
721 } 724 }
722 725
723 void ShillToONCTranslator::CopyPropertiesAccordingToSignature() { 726 void ShillToONCTranslator::CopyPropertiesAccordingToSignature() {
724 CopyPropertiesAccordingToSignature(onc_signature_); 727 CopyPropertiesAccordingToSignature(onc_signature_);
725 } 728 }
726 729
727 void ShillToONCTranslator::CopyPropertiesAccordingToSignature( 730 void ShillToONCTranslator::CopyPropertiesAccordingToSignature(
728 const OncValueSignature* value_signature) { 731 const OncValueSignature* value_signature) {
729 if (value_signature->base_signature) 732 if (value_signature->base_signature)
730 CopyPropertiesAccordingToSignature(value_signature->base_signature); 733 CopyPropertiesAccordingToSignature(value_signature->base_signature);
(...skipping 20 matching lines...) Expand all
751 if (shill_value->GetType() != field_signature->value_signature->onc_type) { 754 if (shill_value->GetType() != field_signature->value_signature->onc_type) {
752 LOG(ERROR) << "Shill property '" << shill_property_name << "' with value " 755 LOG(ERROR) << "Shill property '" << shill_property_name << "' with value "
753 << *shill_value << " has base::Value::Type " 756 << *shill_value << " has base::Value::Type "
754 << shill_value->GetType() << " but ONC field '" 757 << shill_value->GetType() << " but ONC field '"
755 << field_signature->onc_field_name << "' requires type " 758 << field_signature->onc_field_name << "' requires type "
756 << field_signature->value_signature->onc_type << ": " 759 << field_signature->value_signature->onc_type << ": "
757 << GetName(); 760 << GetName();
758 return; 761 return;
759 } 762 }
760 763
761 onc_object_->SetWithoutPathExpansion(field_signature->onc_field_name, 764 onc_object_->SetWithoutPathExpansion(
762 shill_value->DeepCopy()); 765 field_signature->onc_field_name,
766 base::MakeUnique<base::Value>(*shill_value));
763 } 767 }
764 768
765 void ShillToONCTranslator::TranslateWithTableAndSet( 769 void ShillToONCTranslator::TranslateWithTableAndSet(
766 const std::string& shill_property_name, 770 const std::string& shill_property_name,
767 const StringTranslationEntry table[], 771 const StringTranslationEntry table[],
768 const std::string& onc_field_name) { 772 const std::string& onc_field_name) {
769 std::string shill_value; 773 std::string shill_value;
770 if (!shill_dictionary_->GetStringWithoutPathExpansion(shill_property_name, 774 if (!shill_dictionary_->GetStringWithoutPathExpansion(shill_property_name,
771 &shill_value)) { 775 &shill_value)) {
772 return; 776 return;
(...skipping 23 matching lines...) Expand all
796 const NetworkState* network_state) { 800 const NetworkState* network_state) {
797 CHECK(onc_signature != NULL); 801 CHECK(onc_signature != NULL);
798 802
799 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature, 803 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature,
800 network_state); 804 network_state);
801 return translator.CreateTranslatedONCObject(); 805 return translator.CreateTranslatedONCObject();
802 } 806 }
803 807
804 } // namespace onc 808 } // namespace onc
805 } // namespace chromeos 809 } // namespace chromeos
OLDNEW
« no previous file with comments | « base/values.cc ('k') | components/policy/core/common/policy_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698