| 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 NetworkState::NetworkState(const std::string& path) | 12 NetworkState::NetworkState(const std::string& path) |
| 13 : ManagedState(MANAGED_TYPE_NETWORK, path), | 13 : ManagedState(MANAGED_TYPE_NETWORK, path), |
| 14 signal_strength_(0) { | 14 signal_strength_(0) { |
| 15 } | 15 } |
| 16 | 16 |
| 17 NetworkState::~NetworkState() { | 17 NetworkState::~NetworkState() { |
| 18 } | 18 } |
| 19 | 19 |
| 20 bool NetworkState::PropertyChanged(const std::string& key, | 20 bool NetworkState::PropertyChanged(const std::string& key, |
| 21 const base::Value& value) { | 21 const base::Value& value) { |
| 22 // Keep care that these properties are the same as in |GetProperties|. |
| 22 if (ManagedStatePropertyChanged(key, value)) | 23 if (ManagedStatePropertyChanged(key, value)) |
| 23 return true; | 24 return true; |
| 24 if (key == flimflam::kSignalStrengthProperty) { | 25 if (key == flimflam::kSignalStrengthProperty) { |
| 25 return GetIntegerValue(key, value, &signal_strength_); | 26 return GetIntegerValue(key, value, &signal_strength_); |
| 26 } else if (key == flimflam::kStateProperty) { | 27 } else if (key == flimflam::kStateProperty) { |
| 27 return GetStringValue(key, value, &connection_state_); | 28 return GetStringValue(key, value, &connection_state_); |
| 28 } else if (key == flimflam::kErrorProperty) { | 29 } else if (key == flimflam::kErrorProperty) { |
| 29 return GetStringValue(key, value, &error_); | 30 return GetStringValue(key, value, &error_); |
| 30 } else if (key == flimflam::kActivationStateProperty) { | 31 } else if (key == flimflam::kActivationStateProperty) { |
| 31 return GetStringValue(key, value, &activation_state_); | 32 return GetStringValue(key, value, &activation_state_); |
| 32 } else if (key == flimflam::kRoamingStateProperty) { | 33 } else if (key == flimflam::kRoamingStateProperty) { |
| 33 return GetStringValue(key, value, &roaming_); | 34 return GetStringValue(key, value, &roaming_); |
| 34 } else if (key == flimflam::kSecurityProperty) { | 35 } else if (key == flimflam::kSecurityProperty) { |
| 35 return GetStringValue(key, value, &security_); | 36 return GetStringValue(key, value, &security_); |
| 36 } else if (key == flimflam::kNetworkTechnologyProperty) { | 37 } else if (key == flimflam::kNetworkTechnologyProperty) { |
| 37 return GetStringValue(key, value, &technology_); | 38 return GetStringValue(key, value, &technology_); |
| 38 } else if (key == flimflam::kDeviceProperty) { | 39 } else if (key == flimflam::kDeviceProperty) { |
| 39 return GetStringValue(key, value, &device_path_); | 40 return GetStringValue(key, value, &device_path_); |
| 40 } else if (key == flimflam::kGuidProperty) { | 41 } else if (key == flimflam::kGuidProperty) { |
| 41 return GetStringValue(key, value, &guid_); | 42 return GetStringValue(key, value, &guid_); |
| 42 } | 43 } |
| 43 return false; | 44 return false; |
| 44 } | 45 } |
| 45 | 46 |
| 47 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { |
| 48 // Keep care that these properties are the same as in |PropertyChanged|. |
| 49 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); |
| 50 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); |
| 51 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, |
| 52 signal_strength()); |
| 53 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, |
| 54 connection_state()); |
| 55 dictionary->SetStringWithoutPathExpansion(flimflam::kErrorProperty, |
| 56 error()); |
| 57 dictionary->SetStringWithoutPathExpansion(flimflam::kActivationStateProperty, |
| 58 activation_state()); |
| 59 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, |
| 60 roaming()); |
| 61 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, |
| 62 security()); |
| 63 dictionary->SetStringWithoutPathExpansion( |
| 64 flimflam::kNetworkTechnologyProperty, |
| 65 technology()); |
| 66 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
| 67 device_path()); |
| 68 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid()); |
| 69 } |
| 70 |
| 46 bool NetworkState::IsConnectedState() const { | 71 bool NetworkState::IsConnectedState() const { |
| 47 return StateIsConnected(connection_state_); | 72 return StateIsConnected(connection_state_); |
| 48 } | 73 } |
| 49 | 74 |
| 50 bool NetworkState::IsConnectingState() const { | 75 bool NetworkState::IsConnectingState() const { |
| 51 return StateIsConnecting(connection_state_); | 76 return StateIsConnecting(connection_state_); |
| 52 } | 77 } |
| 53 | 78 |
| 54 // static | 79 // static |
| 55 bool NetworkState::StateIsConnected(const std::string& connection_state) { | 80 bool NetworkState::StateIsConnected(const std::string& connection_state) { |
| 56 return (connection_state == flimflam::kStateReady || | 81 return (connection_state == flimflam::kStateReady || |
| 57 connection_state == flimflam::kStateOnline || | 82 connection_state == flimflam::kStateOnline || |
| 58 connection_state == flimflam::kStatePortal); | 83 connection_state == flimflam::kStatePortal); |
| 59 } | 84 } |
| 60 | 85 |
| 61 // static | 86 // static |
| 62 bool NetworkState::StateIsConnecting(const std::string& connection_state) { | 87 bool NetworkState::StateIsConnecting(const std::string& connection_state) { |
| 63 return (connection_state == flimflam::kStateAssociation || | 88 return (connection_state == flimflam::kStateAssociation || |
| 64 connection_state == flimflam::kStateConfiguration || | 89 connection_state == flimflam::kStateConfiguration || |
| 65 connection_state == flimflam::kStateCarrier); | 90 connection_state == flimflam::kStateCarrier); |
| 66 } | 91 } |
| 67 | 92 |
| 68 } // namespace chromeos | 93 } // namespace chromeos |
| OLD | NEW |