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

Side by Side Diff: chrome/browser/autofill/autofill_profile.cc

Issue 7892048: Autofill: Remove fax number completely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fix. Created 9 years, 3 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <functional> 8 #include <functional>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 static const AutofillFieldType kDefaultDistinguishingFields[] = { 49 static const AutofillFieldType kDefaultDistinguishingFields[] = {
50 NAME_FULL, 50 NAME_FULL,
51 ADDRESS_HOME_LINE1, 51 ADDRESS_HOME_LINE1,
52 ADDRESS_HOME_LINE2, 52 ADDRESS_HOME_LINE2,
53 ADDRESS_HOME_CITY, 53 ADDRESS_HOME_CITY,
54 ADDRESS_HOME_STATE, 54 ADDRESS_HOME_STATE,
55 ADDRESS_HOME_ZIP, 55 ADDRESS_HOME_ZIP,
56 ADDRESS_HOME_COUNTRY, 56 ADDRESS_HOME_COUNTRY,
57 EMAIL_ADDRESS, 57 EMAIL_ADDRESS,
58 PHONE_HOME_WHOLE_NUMBER, 58 PHONE_HOME_WHOLE_NUMBER,
59 PHONE_FAX_WHOLE_NUMBER,
60 COMPANY_NAME, 59 COMPANY_NAME,
61 }; 60 };
62 61
63 if (!suggested_fields) { 62 if (!suggested_fields) {
64 DCHECK_EQ(excluded_field, UNKNOWN_TYPE); 63 DCHECK_EQ(excluded_field, UNKNOWN_TYPE);
65 distinguishing_fields->assign( 64 distinguishing_fields->assign(
66 kDefaultDistinguishingFields, 65 kDefaultDistinguishingFields,
67 kDefaultDistinguishingFields + arraysize(kDefaultDistinguishingFields)); 66 kDefaultDistinguishingFields + arraysize(kDefaultDistinguishingFields));
68 return; 67 return;
69 } 68 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 break; 159 break;
161 160
162 case PHONE_HOME_NUMBER: 161 case PHONE_HOME_NUMBER:
163 case PHONE_HOME_CITY_CODE: 162 case PHONE_HOME_CITY_CODE:
164 case PHONE_HOME_COUNTRY_CODE: 163 case PHONE_HOME_COUNTRY_CODE:
165 case PHONE_HOME_CITY_AND_NUMBER: 164 case PHONE_HOME_CITY_AND_NUMBER:
166 case PHONE_HOME_WHOLE_NUMBER: 165 case PHONE_HOME_WHOLE_NUMBER:
167 collapsed_set.insert(PHONE_HOME_WHOLE_NUMBER); 166 collapsed_set.insert(PHONE_HOME_WHOLE_NUMBER);
168 break; 167 break;
169 168
170 case PHONE_FAX_NUMBER:
171 case PHONE_FAX_CITY_CODE:
172 case PHONE_FAX_COUNTRY_CODE:
173 case PHONE_FAX_CITY_AND_NUMBER:
174 case PHONE_FAX_WHOLE_NUMBER:
175 collapsed_set.insert(PHONE_FAX_WHOLE_NUMBER);
176 break;
177
178 default: 169 default:
179 collapsed_set.insert(*iter); 170 collapsed_set.insert(*iter);
180 } 171 }
181 } 172 }
182 std::swap(*type_set, collapsed_set); 173 std::swap(*type_set, collapsed_set);
183 } 174 }
184 175
185 class FindByPhone { 176 class FindByPhone {
186 public: 177 public:
187 FindByPhone(const string16& phone, const std::string& country_code) 178 FindByPhone(const string16& phone, const std::string& country_code)
(...skipping 13 matching lines...) Expand all
201 string16 phone_; 192 string16 phone_;
202 std::string country_code_; 193 std::string country_code_;
203 }; 194 };
204 195
205 } // namespace 196 } // namespace
206 197
207 AutofillProfile::AutofillProfile(const std::string& guid) 198 AutofillProfile::AutofillProfile(const std::string& guid)
208 : guid_(guid), 199 : guid_(guid),
209 name_(1), 200 name_(1),
210 email_(1), 201 email_(1),
211 home_number_(1, PhoneNumber(AutofillType::PHONE_HOME, this)), 202 home_number_(1, PhoneNumber(this)) {
212 fax_number_(1, PhoneNumber(AutofillType::PHONE_FAX, this)) {
213 } 203 }
214 204
215 AutofillProfile::AutofillProfile() 205 AutofillProfile::AutofillProfile()
216 : guid_(guid::GenerateGUID()), 206 : guid_(guid::GenerateGUID()),
217 name_(1), 207 name_(1),
218 email_(1), 208 email_(1),
219 home_number_(1, PhoneNumber(AutofillType::PHONE_HOME, this)), 209 home_number_(1, PhoneNumber(this)) {
220 fax_number_(1, PhoneNumber(AutofillType::PHONE_FAX, this)) {
221 } 210 }
222 211
223 AutofillProfile::AutofillProfile(const AutofillProfile& profile) 212 AutofillProfile::AutofillProfile(const AutofillProfile& profile)
224 : FormGroup() { 213 : FormGroup() {
225 operator=(profile); 214 operator=(profile);
226 } 215 }
227 216
228 AutofillProfile::~AutofillProfile() { 217 AutofillProfile::~AutofillProfile() {
229 } 218 }
230 219
231 AutofillProfile& AutofillProfile::operator=(const AutofillProfile& profile) { 220 AutofillProfile& AutofillProfile::operator=(const AutofillProfile& profile) {
232 if (this == &profile) 221 if (this == &profile)
233 return *this; 222 return *this;
234 223
235 label_ = profile.label_; 224 label_ = profile.label_;
236 guid_ = profile.guid_; 225 guid_ = profile.guid_;
237 226
238 name_ = profile.name_; 227 name_ = profile.name_;
239 email_ = profile.email_; 228 email_ = profile.email_;
240 company_ = profile.company_; 229 company_ = profile.company_;
241 home_number_ = profile.home_number_; 230 home_number_ = profile.home_number_;
242 for (size_t i = 0; i < home_number_.size(); ++i) { 231
232 for (size_t i = 0; i < home_number_.size(); ++i)
243 home_number_[i].set_profile(this); 233 home_number_[i].set_profile(this);
244 } 234
245 fax_number_ = profile.fax_number_;
246 for (size_t i = 0; i < fax_number_.size(); ++i) {
247 fax_number_[i].set_profile(this);
248 }
249 address_ = profile.address_; 235 address_ = profile.address_;
250 236
251 return *this; 237 return *this;
252 } 238 }
253 239
254 void AutofillProfile::GetSupportedTypes(FieldTypeSet* supported_types) const { 240 void AutofillProfile::GetSupportedTypes(FieldTypeSet* supported_types) const {
255 FormGroupList info = FormGroups(); 241 FormGroupList info = FormGroups();
256 for (FormGroupList::const_iterator it = info.begin(); it != info.end(); ++it) 242 for (FormGroupList::const_iterator it = info.begin(); it != info.end(); ++it)
257 (*it)->GetSupportedTypes(supported_types); 243 (*it)->GetSupportedTypes(supported_types);
258 } 244 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 case AutofillType::NAME: 292 case AutofillType::NAME:
307 CopyValuesToItems(type, values, &name_, NameInfo()); 293 CopyValuesToItems(type, values, &name_, NameInfo());
308 break; 294 break;
309 case AutofillType::EMAIL: 295 case AutofillType::EMAIL:
310 CopyValuesToItems(type, values, &email_, EmailInfo()); 296 CopyValuesToItems(type, values, &email_, EmailInfo());
311 break; 297 break;
312 case AutofillType::PHONE_HOME: 298 case AutofillType::PHONE_HOME:
313 CopyValuesToItems(type, 299 CopyValuesToItems(type,
314 values, 300 values,
315 &home_number_, 301 &home_number_,
316 PhoneNumber(AutofillType::PHONE_HOME, this)); 302 PhoneNumber(this));
317 break;
318 case AutofillType::PHONE_FAX:
319 CopyValuesToItems(type,
320 values,
321 &fax_number_,
322 PhoneNumber(AutofillType::PHONE_FAX, this));
323 break; 303 break;
324 default: 304 default:
325 if (values.size() == 1) { 305 if (values.size() == 1) {
326 SetInfo(type, values[0]); 306 SetInfo(type, values[0]);
327 } else if (values.size() == 0) { 307 } else if (values.size() == 0) {
328 SetInfo(type, string16()); 308 SetInfo(type, string16());
329 } else { 309 } else {
330 NOTREACHED() 310 NOTREACHED()
331 << "Attempt to set multiple values on single-valued field."; 311 << "Attempt to set multiple values on single-valued field.";
332 } 312 }
(...skipping 17 matching lines...) Expand all
350 switch (AutofillType(type).group()) { 330 switch (AutofillType(type).group()) {
351 case AutofillType::NAME: 331 case AutofillType::NAME:
352 CopyItemsToValues(type, name_, canonicalize, values); 332 CopyItemsToValues(type, name_, canonicalize, values);
353 break; 333 break;
354 case AutofillType::EMAIL: 334 case AutofillType::EMAIL:
355 CopyItemsToValues(type, email_, canonicalize, values); 335 CopyItemsToValues(type, email_, canonicalize, values);
356 break; 336 break;
357 case AutofillType::PHONE_HOME: 337 case AutofillType::PHONE_HOME:
358 CopyItemsToValues(type, home_number_, canonicalize, values); 338 CopyItemsToValues(type, home_number_, canonicalize, values);
359 break; 339 break;
360 case AutofillType::PHONE_FAX:
361 CopyItemsToValues(type, fax_number_, canonicalize, values);
362 break;
363 default: 340 default:
364 values->resize(1); 341 values->resize(1);
365 (*values)[0] = GetInfo(type); 342 (*values)[0] = GetInfo(type);
366 } 343 }
367 } 344 }
368 345
369 // static 346 // static
370 bool AutofillProfile::SupportsMultiValue(AutofillFieldType type) { 347 bool AutofillProfile::SupportsMultiValue(AutofillFieldType type) {
371 AutofillType::FieldTypeGroup group = AutofillType(type).group(); 348 AutofillType::FieldTypeGroup group = AutofillType(type).group();
372 return group == AutofillType::NAME || 349 return group == AutofillType::NAME ||
373 group == AutofillType::EMAIL || 350 group == AutofillType::EMAIL ||
374 group == AutofillType::PHONE_HOME || 351 group == AutofillType::PHONE_HOME;
375 group == AutofillType::PHONE_FAX;
376 } 352 }
377 353
378 const string16 AutofillProfile::Label() const { 354 const string16 AutofillProfile::Label() const {
379 return label_; 355 return label_;
380 } 356 }
381 357
382 const std::string AutofillProfile::CountryCode() const { 358 const std::string AutofillProfile::CountryCode() const {
383 return address_.country_code(); 359 return address_.country_code();
384 } 360 }
385 361
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 NAME_MIDDLE, 439 NAME_MIDDLE,
464 NAME_LAST, 440 NAME_LAST,
465 EMAIL_ADDRESS, 441 EMAIL_ADDRESS,
466 COMPANY_NAME, 442 COMPANY_NAME,
467 ADDRESS_HOME_LINE1, 443 ADDRESS_HOME_LINE1,
468 ADDRESS_HOME_LINE2, 444 ADDRESS_HOME_LINE2,
469 ADDRESS_HOME_CITY, 445 ADDRESS_HOME_CITY,
470 ADDRESS_HOME_STATE, 446 ADDRESS_HOME_STATE,
471 ADDRESS_HOME_ZIP, 447 ADDRESS_HOME_ZIP,
472 ADDRESS_HOME_COUNTRY, 448 ADDRESS_HOME_COUNTRY,
473 PHONE_HOME_NUMBER, 449 PHONE_HOME_NUMBER };
474 PHONE_FAX_NUMBER };
475 450
476 for (size_t index = 0; index < arraysize(types); ++index) { 451 for (size_t index = 0; index < arraysize(types); ++index) {
477 int comparison = GetInfo(types[index]).compare( 452 int comparison = GetInfo(types[index]).compare(
478 profile.GetInfo(types[index])); 453 profile.GetInfo(types[index]));
479 if (comparison != 0) 454 if (comparison != 0)
480 return comparison; 455 return comparison;
481 } 456 }
482 457
483 return 0; 458 return 0;
484 } 459 }
(...skipping 11 matching lines...) Expand all
496 int comparison = GetInfo(single_value_types[i]).compare( 471 int comparison = GetInfo(single_value_types[i]).compare(
497 profile.GetInfo(single_value_types[i])); 472 profile.GetInfo(single_value_types[i]));
498 if (comparison != 0) 473 if (comparison != 0)
499 return comparison; 474 return comparison;
500 } 475 }
501 476
502 const AutofillFieldType multi_value_types[] = { NAME_FIRST, 477 const AutofillFieldType multi_value_types[] = { NAME_FIRST,
503 NAME_MIDDLE, 478 NAME_MIDDLE,
504 NAME_LAST, 479 NAME_LAST,
505 EMAIL_ADDRESS, 480 EMAIL_ADDRESS,
506 PHONE_HOME_NUMBER, 481 PHONE_HOME_NUMBER };
507 PHONE_FAX_NUMBER };
508 482
509 for (size_t i = 0; i < arraysize(multi_value_types); ++i) { 483 for (size_t i = 0; i < arraysize(multi_value_types); ++i) {
510 std::vector<string16> values_a; 484 std::vector<string16> values_a;
511 std::vector<string16> values_b; 485 std::vector<string16> values_b;
512 GetMultiInfo(multi_value_types[i], &values_a); 486 GetMultiInfo(multi_value_types[i], &values_a);
513 profile.GetMultiInfo(multi_value_types[i], &values_b); 487 profile.GetMultiInfo(multi_value_types[i], &values_b);
514 if (values_a.size() < values_b.size()) 488 if (values_a.size() < values_b.size())
515 return -1; 489 return -1;
516 if (values_a.size() > values_b.size()) 490 if (values_a.size() > values_b.size())
517 return 1; 491 return 1;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 iter != field_types.end(); ++iter) { 534 iter != field_types.end(); ++iter) {
561 if (AutofillProfile::SupportsMultiValue(*iter)) { 535 if (AutofillProfile::SupportsMultiValue(*iter)) {
562 std::vector<string16> new_values; 536 std::vector<string16> new_values;
563 profile.GetMultiInfo(*iter, &new_values); 537 profile.GetMultiInfo(*iter, &new_values);
564 std::vector<string16> existing_values; 538 std::vector<string16> existing_values;
565 GetMultiInfo(*iter, &existing_values); 539 GetMultiInfo(*iter, &existing_values);
566 FieldTypeGroup group = AutofillType(*iter).group(); 540 FieldTypeGroup group = AutofillType(*iter).group();
567 for (std::vector<string16>::iterator value_iter = new_values.begin(); 541 for (std::vector<string16>::iterator value_iter = new_values.begin();
568 value_iter != new_values.end(); ++value_iter) { 542 value_iter != new_values.end(); ++value_iter) {
569 // Don't add duplicates. 543 // Don't add duplicates.
570 if (group == AutofillType::PHONE_HOME || 544 if (group == AutofillType::PHONE_HOME) {
571 group == AutofillType::PHONE_FAX) {
572 AddPhoneIfUnique(*value_iter, &existing_values); 545 AddPhoneIfUnique(*value_iter, &existing_values);
573 } else { 546 } else {
574 std::vector<string16>::const_iterator existing_iter = std::find_if( 547 std::vector<string16>::const_iterator existing_iter = std::find_if(
575 existing_values.begin(), existing_values.end(), 548 existing_values.begin(), existing_values.end(),
576 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); 549 std::bind1st(CaseInsensitiveStringEquals(), *value_iter));
577 if (existing_iter == existing_values.end()) 550 if (existing_iter == existing_values.end())
578 existing_values.insert(existing_values.end(), *value_iter); 551 existing_values.insert(existing_values.end(), *value_iter);
579 } 552 }
580 } 553 }
581 SetMultiInfo(*iter, existing_values); 554 SetMultiInfo(*iter, existing_values);
(...skipping 28 matching lines...) Expand all
610 included_fields.begin(); 583 included_fields.begin();
611 it != included_fields.end() && num_fields_used < num_fields_to_use; 584 it != included_fields.end() && num_fields_used < num_fields_to_use;
612 ++it) { 585 ++it) {
613 string16 field = GetInfo(*it); 586 string16 field = GetInfo(*it);
614 if (field.empty()) 587 if (field.empty())
615 continue; 588 continue;
616 589
617 if (!label.empty()) 590 if (!label.empty())
618 label.append(separator); 591 label.append(separator);
619 592
620 // Fax number has special format, to indicate that this is a fax number.
621 if (*it == PHONE_FAX_WHOLE_NUMBER) {
622 field = l10n_util::GetStringFUTF16(
623 IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_FAX_FORMAT, field);
624 }
625 label.append(field); 593 label.append(field);
626 ++num_fields_used; 594 ++num_fields_used;
627 } 595 }
628 return label; 596 return label;
629 } 597 }
630 598
631 // static 599 // static
632 void AutofillProfile::CreateDifferentiatingLabels( 600 void AutofillProfile::CreateDifferentiatingLabels(
633 const std::vector<AutofillProfile*>& profiles, 601 const std::vector<AutofillProfile*>& profiles,
634 const std::list<size_t>& indices, 602 const std::list<size_t>& indices,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 break; 667 break;
700 } 668 }
701 669
702 (*created_labels)[*it] = 670 (*created_labels)[*it] =
703 profile->ConstructInferredLabel(label_fields, 671 profile->ConstructInferredLabel(label_fields,
704 label_fields.size()); 672 label_fields.size());
705 } 673 }
706 } 674 }
707 675
708 AutofillProfile::FormGroupList AutofillProfile::FormGroups() const { 676 AutofillProfile::FormGroupList AutofillProfile::FormGroups() const {
709 FormGroupList v(6); 677 FormGroupList v(5);
710 v[0] = &name_[0]; 678 v[0] = &name_[0];
711 v[1] = &email_[0]; 679 v[1] = &email_[0];
712 v[2] = &company_; 680 v[2] = &company_;
713 v[3] = &home_number_[0]; 681 v[3] = &home_number_[0];
714 v[4] = &fax_number_[0]; 682 v[4] = &address_;
715 v[5] = &address_;
716 return v; 683 return v;
717 } 684 }
718 685
719 const FormGroup* AutofillProfile::FormGroupForType( 686 const FormGroup* AutofillProfile::FormGroupForType(
720 AutofillFieldType type) const { 687 AutofillFieldType type) const {
721 return const_cast<AutofillProfile*>(this)->MutableFormGroupForType(type); 688 return const_cast<AutofillProfile*>(this)->MutableFormGroupForType(type);
722 } 689 }
723 690
724 FormGroup* AutofillProfile::MutableFormGroupForType(AutofillFieldType type) { 691 FormGroup* AutofillProfile::MutableFormGroupForType(AutofillFieldType type) {
725 FormGroup* form_group = NULL; 692 FormGroup* form_group = NULL;
726 switch (AutofillType(type).group()) { 693 switch (AutofillType(type).group()) {
727 case AutofillType::NAME: 694 case AutofillType::NAME:
728 form_group = &name_[0]; 695 form_group = &name_[0];
729 break; 696 break;
730 case AutofillType::EMAIL: 697 case AutofillType::EMAIL:
731 form_group = &email_[0]; 698 form_group = &email_[0];
732 break; 699 break;
733 case AutofillType::COMPANY: 700 case AutofillType::COMPANY:
734 form_group = &company_; 701 form_group = &company_;
735 break; 702 break;
736 case AutofillType::PHONE_HOME: 703 case AutofillType::PHONE_HOME:
737 form_group = &home_number_[0]; 704 form_group = &home_number_[0];
738 break; 705 break;
739 case AutofillType::PHONE_FAX:
740 form_group = &fax_number_[0];
741 break;
742 case AutofillType::ADDRESS_HOME: 706 case AutofillType::ADDRESS_HOME:
743 form_group = &address_; 707 form_group = &address_;
744 break; 708 break;
745 default: 709 default:
746 break; 710 break;
747 } 711 }
748 return form_group; 712 return form_group;
749 } 713 }
750 714
751 // So we can compare AutofillProfiles with EXPECT_EQ(). 715 // So we can compare AutofillProfiles with EXPECT_EQ().
(...skipping 18 matching lines...) Expand all
770 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_LINE2)) 734 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_LINE2))
771 << " " 735 << " "
772 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_CITY)) 736 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_CITY))
773 << " " 737 << " "
774 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_STATE)) 738 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_STATE))
775 << " " 739 << " "
776 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_ZIP)) 740 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_ZIP))
777 << " " 741 << " "
778 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_COUNTRY)) 742 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_COUNTRY))
779 << " " 743 << " "
780 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)) 744 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER));
781 << " "
782 << UTF16ToUTF8(MultiString(profile, PHONE_FAX_WHOLE_NUMBER));
783 } 745 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_profile.h ('k') | chrome/browser/autofill/autofill_profile_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698