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 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; |
106 } else if (key == flimflam::kNetworkTechnologyProperty) { | 129 } else if (key == flimflam::kNetworkTechnologyProperty) { |
107 return GetStringValue(key, value, &technology_); | 130 return GetStringValue(key, value, &technology_); |
108 } else if (key == flimflam::kDeviceProperty) { | 131 } else if (key == flimflam::kDeviceProperty) { |
109 return GetStringValue(key, value, &device_path_); | 132 return GetStringValue(key, value, &device_path_); |
110 } else if (key == flimflam::kGuidProperty) { | 133 } else if (key == flimflam::kGuidProperty) { |
111 return GetStringValue(key, value, &guid_); | 134 return GetStringValue(key, value, &guid_); |
112 } else if (key == flimflam::kProfileProperty) { | 135 } else if (key == flimflam::kProfileProperty) { |
113 return GetStringValue(key, value, &profile_path_); | 136 return GetStringValue(key, value, &profile_path_); |
114 } else if (key == flimflam::kProxyConfigProperty) { | |
115 return GetStringValue(key, value, &proxy_config_); | |
116 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { | 137 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { |
117 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); | 138 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); |
118 } else if (key == shill::kOutOfCreditsProperty) { | 139 } else if (key == shill::kOutOfCreditsProperty) { |
119 return GetBooleanValue(key, value, &cellular_out_of_credits_); | 140 return GetBooleanValue(key, value, &cellular_out_of_credits_); |
120 } else if (key == flimflam::kWifiHexSsid) { | 141 } else if (key == flimflam::kWifiHexSsid) { |
121 return GetStringValue(key, value, &hex_ssid_); | 142 return GetStringValue(key, value, &hex_ssid_); |
122 } else if (key == flimflam::kCountryProperty) { | 143 } else if (key == flimflam::kCountryProperty) { |
123 // TODO(stevenjb): This is currently experimental. If we find a case where | 144 // TODO(stevenjb): This is currently experimental. If we find a case where |
124 // base::DetectEncoding() fails in UpdateName(), where country_code_ is | 145 // base::DetectEncoding() fails in UpdateName(), where country_code_ is |
125 // set, figure out whether we can use country_code_ with ConvertToUtf8(). | 146 // set, figure out whether we can use country_code_ with ConvertToUtf8(). |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, | 185 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, |
165 roaming_); | 186 roaming_); |
166 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, | 187 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, |
167 security_); | 188 security_); |
168 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, | 189 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, |
169 auto_connect_); | 190 auto_connect_); |
170 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, | 191 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, |
171 favorite_); | 192 favorite_); |
172 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, | 193 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, |
173 priority_); | 194 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. |
174 dictionary->SetStringWithoutPathExpansion( | 200 dictionary->SetStringWithoutPathExpansion( |
175 flimflam::kNetworkTechnologyProperty, | 201 flimflam::kNetworkTechnologyProperty, |
176 technology_); | 202 technology_); |
177 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, | 203 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
178 device_path_); | 204 device_path_); |
179 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); | 205 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); |
180 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, | 206 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, |
181 profile_path_); | 207 profile_path_); |
182 dictionary->SetStringWithoutPathExpansion(flimflam::kProxyConfigProperty, | |
183 proxy_config_); | |
184 dictionary->SetBooleanWithoutPathExpansion( | 208 dictionary->SetBooleanWithoutPathExpansion( |
185 shill::kActivateOverNonCellularNetworkProperty, | 209 shill::kActivateOverNonCellularNetworkProperty, |
186 activate_over_non_cellular_networks_); | 210 activate_over_non_cellular_networks_); |
187 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, | 211 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, |
188 cellular_out_of_credits_); | 212 cellular_out_of_credits_); |
189 } | 213 } |
190 | 214 |
191 bool NetworkState::IsConnectedState() const { | 215 bool NetworkState::IsConnectedState() const { |
192 return StateIsConnected(connection_state_); | 216 return StateIsConnected(connection_state_); |
193 } | 217 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 connection_state == flimflam::kStateConfiguration || | 301 connection_state == flimflam::kStateConfiguration || |
278 connection_state == flimflam::kStateCarrier); | 302 connection_state == flimflam::kStateCarrier); |
279 } | 303 } |
280 | 304 |
281 // static | 305 // static |
282 std::string NetworkState::IPConfigProperty(const char* key) { | 306 std::string NetworkState::IPConfigProperty(const char* key) { |
283 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | 307 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
284 } | 308 } |
285 | 309 |
286 } // namespace chromeos | 310 } // namespace chromeos |
OLD | NEW |