| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chromeos/network/shill_property_util.h" | 5 #include "chromeos/network/shill_property_util.h" |
| 6 | 6 |
| 7 #include "base/i18n/icu_encoding_detection.h" | 7 #include "base/i18n/icu_encoding_detection.h" |
| 8 #include "base/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 void SetUIData(const NetworkUIData& ui_data, | 171 void SetUIData(const NetworkUIData& ui_data, |
| 172 base::DictionaryValue* shill_dictionary) { | 172 base::DictionaryValue* shill_dictionary) { |
| 173 base::DictionaryValue ui_data_dict; | 173 base::DictionaryValue ui_data_dict; |
| 174 ui_data.FillDictionary(&ui_data_dict); | 174 ui_data.FillDictionary(&ui_data_dict); |
| 175 std::string ui_data_blob; | 175 std::string ui_data_blob; |
| 176 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob); | 176 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob); |
| 177 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kUIDataProperty, | 177 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kUIDataProperty, |
| 178 ui_data_blob); | 178 ui_data_blob); |
| 179 } | 179 } |
| 180 | 180 |
| 181 bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties, | |
| 182 base::DictionaryValue* dest) { | |
| 183 bool success = true; | |
| 184 | |
| 185 // GUID is optional. | |
| 186 CopyStringFromDictionary(service_properties, flimflam::kGuidProperty, dest); | |
| 187 | |
| 188 std::string type; | |
| 189 service_properties.GetStringWithoutPathExpansion(flimflam::kTypeProperty, | |
| 190 &type); | |
| 191 success &= !type.empty(); | |
| 192 dest->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type); | |
| 193 if (type == flimflam::kTypeWifi) { | |
| 194 success &= CopyStringFromDictionary( | |
| 195 service_properties, flimflam::kSecurityProperty, dest); | |
| 196 success &= CopyStringFromDictionary( | |
| 197 service_properties, flimflam::kSSIDProperty, dest); | |
| 198 success &= CopyStringFromDictionary( | |
| 199 service_properties, flimflam::kModeProperty, dest); | |
| 200 } else if (type == flimflam::kTypeVPN) { | |
| 201 success &= CopyStringFromDictionary( | |
| 202 service_properties, flimflam::kNameProperty, dest); | |
| 203 // VPN Provider values are read from the "Provider" dictionary, but written | |
| 204 // with the keys "Provider.Type" and "Provider.Host". | |
| 205 const base::DictionaryValue* provider_properties = NULL; | |
| 206 if (!service_properties.GetDictionaryWithoutPathExpansion( | |
| 207 flimflam::kProviderProperty, &provider_properties)) { | |
| 208 NET_LOG_ERROR("CopyIdentifyingProperties", "Missing VPN provider dict"); | |
| 209 return false; | |
| 210 } | |
| 211 std::string vpn_provider_type; | |
| 212 provider_properties->GetStringWithoutPathExpansion(flimflam::kTypeProperty, | |
| 213 &vpn_provider_type); | |
| 214 success &= !vpn_provider_type.empty(); | |
| 215 dest->SetStringWithoutPathExpansion(flimflam::kProviderTypeProperty, | |
| 216 vpn_provider_type); | |
| 217 | |
| 218 std::string vpn_provider_host; | |
| 219 provider_properties->GetStringWithoutPathExpansion(flimflam::kHostProperty, | |
| 220 &vpn_provider_host); | |
| 221 success &= !vpn_provider_host.empty(); | |
| 222 dest->SetStringWithoutPathExpansion(flimflam::kProviderHostProperty, | |
| 223 vpn_provider_host); | |
| 224 } else if (type == flimflam::kTypeEthernet || | |
| 225 type == shill::kTypeEthernetEap) { | |
| 226 // Ethernet and EthernetEAP don't have any additional identifying | |
| 227 // properties. | |
| 228 } else { | |
| 229 NOTREACHED() << "Unsupported network type " << type; | |
| 230 success = false; | |
| 231 } | |
| 232 if (!success) | |
| 233 NET_LOG_ERROR("CopyIdentifyingProperties", "Missing required properties"); | |
| 234 return success; | |
| 235 } | |
| 236 | |
| 237 } // namespace shill_property_util | 181 } // namespace shill_property_util |
| 238 | 182 |
| 239 namespace { | 183 namespace { |
| 240 | 184 |
| 241 const char kPatternDefault[] = "PatternDefault"; | 185 const char kPatternDefault[] = "PatternDefault"; |
| 242 const char kPatternEthernet[] = "PatternEthernet"; | 186 const char kPatternEthernet[] = "PatternEthernet"; |
| 243 const char kPatternWireless[] = "PatternWireless"; | 187 const char kPatternWireless[] = "PatternWireless"; |
| 244 const char kPatternMobile[] = "PatternMobile"; | 188 const char kPatternMobile[] = "PatternMobile"; |
| 245 const char kPatternNonVirtual[] = "PatternNonVirtual"; | 189 const char kPatternNonVirtual[] = "PatternNonVirtual"; |
| 246 | 190 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 if (!str.empty()) | 309 if (!str.empty()) |
| 366 str += "|"; | 310 str += "|"; |
| 367 str += shill_type_to_flag[i].shill_network_type; | 311 str += shill_type_to_flag[i].shill_network_type; |
| 368 } | 312 } |
| 369 return str; | 313 return str; |
| 370 } | 314 } |
| 371 | 315 |
| 372 NetworkTypePattern::NetworkTypePattern(int pattern) : pattern_(pattern) {} | 316 NetworkTypePattern::NetworkTypePattern(int pattern) : pattern_(pattern) {} |
| 373 | 317 |
| 374 } // namespace chromeos | 318 } // namespace chromeos |
| OLD | NEW |