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" | |
9 #include "chromeos/network/network_event_log.h" | 8 #include "chromeos/network/network_event_log.h" |
10 #include "chromeos/network/network_profile_handler.h" | 9 #include "chromeos/network/network_profile_handler.h" |
11 #include "chromeos/network/network_type_pattern.h" | 10 #include "chromeos/network/network_type_pattern.h" |
12 #include "chromeos/network/network_util.h" | 11 #include "chromeos/network/network_util.h" |
12 #include "chromeos/network/onc/onc_utils.h" | |
13 #include "chromeos/network/shill_property_util.h" | 13 #include "chromeos/network/shill_property_util.h" |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 14 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 const char kErrorUnknown[] = "Unknown"; | 18 const char kErrorUnknown[] = "Unknown"; |
19 | 19 |
20 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 20 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
21 std::vector<std::string>* result) { | 21 std::vector<std::string>* result) { |
22 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 22 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 | 54 |
55 return false; | 55 return false; |
56 } | 56 } |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 namespace chromeos { | 60 namespace chromeos { |
61 | 61 |
62 NetworkState::NetworkState(const std::string& path) | 62 NetworkState::NetworkState(const std::string& path) |
63 : ManagedState(MANAGED_TYPE_NETWORK, path), | 63 : ManagedState(MANAGED_TYPE_NETWORK, path), |
64 visible_(false), | |
64 connectable_(false), | 65 connectable_(false), |
65 prefix_length_(0), | 66 prefix_length_(0), |
66 signal_strength_(0), | 67 signal_strength_(0), |
67 activate_over_non_cellular_networks_(false), | 68 activate_over_non_cellular_networks_(false), |
68 cellular_out_of_credits_(false), | 69 cellular_out_of_credits_(false), |
69 has_ca_cert_nss_(false) { | 70 has_ca_cert_nss_(false) { |
70 } | 71 } |
71 | 72 |
72 NetworkState::~NetworkState() { | 73 NetworkState::~NetworkState() { |
73 } | 74 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 } else if (key == shill::kDeviceProperty) { | 114 } else if (key == shill::kDeviceProperty) { |
114 return GetStringValue(key, value, &device_path_); | 115 return GetStringValue(key, value, &device_path_); |
115 } else if (key == shill::kGuidProperty) { | 116 } else if (key == shill::kGuidProperty) { |
116 return GetStringValue(key, value, &guid_); | 117 return GetStringValue(key, value, &guid_); |
117 } else if (key == shill::kProfileProperty) { | 118 } else if (key == shill::kProfileProperty) { |
118 return GetStringValue(key, value, &profile_path_); | 119 return GetStringValue(key, value, &profile_path_); |
119 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { | 120 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { |
120 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); | 121 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); |
121 } else if (key == shill::kOutOfCreditsProperty) { | 122 } else if (key == shill::kOutOfCreditsProperty) { |
122 return GetBooleanValue(key, value, &cellular_out_of_credits_); | 123 return GetBooleanValue(key, value, &cellular_out_of_credits_); |
124 } else if (key == shill::kProxyConfigProperty) { | |
125 std::string proxy_config_str; | |
126 if (!value.GetAsString(&proxy_config_str)) { | |
127 NET_LOG_ERROR("Failed to parse " + key, path()); | |
128 return false; | |
129 } | |
130 | |
131 proxy_config_.Clear(); | |
132 if (proxy_config_str.empty()) | |
133 return true; | |
134 | |
135 scoped_ptr<base::DictionaryValue> proxy_config_dict( | |
136 onc::ReadDictionaryFromJson(proxy_config_str)); | |
137 if (proxy_config_dict) { | |
138 // Warning: The DictionaryValue returned from | |
139 // ReadDictionaryFromJson/JSONParser is an optimized derived class that | |
140 // doesn't allow releasing ownership of nested values. A Swap in the wrong | |
141 // order leads to memory access errors. | |
142 proxy_config_.MergeDictionary(proxy_config_dict.get()); | |
143 } else { | |
144 NET_LOG_ERROR("Failed to parse " + key, path()); | |
145 } | |
146 return true; | |
123 } | 147 } |
124 return false; | 148 return false; |
125 } | 149 } |
126 | 150 |
127 bool NetworkState::InitialPropertiesReceived( | 151 bool NetworkState::InitialPropertiesReceived( |
128 const base::DictionaryValue& properties) { | 152 const base::DictionaryValue& properties) { |
129 NET_LOG_DEBUG("InitialPropertiesReceived", path()); | 153 NET_LOG_DEBUG("InitialPropertiesReceived", path()); |
130 bool changed = false; | 154 bool changed = false; |
131 if (!properties.HasKey(shill::kTypeProperty)) { | 155 if (!properties.HasKey(shill::kTypeProperty)) { |
132 NET_LOG_ERROR("NetworkState has no type", | 156 NET_LOG_ERROR("NetworkState has no type", |
133 shill_property_util::GetNetworkIdFromProperties(properties)); | 157 shill_property_util::GetNetworkIdFromProperties(properties)); |
134 return false; | 158 return false; |
135 } | 159 } |
136 // Ensure that the network has a valid name. | 160 // Ensure that the network has a valid name. |
137 changed |= UpdateName(properties); | 161 changed |= UpdateName(properties); |
138 | 162 |
139 // Set the has_ca_cert_nss_ property. | 163 // Set the has_ca_cert_nss_ property. |
140 bool had_ca_cert_nss = has_ca_cert_nss_; | 164 bool had_ca_cert_nss = has_ca_cert_nss_; |
141 has_ca_cert_nss_ = IsCaCertNssSet(properties); | 165 has_ca_cert_nss_ = IsCaCertNssSet(properties); |
142 changed |= had_ca_cert_nss != has_ca_cert_nss_; | 166 changed |= had_ca_cert_nss != has_ca_cert_nss_; |
143 | 167 |
144 // By convention, all visible WiFi networks have a SignalStrength > 0. | 168 // By convention, all visible WiFi networks have a SignalStrength > 0. |
145 if (type() == shill::kTypeWifi) { | 169 if (visible() && type() == shill::kTypeWifi) { |
146 if (signal_strength_ <= 0) | 170 if (signal_strength_ <= 0) |
147 signal_strength_ = 1; | 171 signal_strength_ = 1; |
148 } | 172 } |
149 | 173 |
150 return changed; | 174 return changed; |
151 } | 175 } |
152 | 176 |
153 void NetworkState::GetStateProperties(base::DictionaryValue* dictionary) const { | 177 void NetworkState::GetStateProperties(base::DictionaryValue* dictionary) const { |
pneubeck (no reviews)
2014/06/11 12:44:56
seems that you dropped the properties NetworkUIDat
stevenjb
2014/06/11 23:31:41
Yes, that was intentional, we now add those explic
| |
154 ManagedState::GetStateProperties(dictionary); | 178 ManagedState::GetStateProperties(dictionary); |
155 | 179 |
156 // Properties shared by all types. | 180 // Properties shared by all types. |
157 dictionary->SetStringWithoutPathExpansion(shill::kGuidProperty, guid()); | 181 dictionary->SetStringWithoutPathExpansion(shill::kGuidProperty, guid()); |
158 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, | |
159 connection_state()); | |
160 dictionary->SetStringWithoutPathExpansion(shill::kSecurityProperty, | 182 dictionary->SetStringWithoutPathExpansion(shill::kSecurityProperty, |
161 security()); | 183 security()); |
162 if (!error().empty()) | |
163 dictionary->SetStringWithoutPathExpansion(shill::kErrorProperty, error()); | |
164 | 184 |
185 if (visible()) { | |
186 if (!error().empty()) | |
187 dictionary->SetStringWithoutPathExpansion(shill::kErrorProperty, error()); | |
188 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, | |
189 connection_state()); | |
190 } | |
191 | |
192 // Wireless properties | |
165 if (!NetworkTypePattern::Wireless().MatchesType(type())) | 193 if (!NetworkTypePattern::Wireless().MatchesType(type())) |
166 return; | 194 return; |
167 | 195 |
168 // Wireless properties | 196 if (visible()) { |
169 dictionary->SetBooleanWithoutPathExpansion(shill::kConnectableProperty, | 197 dictionary->SetBooleanWithoutPathExpansion(shill::kConnectableProperty, |
170 connectable()); | 198 connectable()); |
171 dictionary->SetIntegerWithoutPathExpansion(shill::kSignalStrengthProperty, | 199 dictionary->SetIntegerWithoutPathExpansion(shill::kSignalStrengthProperty, |
172 signal_strength()); | 200 signal_strength()); |
201 } | |
173 | 202 |
174 // Wifi properties | 203 // Wifi properties |
175 if (NetworkTypePattern::WiFi().MatchesType(type())) { | 204 if (NetworkTypePattern::WiFi().MatchesType(type())) { |
176 dictionary->SetStringWithoutPathExpansion(shill::kEapMethodProperty, | 205 dictionary->SetStringWithoutPathExpansion(shill::kEapMethodProperty, |
177 eap_method()); | 206 eap_method()); |
178 } | 207 } |
179 | 208 |
180 // Mobile properties | 209 // Mobile properties |
181 if (NetworkTypePattern::Mobile().MatchesType(type())) { | 210 if (NetworkTypePattern::Mobile().MatchesType(type())) { |
182 dictionary->SetStringWithoutPathExpansion( | 211 dictionary->SetStringWithoutPathExpansion( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 } | 266 } |
238 | 267 |
239 bool NetworkState::IsConnectedState() const { | 268 bool NetworkState::IsConnectedState() const { |
240 return StateIsConnected(connection_state_); | 269 return StateIsConnected(connection_state_); |
241 } | 270 } |
242 | 271 |
243 bool NetworkState::IsConnectingState() const { | 272 bool NetworkState::IsConnectingState() const { |
244 return StateIsConnecting(connection_state_); | 273 return StateIsConnecting(connection_state_); |
245 } | 274 } |
246 | 275 |
276 bool NetworkState::IsInProfile() const { | |
277 // kTypeEthernetEap is always saved. We need this check because it does | |
278 // not show up in the visible list, but its properties may not be available | |
279 // when it first shows up in ServiceCompleteList. See crbug.com/355117. | |
280 return !profile_path_.empty() || type() == shill::kTypeEthernetEap; | |
281 } | |
282 | |
247 bool NetworkState::IsPrivate() const { | 283 bool NetworkState::IsPrivate() const { |
248 return !profile_path_.empty() && | 284 return !profile_path_.empty() && |
249 profile_path_ != NetworkProfileHandler::GetSharedProfilePath(); | 285 profile_path_ != NetworkProfileHandler::GetSharedProfilePath(); |
250 } | 286 } |
251 | 287 |
252 std::string NetworkState::GetDnsServersAsString() const { | 288 std::string NetworkState::GetDnsServersAsString() const { |
253 std::string result; | 289 std::string result; |
254 for (size_t i = 0; i < dns_servers_.size(); ++i) { | 290 for (size_t i = 0; i < dns_servers_.size(); ++i) { |
255 if (i != 0) | 291 if (i != 0) |
256 result += ","; | 292 result += ","; |
257 result += dns_servers_[i]; | 293 result += dns_servers_[i]; |
258 } | 294 } |
259 return result; | 295 return result; |
260 } | 296 } |
261 | 297 |
262 std::string NetworkState::GetNetmask() const { | 298 std::string NetworkState::GetNetmask() const { |
263 return network_util::PrefixLengthToNetmask(prefix_length_); | 299 return network_util::PrefixLengthToNetmask(prefix_length_); |
264 } | 300 } |
265 | 301 |
302 std::string NetworkState::GetSpecifier() const { | |
303 if (!update_received()) { | |
304 NET_LOG_ERROR("GetSpecifier called before update", path()); | |
305 return std::string(); | |
306 } | |
307 if (type() == shill::kTypeWifi) | |
308 return name() + "_" + security_; | |
309 if (!name().empty()) | |
310 return name(); | |
311 return type(); // For unnamed networks such as ethernet. | |
312 } | |
313 | |
266 void NetworkState::SetGuid(const std::string& guid) { | 314 void NetworkState::SetGuid(const std::string& guid) { |
267 guid_ = guid; | 315 guid_ = guid; |
268 } | 316 } |
269 | 317 |
270 bool NetworkState::UpdateName(const base::DictionaryValue& properties) { | 318 bool NetworkState::UpdateName(const base::DictionaryValue& properties) { |
271 std::string updated_name = | 319 std::string updated_name = |
272 shill_property_util::GetNameFromProperties(path(), properties); | 320 shill_property_util::GetNameFromProperties(path(), properties); |
273 if (updated_name != name()) { | 321 if (updated_name != name()) { |
274 set_name(updated_name); | 322 set_name(updated_name); |
275 return true; | 323 return true; |
(...skipping 15 matching lines...) Expand all Loading... | |
291 connection_state == shill::kStateCarrier); | 339 connection_state == shill::kStateCarrier); |
292 } | 340 } |
293 | 341 |
294 // static | 342 // static |
295 bool NetworkState::ErrorIsValid(const std::string& error) { | 343 bool NetworkState::ErrorIsValid(const std::string& error) { |
296 // Shill uses "Unknown" to indicate an unset or cleared error state. | 344 // Shill uses "Unknown" to indicate an unset or cleared error state. |
297 return !error.empty() && error != kErrorUnknown; | 345 return !error.empty() && error != kErrorUnknown; |
298 } | 346 } |
299 | 347 |
300 } // namespace chromeos | 348 } // namespace chromeos |
OLD | NEW |