Chromium Code Reviews| 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 { | |
| 11 | |
| 12 // Helper to convert a ListValue of strings into a comma separated string. | |
| 13 bool ConvertListValueToString(const base::ListValue& string_list, | |
|
pneubeck (no reviews)
2013/03/28 10:37:54
You can use this one (move it to base/value_conver
gauravsh
2013/03/28 18:48:54
I don't think this is general and universal enough
stevenjb
2013/03/28 19:27:13
I tend to agree that this shouldn't be generalized
| |
| 14 std::string* result) { | |
| 15 for (size_t i = 0; i < string_list.GetSize(); ++i) { | |
| 16 std::string name_server; | |
| 17 if (!string_list.GetString(i, &name_server)) | |
| 18 return false; | |
| 19 if (!result->empty()) | |
| 20 *result += ","; | |
| 21 result->append(name_server); | |
| 22 } | |
| 23 return true; | |
| 24 } | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 10 namespace chromeos { | 28 namespace chromeos { |
| 11 | 29 |
| 12 NetworkState::NetworkState(const std::string& path) | 30 NetworkState::NetworkState(const std::string& path) |
| 13 : ManagedState(MANAGED_TYPE_NETWORK, path), | 31 : ManagedState(MANAGED_TYPE_NETWORK, path), |
| 14 signal_strength_(0) { | 32 signal_strength_(0) { |
| 15 } | 33 } |
| 16 | 34 |
| 17 NetworkState::~NetworkState() { | 35 NetworkState::~NetworkState() { |
| 18 } | 36 } |
| 19 | 37 |
| 20 bool NetworkState::PropertyChanged(const std::string& key, | 38 bool NetworkState::PropertyChanged(const std::string& key, |
| 21 const base::Value& value) { | 39 const base::Value& value) { |
| 22 // Keep care that these properties are the same as in |GetProperties|. | 40 // Keep care that these properties are the same as in |GetProperties|. |
| 23 if (ManagedStatePropertyChanged(key, value)) | 41 if (ManagedStatePropertyChanged(key, value)) |
| 24 return true; | 42 return true; |
| 25 if (key == flimflam::kSignalStrengthProperty) { | 43 if (key == flimflam::kSignalStrengthProperty) { |
| 26 return GetIntegerValue(key, value, &signal_strength_); | 44 return GetIntegerValue(key, value, &signal_strength_); |
| 27 } else if (key == flimflam::kStateProperty) { | 45 } else if (key == flimflam::kStateProperty) { |
| 28 return GetStringValue(key, value, &connection_state_); | 46 return GetStringValue(key, value, &connection_state_); |
| 29 } else if (key == flimflam::kErrorProperty) { | 47 } else if (key == flimflam::kErrorProperty) { |
| 30 return GetStringValue(key, value, &error_); | 48 return GetStringValue(key, value, &error_); |
| 49 } else if (key == flimflam::kAddressProperty) { | |
| 50 return GetStringValue(key, value, &ip_address_); | |
| 51 } else if (key == flimflam::kNameServersProperty) { | |
| 52 const base::ListValue* dns_list; | |
| 53 if (value.GetAsList(&dns_list) && | |
| 54 ConvertListValueToString(*dns_list, &dns_servers_)) | |
| 55 return true; | |
| 31 } else if (key == flimflam::kActivationStateProperty) { | 56 } else if (key == flimflam::kActivationStateProperty) { |
| 32 return GetStringValue(key, value, &activation_state_); | 57 return GetStringValue(key, value, &activation_state_); |
| 33 } else if (key == flimflam::kRoamingStateProperty) { | 58 } else if (key == flimflam::kRoamingStateProperty) { |
| 34 return GetStringValue(key, value, &roaming_); | 59 return GetStringValue(key, value, &roaming_); |
| 35 } else if (key == flimflam::kSecurityProperty) { | 60 } else if (key == flimflam::kSecurityProperty) { |
| 36 return GetStringValue(key, value, &security_); | 61 return GetStringValue(key, value, &security_); |
| 37 } else if (key == flimflam::kNetworkTechnologyProperty) { | 62 } else if (key == flimflam::kNetworkTechnologyProperty) { |
| 38 return GetStringValue(key, value, &technology_); | 63 return GetStringValue(key, value, &technology_); |
| 39 } else if (key == flimflam::kDeviceProperty) { | 64 } else if (key == flimflam::kDeviceProperty) { |
| 40 return GetStringValue(key, value, &device_path_); | 65 return GetStringValue(key, value, &device_path_); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 51 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { | 76 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { |
| 52 // Keep care that these properties are the same as in |PropertyChanged|. | 77 // Keep care that these properties are the same as in |PropertyChanged|. |
| 53 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); | 78 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); |
| 54 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); | 79 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); |
| 55 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, | 80 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, |
| 56 signal_strength()); | 81 signal_strength()); |
| 57 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, | 82 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, |
| 58 connection_state()); | 83 connection_state()); |
| 59 dictionary->SetStringWithoutPathExpansion(flimflam::kErrorProperty, | 84 dictionary->SetStringWithoutPathExpansion(flimflam::kErrorProperty, |
| 60 error()); | 85 error()); |
| 86 dictionary->SetStringWithoutPathExpansion(flimflam::kAddressProperty, | |
|
pneubeck (no reviews)
2013/03/28 10:37:54
Create a nested IPConfig (shill::kIPConfigProperty
gauravsh
2013/03/28 18:48:54
Wouldn't that be confusing - this isn't the comple
stevenjb
2013/03/28 19:27:13
For now I think that keeping them separate is fine
| |
| 87 ip_address()); | |
| 88 dictionary->SetStringWithoutPathExpansion(flimflam::kNameServersProperty, | |
| 89 dns_servers()); | |
| 61 dictionary->SetStringWithoutPathExpansion(flimflam::kActivationStateProperty, | 90 dictionary->SetStringWithoutPathExpansion(flimflam::kActivationStateProperty, |
| 62 activation_state()); | 91 activation_state()); |
| 63 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, | 92 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, |
| 64 roaming()); | 93 roaming()); |
| 65 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, | 94 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, |
| 66 security()); | 95 security()); |
| 67 dictionary->SetStringWithoutPathExpansion( | 96 dictionary->SetStringWithoutPathExpansion( |
| 68 flimflam::kNetworkTechnologyProperty, | 97 flimflam::kNetworkTechnologyProperty, |
| 69 technology()); | 98 technology()); |
| 70 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, | 99 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 93 } | 122 } |
| 94 | 123 |
| 95 // static | 124 // static |
| 96 bool NetworkState::StateIsConnecting(const std::string& connection_state) { | 125 bool NetworkState::StateIsConnecting(const std::string& connection_state) { |
| 97 return (connection_state == flimflam::kStateAssociation || | 126 return (connection_state == flimflam::kStateAssociation || |
| 98 connection_state == flimflam::kStateConfiguration || | 127 connection_state == flimflam::kStateConfiguration || |
| 99 connection_state == flimflam::kStateCarrier); | 128 connection_state == flimflam::kStateCarrier); |
| 100 } | 129 } |
| 101 | 130 |
| 102 } // namespace chromeos | 131 } // namespace chromeos |
| OLD | NEW |