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 "chromeos/network/network_event_log.h" | 8 #include "chromeos/network/network_event_log.h" |
9 #include "chromeos/network/network_profile_handler.h" | 9 #include "chromeos/network/network_profile_handler.h" |
10 #include "chromeos/network/network_util.h" | 10 #include "chromeos/network/network_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
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; |
25 result->push_back(str); | 25 result->push_back(str); |
26 } | 26 } |
27 return true; | 27 return true; |
28 } | 28 } |
29 | 29 |
30 bool IsCaCertNssSet(const base::DictionaryValue& properties) { | 30 bool IsCaCertNssSet(const base::DictionaryValue& properties) { |
31 std::string ca_cert_nss; | 31 std::string ca_cert_nss; |
32 if (properties.GetStringWithoutPathExpansion(flimflam::kEapCaCertNssProperty, | 32 if (properties.GetStringWithoutPathExpansion(shill::kEapCaCertNssProperty, |
33 &ca_cert_nss) && | 33 &ca_cert_nss) && |
34 !ca_cert_nss.empty()) { | 34 !ca_cert_nss.empty()) { |
35 return true; | 35 return true; |
36 } | 36 } |
37 | 37 |
38 const base::DictionaryValue* provider = NULL; | 38 const base::DictionaryValue* provider = NULL; |
39 properties.GetDictionaryWithoutPathExpansion(flimflam::kProviderProperty, | 39 properties.GetDictionaryWithoutPathExpansion(shill::kProviderProperty, |
40 &provider); | 40 &provider); |
41 if (!provider) | 41 if (!provider) |
42 return false; | 42 return false; |
43 if (provider->GetStringWithoutPathExpansion( | 43 if (provider->GetStringWithoutPathExpansion( |
44 flimflam::kL2tpIpsecCaCertNssProperty, &ca_cert_nss) && | 44 shill::kL2tpIpsecCaCertNssProperty, &ca_cert_nss) && |
45 !ca_cert_nss.empty()) { | 45 !ca_cert_nss.empty()) { |
46 return true; | 46 return true; |
47 } | 47 } |
48 if (provider->GetStringWithoutPathExpansion( | 48 if (provider->GetStringWithoutPathExpansion( |
49 flimflam::kOpenVPNCaCertNSSProperty, &ca_cert_nss) && | 49 shill::kOpenVPNCaCertNSSProperty, &ca_cert_nss) && |
50 !ca_cert_nss.empty()) { | 50 !ca_cert_nss.empty()) { |
51 return true; | 51 return true; |
52 } | 52 } |
53 | 53 |
54 return false; | 54 return false; |
55 } | 55 } |
56 | 56 |
57 } // namespace | 57 } // namespace |
58 | 58 |
59 namespace chromeos { | 59 namespace chromeos { |
60 | 60 |
61 NetworkState::NetworkState(const std::string& path) | 61 NetworkState::NetworkState(const std::string& path) |
62 : ManagedState(MANAGED_TYPE_NETWORK, path), | 62 : ManagedState(MANAGED_TYPE_NETWORK, path), |
63 connectable_(false), | 63 connectable_(false), |
64 prefix_length_(0), | 64 prefix_length_(0), |
65 signal_strength_(0), | 65 signal_strength_(0), |
66 activate_over_non_cellular_networks_(false), | 66 activate_over_non_cellular_networks_(false), |
67 cellular_out_of_credits_(false), | 67 cellular_out_of_credits_(false), |
68 has_ca_cert_nss_(false) { | 68 has_ca_cert_nss_(false) { |
69 } | 69 } |
70 | 70 |
71 NetworkState::~NetworkState() { | 71 NetworkState::~NetworkState() { |
72 } | 72 } |
73 | 73 |
74 bool NetworkState::PropertyChanged(const std::string& key, | 74 bool NetworkState::PropertyChanged(const std::string& key, |
75 const base::Value& value) { | 75 const base::Value& value) { |
76 // Keep care that these properties are the same as in |GetProperties|. | 76 // Keep care that these properties are the same as in |GetProperties|. |
77 if (ManagedStatePropertyChanged(key, value)) | 77 if (ManagedStatePropertyChanged(key, value)) |
78 return true; | 78 return true; |
79 if (key == flimflam::kSignalStrengthProperty) { | 79 if (key == shill::kSignalStrengthProperty) { |
80 return GetIntegerValue(key, value, &signal_strength_); | 80 return GetIntegerValue(key, value, &signal_strength_); |
81 } else if (key == flimflam::kStateProperty) { | 81 } else if (key == shill::kStateProperty) { |
82 return GetStringValue(key, value, &connection_state_); | 82 return GetStringValue(key, value, &connection_state_); |
83 } else if (key == flimflam::kConnectableProperty) { | 83 } else if (key == shill::kConnectableProperty) { |
84 return GetBooleanValue(key, value, &connectable_); | 84 return GetBooleanValue(key, value, &connectable_); |
85 } else if (key == flimflam::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 // Shill uses "Unknown" to indicate an unset error state. | 88 // Shill uses "Unknown" to indicate an unset error state. |
89 if (error_ == kErrorUnknown) | 89 if (error_ == kErrorUnknown) |
90 error_.clear(); | 90 error_.clear(); |
91 return true; | 91 return true; |
92 } else if (key == IPConfigProperty(flimflam::kAddressProperty)) { | 92 } else if (key == IPConfigProperty(shill::kAddressProperty)) { |
93 return GetStringValue(key, value, &ip_address_); | 93 return GetStringValue(key, value, &ip_address_); |
94 } else if (key == IPConfigProperty(flimflam::kGatewayProperty)) { | 94 } else if (key == IPConfigProperty(shill::kGatewayProperty)) { |
95 return GetStringValue(key, value, &gateway_); | 95 return GetStringValue(key, value, &gateway_); |
96 } else if (key == IPConfigProperty(flimflam::kNameServersProperty)) { | 96 } else if (key == IPConfigProperty(shill::kNameServersProperty)) { |
97 const base::ListValue* dns_servers; | 97 const base::ListValue* dns_servers; |
98 if (!value.GetAsList(&dns_servers)) | 98 if (!value.GetAsList(&dns_servers)) |
99 return false; | 99 return false; |
100 dns_servers_.clear(); | 100 dns_servers_.clear(); |
101 ConvertListValueToStringVector(*dns_servers, &dns_servers_); | 101 ConvertListValueToStringVector(*dns_servers, &dns_servers_); |
102 return true; | 102 return true; |
103 } else if (key == IPConfigProperty(flimflam::kPrefixlenProperty)) { | 103 } else if (key == IPConfigProperty(shill::kPrefixlenProperty)) { |
104 return GetIntegerValue(key, value, &prefix_length_); | 104 return GetIntegerValue(key, value, &prefix_length_); |
105 } else if (key == IPConfigProperty( | 105 } else if (key == IPConfigProperty( |
106 shill::kWebProxyAutoDiscoveryUrlProperty)) { | 106 shill::kWebProxyAutoDiscoveryUrlProperty)) { |
107 std::string url_string; | 107 std::string url_string; |
108 if (!GetStringValue(key, value, &url_string)) | 108 if (!GetStringValue(key, value, &url_string)) |
109 return false; | 109 return false; |
110 if (url_string.empty()) { | 110 if (url_string.empty()) { |
111 web_proxy_auto_discovery_url_ = GURL(); | 111 web_proxy_auto_discovery_url_ = GURL(); |
112 } else { | 112 } else { |
113 GURL gurl(url_string); | 113 GURL gurl(url_string); |
114 if (!gurl.is_valid()) { | 114 if (!gurl.is_valid()) { |
115 web_proxy_auto_discovery_url_ = gurl; | 115 web_proxy_auto_discovery_url_ = gurl; |
116 } else { | 116 } else { |
117 NET_LOG_ERROR("Invalid WebProxyAutoDiscoveryUrl: " + url_string, | 117 NET_LOG_ERROR("Invalid WebProxyAutoDiscoveryUrl: " + url_string, |
118 path()); | 118 path()); |
119 web_proxy_auto_discovery_url_ = GURL(); | 119 web_proxy_auto_discovery_url_ = GURL(); |
120 } | 120 } |
121 } | 121 } |
122 return true; | 122 return true; |
123 } else if (key == flimflam::kActivationStateProperty) { | 123 } else if (key == shill::kActivationStateProperty) { |
124 return GetStringValue(key, value, &activation_state_); | 124 return GetStringValue(key, value, &activation_state_); |
125 } else if (key == flimflam::kRoamingStateProperty) { | 125 } else if (key == shill::kRoamingStateProperty) { |
126 return GetStringValue(key, value, &roaming_); | 126 return GetStringValue(key, value, &roaming_); |
127 } else if (key == flimflam::kSecurityProperty) { | 127 } else if (key == shill::kSecurityProperty) { |
128 return GetStringValue(key, value, &security_); | 128 return GetStringValue(key, value, &security_); |
129 } else if (key == flimflam::kProxyConfigProperty) { | 129 } else if (key == shill::kProxyConfigProperty) { |
130 std::string proxy_config_str; | 130 std::string proxy_config_str; |
131 if (!value.GetAsString(&proxy_config_str)) { | 131 if (!value.GetAsString(&proxy_config_str)) { |
132 NET_LOG_ERROR("Failed to parse " + key, path()); | 132 NET_LOG_ERROR("Failed to parse " + key, path()); |
133 return false; | 133 return false; |
134 } | 134 } |
135 | 135 |
136 proxy_config_.Clear(); | 136 proxy_config_.Clear(); |
137 if (proxy_config_str.empty()) | 137 if (proxy_config_str.empty()) |
138 return true; | 138 return true; |
139 | 139 |
140 scoped_ptr<base::DictionaryValue> proxy_config_dict( | 140 scoped_ptr<base::DictionaryValue> proxy_config_dict( |
141 onc::ReadDictionaryFromJson(proxy_config_str)); | 141 onc::ReadDictionaryFromJson(proxy_config_str)); |
142 if (proxy_config_dict) { | 142 if (proxy_config_dict) { |
143 // Warning: The DictionaryValue returned from | 143 // Warning: The DictionaryValue returned from |
144 // ReadDictionaryFromJson/JSONParser is an optimized derived class that | 144 // ReadDictionaryFromJson/JSONParser is an optimized derived class that |
145 // doesn't allow releasing ownership of nested values. A Swap in the wrong | 145 // doesn't allow releasing ownership of nested values. A Swap in the wrong |
146 // order leads to memory access errors. | 146 // order leads to memory access errors. |
147 proxy_config_.MergeDictionary(proxy_config_dict.get()); | 147 proxy_config_.MergeDictionary(proxy_config_dict.get()); |
148 } else { | 148 } else { |
149 NET_LOG_ERROR("Failed to parse " + key, path()); | 149 NET_LOG_ERROR("Failed to parse " + key, path()); |
150 } | 150 } |
151 return true; | 151 return true; |
152 } else if (key == flimflam::kUIDataProperty) { | 152 } else if (key == shill::kUIDataProperty) { |
153 scoped_ptr<NetworkUIData> new_ui_data = | 153 scoped_ptr<NetworkUIData> new_ui_data = |
154 shill_property_util::GetUIDataFromValue(value); | 154 shill_property_util::GetUIDataFromValue(value); |
155 if (!new_ui_data) { | 155 if (!new_ui_data) { |
156 NET_LOG_ERROR("Failed to parse " + key, path()); | 156 NET_LOG_ERROR("Failed to parse " + key, path()); |
157 return false; | 157 return false; |
158 } | 158 } |
159 ui_data_ = *new_ui_data; | 159 ui_data_ = *new_ui_data; |
160 return true; | 160 return true; |
161 } else if (key == flimflam::kNetworkTechnologyProperty) { | 161 } else if (key == shill::kNetworkTechnologyProperty) { |
162 return GetStringValue(key, value, &network_technology_); | 162 return GetStringValue(key, value, &network_technology_); |
163 } else if (key == flimflam::kDeviceProperty) { | 163 } else if (key == shill::kDeviceProperty) { |
164 return GetStringValue(key, value, &device_path_); | 164 return GetStringValue(key, value, &device_path_); |
165 } else if (key == flimflam::kGuidProperty) { | 165 } else if (key == shill::kGuidProperty) { |
166 return GetStringValue(key, value, &guid_); | 166 return GetStringValue(key, value, &guid_); |
167 } else if (key == flimflam::kProfileProperty) { | 167 } else if (key == shill::kProfileProperty) { |
168 return GetStringValue(key, value, &profile_path_); | 168 return GetStringValue(key, value, &profile_path_); |
169 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { | 169 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { |
170 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); | 170 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); |
171 } else if (key == shill::kOutOfCreditsProperty) { | 171 } else if (key == shill::kOutOfCreditsProperty) { |
172 return GetBooleanValue(key, value, &cellular_out_of_credits_); | 172 return GetBooleanValue(key, value, &cellular_out_of_credits_); |
173 } | 173 } |
174 return false; | 174 return false; |
175 } | 175 } |
176 | 176 |
177 bool NetworkState::InitialPropertiesReceived( | 177 bool NetworkState::InitialPropertiesReceived( |
178 const base::DictionaryValue& properties) { | 178 const base::DictionaryValue& properties) { |
179 NET_LOG_DEBUG("InitialPropertiesReceived", path()); | 179 NET_LOG_DEBUG("InitialPropertiesReceived", path()); |
180 bool changed = UpdateName(properties); | 180 bool changed = UpdateName(properties); |
181 bool had_ca_cert_nss = has_ca_cert_nss_; | 181 bool had_ca_cert_nss = has_ca_cert_nss_; |
182 has_ca_cert_nss_ = IsCaCertNssSet(properties); | 182 has_ca_cert_nss_ = IsCaCertNssSet(properties); |
183 changed |= had_ca_cert_nss != has_ca_cert_nss_; | 183 changed |= had_ca_cert_nss != has_ca_cert_nss_; |
184 return changed; | 184 return changed; |
185 } | 185 } |
186 | 186 |
187 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { | 187 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { |
188 // Keep care that these properties are the same as in |PropertyChanged|. | 188 // Keep care that these properties are the same as in |PropertyChanged|. |
189 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); | 189 dictionary->SetStringWithoutPathExpansion(shill::kNameProperty, name()); |
190 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); | 190 dictionary->SetStringWithoutPathExpansion(shill::kTypeProperty, type()); |
191 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, | 191 dictionary->SetIntegerWithoutPathExpansion(shill::kSignalStrengthProperty, |
192 signal_strength_); | 192 signal_strength_); |
193 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, | 193 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, |
194 connection_state_); | 194 connection_state_); |
195 dictionary->SetBooleanWithoutPathExpansion(flimflam::kConnectableProperty, | 195 dictionary->SetBooleanWithoutPathExpansion(shill::kConnectableProperty, |
196 connectable_); | 196 connectable_); |
197 | 197 |
198 dictionary->SetStringWithoutPathExpansion(flimflam::kErrorProperty, | 198 dictionary->SetStringWithoutPathExpansion(shill::kErrorProperty, error_); |
199 error_); | |
200 | 199 |
201 // IPConfig properties | 200 // IPConfig properties |
202 base::DictionaryValue* ipconfig_properties = new base::DictionaryValue; | 201 base::DictionaryValue* ipconfig_properties = new base::DictionaryValue; |
203 ipconfig_properties->SetStringWithoutPathExpansion(flimflam::kAddressProperty, | 202 ipconfig_properties->SetStringWithoutPathExpansion(shill::kAddressProperty, |
204 ip_address_); | 203 ip_address_); |
205 ipconfig_properties->SetStringWithoutPathExpansion(flimflam::kGatewayProperty, | 204 ipconfig_properties->SetStringWithoutPathExpansion(shill::kGatewayProperty, |
206 gateway_); | 205 gateway_); |
207 base::ListValue* name_servers = new base::ListValue; | 206 base::ListValue* name_servers = new base::ListValue; |
208 name_servers->AppendStrings(dns_servers_); | 207 name_servers->AppendStrings(dns_servers_); |
209 ipconfig_properties->SetWithoutPathExpansion(flimflam::kNameServersProperty, | 208 ipconfig_properties->SetWithoutPathExpansion(shill::kNameServersProperty, |
210 name_servers); | 209 name_servers); |
211 ipconfig_properties->SetStringWithoutPathExpansion( | 210 ipconfig_properties->SetStringWithoutPathExpansion( |
212 shill::kWebProxyAutoDiscoveryUrlProperty, | 211 shill::kWebProxyAutoDiscoveryUrlProperty, |
213 web_proxy_auto_discovery_url_.spec()); | 212 web_proxy_auto_discovery_url_.spec()); |
214 dictionary->SetWithoutPathExpansion(shill::kIPConfigProperty, | 213 dictionary->SetWithoutPathExpansion(shill::kIPConfigProperty, |
215 ipconfig_properties); | 214 ipconfig_properties); |
216 | 215 |
217 dictionary->SetStringWithoutPathExpansion(flimflam::kActivationStateProperty, | 216 dictionary->SetStringWithoutPathExpansion(shill::kActivationStateProperty, |
218 activation_state_); | 217 activation_state_); |
219 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, | 218 dictionary->SetStringWithoutPathExpansion(shill::kRoamingStateProperty, |
220 roaming_); | 219 roaming_); |
221 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, | 220 dictionary->SetStringWithoutPathExpansion(shill::kSecurityProperty, |
222 security_); | 221 security_); |
223 // Proxy config and ONC source are intentionally omitted: These properties are | 222 // Proxy config and ONC source are intentionally omitted: These properties are |
224 // placed in NetworkState to transition ProxyConfigServiceImpl from | 223 // placed in NetworkState to transition ProxyConfigServiceImpl from |
225 // NetworkLibrary to the new network stack. The networking extension API | 224 // NetworkLibrary to the new network stack. The networking extension API |
226 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler | 225 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler |
227 // is used instead of NetworkLibrary, we can remove them again. | 226 // is used instead of NetworkLibrary, we can remove them again. |
228 dictionary->SetStringWithoutPathExpansion( | 227 dictionary->SetStringWithoutPathExpansion( |
229 flimflam::kNetworkTechnologyProperty, | 228 shill::kNetworkTechnologyProperty, |
230 network_technology_); | 229 network_technology_); |
231 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, | 230 dictionary->SetStringWithoutPathExpansion(shill::kDeviceProperty, |
232 device_path_); | 231 device_path_); |
233 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); | 232 dictionary->SetStringWithoutPathExpansion(shill::kGuidProperty, guid_); |
234 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, | 233 dictionary->SetStringWithoutPathExpansion(shill::kProfileProperty, |
235 profile_path_); | 234 profile_path_); |
236 dictionary->SetBooleanWithoutPathExpansion( | 235 dictionary->SetBooleanWithoutPathExpansion( |
237 shill::kActivateOverNonCellularNetworkProperty, | 236 shill::kActivateOverNonCellularNetworkProperty, |
238 activate_over_non_cellular_networks_); | 237 activate_over_non_cellular_networks_); |
239 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, | 238 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, |
240 cellular_out_of_credits_); | 239 cellular_out_of_credits_); |
241 } | 240 } |
242 | 241 |
243 bool NetworkState::RequiresActivation() const { | 242 bool NetworkState::RequiresActivation() const { |
244 return (type() == flimflam::kTypeCellular && | 243 return (type() == shill::kTypeCellular && |
245 activation_state() != flimflam::kActivationStateActivated && | 244 activation_state() != shill::kActivationStateActivated && |
246 activation_state() != flimflam::kActivationStateUnknown); | 245 activation_state() != shill::kActivationStateUnknown); |
247 } | 246 } |
248 | 247 |
249 bool NetworkState::IsConnectedState() const { | 248 bool NetworkState::IsConnectedState() const { |
250 return StateIsConnected(connection_state_); | 249 return StateIsConnected(connection_state_); |
251 } | 250 } |
252 | 251 |
253 bool NetworkState::IsConnectingState() const { | 252 bool NetworkState::IsConnectingState() const { |
254 return StateIsConnecting(connection_state_); | 253 return StateIsConnecting(connection_state_); |
255 } | 254 } |
256 | 255 |
(...skipping 26 matching lines...) Expand all Loading... |
283 shill_property_util::GetNameFromProperties(path(), properties); | 282 shill_property_util::GetNameFromProperties(path(), properties); |
284 if (updated_name != name()) { | 283 if (updated_name != name()) { |
285 set_name(updated_name); | 284 set_name(updated_name); |
286 return true; | 285 return true; |
287 } | 286 } |
288 return false; | 287 return false; |
289 } | 288 } |
290 | 289 |
291 // static | 290 // static |
292 bool NetworkState::StateIsConnected(const std::string& connection_state) { | 291 bool NetworkState::StateIsConnected(const std::string& connection_state) { |
293 return (connection_state == flimflam::kStateReady || | 292 return (connection_state == shill::kStateReady || |
294 connection_state == flimflam::kStateOnline || | 293 connection_state == shill::kStateOnline || |
295 connection_state == flimflam::kStatePortal); | 294 connection_state == shill::kStatePortal); |
296 } | 295 } |
297 | 296 |
298 // static | 297 // static |
299 bool NetworkState::StateIsConnecting(const std::string& connection_state) { | 298 bool NetworkState::StateIsConnecting(const std::string& connection_state) { |
300 return (connection_state == flimflam::kStateAssociation || | 299 return (connection_state == shill::kStateAssociation || |
301 connection_state == flimflam::kStateConfiguration || | 300 connection_state == shill::kStateConfiguration || |
302 connection_state == flimflam::kStateCarrier); | 301 connection_state == shill::kStateCarrier); |
303 } | 302 } |
304 | 303 |
305 // static | 304 // static |
306 std::string NetworkState::IPConfigProperty(const char* key) { | 305 std::string NetworkState::IPConfigProperty(const char* key) { |
307 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | 306 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
308 } | 307 } |
309 | 308 |
310 } // namespace chromeos | 309 } // namespace chromeos |
OLD | NEW |