Chromium Code Reviews| 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 third_party_vpn_provider_extension_id_.clear(); | |
|
pneubeck (no reviews)
2015/03/18 19:35:29
I found the reason why I said we must be cautious
bartfab (slow)
2015/03/18 20:02:14
Fixed, including the corner case.
| |
| 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 | |
| 179 // provider extension ID to an empty string. | |
| 180 vpn_provider_extension_id_.clear(); | |
| 181 return true; | 180 return true; |
| 182 } | |
| 183 | 181 |
| 184 // If the network uses a third-party VPN provider, copy over the provider's | 182 // If the network uses a third-party VPN provider, copy over the provider's |
| 185 // extension ID, which is held in |shill::kHostProperty|. | 183 // extension ID, which is held in |shill::kHostProperty|. |
| 186 return dict->GetStringWithoutPathExpansion(shill::kHostProperty, | 184 if (!dict->GetStringWithoutPathExpansion( |
| 187 &vpn_provider_extension_id_); | 185 shill::kHostProperty, &third_party_vpn_provider_extension_id_)) { |
| 186 NET_LOG(ERROR) << "Failed to parse " << path() << "." << key; | |
| 187 return false; | |
| 188 } | |
| 189 | |
| 190 return true; | |
| 188 } | 191 } |
| 189 return false; | 192 return false; |
| 190 } | 193 } |
| 191 | 194 |
| 192 bool NetworkState::InitialPropertiesReceived( | 195 bool NetworkState::InitialPropertiesReceived( |
| 193 const base::DictionaryValue& properties) { | 196 const base::DictionaryValue& properties) { |
| 194 NET_LOG(EVENT) << "InitialPropertiesReceived: " << path() << ": " << name() | 197 NET_LOG(EVENT) << "InitialPropertiesReceived: " << path() << ": " << name() |
| 195 << " State: " << connection_state_ << " Visible: " << visible_; | 198 << " State: " << connection_state_ << " Visible: " << visible_; |
| 196 if (!properties.HasKey(shill::kTypeProperty)) { | 199 if (!properties.HasKey(shill::kTypeProperty)) { |
| 197 NET_LOG(ERROR) << "NetworkState has no type: " | 200 NET_LOG(ERROR) << "NetworkState has no type: " |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 225 dictionary->SetStringWithoutPathExpansion(shill::kProfileProperty, | 228 dictionary->SetStringWithoutPathExpansion(shill::kProfileProperty, |
| 226 profile_path()); | 229 profile_path()); |
| 227 | 230 |
| 228 if (visible()) { | 231 if (visible()) { |
| 229 if (!error().empty()) | 232 if (!error().empty()) |
| 230 dictionary->SetStringWithoutPathExpansion(shill::kErrorProperty, error()); | 233 dictionary->SetStringWithoutPathExpansion(shill::kErrorProperty, error()); |
| 231 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, | 234 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, |
| 232 connection_state()); | 235 connection_state()); |
| 233 } | 236 } |
| 234 | 237 |
| 238 // VPN properties. | |
| 239 if (NetworkTypePattern::VPN().MatchesType(type())) { | |
| 240 scoped_ptr<base::DictionaryValue> provider_property( | |
|
pneubeck (no reviews)
2015/03/18 19:35:29
nit: drop a comment before this line, like:
"Shil
bartfab (slow)
2015/03/18 20:02:14
Done.
| |
| 241 new base::DictionaryValue); | |
| 242 provider_property->SetStringWithoutPathExpansion(shill::kTypeProperty, | |
| 243 vpn_provider_type_); | |
| 244 if (vpn_provider_type_ == shill::kProviderThirdPartyVpn) { | |
| 245 provider_property->SetStringWithoutPathExpansion( | |
| 246 shill::kHostProperty, third_party_vpn_provider_extension_id_); | |
| 247 } | |
| 248 dictionary->SetWithoutPathExpansion(shill::kProviderProperty, | |
| 249 provider_property.release()); | |
| 250 } | |
| 251 | |
| 235 // Wireless properties | 252 // Wireless properties |
| 236 if (!NetworkTypePattern::Wireless().MatchesType(type())) | 253 if (!NetworkTypePattern::Wireless().MatchesType(type())) |
| 237 return; | 254 return; |
| 238 | 255 |
| 239 if (visible()) { | 256 if (visible()) { |
| 240 dictionary->SetBooleanWithoutPathExpansion(shill::kConnectableProperty, | 257 dictionary->SetBooleanWithoutPathExpansion(shill::kConnectableProperty, |
| 241 connectable()); | 258 connectable()); |
| 242 dictionary->SetIntegerWithoutPathExpansion(shill::kSignalStrengthProperty, | 259 dictionary->SetIntegerWithoutPathExpansion(shill::kSignalStrengthProperty, |
| 243 signal_strength()); | 260 signal_strength()); |
| 244 } | 261 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 return IsCaptivePortalState(shill_properties, false /* log */); | 414 return IsCaptivePortalState(shill_properties, false /* log */); |
| 398 } | 415 } |
| 399 | 416 |
| 400 // static | 417 // static |
| 401 bool NetworkState::ErrorIsValid(const std::string& error) { | 418 bool NetworkState::ErrorIsValid(const std::string& error) { |
| 402 // Shill uses "Unknown" to indicate an unset or cleared error state. | 419 // Shill uses "Unknown" to indicate an unset or cleared error state. |
| 403 return !error.empty() && error != kErrorUnknown; | 420 return !error.empty() && error != kErrorUnknown; |
| 404 } | 421 } |
| 405 | 422 |
| 406 } // namespace chromeos | 423 } // namespace chromeos |
| OLD | NEW |