Chromium Code Reviews| 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 <ostream> | 10 #include <ostream> |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 } else if (values.size() == 0) { | 352 } else if (values.size() == 0) { |
| 353 SetRawInfo(type, base::string16()); | 353 SetRawInfo(type, base::string16()); |
| 354 } else { | 354 } else { |
| 355 // Shouldn't attempt to set multiple values on single-valued field. | 355 // Shouldn't attempt to set multiple values on single-valued field. |
| 356 NOTREACHED(); | 356 NOTREACHED(); |
| 357 } | 357 } |
| 358 break; | 358 break; |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 void AutofillProfile::SetPreferredNameInfo( | |
| 363 const std::vector<NameInfo>& profiles) { | |
| 364 if (!profiles.size()) | |
| 365 return; | |
| 366 | |
| 367 bool preferImportedProfile = true; | |
| 368 NameInfo importedProfile = profiles[0]; | |
|
Ilya Sherman
2014/05/15 22:21:27
Why pass a vector if you're only going to use the
Pritam Nikam
2014/05/19 12:09:15
Done.
| |
| 369 std::vector<NameInfo> namelist(name_); | |
| 370 for (size_t index = 0; index < name_.size(); index++) { | |
| 371 NameInfo prof = name_[index]; | |
| 372 if (prof.GetRawInfo(NAME_FULL) != importedProfile.GetRawInfo(NAME_FULL)) { | |
| 373 namelist.push_back(importedProfile); | |
|
Ilya Sherman
2014/05/15 22:21:27
If the existing profile has 10 names, none of whic
Pritam Nikam
2014/05/19 12:09:15
Done.
| |
| 374 continue; | |
| 375 } | |
| 376 | |
| 377 // Identical full names, we should always prefer to keep ones with more | |
| 378 // information i.e. where parsing the full_name_ does not give the same | |
| 379 // results as are stored in first_, middle_, and last_. Prefer profile | |
| 380 // with smaller middle names. | |
| 381 if (prof.GetRawInfo(NAME_MIDDLE).length() < | |
| 382 importedProfile.GetRawInfo(NAME_MIDDLE).length()) | |
|
Ilya Sherman
2014/05/15 22:21:27
I was thinking of something more like:
base::stri
Pritam Nikam
2014/05/19 12:09:15
Done.
| |
| 383 preferImportedProfile = false; | |
| 384 | |
| 385 if (preferImportedProfile) { | |
| 386 namelist[index] = importedProfile; | |
| 387 } | |
| 388 } | |
| 389 name_.swap(namelist); | |
| 390 } | |
|
Ilya Sherman
2014/05/15 22:21:27
There are many style guide violations in this code
Pritam Nikam
2014/05/19 12:09:15
Done.
| |
| 391 | |
| 362 void AutofillProfile::GetRawMultiInfo( | 392 void AutofillProfile::GetRawMultiInfo( |
| 363 ServerFieldType type, | 393 ServerFieldType type, |
| 364 std::vector<base::string16>* values) const { | 394 std::vector<base::string16>* values) const { |
| 365 GetMultiInfoImpl(AutofillType(type), std::string(), values); | 395 GetMultiInfoImpl(AutofillType(type), std::string(), values); |
| 366 } | 396 } |
| 367 | 397 |
| 368 void AutofillProfile::GetMultiInfo(const AutofillType& type, | 398 void AutofillProfile::GetMultiInfo(const AutofillType& type, |
| 369 const std::string& app_locale, | 399 const std::string& app_locale, |
| 370 std::vector<base::string16>* values) const { | 400 std::vector<base::string16>* values) const { |
| 371 GetMultiInfoImpl(type, app_locale, values); | 401 GetMultiInfoImpl(type, app_locale, values); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); | 577 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); |
| 548 } else { | 578 } else { |
| 549 std::vector<base::string16>::const_iterator existing_iter = | 579 std::vector<base::string16>::const_iterator existing_iter = |
| 550 std::find_if( | 580 std::find_if( |
| 551 existing_values.begin(), existing_values.end(), | 581 existing_values.begin(), existing_values.end(), |
| 552 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); | 582 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); |
| 553 if (existing_iter == existing_values.end()) | 583 if (existing_iter == existing_values.end()) |
| 554 existing_values.insert(existing_values.end(), *value_iter); | 584 existing_values.insert(existing_values.end(), *value_iter); |
| 555 } | 585 } |
| 556 } | 586 } |
| 557 SetRawMultiInfo(*iter, existing_values); | 587 |
| 588 if (group == NAME) | |
| 589 SetPreferredNameInfo(profile.name_); | |
| 590 else | |
| 591 SetRawMultiInfo(*iter, existing_values); | |
| 558 } else { | 592 } else { |
| 559 base::string16 new_value = profile.GetRawInfo(*iter); | 593 base::string16 new_value = profile.GetRawInfo(*iter); |
| 560 if (StringToLowerASCII(GetRawInfo(*iter)) != | 594 if (StringToLowerASCII(GetRawInfo(*iter)) != |
| 561 StringToLowerASCII(new_value)) { | 595 StringToLowerASCII(new_value)) { |
| 562 SetRawInfo(*iter, new_value); | 596 SetRawInfo(*iter, new_value); |
| 563 } | 597 } |
| 564 } | 598 } |
| 565 } | 599 } |
| 566 } | 600 } |
| 567 | 601 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 855 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) | 889 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) |
| 856 << " " | 890 << " " |
| 857 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 891 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
| 858 << " " | 892 << " " |
| 859 << profile.language_code() | 893 << profile.language_code() |
| 860 << " " | 894 << " " |
| 861 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 895 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
| 862 } | 896 } |
| 863 | 897 |
| 864 } // namespace autofill | 898 } // namespace autofill |
| OLD | NEW |