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/json/json_writer.h" | |
9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversion_utils.h" | 13 #include "base/strings/utf_string_conversion_utils.h" |
13 #include "chromeos/network/network_event_log.h" | 14 #include "chromeos/network/network_event_log.h" |
14 #include "chromeos/network/network_ui_data.h" | 15 #include "chromeos/network/network_ui_data.h" |
15 #include "chromeos/network/onc/onc_utils.h" | 16 #include "chromeos/network/onc/onc_utils.h" |
16 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
17 | 18 |
19 // TODO(stevenjb): Use flimflam:: property when defined in service_constants.h | |
20 const char kWifiFrequencyListProperty[] = "WiFi.FrequencyList"; | |
stevenjb
2013/06/20 20:19:30
This will be removed before comitting
| |
21 | |
18 namespace { | 22 namespace { |
19 | 23 |
20 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 24 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
21 std::vector<std::string>* result) { | 25 std::vector<std::string>* result) { |
22 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 26 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
23 std::string str; | 27 std::string str; |
24 if (!string_list.GetString(i, &str)) | 28 if (!string_list.GetString(i, &str)) |
25 return false; | 29 return false; |
26 result->push_back(str); | 30 result->push_back(str); |
27 } | 31 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 if (ManagedStatePropertyChanged(key, value)) | 78 if (ManagedStatePropertyChanged(key, value)) |
75 return true; | 79 return true; |
76 if (key == flimflam::kSignalStrengthProperty) { | 80 if (key == flimflam::kSignalStrengthProperty) { |
77 return GetIntegerValue(key, value, &signal_strength_); | 81 return GetIntegerValue(key, value, &signal_strength_); |
78 } else if (key == flimflam::kStateProperty) { | 82 } else if (key == flimflam::kStateProperty) { |
79 return GetStringValue(key, value, &connection_state_); | 83 return GetStringValue(key, value, &connection_state_); |
80 } else if (key == flimflam::kConnectableProperty) { | 84 } else if (key == flimflam::kConnectableProperty) { |
81 return GetBooleanValue(key, value, &connectable_); | 85 return GetBooleanValue(key, value, &connectable_); |
82 } else if (key == flimflam::kPassphraseRequiredProperty) { | 86 } else if (key == flimflam::kPassphraseRequiredProperty) { |
83 return GetBooleanValue(key, value, &passphrase_required_); | 87 return GetBooleanValue(key, value, &passphrase_required_); |
88 } else if (key == kWifiFrequencyListProperty) { | |
89 const base::ListValue* frequencies; | |
90 if (!value.GetAsList(&frequencies)) { | |
91 NET_LOG_ERROR("Failed to parse " + key, path()); | |
92 return false; | |
93 } | |
94 wifi_frequencies_.clear(); | |
95 for (base::ListValue::const_iterator iter = frequencies->begin(); | |
96 iter != frequencies->end(); ++iter) { | |
97 int frequency; | |
98 if ((*iter)->GetAsInteger(&frequency)) | |
99 wifi_frequencies_.push_back(frequency); | |
100 } | |
101 if (!wifi_frequencies_.empty()) { | |
102 std::string str; | |
103 base::JSONWriter::Write(frequencies, &str); | |
104 NET_LOG_DEBUG("WifiFrequencies for " + path(), str); | |
105 } | |
84 } else if (key == flimflam::kErrorProperty) { | 106 } else if (key == flimflam::kErrorProperty) { |
85 return GetStringValue(key, value, &error_); | 107 return GetStringValue(key, value, &error_); |
86 } else if (key == shill::kErrorDetailsProperty) { | 108 } else if (key == shill::kErrorDetailsProperty) { |
87 return GetStringValue(key, value, &error_details_); | 109 return GetStringValue(key, value, &error_details_); |
88 } else if (key == IPConfigProperty(flimflam::kAddressProperty)) { | 110 } else if (key == IPConfigProperty(flimflam::kAddressProperty)) { |
89 return GetStringValue(key, value, &ip_address_); | 111 return GetStringValue(key, value, &ip_address_); |
90 } else if (key == IPConfigProperty(flimflam::kNameServersProperty)) { | 112 } else if (key == IPConfigProperty(flimflam::kNameServersProperty)) { |
91 dns_servers_.clear(); | 113 dns_servers_.clear(); |
92 const base::ListValue* dns_servers; | 114 const base::ListValue* dns_servers; |
93 if (value.GetAsList(&dns_servers)) | 115 if (value.GetAsList(&dns_servers)) |
94 ConvertListValueToStringVector(*dns_servers, &dns_servers_); | 116 ConvertListValueToStringVector(*dns_servers, &dns_servers_); |
95 return true; | 117 return true; |
96 } else if (key == flimflam::kActivationStateProperty) { | 118 } else if (key == flimflam::kActivationStateProperty) { |
97 return GetStringValue(key, value, &activation_state_); | 119 return GetStringValue(key, value, &activation_state_); |
98 } else if (key == flimflam::kRoamingStateProperty) { | 120 } else if (key == flimflam::kRoamingStateProperty) { |
99 return GetStringValue(key, value, &roaming_); | 121 return GetStringValue(key, value, &roaming_); |
100 } else if (key == flimflam::kSecurityProperty) { | 122 } else if (key == flimflam::kSecurityProperty) { |
101 return GetStringValue(key, value, &security_); | 123 return GetStringValue(key, value, &security_); |
102 } else if (key == flimflam::kAutoConnectProperty) { | 124 } else if (key == flimflam::kAutoConnectProperty) { |
103 return GetBooleanValue(key, value, &auto_connect_); | 125 return GetBooleanValue(key, value, &auto_connect_); |
104 } else if (key == flimflam::kFavoriteProperty) { | 126 } else if (key == flimflam::kFavoriteProperty) { |
105 return GetBooleanValue(key, value, &favorite_); | 127 return GetBooleanValue(key, value, &favorite_); |
106 } else if (key == flimflam::kPriorityProperty) { | 128 } else if (key == flimflam::kPriorityProperty) { |
107 return GetIntegerValue(key, value, &priority_); | 129 return GetIntegerValue(key, value, &priority_); |
108 } else if (key == flimflam::kProxyConfigProperty) { | 130 } else if (key == flimflam::kProxyConfigProperty) { |
109 std::string proxy_config_str; | 131 std::string proxy_config_str; |
110 if (!value.GetAsString(&proxy_config_str)) { | 132 if (!value.GetAsString(&proxy_config_str)) { |
111 LOG(WARNING) << "Failed to parse string value for:" << key; | 133 NET_LOG_ERROR("Failed to parse " + key, path()); |
112 return false; | 134 return false; |
113 } | 135 } |
114 | 136 |
115 proxy_config_.Clear(); | 137 proxy_config_.Clear(); |
116 if (proxy_config_str.empty()) | 138 if (proxy_config_str.empty()) |
117 return true; | 139 return true; |
118 | 140 |
119 scoped_ptr<base::DictionaryValue> proxy_config_dict( | 141 scoped_ptr<base::DictionaryValue> proxy_config_dict( |
120 onc::ReadDictionaryFromJson(proxy_config_str)); | 142 onc::ReadDictionaryFromJson(proxy_config_str)); |
121 if (proxy_config_dict) { | 143 if (proxy_config_dict) { |
122 // Warning: The DictionaryValue returned from | 144 // Warning: The DictionaryValue returned from |
123 // ReadDictionaryFromJson/JSONParser is an optimized derived class that | 145 // ReadDictionaryFromJson/JSONParser is an optimized derived class that |
124 // doesn't allow releasing ownership of nested values. A Swap in the wrong | 146 // doesn't allow releasing ownership of nested values. A Swap in the wrong |
125 // order leads to memory access errors. | 147 // order leads to memory access errors. |
126 proxy_config_.MergeDictionary(proxy_config_dict.get()); | 148 proxy_config_.MergeDictionary(proxy_config_dict.get()); |
127 } else { | 149 } else { |
128 LOG(WARNING) << "Failed to parse dictionary value for: " << key; | 150 NET_LOG_ERROR("Failed to parse " + key, path()); |
129 } | 151 } |
130 return true; | 152 return true; |
131 } else if (key == flimflam::kUIDataProperty) { | 153 } else if (key == flimflam::kUIDataProperty) { |
132 std::string ui_data_str; | 154 std::string ui_data_str; |
133 if (!value.GetAsString(&ui_data_str)) { | 155 if (!value.GetAsString(&ui_data_str)) { |
134 LOG(WARNING) << "Failed to parse string value for:" << key; | 156 NET_LOG_ERROR("Failed to parse " + key, path()); |
135 return false; | 157 return false; |
136 } | 158 } |
137 | 159 |
138 onc_source_ = onc::ONC_SOURCE_NONE; | 160 onc_source_ = onc::ONC_SOURCE_NONE; |
139 if (ui_data_str.empty()) | 161 if (ui_data_str.empty()) |
140 return true; | 162 return true; |
141 | 163 |
142 scoped_ptr<base::DictionaryValue> ui_data_dict( | 164 scoped_ptr<base::DictionaryValue> ui_data_dict( |
143 onc::ReadDictionaryFromJson(ui_data_str)); | 165 onc::ReadDictionaryFromJson(ui_data_str)); |
144 if (ui_data_dict) | 166 if (ui_data_dict) |
145 onc_source_ = NetworkUIData(*ui_data_dict).onc_source(); | 167 onc_source_ = NetworkUIData(*ui_data_dict).onc_source(); |
146 else | 168 else |
147 LOG(WARNING) << "Failed to parse dictionary value for: " << key; | 169 NET_LOG_ERROR("Failed to parse " + key, path()); |
148 return true; | 170 return true; |
149 } else if (key == flimflam::kNetworkTechnologyProperty) { | 171 } else if (key == flimflam::kNetworkTechnologyProperty) { |
150 return GetStringValue(key, value, &technology_); | 172 return GetStringValue(key, value, &technology_); |
151 } else if (key == flimflam::kDeviceProperty) { | 173 } else if (key == flimflam::kDeviceProperty) { |
152 return GetStringValue(key, value, &device_path_); | 174 return GetStringValue(key, value, &device_path_); |
153 } else if (key == flimflam::kGuidProperty) { | 175 } else if (key == flimflam::kGuidProperty) { |
154 return GetStringValue(key, value, &guid_); | 176 return GetStringValue(key, value, &guid_); |
155 } else if (key == flimflam::kProfileProperty) { | 177 } else if (key == flimflam::kProfileProperty) { |
156 return GetStringValue(key, value, &profile_path_); | 178 return GetStringValue(key, value, &profile_path_); |
157 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { | 179 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { |
(...skipping 21 matching lines...) Expand all Loading... | |
179 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); | 201 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); |
180 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); | 202 dictionary->SetStringWithoutPathExpansion(flimflam::kTypeProperty, type()); |
181 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, | 203 dictionary->SetIntegerWithoutPathExpansion(flimflam::kSignalStrengthProperty, |
182 signal_strength_); | 204 signal_strength_); |
183 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, | 205 dictionary->SetStringWithoutPathExpansion(flimflam::kStateProperty, |
184 connection_state_); | 206 connection_state_); |
185 dictionary->SetBooleanWithoutPathExpansion(flimflam::kConnectableProperty, | 207 dictionary->SetBooleanWithoutPathExpansion(flimflam::kConnectableProperty, |
186 connectable_); | 208 connectable_); |
187 dictionary->SetBooleanWithoutPathExpansion( | 209 dictionary->SetBooleanWithoutPathExpansion( |
188 flimflam::kPassphraseRequiredProperty, passphrase_required_); | 210 flimflam::kPassphraseRequiredProperty, passphrase_required_); |
211 | |
212 base::ListValue* frequencies = new base::ListValue; | |
213 for (FrequencyList::const_iterator iter = wifi_frequencies_.begin(); | |
214 iter != wifi_frequencies_.end(); ++iter) { | |
215 frequencies->AppendInteger(*iter); | |
216 } | |
217 dictionary->SetWithoutPathExpansion(kWifiFrequencyListProperty, frequencies); | |
218 | |
189 dictionary->SetStringWithoutPathExpansion(flimflam::kErrorProperty, | 219 dictionary->SetStringWithoutPathExpansion(flimflam::kErrorProperty, |
190 error_); | 220 error_); |
191 dictionary->SetStringWithoutPathExpansion(shill::kErrorDetailsProperty, | 221 dictionary->SetStringWithoutPathExpansion(shill::kErrorDetailsProperty, |
192 error_details_); | 222 error_details_); |
193 base::DictionaryValue* ipconfig_properties = new DictionaryValue; | 223 base::DictionaryValue* ipconfig_properties = new DictionaryValue; |
194 ipconfig_properties->SetStringWithoutPathExpansion(flimflam::kAddressProperty, | 224 ipconfig_properties->SetStringWithoutPathExpansion(flimflam::kAddressProperty, |
195 ip_address_); | 225 ip_address_); |
196 base::ListValue* name_servers = new ListValue; | 226 base::ListValue* name_servers = new ListValue; |
197 name_servers->AppendStrings(dns_servers_); | 227 name_servers->AppendStrings(dns_servers_); |
198 ipconfig_properties->SetWithoutPathExpansion(flimflam::kNameServersProperty, | 228 ipconfig_properties->SetWithoutPathExpansion(flimflam::kNameServersProperty, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 connection_state == flimflam::kStateConfiguration || | 360 connection_state == flimflam::kStateConfiguration || |
331 connection_state == flimflam::kStateCarrier); | 361 connection_state == flimflam::kStateCarrier); |
332 } | 362 } |
333 | 363 |
334 // static | 364 // static |
335 std::string NetworkState::IPConfigProperty(const char* key) { | 365 std::string NetworkState::IPConfigProperty(const char* key) { |
336 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | 366 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
337 } | 367 } |
338 | 368 |
339 } // namespace chromeos | 369 } // namespace chromeos |
OLD | NEW |