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

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

Issue 12390017: Separating ONC<->Shill translation from the ONC signature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed browser tests. Created 7 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 | 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 28 matching lines...) Expand all
39 // not nested objects because recursion is handled by the calling function 39 // not nested objects because recursion is handled by the calling function
40 // TranslateONCHierarchy. 40 // TranslateONCHierarchy.
41 class LocalTranslator { 41 class LocalTranslator {
42 public: 42 public:
43 LocalTranslator(const OncValueSignature& onc_signature, 43 LocalTranslator(const OncValueSignature& onc_signature,
44 const base::DictionaryValue& onc_object, 44 const base::DictionaryValue& onc_object,
45 base::DictionaryValue* shill_dictionary) 45 base::DictionaryValue* shill_dictionary)
46 : onc_signature_(&onc_signature), 46 : onc_signature_(&onc_signature),
47 onc_object_(&onc_object), 47 onc_object_(&onc_object),
48 shill_dictionary_(shill_dictionary) { 48 shill_dictionary_(shill_dictionary) {
49 field_translation_table_ = GetFieldTranslationTable(onc_signature);
49 } 50 }
50 51
51 void TranslateFields(); 52 void TranslateFields();
52 53
53 private: 54 private:
54 void TranslateOpenVPN(); 55 void TranslateOpenVPN();
55 void TranslateVPN(); 56 void TranslateVPN();
56 void TranslateWiFi(); 57 void TranslateWiFi();
57 void TranslateEAP(); 58 void TranslateEAP();
58 void TranslateNetworkConfiguration(); 59 void TranslateNetworkConfiguration();
59 60
60 // Copies all entries from |onc_object_| to |shill_dictionary_| for which a 61 // Copies all entries from |onc_object_| to |shill_dictionary_| for which a
61 // translation (shill_property_name) is defined by |onc_signature_|. 62 // translation (shill_property_name) is defined by |onc_signature_|.
62 void CopyFieldsAccordingToSignature(); 63 void CopyFieldsAccordingToSignature();
63 64
64 // Adds |value| to |shill_dictionary| at the field shill_property_name given 65 // Adds |value| to |shill_dictionary| at the field shill_property_name given
65 // by the associated signature. Takes ownership of |value|. Does nothing if 66 // by the associated signature. Takes ownership of |value|. Does nothing if
66 // |value| is NULL or the property name cannot be read from the signature. 67 // |value| is NULL or the property name cannot be read from the signature.
67 void AddValueAccordingToSignature(const std::string& onc_field_name, 68 void AddValueAccordingToSignature(const std::string& onc_field_name,
68 scoped_ptr<base::Value> value); 69 scoped_ptr<base::Value> value);
69 70
70 // If existent, translates the entry at |onc_field_name| in |onc_object_| 71 // If existent, translates the entry at |onc_field_name| in |onc_object_|
71 // using |table|. It is an error if no matching table entry is found. Writes 72 // using |table|. It is an error if no matching table entry is found. Writes
72 // the result as entry at |shill_property_name| in |shill_dictionary_|. 73 // the result as entry at |shill_property_name| in |shill_dictionary_|.
73 void TranslateWithTableAndSet(const std::string& onc_field_name, 74 void TranslateWithTableAndSet(const std::string& onc_field_name,
74 const StringTranslationEntry table[], 75 const StringTranslationEntry table[],
75 const std::string& shill_property_name); 76 const std::string& shill_property_name);
76 77
77 const OncValueSignature* onc_signature_; 78 const OncValueSignature* onc_signature_;
79 const FieldTranslationEntry* field_translation_table_;
78 const base::DictionaryValue* onc_object_; 80 const base::DictionaryValue* onc_object_;
79 base::DictionaryValue* shill_dictionary_; 81 base::DictionaryValue* shill_dictionary_;
80 82
81 DISALLOW_COPY_AND_ASSIGN(LocalTranslator); 83 DISALLOW_COPY_AND_ASSIGN(LocalTranslator);
82 }; 84 };
83 85
84 void LocalTranslator::TranslateFields() { 86 void LocalTranslator::TranslateFields() {
85 if (onc_signature_ == &kNetworkConfigurationSignature) 87 if (onc_signature_ == &kNetworkConfigurationSignature)
86 TranslateNetworkConfiguration(); 88 TranslateNetworkConfiguration();
87 else if (onc_signature_ == &kVPNSignature) 89 else if (onc_signature_ == &kVPNSignature)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 for (base::DictionaryValue::Iterator it(*onc_object_); it.HasNext(); 185 for (base::DictionaryValue::Iterator it(*onc_object_); it.HasNext();
184 it.Advance()) { 186 it.Advance()) {
185 AddValueAccordingToSignature(it.key(), 187 AddValueAccordingToSignature(it.key(),
186 make_scoped_ptr(it.value().DeepCopy())); 188 make_scoped_ptr(it.value().DeepCopy()));
187 } 189 }
188 } 190 }
189 191
190 void LocalTranslator::AddValueAccordingToSignature( 192 void LocalTranslator::AddValueAccordingToSignature(
191 const std::string& onc_name, 193 const std::string& onc_name,
192 scoped_ptr<base::Value> value) { 194 scoped_ptr<base::Value> value) {
193 if (value.get() == NULL) 195 if (!value || !field_translation_table_)
194 return;
195 const OncFieldSignature* field_signature =
196 GetFieldSignature(*onc_signature_, onc_name);
197 DCHECK(field_signature != NULL);
198 if (field_signature == NULL || field_signature->shill_property_name == NULL)
199 return; 196 return;
200 197
201 shill_dictionary_->SetWithoutPathExpansion( 198 std::string shill_property_name;
202 field_signature->shill_property_name, value.release()); 199 if (!GetShillPropertyName(onc_name,
200 field_translation_table_,
201 &shill_property_name))
202 return;
203
204 shill_dictionary_->SetWithoutPathExpansion(shill_property_name,
205 value.release());
203 } 206 }
204 207
205 void LocalTranslator::TranslateWithTableAndSet( 208 void LocalTranslator::TranslateWithTableAndSet(
206 const std::string& onc_value, 209 const std::string& onc_value,
207 const StringTranslationEntry table[], 210 const StringTranslationEntry table[],
208 const std::string& shill_property_name) { 211 const std::string& shill_property_name) {
209 std::string shill_value; 212 std::string shill_value;
210 if (TranslateStringToShill(table, onc_value, &shill_value)) { 213 if (TranslateStringToShill(table, onc_value, &shill_value)) {
211 shill_dictionary_->SetStringWithoutPathExpansion(shill_property_name, 214 shill_dictionary_->SetStringWithoutPathExpansion(shill_property_name,
212 shill_value); 215 shill_value);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 const OncValueSignature* onc_signature, 254 const OncValueSignature* onc_signature,
252 const base::DictionaryValue& onc_object) { 255 const base::DictionaryValue& onc_object) {
253 CHECK(onc_signature != NULL); 256 CHECK(onc_signature != NULL);
254 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); 257 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue);
255 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); 258 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get());
256 return shill_dictionary.Pass(); 259 return shill_dictionary.Pass();
257 } 260 }
258 261
259 } // namespace onc 262 } // namespace onc
260 } // namespace chromeos 263 } // 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