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/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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 return false; | 79 return false; |
80 } | 80 } |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 namespace chromeos { | 84 namespace chromeos { |
85 | 85 |
86 NetworkState::NetworkState(const std::string& path) | 86 NetworkState::NetworkState(const std::string& path) |
87 : ManagedState(MANAGED_TYPE_NETWORK, path), | 87 : ManagedState(MANAGED_TYPE_NETWORK, path), |
88 auto_connect_(false), | 88 connectable_(false), |
89 favorite_(false), | |
90 priority_(0), | |
91 prefix_length_(0), | 89 prefix_length_(0), |
92 signal_strength_(0), | 90 signal_strength_(0), |
93 connectable_(false), | |
94 activate_over_non_cellular_networks_(false), | 91 activate_over_non_cellular_networks_(false), |
95 cellular_out_of_credits_(false), | 92 cellular_out_of_credits_(false), |
96 has_ca_cert_nss_(false) { | 93 has_ca_cert_nss_(false) { |
97 } | 94 } |
98 | 95 |
99 NetworkState::~NetworkState() { | 96 NetworkState::~NetworkState() { |
100 } | 97 } |
101 | 98 |
102 bool NetworkState::PropertyChanged(const std::string& key, | 99 bool NetworkState::PropertyChanged(const std::string& key, |
103 const base::Value& value) { | 100 const base::Value& value) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 web_proxy_auto_discovery_url_ = GURL(); | 144 web_proxy_auto_discovery_url_ = GURL(); |
148 } | 145 } |
149 } | 146 } |
150 return true; | 147 return true; |
151 } else if (key == flimflam::kActivationStateProperty) { | 148 } else if (key == flimflam::kActivationStateProperty) { |
152 return GetStringValue(key, value, &activation_state_); | 149 return GetStringValue(key, value, &activation_state_); |
153 } else if (key == flimflam::kRoamingStateProperty) { | 150 } else if (key == flimflam::kRoamingStateProperty) { |
154 return GetStringValue(key, value, &roaming_); | 151 return GetStringValue(key, value, &roaming_); |
155 } else if (key == flimflam::kSecurityProperty) { | 152 } else if (key == flimflam::kSecurityProperty) { |
156 return GetStringValue(key, value, &security_); | 153 return GetStringValue(key, value, &security_); |
157 } else if (key == flimflam::kAutoConnectProperty) { | |
158 return GetBooleanValue(key, value, &auto_connect_); | |
159 } else if (key == flimflam::kFavoriteProperty) { | |
160 return GetBooleanValue(key, value, &favorite_); | |
161 } else if (key == flimflam::kPriorityProperty) { | |
162 return GetIntegerValue(key, value, &priority_); | |
163 } else if (key == flimflam::kProxyConfigProperty) { | 154 } else if (key == flimflam::kProxyConfigProperty) { |
164 std::string proxy_config_str; | 155 std::string proxy_config_str; |
165 if (!value.GetAsString(&proxy_config_str)) { | 156 if (!value.GetAsString(&proxy_config_str)) { |
166 NET_LOG_ERROR("Failed to parse " + key, path()); | 157 NET_LOG_ERROR("Failed to parse " + key, path()); |
167 return false; | 158 return false; |
168 } | 159 } |
169 | 160 |
170 proxy_config_.Clear(); | 161 proxy_config_.Clear(); |
171 if (proxy_config_str.empty()) | 162 if (proxy_config_str.empty()) |
172 return true; | 163 return true; |
(...skipping 21 matching lines...) Expand all Loading... |
194 } else if (key == flimflam::kDeviceProperty) { | 185 } else if (key == flimflam::kDeviceProperty) { |
195 return GetStringValue(key, value, &device_path_); | 186 return GetStringValue(key, value, &device_path_); |
196 } else if (key == flimflam::kGuidProperty) { | 187 } else if (key == flimflam::kGuidProperty) { |
197 return GetStringValue(key, value, &guid_); | 188 return GetStringValue(key, value, &guid_); |
198 } else if (key == flimflam::kProfileProperty) { | 189 } else if (key == flimflam::kProfileProperty) { |
199 return GetStringValue(key, value, &profile_path_); | 190 return GetStringValue(key, value, &profile_path_); |
200 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { | 191 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { |
201 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); | 192 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); |
202 } else if (key == shill::kOutOfCreditsProperty) { | 193 } else if (key == shill::kOutOfCreditsProperty) { |
203 return GetBooleanValue(key, value, &cellular_out_of_credits_); | 194 return GetBooleanValue(key, value, &cellular_out_of_credits_); |
204 } else if (key == flimflam::kUsageURLProperty) { | |
205 return GetStringValue(key, value, &usage_url_); | |
206 } else if (key == flimflam::kPaymentPortalProperty) { | |
207 const DictionaryValue* dict; | |
208 if (!value.GetAsDictionary(&dict)) | |
209 return false; | |
210 if (!dict->GetStringWithoutPathExpansion( | |
211 flimflam::kPaymentPortalURL, &payment_url_) || | |
212 !dict->GetStringWithoutPathExpansion( | |
213 flimflam::kPaymentPortalMethod, &post_method_) || | |
214 !dict->GetStringWithoutPathExpansion( | |
215 flimflam::kPaymentPortalPostData, &post_data_)) { | |
216 return false; | |
217 } | |
218 return true; | |
219 } | 195 } |
220 return false; | 196 return false; |
221 } | 197 } |
222 | 198 |
223 bool NetworkState::InitialPropertiesReceived( | 199 bool NetworkState::InitialPropertiesReceived( |
224 const base::DictionaryValue& properties) { | 200 const base::DictionaryValue& properties) { |
225 NET_LOG_DEBUG("InitialPropertiesReceived", path()); | 201 NET_LOG_DEBUG("InitialPropertiesReceived", path()); |
226 bool changed = UpdateName(properties); | 202 bool changed = UpdateName(properties); |
227 bool had_ca_cert_nss = has_ca_cert_nss_; | 203 bool had_ca_cert_nss = has_ca_cert_nss_; |
228 has_ca_cert_nss_ = IsCaCertNssSet(properties); | 204 has_ca_cert_nss_ = IsCaCertNssSet(properties); |
(...skipping 18 matching lines...) Expand all Loading... |
247 // IPConfig properties | 223 // IPConfig properties |
248 base::DictionaryValue* ipconfig_properties = new base::DictionaryValue; | 224 base::DictionaryValue* ipconfig_properties = new base::DictionaryValue; |
249 ipconfig_properties->SetStringWithoutPathExpansion(flimflam::kAddressProperty, | 225 ipconfig_properties->SetStringWithoutPathExpansion(flimflam::kAddressProperty, |
250 ip_address_); | 226 ip_address_); |
251 ipconfig_properties->SetStringWithoutPathExpansion(flimflam::kGatewayProperty, | 227 ipconfig_properties->SetStringWithoutPathExpansion(flimflam::kGatewayProperty, |
252 gateway_); | 228 gateway_); |
253 base::ListValue* name_servers = new base::ListValue; | 229 base::ListValue* name_servers = new base::ListValue; |
254 name_servers->AppendStrings(dns_servers_); | 230 name_servers->AppendStrings(dns_servers_); |
255 ipconfig_properties->SetWithoutPathExpansion(flimflam::kNameServersProperty, | 231 ipconfig_properties->SetWithoutPathExpansion(flimflam::kNameServersProperty, |
256 name_servers); | 232 name_servers); |
257 ipconfig_properties->SetIntegerWithoutPathExpansion( | |
258 flimflam::kPrefixlenProperty, prefix_length_); | |
259 ipconfig_properties->SetStringWithoutPathExpansion( | 233 ipconfig_properties->SetStringWithoutPathExpansion( |
260 shill::kWebProxyAutoDiscoveryUrlProperty, | 234 shill::kWebProxyAutoDiscoveryUrlProperty, |
261 web_proxy_auto_discovery_url_.spec()); | 235 web_proxy_auto_discovery_url_.spec()); |
262 dictionary->SetWithoutPathExpansion(shill::kIPConfigProperty, | 236 dictionary->SetWithoutPathExpansion(shill::kIPConfigProperty, |
263 ipconfig_properties); | 237 ipconfig_properties); |
264 | 238 |
265 dictionary->SetStringWithoutPathExpansion(flimflam::kActivationStateProperty, | 239 dictionary->SetStringWithoutPathExpansion(flimflam::kActivationStateProperty, |
266 activation_state_); | 240 activation_state_); |
267 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, | 241 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, |
268 roaming_); | 242 roaming_); |
269 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, | 243 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, |
270 security_); | 244 security_); |
271 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, | |
272 auto_connect_); | |
273 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, | |
274 favorite_); | |
275 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, | |
276 priority_); | |
277 // Proxy config and ONC source are intentionally omitted: These properties are | 245 // Proxy config and ONC source are intentionally omitted: These properties are |
278 // placed in NetworkState to transition ProxyConfigServiceImpl from | 246 // placed in NetworkState to transition ProxyConfigServiceImpl from |
279 // NetworkLibrary to the new network stack. The networking extension API | 247 // NetworkLibrary to the new network stack. The networking extension API |
280 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler | 248 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler |
281 // is used instead of NetworkLibrary, we can remove them again. | 249 // is used instead of NetworkLibrary, we can remove them again. |
282 dictionary->SetStringWithoutPathExpansion( | 250 dictionary->SetStringWithoutPathExpansion( |
283 flimflam::kNetworkTechnologyProperty, | 251 flimflam::kNetworkTechnologyProperty, |
284 network_technology_); | 252 network_technology_); |
285 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, | 253 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
286 device_path_); | 254 device_path_); |
287 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); | 255 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); |
288 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, | 256 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, |
289 profile_path_); | 257 profile_path_); |
290 dictionary->SetBooleanWithoutPathExpansion( | 258 dictionary->SetBooleanWithoutPathExpansion( |
291 shill::kActivateOverNonCellularNetworkProperty, | 259 shill::kActivateOverNonCellularNetworkProperty, |
292 activate_over_non_cellular_networks_); | 260 activate_over_non_cellular_networks_); |
293 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, | 261 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, |
294 cellular_out_of_credits_); | 262 cellular_out_of_credits_); |
295 base::DictionaryValue* payment_portal_properties = new DictionaryValue; | |
296 payment_portal_properties->SetStringWithoutPathExpansion( | |
297 flimflam::kPaymentPortalURL, | |
298 payment_url_); | |
299 payment_portal_properties->SetStringWithoutPathExpansion( | |
300 flimflam::kPaymentPortalMethod, | |
301 post_method_); | |
302 payment_portal_properties->SetStringWithoutPathExpansion( | |
303 flimflam::kPaymentPortalPostData, | |
304 post_data_); | |
305 dictionary->SetWithoutPathExpansion(flimflam::kPaymentPortalProperty, | |
306 payment_portal_properties); | |
307 } | 263 } |
308 | 264 |
309 bool NetworkState::IsConnectedState() const { | 265 bool NetworkState::IsConnectedState() const { |
310 return StateIsConnected(connection_state_); | 266 return StateIsConnected(connection_state_); |
311 } | 267 } |
312 | 268 |
313 bool NetworkState::IsConnectingState() const { | 269 bool NetworkState::IsConnectingState() const { |
314 return StateIsConnecting(connection_state_); | 270 return StateIsConnecting(connection_state_); |
315 } | 271 } |
316 | 272 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 } | 408 } |
453 scoped_ptr<base::DictionaryValue> ui_data_dict( | 409 scoped_ptr<base::DictionaryValue> ui_data_dict( |
454 chromeos::onc::ReadDictionaryFromJson(ui_data_str)); | 410 chromeos::onc::ReadDictionaryFromJson(ui_data_str)); |
455 if (!ui_data_dict) | 411 if (!ui_data_dict) |
456 return false; | 412 return false; |
457 *out = NetworkUIData(*ui_data_dict); | 413 *out = NetworkUIData(*ui_data_dict); |
458 return true; | 414 return true; |
459 } | 415 } |
460 | 416 |
461 } // namespace chromeos | 417 } // namespace chromeos |
OLD | NEW |