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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 | 255 |
| 256 name_ = profile.name_; | 256 name_ = profile.name_; |
| 257 email_ = profile.email_; | 257 email_ = profile.email_; |
| 258 company_ = profile.company_; | 258 company_ = profile.company_; |
| 259 phone_number_ = profile.phone_number_; | 259 phone_number_ = profile.phone_number_; |
| 260 | 260 |
| 261 for (size_t i = 0; i < phone_number_.size(); ++i) | 261 for (size_t i = 0; i < phone_number_.size(); ++i) |
| 262 phone_number_[i].set_profile(this); | 262 phone_number_[i].set_profile(this); |
| 263 | 263 |
| 264 address_ = profile.address_; | 264 address_ = profile.address_; |
| 265 set_language_code(profile.language_code()); | |
| 265 | 266 |
| 266 return *this; | 267 return *this; |
| 267 } | 268 } |
| 268 | 269 |
| 269 void AutofillProfile::GetMatchingTypes( | 270 void AutofillProfile::GetMatchingTypes( |
| 270 const base::string16& text, | 271 const base::string16& text, |
| 271 const std::string& app_locale, | 272 const std::string& app_locale, |
| 272 ServerFieldTypeSet* matching_types) const { | 273 ServerFieldTypeSet* matching_types) const { |
| 273 FormGroupList info = FormGroups(); | 274 FormGroupList info = FormGroups(); |
| 274 for (FormGroupList::const_iterator it = info.begin(); it != info.end(); ++it) | 275 for (FormGroupList::const_iterator it = info.begin(); it != info.end(); ++it) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 | 395 |
| 395 case EMAIL_ADDRESS: | 396 case EMAIL_ADDRESS: |
| 396 return !autofill::IsValidEmailAddress(data); | 397 return !autofill::IsValidEmailAddress(data); |
| 397 | 398 |
| 398 default: | 399 default: |
| 399 NOTREACHED(); | 400 NOTREACHED(); |
| 400 return false; | 401 return false; |
| 401 } | 402 } |
| 402 } | 403 } |
| 403 | 404 |
| 404 | |
| 405 int AutofillProfile::Compare(const AutofillProfile& profile) const { | 405 int AutofillProfile::Compare(const AutofillProfile& profile) const { |
| 406 const ServerFieldType single_value_types[] = { | 406 const ServerFieldType single_value_types[] = { |
| 407 COMPANY_NAME, | 407 COMPANY_NAME, |
| 408 ADDRESS_HOME_LINE1, | 408 ADDRESS_HOME_LINE1, |
| 409 ADDRESS_HOME_LINE2, | 409 ADDRESS_HOME_LINE2, |
| 410 ADDRESS_HOME_DEPENDENT_LOCALITY, | 410 ADDRESS_HOME_DEPENDENT_LOCALITY, |
| 411 ADDRESS_HOME_CITY, | 411 ADDRESS_HOME_CITY, |
| 412 ADDRESS_HOME_STATE, | 412 ADDRESS_HOME_STATE, |
| 413 ADDRESS_HOME_ZIP, | 413 ADDRESS_HOME_ZIP, |
| 414 ADDRESS_HOME_SORTING_CODE, | 414 ADDRESS_HOME_SORTING_CODE, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 440 for (size_t j = 0; j < values_a.size(); ++j) { | 440 for (size_t j = 0; j < values_a.size(); ++j) { |
| 441 int comparison = values_a[j].compare(values_b[j]); | 441 int comparison = values_a[j].compare(values_b[j]); |
| 442 if (comparison != 0) | 442 if (comparison != 0) |
| 443 return comparison; | 443 return comparison; |
| 444 } | 444 } |
| 445 } | 445 } |
| 446 | 446 |
| 447 return 0; | 447 return 0; |
| 448 } | 448 } |
| 449 | 449 |
| 450 bool AutofillProfile::EqualsSansOrigin(const AutofillProfile& profile) const { | |
| 451 return guid() == profile.guid() && | |
| 452 language_code() == profile.language_code() && | |
| 453 Compare(profile) == 0; | |
| 454 } | |
| 455 | |
| 456 bool AutofillProfile::EqualsSansGuid(const AutofillProfile& profile) const { | |
| 457 return origin() == profile.origin() && | |
| 458 language_code() == profile.language_code() && | |
| 459 Compare(profile) == 0; | |
|
Ilya Sherman
2014/04/09 23:17:49
nit: Perhaps call EqualsSansGuidAndOrigin() from b
please use gerrit instead
2014/04/09 23:43:58
EqualsSansGuidAndOrigin() is removed, as it's no l
| |
| 460 } | |
| 461 | |
| 462 bool AutofillProfile::EqualsSansGuidAndOrigin( | |
| 463 const AutofillProfile& profile) const { | |
| 464 return language_code() == profile.language_code() && | |
| 465 Compare(profile) == 0; | |
| 466 } | |
| 467 | |
| 450 bool AutofillProfile::operator==(const AutofillProfile& profile) const { | 468 bool AutofillProfile::operator==(const AutofillProfile& profile) const { |
| 451 return guid() == profile.guid() && | 469 return guid() == profile.guid() && |
| 452 origin() == profile.origin() && | 470 origin() == profile.origin() && |
| 471 language_code() == profile.language_code() && | |
| 453 Compare(profile) == 0; | 472 Compare(profile) == 0; |
|
Ilya Sherman
2014/04/09 23:17:49
nit: Perhaps call one of EqualsSans...() methods h
please use gerrit instead
2014/04/09 23:43:58
Calling EqualsSansGuid().
| |
| 454 } | 473 } |
| 455 | 474 |
| 456 bool AutofillProfile::operator!=(const AutofillProfile& profile) const { | 475 bool AutofillProfile::operator!=(const AutofillProfile& profile) const { |
| 457 return !operator==(profile); | 476 return !operator==(profile); |
| 458 } | 477 } |
| 459 | 478 |
| 460 const base::string16 AutofillProfile::PrimaryValue() const { | 479 const base::string16 AutofillProfile::PrimaryValue() const { |
| 461 return GetRawInfo(ADDRESS_HOME_LINE1) + GetRawInfo(ADDRESS_HOME_CITY); | 480 return GetRawInfo(ADDRESS_HOME_LINE1) + GetRawInfo(ADDRESS_HOME_CITY); |
| 462 } | 481 } |
| 463 | 482 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 493 } | 512 } |
| 494 | 513 |
| 495 return true; | 514 return true; |
| 496 } | 515 } |
| 497 | 516 |
| 498 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, | 517 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, |
| 499 const std::string& app_locale) { | 518 const std::string& app_locale) { |
| 500 // Verified profiles should never be overwritten with unverified data. | 519 // Verified profiles should never be overwritten with unverified data. |
| 501 DCHECK(!IsVerified() || profile.IsVerified()); | 520 DCHECK(!IsVerified() || profile.IsVerified()); |
| 502 set_origin(profile.origin()); | 521 set_origin(profile.origin()); |
| 522 set_language_code(profile.language_code()); | |
| 503 | 523 |
| 504 ServerFieldTypeSet field_types; | 524 ServerFieldTypeSet field_types; |
| 505 profile.GetNonEmptyTypes(app_locale, &field_types); | 525 profile.GetNonEmptyTypes(app_locale, &field_types); |
| 506 | 526 |
| 507 // Only transfer "full" types (e.g. full name) and not fragments (e.g. | 527 // Only transfer "full" types (e.g. full name) and not fragments (e.g. |
| 508 // first name, last name). | 528 // first name, last name). |
| 509 CollapseCompoundFieldTypes(&field_types); | 529 CollapseCompoundFieldTypes(&field_types); |
| 510 | 530 |
| 511 // TODO(isherman): Revisit this decision in the context of i18n and storing | 531 // TODO(isherman): Revisit this decision in the context of i18n and storing |
| 512 // full addresses rather than storing 1-to-2 lines of an address. | 532 // full addresses rather than storing 1-to-2 lines of an address. |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) | 858 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) |
| 839 << " " | 859 << " " |
| 840 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) | 860 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) |
| 841 << " " | 861 << " " |
| 842 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) | 862 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) |
| 843 << " " | 863 << " " |
| 844 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) | 864 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) |
| 845 << " " | 865 << " " |
| 846 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 866 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
| 847 << " " | 867 << " " |
| 868 << profile.language_code() | |
| 869 << " " | |
| 848 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 870 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
| 849 } | 871 } |
| 850 | 872 |
| 851 } // namespace autofill | 873 } // namespace autofill |
| OLD | NEW |