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