Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: chromeos/network/network_state.cc

Issue 22908005: Improve debug logging for GetNameFromProperties (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/json/json_writer.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 flimflam::kPaymentPortalPostData, &post_data_)) { 199 flimflam::kPaymentPortalPostData, &post_data_)) {
200 return false; 200 return false;
201 } 201 }
202 return true; 202 return true;
203 } 203 }
204 return false; 204 return false;
205 } 205 }
206 206
207 bool NetworkState::InitialPropertiesReceived( 207 bool NetworkState::InitialPropertiesReceived(
208 const base::DictionaryValue& properties) { 208 const base::DictionaryValue& properties) {
209 NET_LOG_DEBUG("InitialPropertiesReceived", path());
209 bool changed = UpdateName(properties); 210 bool changed = UpdateName(properties);
210 bool had_ca_cert_nss = has_ca_cert_nss_; 211 bool had_ca_cert_nss = has_ca_cert_nss_;
211 has_ca_cert_nss_ = IsCaCertNssSet(properties); 212 has_ca_cert_nss_ = IsCaCertNssSet(properties);
212 changed |= had_ca_cert_nss != has_ca_cert_nss_; 213 changed |= had_ca_cert_nss != has_ca_cert_nss_;
213 return changed; 214 return changed;
214 } 215 }
215 216
216 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const { 217 void NetworkState::GetProperties(base::DictionaryValue* dictionary) const {
217 // Keep care that these properties are the same as in |PropertyChanged|. 218 // Keep care that these properties are the same as in |PropertyChanged|.
218 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name()); 219 dictionary->SetStringWithoutPathExpansion(flimflam::kNameProperty, name());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 result += dns_servers_[i]; 316 result += dns_servers_[i];
316 } 317 }
317 return result; 318 return result;
318 } 319 }
319 320
320 std::string NetworkState::GetNetmask() const { 321 std::string NetworkState::GetNetmask() const {
321 return network_util::PrefixLengthToNetmask(prefix_length_); 322 return network_util::PrefixLengthToNetmask(prefix_length_);
322 } 323 }
323 324
324 bool NetworkState::UpdateName(const base::DictionaryValue& properties) { 325 bool NetworkState::UpdateName(const base::DictionaryValue& properties) {
325 std::string updated_name = GetNameFromProperties(properties); 326 std::string updated_name = GetNameFromProperties(path(), properties);
326 if (updated_name != name()) { 327 if (updated_name != name()) {
327 set_name(updated_name); 328 set_name(updated_name);
328 return true; 329 return true;
329 } 330 }
330 return false; 331 return false;
331 } 332 }
332 333
333 // static 334 // static
334 std::string NetworkState::GetNameFromProperties( 335 std::string NetworkState::GetNameFromProperties(
336 const std::string& service_path,
335 const base::DictionaryValue& properties) { 337 const base::DictionaryValue& properties) {
336 std::string name; 338 std::string name;
337 properties.GetStringWithoutPathExpansion(flimflam::kNameProperty, &name); 339 properties.GetStringWithoutPathExpansion(flimflam::kNameProperty, &name);
338 340
339 std::string hex_ssid; 341 std::string hex_ssid;
340 properties.GetStringWithoutPathExpansion(flimflam::kWifiHexSsid, &hex_ssid); 342 properties.GetStringWithoutPathExpansion(flimflam::kWifiHexSsid, &hex_ssid);
341 343
342 if (hex_ssid.empty()) { 344 if (hex_ssid.empty()) {
343 // Validate name for UTF8. 345 // Validate name for UTF8.
344 std::string valid_ssid = ValidateUTF8(name); 346 std::string valid_ssid = ValidateUTF8(name);
345 if (valid_ssid != name) { 347 if (valid_ssid != name) {
346 NET_LOG_DEBUG("GetNameFromProperties", base::StringPrintf( 348 NET_LOG_DEBUG("GetNameFromProperties", base::StringPrintf(
347 "%s: UTF8: %s", name.c_str(), valid_ssid.c_str())); 349 "%s: UTF8: %s", service_path.c_str(), valid_ssid.c_str()));
348 } 350 }
349 return valid_ssid; 351 return valid_ssid;
350 } 352 }
351 353
352 std::string ssid; 354 std::string ssid;
353 std::vector<uint8> raw_ssid_bytes; 355 std::vector<uint8> raw_ssid_bytes;
354 if (base::HexStringToBytes(hex_ssid, &raw_ssid_bytes)) { 356 if (base::HexStringToBytes(hex_ssid, &raw_ssid_bytes)) {
355 ssid = std::string(raw_ssid_bytes.begin(), raw_ssid_bytes.end()); 357 ssid = std::string(raw_ssid_bytes.begin(), raw_ssid_bytes.end());
358 NET_LOG_DEBUG("GetNameFromProperties", base::StringPrintf(
359 "%s: %s, SSID: %s", service_path.c_str(),
360 hex_ssid.c_str(), ssid.c_str()));
356 } else { 361 } else {
357 NET_LOG_ERROR("GetNameFromProperties", 362 NET_LOG_ERROR("GetNameFromProperties",
358 base::StringPrintf("%s: Error processing: %s", 363 base::StringPrintf("%s: Error processing: %s",
359 name.c_str(), hex_ssid.c_str())); 364 service_path.c_str(), hex_ssid.c_str()));
360 return name; 365 return name;
361 } 366 }
362 367
363 if (IsStringUTF8(ssid)) { 368 if (IsStringUTF8(ssid)) {
364 if (ssid != name) { 369 if (ssid != name) {
365 NET_LOG_DEBUG("GetNameFromProperties", base::StringPrintf( 370 NET_LOG_DEBUG("GetNameFromProperties", base::StringPrintf(
366 "%s: UTF8: %s", name.c_str(), ssid.c_str())); 371 "%s: UTF8: %s", service_path.c_str(), ssid.c_str()));
367 } 372 }
368 return ssid; 373 return ssid;
369 } 374 }
370 375
371 // Detect encoding and convert to UTF-8. 376 // Detect encoding and convert to UTF-8.
372 std::string country_code; 377 std::string country_code;
373 properties.GetStringWithoutPathExpansion( 378 properties.GetStringWithoutPathExpansion(
374 flimflam::kCountryProperty, &country_code); 379 flimflam::kCountryProperty, &country_code);
375 std::string encoding; 380 std::string encoding;
376 if (!base::DetectEncoding(ssid, &encoding)) { 381 if (!base::DetectEncoding(ssid, &encoding)) {
377 // TODO(stevenjb): This is currently experimental. If we find a case where 382 // TODO(stevenjb): This is currently experimental. If we find a case where
378 // base::DetectEncoding() fails, we need to figure out whether we can use 383 // base::DetectEncoding() fails, we need to figure out whether we can use
379 // country_code with ConvertToUtf8(). crbug.com/233267. 384 // country_code with ConvertToUtf8(). crbug.com/233267.
380 encoding = country_code; 385 encoding = country_code;
381 } 386 }
382 if (!encoding.empty()) { 387 if (!encoding.empty()) {
383 std::string utf8_ssid; 388 std::string utf8_ssid;
384 if (base::ConvertToUtf8AndNormalize(ssid, encoding, &utf8_ssid)) { 389 if (base::ConvertToUtf8AndNormalize(ssid, encoding, &utf8_ssid)) {
385 if (utf8_ssid != name) { 390 if (utf8_ssid != name) {
386 NET_LOG_DEBUG("GetNameFromProperties", base::StringPrintf( 391 NET_LOG_DEBUG("GetNameFromProperties", base::StringPrintf(
387 "%s: Encoding=%s: %s", name.c_str(), 392 "%s: Encoding=%s: %s", service_path.c_str(),
388 encoding.c_str(), utf8_ssid.c_str())); 393 encoding.c_str(), utf8_ssid.c_str()));
389 } 394 }
390 return utf8_ssid; 395 return utf8_ssid;
391 } 396 }
392 } 397 }
393 398
394 // Unrecognized encoding. Only use raw bytes if name_ is empty. 399 // Unrecognized encoding. Only use raw bytes if name_ is empty.
395 NET_LOG_DEBUG("GetNameFromProperties", base::StringPrintf( 400 NET_LOG_DEBUG("GetNameFromProperties", base::StringPrintf(
396 "%s: Unrecognized Encoding=%s: %s", name.c_str(), 401 "%s: Unrecognized Encoding=%s: %s", service_path.c_str(),
397 encoding.c_str(), ssid.c_str())); 402 encoding.c_str(), ssid.c_str()));
398 if (name.empty() && !ssid.empty()) 403 if (name.empty() && !ssid.empty())
399 return ssid; 404 return ssid;
400 return name; 405 return name;
401 } 406 }
402 407
403 // static 408 // static
404 bool NetworkState::StateIsConnected(const std::string& connection_state) { 409 bool NetworkState::StateIsConnected(const std::string& connection_state) {
405 return (connection_state == flimflam::kStateReady || 410 return (connection_state == flimflam::kStateReady ||
406 connection_state == flimflam::kStateOnline || 411 connection_state == flimflam::kStateOnline ||
(...skipping 24 matching lines...) Expand all
431 } 436 }
432 scoped_ptr<base::DictionaryValue> ui_data_dict( 437 scoped_ptr<base::DictionaryValue> ui_data_dict(
433 chromeos::onc::ReadDictionaryFromJson(ui_data_str)); 438 chromeos::onc::ReadDictionaryFromJson(ui_data_str));
434 if (!ui_data_dict) 439 if (!ui_data_dict)
435 return false; 440 return false;
436 *out = NetworkUIData(*ui_data_dict); 441 *out = NetworkUIData(*ui_data_dict);
437 return true; 442 return true;
438 } 443 }
439 444
440 } // namespace chromeos 445 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698