OLD | NEW |
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 <memory> | 10 #include <memory> |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 | 442 |
443 NameInfo name; | 443 NameInfo name; |
444 EmailInfo email; | 444 EmailInfo email; |
445 CompanyInfo company; | 445 CompanyInfo company; |
446 PhoneNumber phone_number(this); | 446 PhoneNumber phone_number(this); |
447 Address address; | 447 Address address; |
448 | 448 |
449 DVLOG(1) << "Merging profiles:\nSource = " << profile << "\nDest = " << *this; | 449 DVLOG(1) << "Merging profiles:\nSource = " << profile << "\nDest = " << *this; |
450 | 450 |
451 // The comparator's merge operations are biased to prefer the data in the | 451 // The comparator's merge operations are biased to prefer the data in the |
452 // first profile parameter when the data is the same modulo case. We pass the | 452 // first profile parameter when the data is the same modulo case. We expect |
453 // incoming profile in this position to prefer accepting updates instead of | 453 // the caller to pass the incoming profile in this position to prefer |
454 // preserving the original data. I.e., passing the incoming profile first | 454 // accepting updates instead of preserving the original data. I.e., passing |
455 // accepts case changes, the other ways does not. | 455 // the incoming profile first accepts case and diacritic changes, for example, |
| 456 // the other ways does not. |
456 if (!comparator.MergeNames(profile, *this, &name) || | 457 if (!comparator.MergeNames(profile, *this, &name) || |
457 !comparator.MergeEmailAddresses(profile, *this, &email) || | 458 !comparator.MergeEmailAddresses(profile, *this, &email) || |
458 !comparator.MergeCompanyNames(profile, *this, &company) || | 459 !comparator.MergeCompanyNames(profile, *this, &company) || |
459 !comparator.MergePhoneNumbers(profile, *this, &phone_number) || | 460 !comparator.MergePhoneNumbers(profile, *this, &phone_number) || |
460 !comparator.MergeAddresses(profile, *this, &address)) { | 461 !comparator.MergeAddresses(profile, *this, &address)) { |
461 NOTREACHED(); | 462 NOTREACHED(); |
462 return false; | 463 return false; |
463 } | 464 } |
464 | 465 |
| 466 // TODO(rogerm): As implemented, "origin" really denotes "domain of last use". |
| 467 // Find a better merge heuristic. Ditto for language code. |
465 set_origin(profile.origin()); | 468 set_origin(profile.origin()); |
466 set_language_code(profile.language_code()); | 469 set_language_code(profile.language_code()); |
467 set_use_count(profile.use_count() + use_count()); | |
468 if (profile.use_date() > use_date()) | |
469 set_use_date(profile.use_date()); | |
470 | 470 |
471 // Now that the preferred values have been obtained, update the fields which | 471 // Update the use-count to be the max of the two merge-counts. Alternatively, |
472 // need to be modified, if any. Note: that we're comparing the fields for | 472 // we could have summed the two merge-counts. We don't sum because it skews |
473 // representational equality below (i.e., are the values byte for byte the | 473 // the frecency value on merge and double counts usage on profile reuse. |
474 // same). | 474 // Profile reuse is accounted for on RecordUseOf() on selection of a profile |
| 475 // in the autofill drop-down; we don't need to account for that here. Further, |
| 476 // a similar, fully-typed submission that merges to an existing profile should |
| 477 // not be counted as a re-use of that profile. |
| 478 set_use_count(std::max(profile.use_count(), use_count())); |
| 479 set_use_date(std::max(profile.use_date(), use_date())); |
| 480 |
| 481 // Update the fields which need to be modified, if any. Note: that we're |
| 482 // comparing the fields for representational equality below (i.e., are the |
| 483 // values byte for byte the same). |
475 | 484 |
476 bool modified = false; | 485 bool modified = false; |
477 | 486 |
478 if (name_ != name) { | 487 if (name_ != name) { |
479 name_ = name; | 488 name_ = name; |
480 modified = true; | 489 modified = true; |
481 } | 490 } |
482 | 491 |
483 if (email_ != email) { | 492 if (email_ != email) { |
484 email_ = email; | 493 email_ = email; |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " " | 855 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " " |
847 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " " | 856 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " " |
848 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " " | 857 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " " |
849 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " " | 858 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " " |
850 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " " | 859 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " " |
851 << profile.language_code() << " " | 860 << profile.language_code() << " " |
852 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | 861 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
853 } | 862 } |
854 | 863 |
855 } // namespace autofill | 864 } // namespace autofill |
OLD | NEW |