| 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" | 13 #include "base/values.h" |
| 14 #include "chromeos/network/network_event_log.h" | 14 #include "chromeos/network/network_event_log.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 const char kLogModule[] = "NetworkState"; | |
| 20 | |
| 21 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 19 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
| 22 std::vector<std::string>* result) { | 20 std::vector<std::string>* result) { |
| 23 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 21 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
| 24 std::string str; | 22 std::string str; |
| 25 if (!string_list.GetString(i, &str)) | 23 if (!string_list.GetString(i, &str)) |
| 26 return false; | 24 return false; |
| 27 result->push_back(str); | 25 result->push_back(str); |
| 28 } | 26 } |
| 29 return true; | 27 return true; |
| 30 } | 28 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 bool NetworkState::IsConnectingState() const { | 187 bool NetworkState::IsConnectingState() const { |
| 190 return StateIsConnecting(connection_state_); | 188 return StateIsConnecting(connection_state_); |
| 191 } | 189 } |
| 192 | 190 |
| 193 void NetworkState::UpdateName() { | 191 void NetworkState::UpdateName() { |
| 194 if (hex_ssid_.empty()) { | 192 if (hex_ssid_.empty()) { |
| 195 // Validate name for UTF8. | 193 // Validate name for UTF8. |
| 196 std::string valid_ssid = ValidateUTF8(name()); | 194 std::string valid_ssid = ValidateUTF8(name()); |
| 197 if (valid_ssid != name()) { | 195 if (valid_ssid != name()) { |
| 198 set_name(valid_ssid); | 196 set_name(valid_ssid); |
| 199 network_event_log::AddEntry( | 197 NET_LOG_DEBUG("UpdateName", base::StringPrintf( |
| 200 kLogModule, "UpdateName", | 198 "%s: UTF8: %s", path().c_str(), name().c_str())); |
| 201 base::StringPrintf("%s: UTF8: %s", path().c_str(), name().c_str())); | |
| 202 } | 199 } |
| 203 return; | 200 return; |
| 204 } | 201 } |
| 205 | 202 |
| 206 std::string ssid; | 203 std::string ssid; |
| 207 std::vector<uint8> raw_ssid_bytes; | 204 std::vector<uint8> raw_ssid_bytes; |
| 208 if (base::HexStringToBytes(hex_ssid_, &raw_ssid_bytes)) { | 205 if (base::HexStringToBytes(hex_ssid_, &raw_ssid_bytes)) { |
| 209 ssid = std::string(raw_ssid_bytes.begin(), raw_ssid_bytes.end()); | 206 ssid = std::string(raw_ssid_bytes.begin(), raw_ssid_bytes.end()); |
| 210 } else { | 207 } else { |
| 211 std::string desc = base::StringPrintf("%s: Error processing: %s", | 208 std::string desc = base::StringPrintf("%s: Error processing: %s", |
| 212 path().c_str(), hex_ssid_.c_str()); | 209 path().c_str(), hex_ssid_.c_str()); |
| 213 network_event_log::AddEntry(kLogModule, "UpdateName", desc); | 210 NET_LOG_DEBUG("UpdateName", desc); |
| 214 LOG(ERROR) << desc; | 211 LOG(ERROR) << desc; |
| 215 ssid = name(); | 212 ssid = name(); |
| 216 } | 213 } |
| 217 | 214 |
| 218 if (IsStringUTF8(ssid)) { | 215 if (IsStringUTF8(ssid)) { |
| 219 if (ssid != name()) { | 216 if (ssid != name()) { |
| 220 set_name(ssid); | 217 set_name(ssid); |
| 221 network_event_log::AddEntry( | 218 NET_LOG_DEBUG("UpdateName", base::StringPrintf( |
| 222 kLogModule, "UpdateName", | 219 "%s: UTF8: %s", path().c_str(), name().c_str())); |
| 223 base::StringPrintf("%s: UTF8: %s", path().c_str(), name().c_str())); | |
| 224 } | 220 } |
| 225 return; | 221 return; |
| 226 } | 222 } |
| 227 | 223 |
| 228 // Detect encoding and convert to UTF-8. | 224 // Detect encoding and convert to UTF-8. |
| 229 std::string encoding; | 225 std::string encoding; |
| 230 if (!base::DetectEncoding(ssid, &encoding)) { | 226 if (!base::DetectEncoding(ssid, &encoding)) { |
| 231 // TODO(stevenjb): Test this. See comment in PropertyChanged() under | 227 // TODO(stevenjb): Test this. See comment in PropertyChanged() under |
| 232 // flimflam::kCountryProperty. | 228 // flimflam::kCountryProperty. |
| 233 encoding = country_code_; | 229 encoding = country_code_; |
| 234 } | 230 } |
| 235 if (!encoding.empty()) { | 231 if (!encoding.empty()) { |
| 236 std::string utf8_ssid; | 232 std::string utf8_ssid; |
| 237 if (base::ConvertToUtf8AndNormalize(ssid, encoding, &utf8_ssid)) { | 233 if (base::ConvertToUtf8AndNormalize(ssid, encoding, &utf8_ssid)) { |
| 238 set_name(utf8_ssid); | 234 set_name(utf8_ssid); |
| 239 network_event_log::AddEntry( | 235 NET_LOG_DEBUG("UpdateName", base::StringPrintf( |
| 240 kLogModule, "UpdateName", | 236 "%s: Encoding=%s: %s", path().c_str(), |
| 241 base::StringPrintf("%s: Encoding=%s: %s", path().c_str(), | 237 encoding.c_str(), name().c_str())); |
| 242 encoding.c_str(), name().c_str())); | |
| 243 return; | 238 return; |
| 244 } | 239 } |
| 245 } | 240 } |
| 246 | 241 |
| 247 // Unrecognized encoding. Only use raw bytes if name_ is empty. | 242 // Unrecognized encoding. Only use raw bytes if name_ is empty. |
| 248 if (name().empty()) | 243 if (name().empty()) |
| 249 set_name(ssid); | 244 set_name(ssid); |
| 250 network_event_log::AddEntry( | 245 NET_LOG_DEBUG("UpdateName", base::StringPrintf( |
| 251 kLogModule, "UpdateName", | 246 "%s: Unrecognized Encoding=%s: %s", path().c_str(), |
| 252 base::StringPrintf("%s: Unrecognized Encoding=%s: %s", path().c_str(), | 247 encoding.c_str(), name().c_str())); |
| 253 encoding.c_str(), name().c_str())); | |
| 254 } | 248 } |
| 255 | 249 |
| 256 // static | 250 // static |
| 257 bool NetworkState::StateIsConnected(const std::string& connection_state) { | 251 bool NetworkState::StateIsConnected(const std::string& connection_state) { |
| 258 return (connection_state == flimflam::kStateReady || | 252 return (connection_state == flimflam::kStateReady || |
| 259 connection_state == flimflam::kStateOnline || | 253 connection_state == flimflam::kStateOnline || |
| 260 connection_state == flimflam::kStatePortal); | 254 connection_state == flimflam::kStatePortal); |
| 261 } | 255 } |
| 262 | 256 |
| 263 // static | 257 // static |
| 264 bool NetworkState::StateIsConnecting(const std::string& connection_state) { | 258 bool NetworkState::StateIsConnecting(const std::string& connection_state) { |
| 265 return (connection_state == flimflam::kStateAssociation || | 259 return (connection_state == flimflam::kStateAssociation || |
| 266 connection_state == flimflam::kStateConfiguration || | 260 connection_state == flimflam::kStateConfiguration || |
| 267 connection_state == flimflam::kStateCarrier); | 261 connection_state == flimflam::kStateCarrier); |
| 268 } | 262 } |
| 269 | 263 |
| 270 // static | 264 // static |
| 271 std::string NetworkState::IPConfigProperty(const char* key) { | 265 std::string NetworkState::IPConfigProperty(const char* key) { |
| 272 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | 266 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
| 273 } | 267 } |
| 274 | 268 |
| 275 } // namespace chromeos | 269 } // namespace chromeos |
| OLD | NEW |