| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 base::DictionaryValue* dest) { | 50 base::DictionaryValue* dest) { |
| 51 std::string string_value; | 51 std::string string_value; |
| 52 if (!source.GetStringWithoutPathExpansion(key, &string_value) || | 52 if (!source.GetStringWithoutPathExpansion(key, &string_value) || |
| 53 string_value.empty()) { | 53 string_value.empty()) { |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 dest->SetStringWithoutPathExpansion(key, string_value); | 56 dest->SetStringWithoutPathExpansion(key, string_value); |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // This is the same normalization that Shill applies to security types for the | |
| 61 // sake of comparing/identifying WiFi networks. See Shill's | |
| 62 // WiFiService::GetSecurityClass. | |
| 63 std::string GetSecurityClass(const std::string& security) { | |
| 64 if (security == shill::kSecurityRsn || security == shill::kSecurityWpa) | |
| 65 return shill::kSecurityPsk; | |
| 66 else | |
| 67 return security; | |
| 68 } | |
| 69 | |
| 70 } // namespace | 60 } // namespace |
| 71 | 61 |
| 72 void SetSSID(const std::string ssid, base::DictionaryValue* properties) { | 62 void SetSSID(const std::string ssid, base::DictionaryValue* properties) { |
| 73 std::string hex_ssid = base::HexEncode(ssid.c_str(), ssid.size()); | 63 std::string hex_ssid = base::HexEncode(ssid.c_str(), ssid.size()); |
| 74 properties->SetStringWithoutPathExpansion(shill::kWifiHexSsid, hex_ssid); | 64 properties->SetStringWithoutPathExpansion(shill::kWifiHexSsid, hex_ssid); |
| 75 } | 65 } |
| 76 | 66 |
| 77 std::string GetSSIDFromProperties(const base::DictionaryValue& properties, | 67 std::string GetSSIDFromProperties(const base::DictionaryValue& properties, |
| 78 bool* unknown_encoding) { | 68 bool* unknown_encoding) { |
| 79 bool verbose_logging = false; | 69 bool verbose_logging = false; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 bool success = true; | 238 bool success = true; |
| 249 | 239 |
| 250 // GUID is optional. | 240 // GUID is optional. |
| 251 CopyStringFromDictionary(service_properties, shill::kGuidProperty, dest); | 241 CopyStringFromDictionary(service_properties, shill::kGuidProperty, dest); |
| 252 | 242 |
| 253 std::string type; | 243 std::string type; |
| 254 service_properties.GetStringWithoutPathExpansion(shill::kTypeProperty, &type); | 244 service_properties.GetStringWithoutPathExpansion(shill::kTypeProperty, &type); |
| 255 success &= !type.empty(); | 245 success &= !type.empty(); |
| 256 dest->SetStringWithoutPathExpansion(shill::kTypeProperty, type); | 246 dest->SetStringWithoutPathExpansion(shill::kTypeProperty, type); |
| 257 if (type == shill::kTypeWifi) { | 247 if (type == shill::kTypeWifi) { |
| 258 std::string security; | 248 std::string security_class; |
| 259 service_properties.GetStringWithoutPathExpansion(shill::kSecurityProperty, | 249 service_properties.GetStringWithoutPathExpansion( |
| 260 &security); | 250 shill::kSecurityClassProperty, &security_class); |
| 261 if (security.empty()) { | 251 if (security_class.empty()) { |
| 262 success = false; | 252 success = false; |
| 263 } else { | 253 } else { |
| 264 dest->SetStringWithoutPathExpansion(shill::kSecurityProperty, | 254 dest->SetStringWithoutPathExpansion(shill::kSecurityClassProperty, |
| 265 GetSecurityClass(security)); | 255 security_class); |
| 266 } | 256 } |
| 267 success &= | 257 success &= |
| 268 CopyStringFromDictionary(service_properties, shill::kWifiHexSsid, dest); | 258 CopyStringFromDictionary(service_properties, shill::kWifiHexSsid, dest); |
| 269 success &= CopyStringFromDictionary( | 259 success &= CopyStringFromDictionary( |
| 270 service_properties, shill::kModeProperty, dest); | 260 service_properties, shill::kModeProperty, dest); |
| 271 } else if (type == shill::kTypeVPN) { | 261 } else if (type == shill::kTypeVPN) { |
| 272 success &= CopyStringFromDictionary( | 262 success &= CopyStringFromDictionary( |
| 273 service_properties, shill::kNameProperty, dest); | 263 service_properties, shill::kNameProperty, dest); |
| 274 | 264 |
| 275 // VPN Provider values are read from the "Provider" dictionary, but written | 265 // VPN Provider values are read from the "Provider" dictionary, but written |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 LOG(WARNING) | 361 LOG(WARNING) |
| 372 << "Provider name and country not defined, using code instead: " | 362 << "Provider name and country not defined, using code instead: " |
| 373 << *home_provider_id; | 363 << *home_provider_id; |
| 374 } | 364 } |
| 375 return true; | 365 return true; |
| 376 } | 366 } |
| 377 | 367 |
| 378 } // namespace shill_property_util | 368 } // namespace shill_property_util |
| 379 | 369 |
| 380 } // namespace chromeos | 370 } // namespace chromeos |
| OLD | NEW |