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

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

Issue 762243002: 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
42 scoped_ptr<base::StringValue> ConvertValueToString(const base::Value& value) { 31 scoped_ptr<base::StringValue> ConvertValueToString(const base::Value& value) {
43 std::string str; 32 std::string str;
44 if (!value.GetAsString(&str)) 33 if (!value.GetAsString(&str))
45 base::JSONWriter::Write(&value, &str); 34 base::JSONWriter::Write(&value, &str);
46 return make_scoped_ptr(new base::StringValue(str)); 35 return make_scoped_ptr(new base::StringValue(str));
47 } 36 }
48 37
49 // This class is responsible to translate the local fields of the given 38 // This class is responsible to translate the local fields of the given
50 // |onc_object| according to |onc_signature| into |shill_dictionary|. This 39 // |onc_object| according to |onc_signature| into |shill_dictionary|. This
51 // translation should consider (if possible) only fields of this ONC object and 40 // translation should consider (if possible) only fields of this ONC object and
(...skipping 12 matching lines...) Expand all
64 53
65 void TranslateFields(); 54 void TranslateFields();
66 55
67 private: 56 private:
68 void TranslateEthernet(); 57 void TranslateEthernet();
69 void TranslateOpenVPN(); 58 void TranslateOpenVPN();
70 void TranslateIPsec(); 59 void TranslateIPsec();
71 void TranslateVPN(); 60 void TranslateVPN();
72 void TranslateWiFi(); 61 void TranslateWiFi();
73 void TranslateEAP(); 62 void TranslateEAP();
74 void TranslateStaticIPConfig();
75 void TranslateNetworkConfiguration(); 63 void TranslateNetworkConfiguration();
76 64
77 // Copies all entries from |onc_object_| to |shill_dictionary_| for which a 65 // Copies all entries from |onc_object_| to |shill_dictionary_| for which a
78 // translation (shill_property_name) is defined by the translation table for 66 // translation (shill_property_name) is defined by the translation table for
79 // |onc_signature_|. 67 // |onc_signature_|.
80 void CopyFieldsAccordingToSignature(); 68 void CopyFieldsAccordingToSignature();
81 69
82 // If existent, copies the value of field |onc_field_name| from |onc_object_| 70 // If existent, copies the value of field |onc_field_name| from |onc_object_|
83 // to the property |shill_property_name| in |shill_dictionary_|. 71 // to the property |shill_property_name| in |shill_dictionary_|.
84 void CopyFieldFromONCToShill(const std::string& onc_field_name, 72 void CopyFieldFromONCToShill(const std::string& onc_field_name,
(...skipping 16 matching lines...) Expand all
101 const FieldTranslationEntry* field_translation_table_; 89 const FieldTranslationEntry* field_translation_table_;
102 const base::DictionaryValue* onc_object_; 90 const base::DictionaryValue* onc_object_;
103 base::DictionaryValue* shill_dictionary_; 91 base::DictionaryValue* shill_dictionary_;
104 92
105 DISALLOW_COPY_AND_ASSIGN(LocalTranslator); 93 DISALLOW_COPY_AND_ASSIGN(LocalTranslator);
106 }; 94 };
107 95
108 void LocalTranslator::TranslateFields() { 96 void LocalTranslator::TranslateFields() {
109 if (onc_signature_ == &kNetworkConfigurationSignature) 97 if (onc_signature_ == &kNetworkConfigurationSignature)
110 TranslateNetworkConfiguration(); 98 TranslateNetworkConfiguration();
111 else if (onc_signature_ == &kStaticIPConfigSignature)
112 TranslateStaticIPConfig();
113 else if (onc_signature_ == &kEthernetSignature) 99 else if (onc_signature_ == &kEthernetSignature)
114 TranslateEthernet(); 100 TranslateEthernet();
115 else if (onc_signature_ == &kVPNSignature) 101 else if (onc_signature_ == &kVPNSignature)
116 TranslateVPN(); 102 TranslateVPN();
117 else if (onc_signature_ == &kOpenVPNSignature) 103 else if (onc_signature_ == &kOpenVPNSignature)
118 TranslateOpenVPN(); 104 TranslateOpenVPN();
119 else if (onc_signature_ == &kIPsecSignature) 105 else if (onc_signature_ == &kIPsecSignature)
120 TranslateIPsec(); 106 TranslateIPsec();
121 else if (onc_signature_ == &kWiFiSignature) 107 else if (onc_signature_ == &kWiFiSignature)
122 TranslateWiFi(); 108 TranslateWiFi();
(...skipping 11 matching lines...) Expand all
134 const char* shill_type = shill::kTypeEthernet; 120 const char* shill_type = shill::kTypeEthernet;
135 if (authentication == ::onc::ethernet::k8021X) 121 if (authentication == ::onc::ethernet::k8021X)
136 shill_type = shill::kTypeEthernetEap; 122 shill_type = shill::kTypeEthernetEap;
137 shill_dictionary_->SetStringWithoutPathExpansion(shill::kTypeProperty, 123 shill_dictionary_->SetStringWithoutPathExpansion(shill::kTypeProperty,
138 shill_type); 124 shill_type);
139 125
140 CopyFieldsAccordingToSignature(); 126 CopyFieldsAccordingToSignature();
141 } 127 }
142 128
143 129
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
158 void LocalTranslator::TranslateOpenVPN() { 130 void LocalTranslator::TranslateOpenVPN() {
159 // SaveCredentials needs special handling when translating from Shill -> ONC 131 // SaveCredentials needs special handling when translating from Shill -> ONC
160 // so handle it explicitly here. 132 // so handle it explicitly here.
161 CopyFieldFromONCToShill(::onc::vpn::kSaveCredentials, 133 CopyFieldFromONCToShill(::onc::vpn::kSaveCredentials,
162 shill::kSaveCredentialsProperty); 134 shill::kSaveCredentialsProperty);
163 135
164 std::string user_auth_type; 136 std::string user_auth_type;
165 onc_object_->GetStringWithoutPathExpansion( 137 onc_object_->GetStringWithoutPathExpansion(
166 ::onc::openvpn::kUserAuthenticationType, &user_auth_type); 138 ::onc::openvpn::kUserAuthenticationType, &user_auth_type);
167 // The default behavior (if user_auth_type is empty) is to use both password 139 // 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
402 const OncValueSignature* onc_signature, 374 const OncValueSignature* onc_signature,
403 const base::DictionaryValue& onc_object) { 375 const base::DictionaryValue& onc_object) {
404 CHECK(onc_signature != NULL); 376 CHECK(onc_signature != NULL);
405 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); 377 scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue);
406 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); 378 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get());
407 return shill_dictionary.Pass(); 379 return shill_dictionary.Pass();
408 } 380 }
409 381
410 } // namespace onc 382 } // namespace onc
411 } // namespace chromeos 383 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698