Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "chromeos/network/network_state.h" | 5 #include "chromeos/network/network_state.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/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/utf_string_conversion_utils.h" | 12 #include "base/strings/utf_string_conversion_utils.h" |
| 13 #include "base/values.h" | |
| 14 #include "chromeos/network/network_event_log.h" | 13 #include "chromeos/network/network_event_log.h" |
| 14 #include "chromeos/network/onc/onc_utils.h" | |
| 15 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kLogModule[] = "NetworkState"; | 19 const char kLogModule[] = "NetworkState"; |
| 20 | 20 |
| 21 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 21 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
| 22 std::vector<std::string>* result) { | 22 std::vector<std::string>* result) { |
| 23 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 23 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
| 24 std::string str; | 24 std::string str; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 return GetBooleanValue(key, value, &connectable_); | 81 return GetBooleanValue(key, value, &connectable_); |
| 82 } else if (key == flimflam::kPassphraseRequiredProperty) { | 82 } else if (key == flimflam::kPassphraseRequiredProperty) { |
| 83 return GetBooleanValue(key, value, &passphrase_required_); | 83 return GetBooleanValue(key, value, &passphrase_required_); |
| 84 } else if (key == flimflam::kErrorProperty) { | 84 } else if (key == flimflam::kErrorProperty) { |
| 85 return GetStringValue(key, value, &error_); | 85 return GetStringValue(key, value, &error_); |
| 86 } else if (key == IPConfigProperty(flimflam::kAddressProperty)) { | 86 } else if (key == IPConfigProperty(flimflam::kAddressProperty)) { |
| 87 return GetStringValue(key, value, &ip_address_); | 87 return GetStringValue(key, value, &ip_address_); |
| 88 } else if (key == IPConfigProperty(flimflam::kNameServersProperty)) { | 88 } else if (key == IPConfigProperty(flimflam::kNameServersProperty)) { |
| 89 dns_servers_.clear(); | 89 dns_servers_.clear(); |
| 90 const base::ListValue* dns_servers; | 90 const base::ListValue* dns_servers; |
| 91 if (value.GetAsList(&dns_servers) && | 91 if (value.GetAsList(&dns_servers)) |
| 92 ConvertListValueToStringVector(*dns_servers, &dns_servers_)) | 92 ConvertListValueToStringVector(*dns_servers, &dns_servers_); |
| 93 return true; | 93 return true; |
| 94 } else if (key == flimflam::kActivationStateProperty) { | 94 } else if (key == flimflam::kActivationStateProperty) { |
| 95 return GetStringValue(key, value, &activation_state_); | 95 return GetStringValue(key, value, &activation_state_); |
| 96 } else if (key == flimflam::kRoamingStateProperty) { | 96 } else if (key == flimflam::kRoamingStateProperty) { |
| 97 return GetStringValue(key, value, &roaming_); | 97 return GetStringValue(key, value, &roaming_); |
| 98 } else if (key == flimflam::kSecurityProperty) { | 98 } else if (key == flimflam::kSecurityProperty) { |
| 99 return GetStringValue(key, value, &security_); | 99 return GetStringValue(key, value, &security_); |
| 100 } else if (key == flimflam::kAutoConnectProperty) { | 100 } else if (key == flimflam::kAutoConnectProperty) { |
| 101 return GetBooleanValue(key, value, &auto_connect_); | 101 return GetBooleanValue(key, value, &auto_connect_); |
| 102 } else if (key == flimflam::kFavoriteProperty) { | 102 } else if (key == flimflam::kFavoriteProperty) { |
| 103 return GetBooleanValue(key, value, &favorite_); | 103 return GetBooleanValue(key, value, &favorite_); |
| 104 } else if (key == flimflam::kPriorityProperty) { | 104 } else if (key == flimflam::kPriorityProperty) { |
| 105 return GetIntegerValue(key, value, &priority_); | 105 return GetIntegerValue(key, value, &priority_); |
| 106 } else if (key == flimflam::kProxyConfigProperty) { | |
| 107 std::string proxy_config_str; | |
| 108 if (!value.GetAsString(&proxy_config_str)) { | |
| 109 LOG(WARNING) << "Failed to parse string value for:" << key; | |
| 110 return false; | |
| 111 } | |
| 112 | |
| 113 proxy_config_.Clear(); | |
| 114 if (proxy_config_str.empty()) | |
| 115 return true; | |
| 116 | |
| 117 scoped_ptr<base::DictionaryValue> proxy_config_dict( | |
| 118 onc::ReadDictionaryFromJson(proxy_config_str)); | |
| 119 if (proxy_config_dict) | |
| 120 proxy_config_.MergeDictionary(proxy_config_dict.get()); | |
|
stevenjb
2013/05/20 15:42:17
Is the merge necessary here, especially given that
pneubeck (no reviews)
2013/05/21 09:17:44
Replaced by swap.
| |
| 121 else | |
| 122 LOG(WARNING) << "Failed to parse dictionary value for: " << key; | |
| 123 return true; | |
| 106 } else if (key == flimflam::kNetworkTechnologyProperty) { | 124 } else if (key == flimflam::kNetworkTechnologyProperty) { |
| 107 return GetStringValue(key, value, &technology_); | 125 return GetStringValue(key, value, &technology_); |
| 108 } else if (key == flimflam::kDeviceProperty) { | 126 } else if (key == flimflam::kDeviceProperty) { |
| 109 return GetStringValue(key, value, &device_path_); | 127 return GetStringValue(key, value, &device_path_); |
| 110 } else if (key == flimflam::kGuidProperty) { | 128 } else if (key == flimflam::kGuidProperty) { |
| 111 return GetStringValue(key, value, &guid_); | 129 return GetStringValue(key, value, &guid_); |
| 112 } else if (key == flimflam::kProfileProperty) { | 130 } else if (key == flimflam::kProfileProperty) { |
| 113 return GetStringValue(key, value, &profile_path_); | 131 return GetStringValue(key, value, &profile_path_); |
| 114 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { | 132 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { |
| 115 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); | 133 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, | 178 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, |
| 161 roaming_); | 179 roaming_); |
| 162 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, | 180 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, |
| 163 security_); | 181 security_); |
| 164 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, | 182 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, |
| 165 auto_connect_); | 183 auto_connect_); |
| 166 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, | 184 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, |
| 167 favorite_); | 185 favorite_); |
| 168 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, | 186 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, |
| 169 priority_); | 187 priority_); |
| 188 // Proxy config is intentionally omitted: This property is | |
| 189 // placed in NetworkState to transition proxy configuration from | |
| 190 // NetworkLibrary to the new network stack. The networking extension API | |
| 191 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler | |
| 192 // is used instead of NetworkLibrary, we can remove them again. | |
| 170 dictionary->SetStringWithoutPathExpansion( | 193 dictionary->SetStringWithoutPathExpansion( |
| 171 flimflam::kNetworkTechnologyProperty, | 194 flimflam::kNetworkTechnologyProperty, |
| 172 technology_); | 195 technology_); |
| 173 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, | 196 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
| 174 device_path_); | 197 device_path_); |
| 175 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); | 198 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); |
| 176 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, | 199 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, |
| 177 profile_path_); | 200 profile_path_); |
| 178 dictionary->SetBooleanWithoutPathExpansion( | 201 dictionary->SetBooleanWithoutPathExpansion( |
| 179 shill::kActivateOverNonCellularNetworkProperty, | 202 shill::kActivateOverNonCellularNetworkProperty, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 connection_state == flimflam::kStateConfiguration || | 289 connection_state == flimflam::kStateConfiguration || |
| 267 connection_state == flimflam::kStateCarrier); | 290 connection_state == flimflam::kStateCarrier); |
| 268 } | 291 } |
| 269 | 292 |
| 270 // static | 293 // static |
| 271 std::string NetworkState::IPConfigProperty(const char* key) { | 294 std::string NetworkState::IPConfigProperty(const char* key) { |
| 272 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | 295 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
| 273 } | 296 } |
| 274 | 297 |
| 275 } // namespace chromeos | 298 } // namespace chromeos |
| OLD | NEW |