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

Side by Side Diff: components/autofill/core/browser/autofill_profile.cc

Issue 21947003: [Autofill] Move FieldTypeGroup out of the AutofillType class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_profile.h" 5 #include "components/autofill/core/browser/autofill_profile.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <map> 9 #include <map>
10 #include <ostream> 10 #include <ostream>
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 return false; 309 return false;
310 310
311 return 311 return
312 form_group->SetInfo(type, CollapseWhitespace(value, false), app_locale); 312 form_group->SetInfo(type, CollapseWhitespace(value, false), app_locale);
313 } 313 }
314 314
315 void AutofillProfile::SetRawMultiInfo( 315 void AutofillProfile::SetRawMultiInfo(
316 AutofillFieldType type, 316 AutofillFieldType type,
317 const std::vector<base::string16>& values) { 317 const std::vector<base::string16>& values) {
318 switch (AutofillType(type).group()) { 318 switch (AutofillType(type).group()) {
319 case AutofillType::NAME: 319 case NAME:
320 case AutofillType::NAME_BILLING: 320 case NAME_BILLING:
321 CopyValuesToItems(type, values, &name_, NameInfo()); 321 CopyValuesToItems(type, values, &name_, NameInfo());
322 break; 322 break;
323 case AutofillType::EMAIL: 323 case EMAIL:
324 CopyValuesToItems(type, values, &email_, EmailInfo()); 324 CopyValuesToItems(type, values, &email_, EmailInfo());
325 break; 325 break;
326 case AutofillType::PHONE_HOME: 326 case PHONE_HOME:
327 case AutofillType::PHONE_BILLING: 327 case PHONE_BILLING:
328 CopyValuesToItems(type, 328 CopyValuesToItems(type,
329 values, 329 values,
330 &phone_number_, 330 &phone_number_,
331 PhoneNumber(this)); 331 PhoneNumber(this));
332 break; 332 break;
333 default: 333 default:
334 if (values.size() == 1) { 334 if (values.size() == 1) {
335 SetRawInfo(type, values[0]); 335 SetRawInfo(type, values[0]);
336 } else if (values.size() == 0) { 336 } else if (values.size() == 0) {
337 SetRawInfo(type, base::string16()); 337 SetRawInfo(type, base::string16());
(...skipping 15 matching lines...) Expand all
353 const std::string& app_locale, 353 const std::string& app_locale,
354 std::vector<base::string16>* values) const { 354 std::vector<base::string16>* values) const {
355 GetMultiInfoImpl(type, app_locale, values); 355 GetMultiInfoImpl(type, app_locale, values);
356 } 356 }
357 357
358 void AutofillProfile::FillFormField(const AutofillField& field, 358 void AutofillProfile::FillFormField(const AutofillField& field,
359 size_t variant, 359 size_t variant,
360 const std::string& app_locale, 360 const std::string& app_locale,
361 FormFieldData* field_data) const { 361 FormFieldData* field_data) const {
362 AutofillFieldType type = field.type(); 362 AutofillFieldType type = field.type();
363 DCHECK_NE(AutofillType::CREDIT_CARD, AutofillType(type).group()); 363 DCHECK_NE(CREDIT_CARD, AutofillType(type).group());
364 DCHECK(field_data); 364 DCHECK(field_data);
365 365
366 if (type == PHONE_HOME_NUMBER || type == PHONE_BILLING_NUMBER) { 366 if (type == PHONE_HOME_NUMBER || type == PHONE_BILLING_NUMBER) {
367 FillPhoneNumberField(field, variant, app_locale, field_data); 367 FillPhoneNumberField(field, variant, app_locale, field_data);
368 } else if (field_data->form_control_type == "select-one") { 368 } else if (field_data->form_control_type == "select-one") {
369 FillSelectControl(type, app_locale, field_data); 369 FillSelectControl(type, app_locale, field_data);
370 } else { 370 } else {
371 std::vector<base::string16> values; 371 std::vector<base::string16> values;
372 GetMultiInfo(type, app_locale, &values); 372 GetMultiInfo(type, app_locale, &values);
373 if (variant >= values.size()) { 373 if (variant >= values.size()) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 GetNonEmptyTypes(app_locale, &types); 507 GetNonEmptyTypes(app_locale, &types);
508 508
509 for (FieldTypeSet::const_iterator iter = types.begin(); iter != types.end(); 509 for (FieldTypeSet::const_iterator iter = types.begin(); iter != types.end();
510 ++iter) { 510 ++iter) {
511 if (*iter == NAME_FULL) { 511 if (*iter == NAME_FULL) {
512 // Ignore the compound "full name" field type. We are only interested in 512 // Ignore the compound "full name" field type. We are only interested in
513 // comparing the constituent parts. For example, if |this| has a middle 513 // comparing the constituent parts. For example, if |this| has a middle
514 // name saved, but |profile| lacks one, |profile| could still be a subset 514 // name saved, but |profile| lacks one, |profile| could still be a subset
515 // of |this|. 515 // of |this|.
516 continue; 516 continue;
517 } else if (AutofillType(*iter).group() == AutofillType::PHONE_HOME) { 517 } else if (AutofillType(*iter).group() == PHONE_HOME) {
518 // Phone numbers should be canonicalized prior to being compared. 518 // Phone numbers should be canonicalized prior to being compared.
519 if (*iter != PHONE_HOME_WHOLE_NUMBER) { 519 if (*iter != PHONE_HOME_WHOLE_NUMBER) {
520 continue; 520 continue;
521 } else if (!i18n::PhoneNumbersMatch( 521 } else if (!i18n::PhoneNumbersMatch(
522 GetRawInfo(*iter), 522 GetRawInfo(*iter),
523 profile.GetRawInfo(*iter), 523 profile.GetRawInfo(*iter),
524 UTF16ToASCII(GetRawInfo(ADDRESS_HOME_COUNTRY)), 524 UTF16ToASCII(GetRawInfo(ADDRESS_HOME_COUNTRY)),
525 app_locale)) { 525 app_locale)) {
526 return false; 526 return false;
527 } 527 }
(...skipping 30 matching lines...) Expand all
558 // GetMultiInfo always returns at least one element, even if the profile 558 // GetMultiInfo always returns at least one element, even if the profile
559 // has no data stored for this field type. 559 // has no data stored for this field type.
560 if (existing_values.size() == 1 && existing_values.front().empty()) 560 if (existing_values.size() == 1 && existing_values.front().empty())
561 existing_values.clear(); 561 existing_values.clear();
562 562
563 FieldTypeGroup group = AutofillType(*iter).group(); 563 FieldTypeGroup group = AutofillType(*iter).group();
564 for (std::vector<base::string16>::iterator value_iter = 564 for (std::vector<base::string16>::iterator value_iter =
565 new_values.begin(); 565 new_values.begin();
566 value_iter != new_values.end(); ++value_iter) { 566 value_iter != new_values.end(); ++value_iter) {
567 // Don't add duplicates. 567 // Don't add duplicates.
568 if (group == AutofillType::PHONE_HOME) { 568 if (group == PHONE_HOME) {
569 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); 569 AddPhoneIfUnique(*value_iter, app_locale, &existing_values);
570 } else { 570 } else {
571 std::vector<base::string16>::const_iterator existing_iter = 571 std::vector<base::string16>::const_iterator existing_iter =
572 std::find_if( 572 std::find_if(
573 existing_values.begin(), existing_values.end(), 573 existing_values.begin(), existing_values.end(),
574 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); 574 std::bind1st(CaseInsensitiveStringEquals(), *value_iter));
575 if (existing_iter == existing_values.end()) 575 if (existing_iter == existing_values.end())
576 existing_values.insert(existing_values.end(), *value_iter); 576 existing_values.insert(existing_values.end(), *value_iter);
577 } 577 }
578 } 578 }
579 SetRawMultiInfo(*iter, existing_values); 579 SetRawMultiInfo(*iter, existing_values);
580 } else { 580 } else {
581 base::string16 new_value = profile.GetRawInfo(*iter); 581 base::string16 new_value = profile.GetRawInfo(*iter);
582 if (StringToLowerASCII(GetRawInfo(*iter)) != 582 if (StringToLowerASCII(GetRawInfo(*iter)) !=
583 StringToLowerASCII(new_value)) { 583 StringToLowerASCII(new_value)) {
584 SetRawInfo(*iter, new_value); 584 SetRawInfo(*iter, new_value);
585 } 585 }
586 } 586 }
587 } 587 }
588 } 588 }
589 589
590 // static 590 // static
591 bool AutofillProfile::SupportsMultiValue(AutofillFieldType type) { 591 bool AutofillProfile::SupportsMultiValue(AutofillFieldType type) {
592 AutofillType::FieldTypeGroup group = AutofillType(type).group(); 592 FieldTypeGroup group = AutofillType(type).group();
593 return group == AutofillType::NAME || 593 return group == NAME ||
594 group == AutofillType::NAME_BILLING || 594 group == NAME_BILLING ||
595 group == AutofillType::EMAIL || 595 group == EMAIL ||
596 group == AutofillType::PHONE_HOME || 596 group == PHONE_HOME ||
597 group == AutofillType::PHONE_BILLING; 597 group == PHONE_BILLING;
598 } 598 }
599 599
600 // static 600 // static
601 bool AutofillProfile::AdjustInferredLabels( 601 bool AutofillProfile::AdjustInferredLabels(
602 std::vector<AutofillProfile*>* profiles) { 602 std::vector<AutofillProfile*>* profiles) {
603 const size_t kMinimalFieldsShown = 2; 603 const size_t kMinimalFieldsShown = 2;
604 604
605 std::vector<base::string16> created_labels; 605 std::vector<base::string16> created_labels;
606 CreateInferredLabels(profiles, NULL, UNKNOWN_TYPE, kMinimalFieldsShown, 606 CreateInferredLabels(profiles, NULL, UNKNOWN_TYPE, kMinimalFieldsShown,
607 &created_labels); 607 &created_labels);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 } 686 }
687 687
688 return false; 688 return false;
689 } 689 }
690 690
691 void AutofillProfile::GetMultiInfoImpl( 691 void AutofillProfile::GetMultiInfoImpl(
692 AutofillFieldType type, 692 AutofillFieldType type,
693 const std::string& app_locale, 693 const std::string& app_locale,
694 std::vector<base::string16>* values) const { 694 std::vector<base::string16>* values) const {
695 switch (AutofillType(type).group()) { 695 switch (AutofillType(type).group()) {
696 case AutofillType::NAME: 696 case NAME:
697 case AutofillType::NAME_BILLING: 697 case NAME_BILLING:
698 CopyItemsToValues(type, name_, app_locale, values); 698 CopyItemsToValues(type, name_, app_locale, values);
699 break; 699 break;
700 case AutofillType::EMAIL: 700 case EMAIL:
701 CopyItemsToValues(type, email_, app_locale, values); 701 CopyItemsToValues(type, email_, app_locale, values);
702 break; 702 break;
703 case AutofillType::PHONE_HOME: 703 case PHONE_HOME:
704 case AutofillType::PHONE_BILLING: 704 case PHONE_BILLING:
705 CopyItemsToValues(type, phone_number_, app_locale, values); 705 CopyItemsToValues(type, phone_number_, app_locale, values);
706 break; 706 break;
707 default: 707 default:
708 values->resize(1); 708 values->resize(1);
709 (*values)[0] = GetFormGroupInfo(*this, type, app_locale); 709 (*values)[0] = GetFormGroupInfo(*this, type, app_locale);
710 } 710 }
711 } 711 }
712 712
713 void AutofillProfile::AddPhoneIfUnique( 713 void AutofillProfile::AddPhoneIfUnique(
714 const base::string16& phone, 714 const base::string16& phone,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 } 838 }
839 839
840 const FormGroup* AutofillProfile::FormGroupForType( 840 const FormGroup* AutofillProfile::FormGroupForType(
841 AutofillFieldType type) const { 841 AutofillFieldType type) const {
842 return const_cast<AutofillProfile*>(this)->MutableFormGroupForType(type); 842 return const_cast<AutofillProfile*>(this)->MutableFormGroupForType(type);
843 } 843 }
844 844
845 FormGroup* AutofillProfile::MutableFormGroupForType(AutofillFieldType type) { 845 FormGroup* AutofillProfile::MutableFormGroupForType(AutofillFieldType type) {
846 FormGroup* form_group = NULL; 846 FormGroup* form_group = NULL;
847 switch (AutofillType(type).group()) { 847 switch (AutofillType(type).group()) {
848 case AutofillType::NAME: 848 case NAME:
849 case AutofillType::NAME_BILLING: 849 case NAME_BILLING:
850 form_group = &name_[0]; 850 form_group = &name_[0];
851 break; 851 break;
852 case AutofillType::EMAIL: 852 case EMAIL:
853 form_group = &email_[0]; 853 form_group = &email_[0];
854 break; 854 break;
855 case AutofillType::COMPANY: 855 case COMPANY:
856 form_group = &company_; 856 form_group = &company_;
857 break; 857 break;
858 case AutofillType::PHONE_HOME: 858 case PHONE_HOME:
859 case AutofillType::PHONE_BILLING: 859 case PHONE_BILLING:
860 form_group = &phone_number_[0]; 860 form_group = &phone_number_[0];
861 break; 861 break;
862 case AutofillType::ADDRESS_HOME: 862 case ADDRESS_HOME:
863 case AutofillType::ADDRESS_BILLING: 863 case ADDRESS_BILLING:
864 form_group = &address_; 864 form_group = &address_;
865 break; 865 break;
866 default: 866 default:
867 break; 867 break;
868 } 868 }
869 869
870 return form_group; 870 return form_group;
871 } 871 }
872 872
873 // So we can compare AutofillProfiles with EXPECT_EQ(). 873 // So we can compare AutofillProfiles with EXPECT_EQ().
(...skipping 24 matching lines...) Expand all
898 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) 898 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE))
899 << " " 899 << " "
900 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) 900 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP))
901 << " " 901 << " "
902 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) 902 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))
903 << " " 903 << " "
904 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); 904 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER));
905 } 905 }
906 906
907 } // namespace autofill 907 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.cc ('k') | components/autofill/core/browser/autofill_type.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698