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