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/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chromeos/network/network_event_log.h" | 9 #include "chromeos/network/network_event_log.h" |
10 #include "chromeos/network/network_profile_handler.h" | 10 #include "chromeos/network/network_profile_handler.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 } else if (key == shill::kConnectableProperty) { | 83 } else if (key == shill::kConnectableProperty) { |
84 return GetBooleanValue(key, value, &connectable_); | 84 return GetBooleanValue(key, value, &connectable_); |
85 } else if (key == shill::kErrorProperty) { | 85 } else if (key == shill::kErrorProperty) { |
86 if (!GetStringValue(key, value, &error_)) | 86 if (!GetStringValue(key, value, &error_)) |
87 return false; | 87 return false; |
88 if (ErrorIsValid(error_)) | 88 if (ErrorIsValid(error_)) |
89 last_error_ = error_; | 89 last_error_ = error_; |
90 else | 90 else |
91 error_.clear(); | 91 error_.clear(); |
92 return true; | 92 return true; |
93 } else if (key == IPConfigProperty(shill::kAddressProperty)) { | |
94 return GetStringValue(key, value, &ip_address_); | |
95 } else if (key == IPConfigProperty(shill::kGatewayProperty)) { | |
96 return GetStringValue(key, value, &gateway_); | |
97 } else if (key == IPConfigProperty(shill::kNameServersProperty)) { | |
98 const base::ListValue* dns_servers; | |
99 if (!value.GetAsList(&dns_servers)) | |
100 return false; | |
101 dns_servers_.clear(); | |
102 ConvertListValueToStringVector(*dns_servers, &dns_servers_); | |
103 return true; | |
104 } else if (key == IPConfigProperty(shill::kPrefixlenProperty)) { | |
105 return GetIntegerValue(key, value, &prefix_length_); | |
106 } else if (key == IPConfigProperty( | |
107 shill::kWebProxyAutoDiscoveryUrlProperty)) { | |
108 std::string url_string; | |
109 if (!GetStringValue(key, value, &url_string)) | |
110 return false; | |
111 if (url_string.empty()) { | |
112 web_proxy_auto_discovery_url_ = GURL(); | |
113 } else { | |
114 GURL gurl(url_string); | |
115 if (!gurl.is_valid()) { | |
116 web_proxy_auto_discovery_url_ = gurl; | |
117 } else { | |
118 NET_LOG_ERROR("Invalid WebProxyAutoDiscoveryUrl: " + url_string, | |
119 path()); | |
120 web_proxy_auto_discovery_url_ = GURL(); | |
121 } | |
122 } | |
123 return true; | |
124 } else if (key == shill::kActivationStateProperty) { | 93 } else if (key == shill::kActivationStateProperty) { |
125 return GetStringValue(key, value, &activation_state_); | 94 return GetStringValue(key, value, &activation_state_); |
126 } else if (key == shill::kRoamingStateProperty) { | 95 } else if (key == shill::kRoamingStateProperty) { |
127 return GetStringValue(key, value, &roaming_); | 96 return GetStringValue(key, value, &roaming_); |
128 } else if (key == shill::kSecurityProperty) { | 97 } else if (key == shill::kSecurityProperty) { |
129 return GetStringValue(key, value, &security_); | 98 return GetStringValue(key, value, &security_); |
130 } else if (key == shill::kEapMethodProperty) { | 99 } else if (key == shill::kEapMethodProperty) { |
131 return GetStringValue(key, value, &eap_method_); | 100 return GetStringValue(key, value, &eap_method_); |
132 } else if (key == shill::kUIDataProperty) { | 101 } else if (key == shill::kUIDataProperty) { |
133 scoped_ptr<NetworkUIData> new_ui_data = | 102 scoped_ptr<NetworkUIData> new_ui_data = |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 network_technology()); | 172 network_technology()); |
204 dictionary->SetStringWithoutPathExpansion(shill::kActivationStateProperty, | 173 dictionary->SetStringWithoutPathExpansion(shill::kActivationStateProperty, |
205 activation_state()); | 174 activation_state()); |
206 dictionary->SetStringWithoutPathExpansion(shill::kRoamingStateProperty, | 175 dictionary->SetStringWithoutPathExpansion(shill::kRoamingStateProperty, |
207 roaming()); | 176 roaming()); |
208 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, | 177 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, |
209 cellular_out_of_credits()); | 178 cellular_out_of_credits()); |
210 } | 179 } |
211 } | 180 } |
212 | 181 |
182 void NetworkState::IPConfigPropertiesChanged( | |
183 const base::DictionaryValue& properties) { | |
184 for (base::DictionaryValue::Iterator iter(properties); | |
185 !iter.IsAtEnd(); iter.Advance()) { | |
186 std::string key = iter.key(); | |
187 const base::Value& value = iter.value(); | |
188 | |
189 if (key == shill::kAddressProperty) { | |
190 GetStringValue(key, value, &ip_address_); | |
191 } else if (key == shill::kGatewayProperty) { | |
192 GetStringValue(key, value, &gateway_); | |
193 } else if (key == shill::kNameServersProperty) { | |
194 const base::ListValue* dns_servers; | |
pneubeck (no reviews)
2014/05/05 21:09:28
nit: initialize with NULL
stevenjb
2014/05/06 01:15:11
Not necessary here, Value is guaranteed to set dns
| |
195 if (value.GetAsList(&dns_servers)) { | |
196 dns_servers_.clear(); | |
197 ConvertListValueToStringVector(*dns_servers, &dns_servers_); | |
198 } | |
199 } else if (key == shill::kPrefixlenProperty) { | |
200 GetIntegerValue(key, value, &prefix_length_); | |
201 } else if (key == shill::kWebProxyAutoDiscoveryUrlProperty) { | |
202 std::string url_string; | |
203 if (GetStringValue(key, value, &url_string)) { | |
204 if (url_string.empty()) { | |
205 web_proxy_auto_discovery_url_ = GURL(); | |
206 } else { | |
207 GURL gurl(url_string); | |
208 if (!gurl.is_valid()) { | |
pneubeck (no reviews)
2014/05/05 21:09:28
wrong negation?
stevenjb
2014/05/06 01:15:11
Huh. Wonder why this hasn't caused us problems? (I
| |
209 web_proxy_auto_discovery_url_ = gurl; | |
210 } else { | |
211 NET_LOG_ERROR("Invalid WebProxyAutoDiscoveryUrl: " + url_string, | |
212 path()); | |
213 web_proxy_auto_discovery_url_ = GURL(); | |
214 } | |
215 } | |
216 } | |
217 } | |
218 } | |
219 } | |
220 | |
213 bool NetworkState::RequiresActivation() const { | 221 bool NetworkState::RequiresActivation() const { |
214 return (type() == shill::kTypeCellular && | 222 return (type() == shill::kTypeCellular && |
215 activation_state() != shill::kActivationStateActivated && | 223 activation_state() != shill::kActivationStateActivated && |
216 activation_state() != shill::kActivationStateUnknown); | 224 activation_state() != shill::kActivationStateUnknown); |
217 } | 225 } |
218 | 226 |
219 bool NetworkState::IsConnectedState() const { | 227 bool NetworkState::IsConnectedState() const { |
220 return StateIsConnected(connection_state_); | 228 return StateIsConnected(connection_state_); |
221 } | 229 } |
222 | 230 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 connection_state == shill::kStateConfiguration || | 274 connection_state == shill::kStateConfiguration || |
267 connection_state == shill::kStateCarrier); | 275 connection_state == shill::kStateCarrier); |
268 } | 276 } |
269 | 277 |
270 // static | 278 // static |
271 bool NetworkState::ErrorIsValid(const std::string& error) { | 279 bool NetworkState::ErrorIsValid(const std::string& error) { |
272 // Shill uses "Unknown" to indicate an unset or cleared error state. | 280 // Shill uses "Unknown" to indicate an unset or cleared error state. |
273 return !error.empty() && error != kErrorUnknown; | 281 return !error.empty() && error != kErrorUnknown; |
274 } | 282 } |
275 | 283 |
276 // static | |
277 std::string NetworkState::IPConfigProperty(const char* key) { | |
278 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | |
279 } | |
280 | |
281 } // namespace chromeos | 284 } // namespace chromeos |
OLD | NEW |