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

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

Issue 776603002: Revert of Change to Shill's IPConfig objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 // The implementation of TranslateONCObjectToShill is structured in two parts: 5 // The implementation of TranslateONCObjectToShill is structured in two parts:
6 // - The recursion through the existing ONC hierarchy 6 // - The recursion through the existing ONC hierarchy
7 // see TranslateONCHierarchy 7 // see TranslateONCHierarchy
8 // - The local translation of an object depending on the associated signature 8 // - The local translation of an object depending on the associated signature
9 // see LocalTranslator::TranslateFields 9 // see LocalTranslator::TranslateFields
10 10
(...skipping 10 matching lines...) Expand all
21 #include "chromeos/network/onc/onc_translation_tables.h" 21 #include "chromeos/network/onc/onc_translation_tables.h"
22 #include "chromeos/network/shill_property_util.h" 22 #include "chromeos/network/shill_property_util.h"
23 #include "components/onc/onc_constants.h" 23 #include "components/onc/onc_constants.h"
24 #include "third_party/cros_system_api/dbus/service_constants.h" 24 #include "third_party/cros_system_api/dbus/service_constants.h"
25 25
26 namespace chromeos { 26 namespace chromeos {
27 namespace onc { 27 namespace onc {
28 28
29 namespace { 29 namespace {
30 30
31 bool ConvertListValueToStringVector(const base::ListValue& string_list,
32 std::vector<std::string>* result) {
33 for (size_t i = 0; i < string_list.GetSize(); ++i) {
34 std::string str;
35 if (!string_list.GetString(i, &str))
36 return false;
37 result->push_back(str);
38 }
39 return true;
40 }
41
31 scoped_ptr<base::StringValue> ConvertValueToString(const base::Value& value) { 42 scoped_ptr<base::StringValue> ConvertValueToString(const base::Value& value) {
32 std::string str; 43 std::string str;
33 if (!value.GetAsString(&str)) 44 if (!value.GetAsString(&str))
34 base::JSONWriter::Write(&value, &str); 45 base::JSONWriter::Write(&value, &str);
35 return make_scoped_ptr(new base::StringValue(str)); 46 return make_scoped_ptr(new base::StringValue(str));
36 } 47 }
37 48
38 // This class is responsible to translate the local fields of the given 49 // This class is responsible to translate the local fields of the given
39 // |onc_object| according to |onc_signature| into |shill_dictionary|. This 50 // |onc_object| according to |onc_signature| into |shill_dictionary|. This
40 // translation should consider (if possible) only fields of this ONC object and 51 // translation should consider (if possible) only fields of this ONC object and
(...skipping 12 matching lines...) Expand all
53 64
54 void TranslateFields(); 65 void TranslateFields();
55 66
56 private: 67 private:
57 void TranslateEthernet(); 68 void TranslateEthernet();
58 void TranslateOpenVPN(); 69 void TranslateOpenVPN();
59 void TranslateIPsec(); 70 void TranslateIPsec();
60 void TranslateVPN(); 71 void TranslateVPN();
61 void TranslateWiFi(); 72 void TranslateWiFi();
62 void TranslateEAP(); 73 void TranslateEAP();
74 void TranslateStaticIPConfig();
63 void TranslateNetworkConfiguration(); 75 void TranslateNetworkConfiguration();
64 76
65 // Copies all entries from |onc_object_| to |shill_dictionary_| for which a 77 // Copies all entries from |onc_object_| to |shill_dictionary_| for which a
66 // translation (shill_property_name) is defined by the translation table for 78 // translation (shill_property_name) is defined by the translation table for
67 // |onc_signature_|. 79 // |onc_signature_|.
68 void CopyFieldsAccordingToSignature(); 80 void CopyFieldsAccordingToSignature();
69 81
70 // If existent, copies the value of field |onc_field_name| from |onc_object_| 82 // If existent, copies the value of field |onc_field_name| from |onc_object_|
71 // to the property |shill_property_name| in |shill_dictionary_|. 83 // to the property |shill_property_name| in |shill_dictionary_|.
72 void CopyFieldFromONCToShill(const std::string& onc_field_name, 84 void CopyFieldFromONCToShill(const std::string& onc_field_name,
(...skipping 16 matching lines...) Expand all
89 const FieldTranslationEntry* field_translation_table_; 101 const FieldTranslationEntry* field_translation_table_;
90 const base::DictionaryValue* onc_object_; 102 const base::DictionaryValue* onc_object_;
91 base::DictionaryValue* shill_dictionary_; 103 base::DictionaryValue* shill_dictionary_;
92 104
93 DISALLOW_COPY_AND_ASSIGN(LocalTranslator); 105 DISALLOW_COPY_AND_ASSIGN(LocalTranslator);
94 }; 106 };
95 107
96 void LocalTranslator::TranslateFields() { 108 void LocalTranslator::TranslateFields() {
97 if (onc_signature_ == &kNetworkConfigurationSignature) 109 if (onc_signature_ == &kNetworkConfigurationSignature)
98 TranslateNetworkConfiguration(); 110 TranslateNetworkConfiguration();
111 else if (onc_signature_ == &kStaticIPConfigSignature)
112 TranslateStaticIPConfig();
99 else if (onc_signature_ == &kEthernetSignature) 113 else if (onc_signature_ == &kEthernetSignature)
100 TranslateEthernet(); 114 TranslateEthernet();
101 else if (onc_signature_ == &kVPNSignature) 115 else if (onc_signature_ == &kVPNSignature)
102 TranslateVPN(); 116 TranslateVPN();
103 else if (onc_signature_ == &kOpenVPNSignature) 117 else if (onc_signature_ == &kOpenVPNSignature)
104 TranslateOpenVPN(); 118 TranslateOpenVPN();
105 else if (onc_signature_ == &kIPsecSignature) 119 else if (onc_signature_ == &kIPsecSignature)
106 TranslateIPsec(); 120 TranslateIPsec();
107 else if (onc_signature_ == &kWiFiSignature) 121 else if (onc_signature_ == &kWiFiSignature)
108 TranslateWiFi(); 122 TranslateWiFi();
(...skipping 11 matching lines...) Expand all
120 const char* shill_type = shill::kTypeEthernet; 134 const char* shill_type = shill::kTypeEthernet;
121 if (authentication == ::onc::ethernet::k8021X) 135 if (authentication == ::onc::ethernet::k8021X)
122 shill_type = shill::kTypeEthernetEap; 136 shill_type = shill::kTypeEthernetEap;
123 shill_dictionary_->SetStringWithoutPathExpansion(shill::kTypeProperty, 137 shill_dictionary_->SetStringWithoutPathExpansion(shill::kTypeProperty,
124 shill_type); 138 shill_type);
125 139
126 CopyFieldsAccordingToSignature(); 140 CopyFieldsAccordingToSignature();
127 } 141 }
128 142
129 143
144 void LocalTranslator::TranslateStaticIPConfig() {
145 const base::ListValue* onc_nameservers = NULL;
146 if (onc_object_->GetListWithoutPathExpansion(::onc::ipconfig::kNameServers,
147 &onc_nameservers)) {
148 std::vector<std::string> onc_nameservers_vector;
149 ConvertListValueToStringVector(*onc_nameservers, &onc_nameservers_vector);
150 std::string shill_nameservers = JoinString(onc_nameservers_vector, ',');
151 shill_dictionary_->SetStringWithoutPathExpansion(
152 shill::kStaticIPNameServersProperty, shill_nameservers);
153 }
154
155 CopyFieldsAccordingToSignature();
156 }
157
130 void LocalTranslator::TranslateOpenVPN() { 158 void LocalTranslator::TranslateOpenVPN() {
131 // SaveCredentials needs special handling when translating from Shill -> ONC 159 // SaveCredentials needs special handling when translating from Shill -> ONC
132 // so handle it explicitly here. 160 // so handle it explicitly here.
133 CopyFieldFromONCToShill(::onc::vpn::kSaveCredentials, 161 CopyFieldFromONCToShill(::onc::vpn::kSaveCredentials,
134 shill::kSaveCredentialsProperty); 162 shill::kSaveCredentialsProperty);
135 163
136 std::string user_auth_type; 164 std::string user_auth_type;
137 onc_object_->GetStringWithoutPathExpansion( 165 onc_object_->GetStringWithoutPathExpansion(
138 ::onc::openvpn::kUserAuthenticationType, &user_auth_type); 166 ::onc::openvpn::kUserAuthenticationType, &user_auth_type);
139 // The default behavior (if user_auth_type is empty) is to use both password 167 // The default behavior (if user_auth_type is empty) is to use both password
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 const OncValueSignature* onc_signature, 402 const OncValueSignature* onc_signature,
375 const base::DictionaryValue& onc_object) { 403 const base::DictionaryValue& onc_object) {
376 CHECK(onc_signature != NULL); 404 CHECK(onc_signature != NULL);
377 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); 405 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue);
378 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); 406 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get());
379 return shill_dictionary.Pass(); 407 return shill_dictionary.Pass();
380 } 408 }
381 409
382 } // namespace onc 410 } // namespace onc
383 } // namespace chromeos 411 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_translation_tables.cc ('k') | chromeos/network/onc/onc_translator_shill_to_onc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698