| 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" |
| 13 #include "chromeos/network/network_event_log.h" | 14 #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 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 19 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
| 20 std::vector<std::string>* result) { | 20 std::vector<std::string>* result) { |
| 21 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 21 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
| 22 std::string str; | 22 std::string str; |
| 23 if (!string_list.GetString(i, &str)) | 23 if (!string_list.GetString(i, &str)) |
| 24 return false; | 24 return false; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 return GetBooleanValue(key, value, &passphrase_required_); | 81 return GetBooleanValue(key, value, &passphrase_required_); |
| 82 } else if (key == flimflam::kErrorProperty) { | 82 } else if (key == flimflam::kErrorProperty) { |
| 83 return GetStringValue(key, value, &error_); | 83 return GetStringValue(key, value, &error_); |
| 84 } else if (key == shill::kErrorDetailsProperty) { | 84 } else if (key == shill::kErrorDetailsProperty) { |
| 85 return GetStringValue(key, value, &error_details_); | 85 return GetStringValue(key, value, &error_details_); |
| 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 // Warning: The DictionaryValue return from | |
| 121 // ReadDictionaryFromJson/JSONParser is an optimized derived class that | |
| 122 // doesn't allow releasing ownership of nested values. A Swap in the wrong | |
| 123 // order leads to memory access errors. | |
| 124 proxy_config_.MergeDictionary(proxy_config_dict.get()); | |
| 125 } else { | |
| 126 LOG(WARNING) << "Failed to parse dictionary value for: " << key; | |
| 127 } | |
| 128 return true; | |
| 129 } else if (key == flimflam::kNetworkTechnologyProperty) { | 106 } else if (key == flimflam::kNetworkTechnologyProperty) { |
| 130 return GetStringValue(key, value, &technology_); | 107 return GetStringValue(key, value, &technology_); |
| 131 } else if (key == flimflam::kDeviceProperty) { | 108 } else if (key == flimflam::kDeviceProperty) { |
| 132 return GetStringValue(key, value, &device_path_); | 109 return GetStringValue(key, value, &device_path_); |
| 133 } else if (key == flimflam::kGuidProperty) { | 110 } else if (key == flimflam::kGuidProperty) { |
| 134 return GetStringValue(key, value, &guid_); | 111 return GetStringValue(key, value, &guid_); |
| 135 } else if (key == flimflam::kProfileProperty) { | 112 } else if (key == flimflam::kProfileProperty) { |
| 136 return GetStringValue(key, value, &profile_path_); | 113 return GetStringValue(key, value, &profile_path_); |
| 114 } else if (key == flimflam::kProxyConfigProperty) { |
| 115 return GetStringValue(key, value, &proxy_config_); |
| 137 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { | 116 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { |
| 138 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); | 117 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); |
| 139 } else if (key == shill::kOutOfCreditsProperty) { | 118 } else if (key == shill::kOutOfCreditsProperty) { |
| 140 return GetBooleanValue(key, value, &cellular_out_of_credits_); | 119 return GetBooleanValue(key, value, &cellular_out_of_credits_); |
| 141 } else if (key == flimflam::kWifiHexSsid) { | 120 } else if (key == flimflam::kWifiHexSsid) { |
| 142 return GetStringValue(key, value, &hex_ssid_); | 121 return GetStringValue(key, value, &hex_ssid_); |
| 143 } else if (key == flimflam::kCountryProperty) { | 122 } else if (key == flimflam::kCountryProperty) { |
| 144 // TODO(stevenjb): This is currently experimental. If we find a case where | 123 // TODO(stevenjb): This is currently experimental. If we find a case where |
| 145 // base::DetectEncoding() fails in UpdateName(), where country_code_ is | 124 // base::DetectEncoding() fails in UpdateName(), where country_code_ is |
| 146 // set, figure out whether we can use country_code_ with ConvertToUtf8(). | 125 // set, figure out whether we can use country_code_ with ConvertToUtf8(). |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, | 164 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, |
| 186 roaming_); | 165 roaming_); |
| 187 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, | 166 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, |
| 188 security_); | 167 security_); |
| 189 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, | 168 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, |
| 190 auto_connect_); | 169 auto_connect_); |
| 191 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, | 170 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, |
| 192 favorite_); | 171 favorite_); |
| 193 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, | 172 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, |
| 194 priority_); | 173 priority_); |
| 195 // Proxy config is intentionally omitted: This property is | |
| 196 // placed in NetworkState to transition proxy configuration from | |
| 197 // NetworkLibrary to the new network stack. The networking extension API | |
| 198 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler | |
| 199 // is used instead of NetworkLibrary, we can remove them again. | |
| 200 dictionary->SetStringWithoutPathExpansion( | 174 dictionary->SetStringWithoutPathExpansion( |
| 201 flimflam::kNetworkTechnologyProperty, | 175 flimflam::kNetworkTechnologyProperty, |
| 202 technology_); | 176 technology_); |
| 203 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, | 177 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
| 204 device_path_); | 178 device_path_); |
| 205 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); | 179 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); |
| 206 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, | 180 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, |
| 207 profile_path_); | 181 profile_path_); |
| 182 dictionary->SetStringWithoutPathExpansion(flimflam::kProxyConfigProperty, |
| 183 proxy_config_); |
| 208 dictionary->SetBooleanWithoutPathExpansion( | 184 dictionary->SetBooleanWithoutPathExpansion( |
| 209 shill::kActivateOverNonCellularNetworkProperty, | 185 shill::kActivateOverNonCellularNetworkProperty, |
| 210 activate_over_non_cellular_networks_); | 186 activate_over_non_cellular_networks_); |
| 211 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, | 187 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, |
| 212 cellular_out_of_credits_); | 188 cellular_out_of_credits_); |
| 213 } | 189 } |
| 214 | 190 |
| 215 bool NetworkState::IsConnectedState() const { | 191 bool NetworkState::IsConnectedState() const { |
| 216 return StateIsConnected(connection_state_); | 192 return StateIsConnected(connection_state_); |
| 217 } | 193 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 connection_state == flimflam::kStateConfiguration || | 277 connection_state == flimflam::kStateConfiguration || |
| 302 connection_state == flimflam::kStateCarrier); | 278 connection_state == flimflam::kStateCarrier); |
| 303 } | 279 } |
| 304 | 280 |
| 305 // static | 281 // static |
| 306 std::string NetworkState::IPConfigProperty(const char* key) { | 282 std::string NetworkState::IPConfigProperty(const char* key) { |
| 307 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | 283 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
| 308 } | 284 } |
| 309 | 285 |
| 310 } // namespace chromeos | 286 } // namespace chromeos |
| OLD | NEW |