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

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

Issue 11962048: This adds Cellular to the Shill to ONC translation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing broken unit test Created 7 years, 11 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
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } else { 115 } else {
116 // Shill wants all Provider/VPN fields to be strings. 116 // Shill wants all Provider/VPN fields to be strings.
117 translated = ConvertValueToString(it.value()); 117 translated = ConvertValueToString(it.value());
118 } 118 }
119 AddValueAccordingToSignature(it.key(), translated.Pass()); 119 AddValueAccordingToSignature(it.key(), translated.Pass());
120 } 120 }
121 } 121 }
122 122
123 void LocalTranslator::TranslateVPN() { 123 void LocalTranslator::TranslateVPN() {
124 std::string type; 124 std::string type;
125 onc_object_->GetStringWithoutPathExpansion(kType, &type); 125 onc_object_->GetStringWithoutPathExpansion(vpn::kType, &type);
126 TranslateWithTableAndSet(type, kVPNTypeTable, 126 TranslateWithTableAndSet(type, kVPNTypeTable,
127 flimflam::kProviderTypeProperty); 127 flimflam::kProviderTypeProperty);
128 128
129 CopyFieldsAccordingToSignature(); 129 CopyFieldsAccordingToSignature();
130 } 130 }
131 131
132 void LocalTranslator::TranslateWiFi() { 132 void LocalTranslator::TranslateWiFi() {
133 std::string security; 133 std::string security;
134 onc_object_->GetStringWithoutPathExpansion(wifi::kSecurity, &security); 134 onc_object_->GetStringWithoutPathExpansion(wifi::kSecurity, &security);
135 TranslateWithTableAndSet(security, kWiFiSecurityTable, 135 TranslateWithTableAndSet(security, kWiFiSecurityTable,
(...skipping 19 matching lines...) Expand all
155 outer == eap::kPEAP ? kEAP_PEAP_InnerTable : kEAP_TTLS_InnerTable; 155 outer == eap::kPEAP ? kEAP_PEAP_InnerTable : kEAP_TTLS_InnerTable;
156 TranslateWithTableAndSet(inner, table, flimflam::kEapPhase2AuthProperty); 156 TranslateWithTableAndSet(inner, table, flimflam::kEapPhase2AuthProperty);
157 } 157 }
158 } 158 }
159 159
160 CopyFieldsAccordingToSignature(); 160 CopyFieldsAccordingToSignature();
161 } 161 }
162 162
163 void LocalTranslator::TranslateNetworkConfiguration() { 163 void LocalTranslator::TranslateNetworkConfiguration() {
164 std::string type; 164 std::string type;
165 onc_object_->GetStringWithoutPathExpansion(kType, &type); 165 onc_object_->GetStringWithoutPathExpansion(network_config::kType, &type);
166 TranslateWithTableAndSet(type, kNetworkTypeTable, flimflam::kTypeProperty); 166 TranslateWithTableAndSet(type, kNetworkTypeTable, flimflam::kTypeProperty);
167 167
168 // Shill doesn't allow setting the name for non-VPN networks. 168 // Shill doesn't allow setting the name for non-VPN networks.
169 if (type == kVPN) { 169 if (type == network_type::kVPN) {
170 std::string name; 170 std::string name;
171 onc_object_->GetStringWithoutPathExpansion(kName, &name); 171 onc_object_->GetStringWithoutPathExpansion(network_config::kName, &name);
172 shill_dictionary_->SetStringWithoutPathExpansion( 172 shill_dictionary_->SetStringWithoutPathExpansion(
173 flimflam::kNameProperty, name); 173 flimflam::kNameProperty, name);
174 } 174 }
175 175
176 CopyFieldsAccordingToSignature(); 176 CopyFieldsAccordingToSignature();
177 } 177 }
178 178
179 void LocalTranslator::CopyFieldsAccordingToSignature() { 179 void LocalTranslator::CopyFieldsAccordingToSignature() {
180 for (base::DictionaryValue::Iterator it(*onc_object_); it.HasNext(); 180 for (base::DictionaryValue::Iterator it(*onc_object_); it.HasNext();
181 it.Advance()) { 181 it.Advance()) {
(...skipping 14 matching lines...) Expand all
196 return; 196 return;
197 197
198 shill_dictionary_->SetWithoutPathExpansion( 198 shill_dictionary_->SetWithoutPathExpansion(
199 field_signature->shill_property_name, value.release()); 199 field_signature->shill_property_name, value.release());
200 } 200 }
201 201
202 void LocalTranslator::TranslateWithTableAndSet( 202 void LocalTranslator::TranslateWithTableAndSet(
203 const std::string& onc_value, 203 const std::string& onc_value,
204 const StringTranslationEntry table[], 204 const StringTranslationEntry table[],
205 const std::string& shill_property_name) { 205 const std::string& shill_property_name) {
206 for (int i = 0; table[i].onc_value != NULL; ++i) { 206 std::string shill_value;
207 if (onc_value != table[i].onc_value) 207 if (TranslateStringToShill(table, onc_value, &shill_value)) {
208 continue;
209 shill_dictionary_->SetStringWithoutPathExpansion(shill_property_name, 208 shill_dictionary_->SetStringWithoutPathExpansion(shill_property_name,
210 table[i].shill_value); 209 shill_value);
211 return; 210 return;
212 } 211 }
213 // As we previously validate ONC, this case should never occur. If it still 212 // As we previously validate ONC, this case should never occur. If it still
214 // occurs, we should check here. Otherwise the failure will only show up much 213 // occurs, we should check here. Otherwise the failure will only show up much
215 // later in Shill. 214 // later in Shill.
216 LOG(ERROR) << "Value '" << onc_value << "cannot be translated to Shill"; 215 LOG(ERROR) << "Value '" << onc_value
216 << " cannot be translated to Shill property "
217 << shill_property_name;
217 } 218 }
218 219
219 // Iterates recursively over |onc_object| and its |signature|. At each object 220 // Iterates recursively over |onc_object| and its |signature|. At each object
220 // applies the local translation using LocalTranslator::TranslateFields. The 221 // applies the local translation using LocalTranslator::TranslateFields. The
221 // results are written to |shill_dictionary|. 222 // results are written to |shill_dictionary|.
222 void TranslateONCHierarchy(const OncValueSignature& signature, 223 void TranslateONCHierarchy(const OncValueSignature& signature,
223 const base::DictionaryValue& onc_object, 224 const base::DictionaryValue& onc_object,
224 base::DictionaryValue* shill_dictionary) { 225 base::DictionaryValue* shill_dictionary) {
225 // Translates fields of |onc_object| and writes them to |shill_dictionary_|. 226 // Translates fields of |onc_object| and writes them to |shill_dictionary_|.
226 LocalTranslator translator(signature, onc_object, shill_dictionary); 227 LocalTranslator translator(signature, onc_object, shill_dictionary);
(...skipping 20 matching lines...) Expand all
247 const OncValueSignature* onc_signature, 248 const OncValueSignature* onc_signature,
248 const base::DictionaryValue& onc_object) { 249 const base::DictionaryValue& onc_object) {
249 CHECK(onc_signature != NULL); 250 CHECK(onc_signature != NULL);
250 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); 251 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue);
251 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); 252 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get());
252 return shill_dictionary.Pass(); 253 return shill_dictionary.Pass();
253 } 254 }
254 255
255 } // namespace onc 256 } // namespace onc
256 } // namespace chromeos 257 } // 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