| 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/values.h" | 7 #include "base/values.h" |
| 8 #include "third_party/cros_system_api/dbus/service_constants.h" | 8 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 9 | 9 |
| 10 namespace chromeos { | 10 namespace chromeos { |
| 11 | 11 |
| 12 const char NetworkState::kMatchTypeDefault[] = "default"; |
| 13 const char NetworkState::kMatchTypeWireless[] = "wireless"; |
| 14 const char NetworkState::kMatchTypeNonVirtual[] = "non-virtual"; |
| 15 |
| 12 NetworkState::NetworkState(const std::string& path) | 16 NetworkState::NetworkState(const std::string& path) |
| 13 : ManagedState(MANAGED_TYPE_NETWORK, path), | 17 : ManagedState(MANAGED_TYPE_NETWORK, path), |
| 14 signal_strength_(0) { | 18 signal_strength_(0) { |
| 15 } | 19 } |
| 16 | 20 |
| 17 NetworkState::~NetworkState() { | 21 NetworkState::~NetworkState() { |
| 18 } | 22 } |
| 19 | 23 |
| 20 bool NetworkState::PropertyChanged(const std::string& key, | 24 bool NetworkState::PropertyChanged(const std::string& key, |
| 21 const base::Value& value) { | 25 const base::Value& value) { |
| 22 if (ManagedStatePropertyChanged(key, value)) | 26 if (ManagedStatePropertyChanged(key, value)) |
| 23 return true; | 27 return true; |
| 24 if (key == flimflam::kSignalStrengthProperty) { | 28 if (key == flimflam::kSignalStrengthProperty) { |
| 25 return GetIntegerValue(key, value, &signal_strength_); | 29 return GetIntegerValue(key, value, &signal_strength_); |
| 26 } else if (key == flimflam::kStateProperty) { | 30 } else if (key == flimflam::kStateProperty) { |
| 27 return GetStringValue(key, value, &state_); | 31 return GetStringValue(key, value, &connection_state_); |
| 28 } else if (key == flimflam::kErrorProperty) { | 32 } else if (key == flimflam::kErrorProperty) { |
| 29 return GetStringValue(key, value, &error_); | 33 return GetStringValue(key, value, &error_); |
| 30 } else if (key == flimflam::kActivationStateProperty) { | 34 } else if (key == flimflam::kActivationStateProperty) { |
| 31 return GetStringValue(key, value, &activation_state_); | 35 return GetStringValue(key, value, &activation_state_); |
| 32 } else if (key == flimflam::kRoamingStateProperty) { | 36 } else if (key == flimflam::kRoamingStateProperty) { |
| 33 return GetStringValue(key, value, &roaming_); | 37 return GetStringValue(key, value, &roaming_); |
| 34 } else if (key == flimflam::kSecurityProperty) { | 38 } else if (key == flimflam::kSecurityProperty) { |
| 35 return GetStringValue(key, value, &security_); | 39 return GetStringValue(key, value, &security_); |
| 36 } else if (key == flimflam::kNetworkTechnologyProperty) { | 40 } else if (key == flimflam::kNetworkTechnologyProperty) { |
| 37 return GetStringValue(key, value, &technology_); | 41 return GetStringValue(key, value, &technology_); |
| 38 } else if (key == flimflam::kDeviceProperty) { | 42 } else if (key == flimflam::kDeviceProperty) { |
| 39 return GetStringValue(key, value, &device_path_); | 43 return GetStringValue(key, value, &device_path_); |
| 40 } | 44 } |
| 41 return false; | 45 return false; |
| 42 } | 46 } |
| 43 | 47 |
| 44 bool NetworkState::IsConnectedState() const { | 48 bool NetworkState::IsConnectedState() const { |
| 45 return StateIsConnected(state_); | 49 return StateIsConnected(connection_state_); |
| 46 } | 50 } |
| 47 | 51 |
| 48 bool NetworkState::IsConnectingState() const { | 52 bool NetworkState::IsConnectingState() const { |
| 49 return StateIsConnecting(state_); | 53 return StateIsConnecting(connection_state_); |
| 54 } |
| 55 |
| 56 bool NetworkState::MatchesType(const std::string& match_type) const { |
| 57 return ((match_type == kMatchTypeDefault) || |
| 58 (match_type == type()) || |
| 59 (match_type == kMatchTypeNonVirtual && |
| 60 type() != flimflam::kTypeVPN) || |
| 61 (match_type == kMatchTypeWireless && |
| 62 type() != flimflam::kTypeEthernet && type() != flimflam::kTypeVPN)); |
| 50 } | 63 } |
| 51 | 64 |
| 52 // static | 65 // static |
| 53 bool NetworkState::StateIsConnected(const std::string& state) { | 66 bool NetworkState::StateIsConnected(const std::string& connection_state) { |
| 54 return (state == flimflam::kStateReady || | 67 return (connection_state == flimflam::kStateReady || |
| 55 state == flimflam::kStateOnline || | 68 connection_state == flimflam::kStateOnline || |
| 56 state == flimflam::kStatePortal); | 69 connection_state == flimflam::kStatePortal); |
| 57 } | 70 } |
| 58 | 71 |
| 59 // static | 72 // static |
| 60 bool NetworkState::StateIsConnecting(const std::string& state) { | 73 bool NetworkState::StateIsConnecting(const std::string& connection_state) { |
| 61 return (state == flimflam::kStateAssociation || | 74 return (connection_state == flimflam::kStateAssociation || |
| 62 state == flimflam::kStateConfiguration || | 75 connection_state == flimflam::kStateConfiguration || |
| 63 state == flimflam::kStateCarrier); | 76 connection_state == flimflam::kStateCarrier); |
| 64 } | 77 } |
| 65 | 78 |
| 66 } // namespace chromeos | 79 } // namespace chromeos |
| OLD | NEW |