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/memory/scoped_ptr.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 ManagedState::GetStateProperties(dictionary); | 224 ManagedState::GetStateProperties(dictionary); |
225 | 225 |
226 // Properties shared by all types. | 226 // Properties shared by all types. |
227 dictionary->SetStringWithoutPathExpansion(shill::kGuidProperty, guid()); | 227 dictionary->SetStringWithoutPathExpansion(shill::kGuidProperty, guid()); |
228 dictionary->SetStringWithoutPathExpansion(shill::kSecurityClassProperty, | 228 dictionary->SetStringWithoutPathExpansion(shill::kSecurityClassProperty, |
229 security_class()); | 229 security_class()); |
230 dictionary->SetStringWithoutPathExpansion(shill::kProfileProperty, | 230 dictionary->SetStringWithoutPathExpansion(shill::kProfileProperty, |
231 profile_path()); | 231 profile_path()); |
232 | 232 |
233 if (visible()) { | 233 if (visible()) { |
234 if (!error().empty()) | 234 std::string error_state = GetErrorState(); |
235 dictionary->SetStringWithoutPathExpansion(shill::kErrorProperty, error()); | 235 if (!error_state.empty()) { |
| 236 dictionary->SetStringWithoutPathExpansion(shill::kErrorProperty, |
| 237 error_state); |
| 238 } |
236 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, | 239 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, |
237 connection_state()); | 240 connection_state()); |
238 } | 241 } |
239 | 242 |
240 // VPN properties. | 243 // VPN properties. |
241 if (NetworkTypePattern::VPN().MatchesType(type())) { | 244 if (NetworkTypePattern::VPN().MatchesType(type())) { |
242 // Shill sends VPN provider properties in a nested dictionary. |dictionary| | 245 // Shill sends VPN provider properties in a nested dictionary. |dictionary| |
243 // must replicate that nested structure. | 246 // must replicate that nested structure. |
244 scoped_ptr<base::DictionaryValue> provider_property( | 247 scoped_ptr<base::DictionaryValue> provider_property( |
245 new base::DictionaryValue); | 248 new base::DictionaryValue); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 bool NetworkState::UpdateName(const base::DictionaryValue& properties) { | 394 bool NetworkState::UpdateName(const base::DictionaryValue& properties) { |
392 std::string updated_name = | 395 std::string updated_name = |
393 shill_property_util::GetNameFromProperties(path(), properties); | 396 shill_property_util::GetNameFromProperties(path(), properties); |
394 if (updated_name != name()) { | 397 if (updated_name != name()) { |
395 set_name(updated_name); | 398 set_name(updated_name); |
396 return true; | 399 return true; |
397 } | 400 } |
398 return false; | 401 return false; |
399 } | 402 } |
400 | 403 |
| 404 std::string NetworkState::GetErrorState() const { |
| 405 if (ErrorIsValid(error())) |
| 406 return error(); |
| 407 return last_error(); |
| 408 } |
| 409 |
401 // static | 410 // static |
402 bool NetworkState::StateIsConnected(const std::string& connection_state) { | 411 bool NetworkState::StateIsConnected(const std::string& connection_state) { |
403 return (connection_state == shill::kStateReady || | 412 return (connection_state == shill::kStateReady || |
404 connection_state == shill::kStateOnline || | 413 connection_state == shill::kStateOnline || |
405 connection_state == shill::kStatePortal); | 414 connection_state == shill::kStatePortal); |
406 } | 415 } |
407 | 416 |
408 // static | 417 // static |
409 bool NetworkState::StateIsConnecting(const std::string& connection_state) { | 418 bool NetworkState::StateIsConnecting(const std::string& connection_state) { |
410 return (connection_state == shill::kStateAssociation || | 419 return (connection_state == shill::kStateAssociation || |
411 connection_state == shill::kStateConfiguration || | 420 connection_state == shill::kStateConfiguration || |
412 connection_state == shill::kStateCarrier); | 421 connection_state == shill::kStateCarrier); |
413 } | 422 } |
414 | 423 |
415 // static | 424 // static |
416 bool NetworkState::NetworkStateIsCaptivePortal( | 425 bool NetworkState::NetworkStateIsCaptivePortal( |
417 const base::DictionaryValue& shill_properties) { | 426 const base::DictionaryValue& shill_properties) { |
418 return IsCaptivePortalState(shill_properties, false /* log */); | 427 return IsCaptivePortalState(shill_properties, false /* log */); |
419 } | 428 } |
420 | 429 |
421 // static | 430 // static |
422 bool NetworkState::ErrorIsValid(const std::string& error) { | 431 bool NetworkState::ErrorIsValid(const std::string& error) { |
423 // Shill uses "Unknown" to indicate an unset or cleared error state. | 432 // Shill uses "Unknown" to indicate an unset or cleared error state. |
424 return !error.empty() && error != kErrorUnknown; | 433 return !error.empty() && error != kErrorUnknown; |
425 } | 434 } |
426 | 435 |
427 } // namespace chromeos | 436 } // namespace chromeos |
OLD | NEW |