| 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()) | |
| 235 dictionary->SetStringWithoutPathExpansion(shill::kErrorProperty, error()); | |
| 236 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, | 234 dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, |
| 237 connection_state()); | 235 connection_state()); |
| 238 } | 236 } |
| 239 | 237 |
| 240 // VPN properties. | 238 // VPN properties. |
| 241 if (NetworkTypePattern::VPN().MatchesType(type())) { | 239 if (NetworkTypePattern::VPN().MatchesType(type())) { |
| 242 // Shill sends VPN provider properties in a nested dictionary. |dictionary| | 240 // Shill sends VPN provider properties in a nested dictionary. |dictionary| |
| 243 // must replicate that nested structure. | 241 // must replicate that nested structure. |
| 244 scoped_ptr<base::DictionaryValue> provider_property( | 242 scoped_ptr<base::DictionaryValue> provider_property( |
| 245 new base::DictionaryValue); | 243 new base::DictionaryValue); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 bool NetworkState::UpdateName(const base::DictionaryValue& properties) { | 389 bool NetworkState::UpdateName(const base::DictionaryValue& properties) { |
| 392 std::string updated_name = | 390 std::string updated_name = |
| 393 shill_property_util::GetNameFromProperties(path(), properties); | 391 shill_property_util::GetNameFromProperties(path(), properties); |
| 394 if (updated_name != name()) { | 392 if (updated_name != name()) { |
| 395 set_name(updated_name); | 393 set_name(updated_name); |
| 396 return true; | 394 return true; |
| 397 } | 395 } |
| 398 return false; | 396 return false; |
| 399 } | 397 } |
| 400 | 398 |
| 399 std::string NetworkState::GetErrorState() const { |
| 400 if (ErrorIsValid(error())) |
| 401 return error(); |
| 402 return last_error(); |
| 403 } |
| 404 |
| 401 // static | 405 // static |
| 402 bool NetworkState::StateIsConnected(const std::string& connection_state) { | 406 bool NetworkState::StateIsConnected(const std::string& connection_state) { |
| 403 return (connection_state == shill::kStateReady || | 407 return (connection_state == shill::kStateReady || |
| 404 connection_state == shill::kStateOnline || | 408 connection_state == shill::kStateOnline || |
| 405 connection_state == shill::kStatePortal); | 409 connection_state == shill::kStatePortal); |
| 406 } | 410 } |
| 407 | 411 |
| 408 // static | 412 // static |
| 409 bool NetworkState::StateIsConnecting(const std::string& connection_state) { | 413 bool NetworkState::StateIsConnecting(const std::string& connection_state) { |
| 410 return (connection_state == shill::kStateAssociation || | 414 return (connection_state == shill::kStateAssociation || |
| 411 connection_state == shill::kStateConfiguration || | 415 connection_state == shill::kStateConfiguration || |
| 412 connection_state == shill::kStateCarrier); | 416 connection_state == shill::kStateCarrier); |
| 413 } | 417 } |
| 414 | 418 |
| 415 // static | 419 // static |
| 416 bool NetworkState::NetworkStateIsCaptivePortal( | 420 bool NetworkState::NetworkStateIsCaptivePortal( |
| 417 const base::DictionaryValue& shill_properties) { | 421 const base::DictionaryValue& shill_properties) { |
| 418 return IsCaptivePortalState(shill_properties, false /* log */); | 422 return IsCaptivePortalState(shill_properties, false /* log */); |
| 419 } | 423 } |
| 420 | 424 |
| 421 // static | 425 // static |
| 422 bool NetworkState::ErrorIsValid(const std::string& error) { | 426 bool NetworkState::ErrorIsValid(const std::string& error) { |
| 423 // Shill uses "Unknown" to indicate an unset or cleared error state. | 427 // Shill uses "Unknown" to indicate an unset or cleared error state. |
| 424 return !error.empty() && error != kErrorUnknown; | 428 return !error.empty() && error != kErrorUnknown; |
| 425 } | 429 } |
| 426 | 430 |
| 427 } // namespace chromeos | 431 } // namespace chromeos |
| OLD | NEW |