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/i18n/icu_encoding_detection.h" | 7 #include "base/i18n/icu_encoding_detection.h" |
8 #include "base/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversion_utils.h" | 12 #include "base/strings/utf_string_conversion_utils.h" |
13 #include "base/values.h" | |
14 #include "chromeos/network/network_event_log.h" | 13 #include "chromeos/network/network_event_log.h" |
| 14 #include "chromeos/network/onc/onc_utils.h" |
15 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 19 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
20 std::vector<std::string>* result) { | 20 std::vector<std::string>* result) { |
21 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 21 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
22 std::string str; | 22 std::string str; |
23 if (!string_list.GetString(i, &str)) | 23 if (!string_list.GetString(i, &str)) |
24 return false; | 24 return false; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 return GetBooleanValue(key, value, &connectable_); | 79 return GetBooleanValue(key, value, &connectable_); |
80 } else if (key == flimflam::kPassphraseRequiredProperty) { | 80 } else if (key == flimflam::kPassphraseRequiredProperty) { |
81 return GetBooleanValue(key, value, &passphrase_required_); | 81 return GetBooleanValue(key, value, &passphrase_required_); |
82 } else if (key == flimflam::kErrorProperty) { | 82 } else if (key == flimflam::kErrorProperty) { |
83 return GetStringValue(key, value, &error_); | 83 return GetStringValue(key, value, &error_); |
84 } else if (key == IPConfigProperty(flimflam::kAddressProperty)) { | 84 } else if (key == IPConfigProperty(flimflam::kAddressProperty)) { |
85 return GetStringValue(key, value, &ip_address_); | 85 return GetStringValue(key, value, &ip_address_); |
86 } else if (key == IPConfigProperty(flimflam::kNameServersProperty)) { | 86 } else if (key == IPConfigProperty(flimflam::kNameServersProperty)) { |
87 dns_servers_.clear(); | 87 dns_servers_.clear(); |
88 const base::ListValue* dns_servers; | 88 const base::ListValue* dns_servers; |
89 if (value.GetAsList(&dns_servers) && | 89 if (value.GetAsList(&dns_servers)) |
90 ConvertListValueToStringVector(*dns_servers, &dns_servers_)) | 90 ConvertListValueToStringVector(*dns_servers, &dns_servers_); |
91 return true; | 91 return true; |
92 } else if (key == flimflam::kActivationStateProperty) { | 92 } else if (key == flimflam::kActivationStateProperty) { |
93 return GetStringValue(key, value, &activation_state_); | 93 return GetStringValue(key, value, &activation_state_); |
94 } else if (key == flimflam::kRoamingStateProperty) { | 94 } else if (key == flimflam::kRoamingStateProperty) { |
95 return GetStringValue(key, value, &roaming_); | 95 return GetStringValue(key, value, &roaming_); |
96 } else if (key == flimflam::kSecurityProperty) { | 96 } else if (key == flimflam::kSecurityProperty) { |
97 return GetStringValue(key, value, &security_); | 97 return GetStringValue(key, value, &security_); |
98 } else if (key == flimflam::kAutoConnectProperty) { | 98 } else if (key == flimflam::kAutoConnectProperty) { |
99 return GetBooleanValue(key, value, &auto_connect_); | 99 return GetBooleanValue(key, value, &auto_connect_); |
100 } else if (key == flimflam::kFavoriteProperty) { | 100 } else if (key == flimflam::kFavoriteProperty) { |
101 return GetBooleanValue(key, value, &favorite_); | 101 return GetBooleanValue(key, value, &favorite_); |
102 } else if (key == flimflam::kPriorityProperty) { | 102 } else if (key == flimflam::kPriorityProperty) { |
103 return GetIntegerValue(key, value, &priority_); | 103 return GetIntegerValue(key, value, &priority_); |
| 104 } else if (key == flimflam::kProxyConfigProperty) { |
| 105 std::string proxy_config_str; |
| 106 if (!value.GetAsString(&proxy_config_str)) { |
| 107 LOG(WARNING) << "Failed to parse string value for:" << key; |
| 108 return false; |
| 109 } |
| 110 |
| 111 proxy_config_.Clear(); |
| 112 if (proxy_config_str.empty()) |
| 113 return true; |
| 114 |
| 115 scoped_ptr<base::DictionaryValue> proxy_config_dict( |
| 116 onc::ReadDictionaryFromJson(proxy_config_str)); |
| 117 if (proxy_config_dict) |
| 118 proxy_config_.Swap(proxy_config_dict.get()); |
| 119 else |
| 120 LOG(WARNING) << "Failed to parse dictionary value for: " << key; |
| 121 return true; |
104 } else if (key == flimflam::kNetworkTechnologyProperty) { | 122 } else if (key == flimflam::kNetworkTechnologyProperty) { |
105 return GetStringValue(key, value, &technology_); | 123 return GetStringValue(key, value, &technology_); |
106 } else if (key == flimflam::kDeviceProperty) { | 124 } else if (key == flimflam::kDeviceProperty) { |
107 return GetStringValue(key, value, &device_path_); | 125 return GetStringValue(key, value, &device_path_); |
108 } else if (key == flimflam::kGuidProperty) { | 126 } else if (key == flimflam::kGuidProperty) { |
109 return GetStringValue(key, value, &guid_); | 127 return GetStringValue(key, value, &guid_); |
110 } else if (key == flimflam::kProfileProperty) { | 128 } else if (key == flimflam::kProfileProperty) { |
111 return GetStringValue(key, value, &profile_path_); | 129 return GetStringValue(key, value, &profile_path_); |
112 } else if (key == flimflam::kProxyConfigProperty) { | |
113 return GetStringValue(key, value, &proxy_config_); | |
114 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { | 130 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { |
115 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); | 131 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); |
116 } else if (key == shill::kOutOfCreditsProperty) { | 132 } else if (key == shill::kOutOfCreditsProperty) { |
117 return GetBooleanValue(key, value, &cellular_out_of_credits_); | 133 return GetBooleanValue(key, value, &cellular_out_of_credits_); |
118 } else if (key == flimflam::kWifiHexSsid) { | 134 } else if (key == flimflam::kWifiHexSsid) { |
119 return GetStringValue(key, value, &hex_ssid_); | 135 return GetStringValue(key, value, &hex_ssid_); |
120 } else if (key == flimflam::kCountryProperty) { | 136 } else if (key == flimflam::kCountryProperty) { |
121 // TODO(stevenjb): This is currently experimental. If we find a case where | 137 // TODO(stevenjb): This is currently experimental. If we find a case where |
122 // base::DetectEncoding() fails in UpdateName(), where country_code_ is | 138 // base::DetectEncoding() fails in UpdateName(), where country_code_ is |
123 // set, figure out whether we can use country_code_ with ConvertToUtf8(). | 139 // set, figure out whether we can use country_code_ with ConvertToUtf8(). |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, | 176 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, |
161 roaming_); | 177 roaming_); |
162 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, | 178 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, |
163 security_); | 179 security_); |
164 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, | 180 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, |
165 auto_connect_); | 181 auto_connect_); |
166 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, | 182 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, |
167 favorite_); | 183 favorite_); |
168 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, | 184 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, |
169 priority_); | 185 priority_); |
| 186 // Proxy config is intentionally omitted: This property is |
| 187 // placed in NetworkState to transition proxy configuration from |
| 188 // NetworkLibrary to the new network stack. The networking extension API |
| 189 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler |
| 190 // is used instead of NetworkLibrary, we can remove them again. |
170 dictionary->SetStringWithoutPathExpansion( | 191 dictionary->SetStringWithoutPathExpansion( |
171 flimflam::kNetworkTechnologyProperty, | 192 flimflam::kNetworkTechnologyProperty, |
172 technology_); | 193 technology_); |
173 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, | 194 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
174 device_path_); | 195 device_path_); |
175 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); | 196 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); |
176 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, | 197 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, |
177 profile_path_); | 198 profile_path_); |
178 dictionary->SetStringWithoutPathExpansion(flimflam::kProxyConfigProperty, | |
179 proxy_config_); | |
180 dictionary->SetBooleanWithoutPathExpansion( | 199 dictionary->SetBooleanWithoutPathExpansion( |
181 shill::kActivateOverNonCellularNetworkProperty, | 200 shill::kActivateOverNonCellularNetworkProperty, |
182 activate_over_non_cellular_networks_); | 201 activate_over_non_cellular_networks_); |
183 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, | 202 dictionary->SetBooleanWithoutPathExpansion(shill::kOutOfCreditsProperty, |
184 cellular_out_of_credits_); | 203 cellular_out_of_credits_); |
185 } | 204 } |
186 | 205 |
187 bool NetworkState::IsConnectedState() const { | 206 bool NetworkState::IsConnectedState() const { |
188 return StateIsConnected(connection_state_); | 207 return StateIsConnected(connection_state_); |
189 } | 208 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 connection_state == flimflam::kStateConfiguration || | 292 connection_state == flimflam::kStateConfiguration || |
274 connection_state == flimflam::kStateCarrier); | 293 connection_state == flimflam::kStateCarrier); |
275 } | 294 } |
276 | 295 |
277 // static | 296 // static |
278 std::string NetworkState::IPConfigProperty(const char* key) { | 297 std::string NetworkState::IPConfigProperty(const char* key) { |
279 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | 298 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
280 } | 299 } |
281 | 300 |
282 } // namespace chromeos | 301 } // namespace chromeos |
OLD | NEW |