| 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/memory/scoped_ptr.h" |
| 7 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 8 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 10 #include "chromeos/network/network_profile_handler.h" | 11 #include "chromeos/network/network_profile_handler.h" |
| 11 #include "chromeos/network/network_type_pattern.h" | 12 #include "chromeos/network/network_type_pattern.h" |
| 12 #include "chromeos/network/network_util.h" | 13 #include "chromeos/network/network_util.h" |
| 13 #include "chromeos/network/onc/onc_utils.h" | 14 #include "chromeos/network/onc/onc_utils.h" |
| 14 #include "chromeos/network/shill_property_util.h" | 15 #include "chromeos/network/shill_property_util.h" |
| 15 #include "components/device_event_log/device_event_log.h" | 16 #include "components/device_event_log/device_event_log.h" |
| 16 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // Warning: The DictionaryValue returned from | 160 // Warning: The DictionaryValue returned from |
| 160 // ReadDictionaryFromJson/JSONParser is an optimized derived class that | 161 // ReadDictionaryFromJson/JSONParser is an optimized derived class that |
| 161 // doesn't allow releasing ownership of nested values. A Swap in the wrong | 162 // doesn't allow releasing ownership of nested values. A Swap in the wrong |
| 162 // order leads to memory access errors. | 163 // order leads to memory access errors. |
| 163 proxy_config_.MergeDictionary(proxy_config_dict.get()); | 164 proxy_config_.MergeDictionary(proxy_config_dict.get()); |
| 164 } else { | 165 } else { |
| 165 NET_LOG(ERROR) << "Failed to parse " << path() << "." << key; | 166 NET_LOG(ERROR) << "Failed to parse " << path() << "." << key; |
| 166 } | 167 } |
| 167 return true; | 168 return true; |
| 168 } else if (key == shill::kProviderProperty) { | 169 } else if (key == shill::kProviderProperty) { |
| 170 std::string vpn_provider_type; |
| 169 const base::DictionaryValue* dict; | 171 const base::DictionaryValue* dict; |
| 170 std::string provider_type; | |
| 171 if (!value.GetAsDictionary(&dict) || | 172 if (!value.GetAsDictionary(&dict) || |
| 172 !dict->GetStringWithoutPathExpansion(shill::kTypeProperty, | 173 !dict->GetStringWithoutPathExpansion(shill::kTypeProperty, |
| 173 &provider_type)) { | 174 &vpn_provider_type)) { |
| 175 NET_LOG(ERROR) << "Failed to parse " << path() << "." << key; |
| 174 return false; | 176 return false; |
| 175 } | 177 } |
| 176 | 178 |
| 177 if (provider_type != shill::kProviderThirdPartyVpn) { | 179 if (vpn_provider_type == shill::kProviderThirdPartyVpn) { |
| 178 // If the network uses the built-in OpenVPN and L2TP support, set the | 180 // If the network uses a third-party VPN provider, copy over the |
| 179 // provider extension ID to an empty string. | 181 // provider's extension ID, which is held in |shill::kHostProperty|. |
| 180 vpn_provider_extension_id_.clear(); | 182 if (!dict->GetStringWithoutPathExpansion( |
| 181 return true; | 183 shill::kHostProperty, &third_party_vpn_provider_extension_id_)) { |
| 184 NET_LOG(ERROR) << "Failed to parse " << path() << "." << key; |
| 185 return false; |
| 186 } |
| 187 } else { |
| 188 third_party_vpn_provider_extension_id_.clear(); |
| 182 } | 189 } |
| 183 | 190 |
| 184 // If the network uses a third-party VPN provider, copy over the provider's | 191 vpn_provider_type_ = vpn_provider_type; |
| 185 // extension ID, which is held in |shill::kHostProperty|. | 192 return true; |
| 186 return dict->GetStringWithoutPathExpansion(shill::kHostProperty, | |
| 187 &vpn_provider_extension_id_); | |
| 188 } | 193 } |
| 189 return false; | 194 return false; |
| 190 } | 195 } |
| 191 | 196 |
| 192 bool NetworkState::InitialPropertiesReceived( | 197 bool NetworkState::InitialPropertiesReceived( |
| 193 const base::DictionaryValue& properties) { | 198 const base::DictionaryValue& properties) { |
| 194 NET_LOG(EVENT) << "InitialPropertiesReceived: " << path() << ": " << name() | 199 NET_LOG(EVENT) << "InitialPropertiesReceived: " << path() << ": " << name() |
| 195 << " State: " << connection_state_ << " Visible: " << visible_; | 200 << " State: " << connection_state_ << " Visible: " << visible_; |
| 196 if (!properties.HasKey(shill::kTypeProperty)) { | 201 if (!properties.HasKey(shill::kTypeProperty)) { |
| 197 NET_LOG(ERROR) << "NetworkState has no type: " | 202 NET_LOG(ERROR) << "NetworkState has no type: " |
| (...skipping 27 matching lines...) Expand all Loading... |
| 225 dictionary->SetStringWithoutPathExpansion(shill::kProfileProperty, | 230 dictionary->SetStringWithoutPathExpansion(shill::kProfileProperty, |
| 226 profile_path()); | 231 profile_path()); |
| 227 | 232 |
| 228 if (visible()) { | 233 if (visible()) { |
| 229 if (!error().empty()) | 234 if (!error().empty()) |
| 230 dictionary->SetStringWithoutPathExpansion(shill::kErrorProperty, error()); | 235 dictionary->SetStringWithoutPathExpansion(shill::kErrorProperty, error()); |
| 231 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, | 236 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, |
| 232 connection_state()); | 237 connection_state()); |
| 233 } | 238 } |
| 234 | 239 |
| 240 // VPN properties. |
| 241 if (NetworkTypePattern::VPN().MatchesType(type())) { |
| 242 // Shill sends VPN provider properties in a nested dictionary. |dictionary| |
| 243 // must replicate that nested structure. |
| 244 scoped_ptr<base::DictionaryValue> provider_property( |
| 245 new base::DictionaryValue); |
| 246 provider_property->SetStringWithoutPathExpansion(shill::kTypeProperty, |
| 247 vpn_provider_type_); |
| 248 if (vpn_provider_type_ == shill::kProviderThirdPartyVpn) { |
| 249 provider_property->SetStringWithoutPathExpansion( |
| 250 shill::kHostProperty, third_party_vpn_provider_extension_id_); |
| 251 } |
| 252 dictionary->SetWithoutPathExpansion(shill::kProviderProperty, |
| 253 provider_property.release()); |
| 254 } |
| 255 |
| 235 // Wireless properties | 256 // Wireless properties |
| 236 if (!NetworkTypePattern::Wireless().MatchesType(type())) | 257 if (!NetworkTypePattern::Wireless().MatchesType(type())) |
| 237 return; | 258 return; |
| 238 | 259 |
| 239 if (visible()) { | 260 if (visible()) { |
| 240 dictionary->SetBooleanWithoutPathExpansion(shill::kConnectableProperty, | 261 dictionary->SetBooleanWithoutPathExpansion(shill::kConnectableProperty, |
| 241 connectable()); | 262 connectable()); |
| 242 dictionary->SetIntegerWithoutPathExpansion(shill::kSignalStrengthProperty, | 263 dictionary->SetIntegerWithoutPathExpansion(shill::kSignalStrengthProperty, |
| 243 signal_strength()); | 264 signal_strength()); |
| 244 } | 265 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 return IsCaptivePortalState(shill_properties, false /* log */); | 418 return IsCaptivePortalState(shill_properties, false /* log */); |
| 398 } | 419 } |
| 399 | 420 |
| 400 // static | 421 // static |
| 401 bool NetworkState::ErrorIsValid(const std::string& error) { | 422 bool NetworkState::ErrorIsValid(const std::string& error) { |
| 402 // Shill uses "Unknown" to indicate an unset or cleared error state. | 423 // Shill uses "Unknown" to indicate an unset or cleared error state. |
| 403 return !error.empty() && error != kErrorUnknown; | 424 return !error.empty() && error != kErrorUnknown; |
| 404 } | 425 } |
| 405 | 426 |
| 406 } // namespace chromeos | 427 } // namespace chromeos |
| OLD | NEW |