OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/autofill/autofill_profile.h" | 5 #include "chrome/browser/autofill/autofill_profile.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 } | 360 } |
361 | 361 |
362 string16 new_label; | 362 string16 new_label; |
363 if (field_it < fields.size() && fields.size() > minimal_fields_shown) { | 363 if (field_it < fields.size() && fields.size() > minimal_fields_shown) { |
364 std::vector<AutoFillFieldType> unique_fields; | 364 std::vector<AutoFillFieldType> unique_fields; |
365 unique_fields.resize(fields.size()); | 365 unique_fields.resize(fields.size()); |
366 std::copy(fields.begin(), fields.end(), unique_fields.begin()); | 366 std::copy(fields.begin(), fields.end(), unique_fields.begin()); |
367 unique_fields.resize(std::max(field_it + 1, minimal_fields_shown)); | 367 unique_fields.resize(std::max(field_it + 1, minimal_fields_shown)); |
368 new_label = | 368 new_label = |
369 profiles->at(*similar_profiles)->ConstructInferredLabel( | 369 profiles->at(*similar_profiles)->ConstructInferredLabel( |
370 &unique_fields); | 370 unique_fields); |
371 } else { | 371 } else { |
372 new_label = | 372 new_label = |
373 profiles->at(*similar_profiles)->ConstructInferredLabel(&fields); | 373 profiles->at(*similar_profiles)->ConstructInferredLabel(fields); |
374 } | 374 } |
375 (*created_labels)[*similar_profiles] = new_label; | 375 (*created_labels)[*similar_profiles] = new_label; |
376 } | 376 } |
377 } else { | 377 } else { |
378 std::vector<AutoFillFieldType> non_empty_fields; | 378 std::vector<AutoFillFieldType> non_empty_fields; |
379 size_t include_fields = minimal_fields_shown ? minimal_fields_shown : 1; | 379 size_t include_fields = minimal_fields_shown ? minimal_fields_shown : 1; |
380 non_empty_fields.reserve(include_fields); | 380 non_empty_fields.reserve(include_fields); |
381 for (size_t i = 0; i < fields_to_use.size(); ++i) { | 381 for (size_t i = 0; i < fields_to_use.size(); ++i) { |
382 if (!profiles->at(label_iterator->second.front())->GetFieldText( | 382 if (!profiles->at(label_iterator->second.front())->GetFieldText( |
383 AutoFillType(fields_to_use[i])).empty()) { | 383 AutoFillType(fields_to_use[i])).empty()) { |
384 non_empty_fields.push_back(fields_to_use[i]); | 384 non_empty_fields.push_back(fields_to_use[i]); |
385 if (non_empty_fields.size() >= include_fields) | 385 if (non_empty_fields.size() >= include_fields) |
386 break; | 386 break; |
387 } | 387 } |
388 } | 388 } |
389 | 389 |
390 (*created_labels)[label_iterator->second.front()] = | 390 (*created_labels)[label_iterator->second.front()] = |
391 profiles->at(label_iterator->second.front())->ConstructInferredLabel( | 391 profiles->at(label_iterator->second.front())->ConstructInferredLabel( |
392 &non_empty_fields); | 392 non_empty_fields); |
393 } | 393 } |
394 } | 394 } |
395 } | 395 } |
396 | 396 |
397 bool AutoFillProfile::IsEmpty() const { | 397 bool AutoFillProfile::IsEmpty() const { |
398 FieldTypeSet types; | 398 FieldTypeSet types; |
399 GetAvailableFieldTypes(&types); | 399 GetAvailableFieldTypes(&types); |
400 return types.empty(); | 400 return types.empty(); |
401 } | 401 } |
402 | 402 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)) + | 462 GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)) + |
463 GetFieldText(AutoFillType(ADDRESS_HOME_LINE2)) + | 463 GetFieldText(AutoFillType(ADDRESS_HOME_LINE2)) + |
464 GetFieldText(AutoFillType(EMAIL_ADDRESS)); | 464 GetFieldText(AutoFillType(EMAIL_ADDRESS)); |
465 } | 465 } |
466 | 466 |
467 Address* AutoFillProfile::GetHomeAddress() { | 467 Address* AutoFillProfile::GetHomeAddress() { |
468 return static_cast<Address*>(personal_info_[AutoFillType::ADDRESS_HOME]); | 468 return static_cast<Address*>(personal_info_[AutoFillType::ADDRESS_HOME]); |
469 } | 469 } |
470 | 470 |
471 string16 AutoFillProfile::ConstructInferredLabel( | 471 string16 AutoFillProfile::ConstructInferredLabel( |
472 const std::vector<AutoFillFieldType>* included_fields) const { | 472 const std::vector<AutoFillFieldType>& included_fields) const { |
473 DCHECK(included_fields); | 473 const string16 separator = |
| 474 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_SEPARATOR); |
| 475 |
474 string16 label; | 476 string16 label; |
475 string16 separator = l10n_util::GetStringUTF16( | |
476 IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_SEPARATOR); | |
477 for (std::vector<AutoFillFieldType>::const_iterator it = | 477 for (std::vector<AutoFillFieldType>::const_iterator it = |
478 included_fields->begin(); it != included_fields->end(); ++it) { | 478 included_fields.begin(); |
| 479 it != included_fields.end(); ++it) { |
479 string16 field = GetFieldText(AutoFillType(*it)); | 480 string16 field = GetFieldText(AutoFillType(*it)); |
480 if (!field.empty()) { | 481 if (field.empty()) |
481 if (!label.empty()) { | 482 continue; |
482 label.append(separator); | 483 |
483 } | 484 if (!label.empty()) |
484 // Fax number has special format, to indicate that this is a fax number. | 485 label.append(separator); |
485 if (*it == PHONE_FAX_WHOLE_NUMBER) { | 486 |
486 field = l10n_util::GetStringFUTF16( | 487 // Fax number has special format, to indicate that this is a fax number. |
487 IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_FAX_FORMAT, field); | 488 if (*it == PHONE_FAX_WHOLE_NUMBER) { |
488 } | 489 field = l10n_util::GetStringFUTF16( |
489 label.append(field); | 490 IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_FAX_FORMAT, field); |
490 } | 491 } |
| 492 label.append(field); |
491 } | 493 } |
492 return label; | 494 return label; |
493 } | 495 } |
494 | 496 |
495 // So we can compare AutoFillProfiles with EXPECT_EQ(). | 497 // So we can compare AutoFillProfiles with EXPECT_EQ(). |
496 std::ostream& operator<<(std::ostream& os, const AutoFillProfile& profile) { | 498 std::ostream& operator<<(std::ostream& os, const AutoFillProfile& profile) { |
497 return os | 499 return os |
498 << UTF16ToUTF8(profile.Label()) | 500 << UTF16ToUTF8(profile.Label()) |
499 << " " | 501 << " " |
500 << profile.guid() | 502 << profile.guid() |
(...skipping 19 matching lines...) Expand all Loading... |
520 << UTF16ToUTF8(profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))) | 522 << UTF16ToUTF8(profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))) |
521 << " " | 523 << " " |
522 << UTF16ToUTF8(profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))) | 524 << UTF16ToUTF8(profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))) |
523 << " " | 525 << " " |
524 << UTF16ToUTF8(profile.GetFieldText(AutoFillType( | 526 << UTF16ToUTF8(profile.GetFieldText(AutoFillType( |
525 PHONE_HOME_WHOLE_NUMBER))) | 527 PHONE_HOME_WHOLE_NUMBER))) |
526 << " " | 528 << " " |
527 << UTF16ToUTF8(profile.GetFieldText(AutoFillType( | 529 << UTF16ToUTF8(profile.GetFieldText(AutoFillType( |
528 PHONE_FAX_WHOLE_NUMBER))); | 530 PHONE_FAX_WHOLE_NUMBER))); |
529 } | 531 } |
OLD | NEW |