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/stringprintf.h" |
7 #include "base/values.h" | 8 #include "base/values.h" |
8 #include "third_party/cros_system_api/dbus/service_constants.h" | 9 #include "third_party/cros_system_api/dbus/service_constants.h" |
9 | 10 |
| 11 namespace { |
| 12 |
| 13 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
| 14 std::vector<std::string>* result) { |
| 15 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
| 16 std::string str; |
| 17 if (!string_list.GetString(i, &str)) |
| 18 return false; |
| 19 result->push_back(str); |
| 20 } |
| 21 return true; |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
10 namespace chromeos { | 26 namespace chromeos { |
11 | 27 |
12 NetworkState::NetworkState(const std::string& path) | 28 NetworkState::NetworkState(const std::string& path) |
13 : ManagedState(MANAGED_TYPE_NETWORK, path), | 29 : ManagedState(MANAGED_TYPE_NETWORK, path), |
14 auto_connect_(false), | 30 auto_connect_(false), |
15 favorite_(false), | 31 favorite_(false), |
16 priority_(0), | 32 priority_(0), |
17 signal_strength_(0), | 33 signal_strength_(0), |
18 activate_over_non_cellular_networks_(false), | 34 activate_over_non_cellular_networks_(false), |
19 cellular_out_of_credits_(false) { | 35 cellular_out_of_credits_(false) { |
20 } | 36 } |
21 | 37 |
22 NetworkState::~NetworkState() { | 38 NetworkState::~NetworkState() { |
23 } | 39 } |
24 | 40 |
25 bool NetworkState::PropertyChanged(const std::string& key, | 41 bool NetworkState::PropertyChanged(const std::string& key, |
26 const base::Value& value) { | 42 const base::Value& value) { |
27 // Keep care that these properties are the same as in |GetProperties|. | 43 // Keep care that these properties are the same as in |GetProperties|. |
28 if (ManagedStatePropertyChanged(key, value)) | 44 if (ManagedStatePropertyChanged(key, value)) |
29 return true; | 45 return true; |
30 if (key == flimflam::kSignalStrengthProperty) { | 46 if (key == flimflam::kSignalStrengthProperty) { |
31 return GetIntegerValue(key, value, &signal_strength_); | 47 return GetIntegerValue(key, value, &signal_strength_); |
32 } else if (key == flimflam::kStateProperty) { | 48 } else if (key == flimflam::kStateProperty) { |
33 return GetStringValue(key, value, &connection_state_); | 49 return GetStringValue(key, value, &connection_state_); |
34 } else if (key == flimflam::kErrorProperty) { | 50 } else if (key == flimflam::kErrorProperty) { |
35 return GetStringValue(key, value, &error_); | 51 return GetStringValue(key, value, &error_); |
| 52 } else if (key == IPConfigProperty(flimflam::kAddressProperty)) { |
| 53 return GetStringValue(key, value, &ip_address_); |
| 54 } else if (key == IPConfigProperty(flimflam::kNameServersProperty)) { |
| 55 dns_servers_.clear(); |
| 56 const base::ListValue* dns_servers; |
| 57 if (value.GetAsList(&dns_servers) && |
| 58 ConvertListValueToStringVector(*dns_servers, &dns_servers_)) |
| 59 return true; |
36 } else if (key == flimflam::kActivationStateProperty) { | 60 } else if (key == flimflam::kActivationStateProperty) { |
37 return GetStringValue(key, value, &activation_state_); | 61 return GetStringValue(key, value, &activation_state_); |
38 } else if (key == flimflam::kRoamingStateProperty) { | 62 } else if (key == flimflam::kRoamingStateProperty) { |
39 return GetStringValue(key, value, &roaming_); | 63 return GetStringValue(key, value, &roaming_); |
40 } else if (key == flimflam::kSecurityProperty) { | 64 } else if (key == flimflam::kSecurityProperty) { |
41 return GetStringValue(key, value, &security_); | 65 return GetStringValue(key, value, &security_); |
42 } else if (key == flimflam::kAutoConnectProperty) { | 66 } else if (key == flimflam::kAutoConnectProperty) { |
43 return GetBooleanValue(key, value, &auto_connect_); | 67 return GetBooleanValue(key, value, &auto_connect_); |
44 } else if (key == flimflam::kFavoriteProperty) { | 68 } else if (key == flimflam::kFavoriteProperty) { |
45 return GetBooleanValue(key, value, &favorite_); | 69 return GetBooleanValue(key, value, &favorite_); |
(...skipping 16 matching lines...) Expand all Loading... |
62 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { | 86 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { |
63 // Keep care that these properties are the same as in |PropertyChanged|. | 87 // Keep care that these properties are the same as in |PropertyChanged|. |
64 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); | 88 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); |
65 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); | 89 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); |
66 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, | 90 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, |
67 signal_strength()); | 91 signal_strength()); |
68 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, | 92 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, |
69 connection_state()); | 93 connection_state()); |
70 dictionary->SetStringWithoutPathExpansion(flimflam::kErrorProperty, | 94 dictionary->SetStringWithoutPathExpansion(flimflam::kErrorProperty, |
71 error()); | 95 error()); |
| 96 base::DictionaryValue* ipconfig_properties = new DictionaryValue; |
| 97 ipconfig_properties->SetStringWithoutPathExpansion(flimflam::kAddressProperty, |
| 98 ip_address()); |
| 99 base::ListValue* name_servers = new ListValue; |
| 100 name_servers->AppendStrings(dns_servers()); |
| 101 ipconfig_properties->SetWithoutPathExpansion(flimflam::kNameServersProperty, |
| 102 name_servers); |
| 103 dictionary->SetWithoutPathExpansion(shill::kIPConfigProperty, |
| 104 ipconfig_properties); |
| 105 |
72 dictionary->SetStringWithoutPathExpansion(flimflam::kActivationStateProperty, | 106 dictionary->SetStringWithoutPathExpansion(flimflam::kActivationStateProperty, |
73 activation_state()); | 107 activation_state()); |
74 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, | 108 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, |
75 roaming()); | 109 roaming()); |
76 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, | 110 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, |
77 security()); | 111 security()); |
78 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, | 112 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, |
79 auto_connect()); | 113 auto_connect()); |
80 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, | 114 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, |
81 favorite()); | 115 favorite()); |
(...skipping 27 matching lines...) Expand all Loading... |
109 connection_state == flimflam::kStatePortal); | 143 connection_state == flimflam::kStatePortal); |
110 } | 144 } |
111 | 145 |
112 // static | 146 // static |
113 bool NetworkState::StateIsConnecting(const std::string& connection_state) { | 147 bool NetworkState::StateIsConnecting(const std::string& connection_state) { |
114 return (connection_state == flimflam::kStateAssociation || | 148 return (connection_state == flimflam::kStateAssociation || |
115 connection_state == flimflam::kStateConfiguration || | 149 connection_state == flimflam::kStateConfiguration || |
116 connection_state == flimflam::kStateCarrier); | 150 connection_state == flimflam::kStateCarrier); |
117 } | 151 } |
118 | 152 |
| 153 // static |
| 154 std::string NetworkState::IPConfigProperty(const char* key) { |
| 155 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
| 156 } |
| 157 |
119 } // namespace chromeos | 158 } // namespace chromeos |
OLD | NEW |