| 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/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 } | 435 } |
| 436 | 436 |
| 437 void PersonalDataManager::RemoveObserver( | 437 void PersonalDataManager::RemoveObserver( |
| 438 PersonalDataManagerObserver* observer) { | 438 PersonalDataManagerObserver* observer) { |
| 439 observers_.RemoveObserver(observer); | 439 observers_.RemoveObserver(observer); |
| 440 } | 440 } |
| 441 | 441 |
| 442 bool PersonalDataManager::ImportFormData( | 442 bool PersonalDataManager::ImportFormData( |
| 443 const FormStructure& form, | 443 const FormStructure& form, |
| 444 bool should_return_local_card, | 444 bool should_return_local_card, |
| 445 std::unique_ptr<CreditCard>* imported_credit_card) { | 445 std::unique_ptr<CreditCard>* imported_credit_card, |
| 446 bool* imported_credit_card_matches_masked_server_credit_card) { |
| 446 // We try the same |form| for both credit card and address import/update. | 447 // We try the same |form| for both credit card and address import/update. |
| 447 // - ImportCreditCard may update an existing card, or fill | 448 // - ImportCreditCard may update an existing card, or fill |
| 448 // |imported_credit_card| with an extracted card. See .h for details of | 449 // |imported_credit_card| with an extracted card. See .h for details of |
| 449 // |should_return_local_card|. | 450 // |should_return_local_card| and |
| 451 // |imported_credit_card_matches_masked_server_credit_card|. |
| 450 bool cc_import = | 452 bool cc_import = |
| 451 ImportCreditCard(form, should_return_local_card, imported_credit_card); | 453 ImportCreditCard(form, should_return_local_card, imported_credit_card, |
| 454 imported_credit_card_matches_masked_server_credit_card); |
| 452 // - ImportAddressProfiles may eventually save or update one or more address | 455 // - ImportAddressProfiles may eventually save or update one or more address |
| 453 // profiles. | 456 // profiles. |
| 454 bool address_import = ImportAddressProfiles(form); | 457 bool address_import = ImportAddressProfiles(form); |
| 455 if (cc_import || address_import) | 458 if (cc_import || address_import) |
| 456 return true; | 459 return true; |
| 457 | 460 |
| 458 for (PersonalDataManagerObserver& observer : observers_) | 461 for (PersonalDataManagerObserver& observer : observers_) |
| 459 observer.OnInsufficientFormData(); | 462 observer.OnInsufficientFormData(); |
| 460 return false; | 463 return false; |
| 461 } | 464 } |
| (...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 if (!IsValidLearnableProfile(candidate_profile, app_locale_)) | 1493 if (!IsValidLearnableProfile(candidate_profile, app_locale_)) |
| 1491 return false; | 1494 return false; |
| 1492 | 1495 |
| 1493 SaveImportedProfile(candidate_profile); | 1496 SaveImportedProfile(candidate_profile); |
| 1494 return true; | 1497 return true; |
| 1495 } | 1498 } |
| 1496 | 1499 |
| 1497 bool PersonalDataManager::ImportCreditCard( | 1500 bool PersonalDataManager::ImportCreditCard( |
| 1498 const FormStructure& form, | 1501 const FormStructure& form, |
| 1499 bool should_return_local_card, | 1502 bool should_return_local_card, |
| 1500 std::unique_ptr<CreditCard>* imported_credit_card) { | 1503 std::unique_ptr<CreditCard>* imported_credit_card, |
| 1504 bool* imported_credit_card_matches_masked_server_credit_card) { |
| 1501 DCHECK(!imported_credit_card->get()); | 1505 DCHECK(!imported_credit_card->get()); |
| 1506 *imported_credit_card_matches_masked_server_credit_card = false; |
| 1502 | 1507 |
| 1503 // The candidate for credit card import. There are many ways for the candidate | 1508 // The candidate for credit card import. There are many ways for the candidate |
| 1504 // to be rejected (see everywhere this function returns false, below). | 1509 // to be rejected (see everywhere this function returns false, below). |
| 1505 CreditCard candidate_credit_card; | 1510 CreditCard candidate_credit_card; |
| 1506 candidate_credit_card.set_origin(form.source_url().spec()); | 1511 candidate_credit_card.set_origin(form.source_url().spec()); |
| 1507 | 1512 |
| 1508 std::set<ServerFieldType> types_seen; | 1513 std::set<ServerFieldType> types_seen; |
| 1509 for (const auto& field : form) { | 1514 for (const auto& field : form) { |
| 1510 base::string16 value; | 1515 base::string16 value; |
| 1511 base::TrimWhitespace(field->value, base::TRIM_ALL, &value); | 1516 base::TrimWhitespace(field->value, base::TRIM_ALL, &value); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1554 | 1559 |
| 1555 // Reject the credit card if we did not detect enough filled credit card | 1560 // Reject the credit card if we did not detect enough filled credit card |
| 1556 // fields (such as valid number, month, year). | 1561 // fields (such as valid number, month, year). |
| 1557 if (!candidate_credit_card.IsValid()) | 1562 if (!candidate_credit_card.IsValid()) |
| 1558 return false; | 1563 return false; |
| 1559 | 1564 |
| 1560 // Attempt to merge with an existing credit card. Don't present a prompt if we | 1565 // Attempt to merge with an existing credit card. Don't present a prompt if we |
| 1561 // have already saved this card number, unless |should_return_local_card| is | 1566 // have already saved this card number, unless |should_return_local_card| is |
| 1562 // true which indicates that upload is enabled. In this case, it's useful to | 1567 // true which indicates that upload is enabled. In this case, it's useful to |
| 1563 // present the upload prompt to the user to promote the card from a local card | 1568 // present the upload prompt to the user to promote the card from a local card |
| 1564 // to a synced server card. | 1569 // to a synced server card, provided we don't have a masked server card with |
| 1570 // the same |TypeAndLastFourDigits|. |
| 1565 for (const auto& card : local_credit_cards_) { | 1571 for (const auto& card : local_credit_cards_) { |
| 1566 // Make a local copy so that the data in |local_credit_cards_| isn't | 1572 // Make a local copy so that the data in |local_credit_cards_| isn't |
| 1567 // modified directly by the UpdateFromImportedCard() call. | 1573 // modified directly by the UpdateFromImportedCard() call. |
| 1568 CreditCard card_copy(*card); | 1574 CreditCard card_copy(*card); |
| 1569 if (card_copy.UpdateFromImportedCard(candidate_credit_card, | 1575 if (card_copy.UpdateFromImportedCard(candidate_credit_card, |
| 1570 app_locale_)) { | 1576 app_locale_)) { |
| 1571 UpdateCreditCard(card_copy); | 1577 UpdateCreditCard(card_copy); |
| 1572 // If we should not return the local card, return that we merged it, | 1578 // If we should not return the local card, return that we merged it, |
| 1573 // without setting |imported_credit_card|. | 1579 // without setting |imported_credit_card|. |
| 1574 if (!should_return_local_card) | 1580 if (!should_return_local_card) |
| 1575 return true; | 1581 return true; |
| 1576 | 1582 |
| 1577 break; | 1583 break; |
| 1578 } | 1584 } |
| 1579 } | 1585 } |
| 1580 | 1586 |
| 1581 // Also don't offer to save if we already have this stored as a server card. | 1587 // Also don't offer to save if we already have this stored as a full server |
| 1582 // We only check the number because if the new card has the same number as the | 1588 // card. We only check the number because if the new card has the same number |
| 1583 // server card, upload is guaranteed to fail. There's no mechanism for entries | 1589 // as the server card, upload is guaranteed to fail. There's no mechanism for |
| 1584 // with the same number but different names or expiration dates as there is | 1590 // entries with the same number but different names or expiration dates as |
| 1585 // for local cards. | 1591 // there is for local cards. |
| 1592 // We can offer to save locally even if we already have this stored another |
| 1593 // masked server card with the same |TypeAndLastFourDigits| so that the user |
| 1594 // can enter the full card number without having to unmask the card. |
| 1586 for (const auto& card : server_credit_cards_) { | 1595 for (const auto& card : server_credit_cards_) { |
| 1587 if (candidate_credit_card.HasSameNumberAs(*card)) | 1596 if (candidate_credit_card.HasSameNumberAs(*card)) { |
| 1588 return false; | 1597 if (card->record_type() == CreditCard::FULL_SERVER_CARD) |
| 1598 return false; |
| 1599 DCHECK_EQ(card->record_type(), CreditCard::MASKED_SERVER_CARD); |
| 1600 *imported_credit_card_matches_masked_server_credit_card = true; |
| 1601 break; |
| 1602 } |
| 1589 } | 1603 } |
| 1590 | 1604 |
| 1591 imported_credit_card->reset(new CreditCard(candidate_credit_card)); | 1605 imported_credit_card->reset(new CreditCard(candidate_credit_card)); |
| 1592 return true; | 1606 return true; |
| 1593 } | 1607 } |
| 1594 | 1608 |
| 1595 const std::vector<AutofillProfile*>& PersonalDataManager::GetProfiles( | 1609 const std::vector<AutofillProfile*>& PersonalDataManager::GetProfiles( |
| 1596 bool record_metrics) const { | 1610 bool record_metrics) const { |
| 1597 profiles_.clear(); | 1611 profiles_.clear(); |
| 1598 for (const auto& profile : web_profiles_) | 1612 for (const auto& profile : web_profiles_) |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2037 existing_profiles->back().SetRawInfo(EMAIL_ADDRESS, email); | 2051 existing_profiles->back().SetRawInfo(EMAIL_ADDRESS, email); |
| 2038 | 2052 |
| 2039 AutofillMetrics::LogWalletAddressConversionType( | 2053 AutofillMetrics::LogWalletAddressConversionType( |
| 2040 AutofillMetrics::CONVERTED_ADDRESS_ADDED); | 2054 AutofillMetrics::CONVERTED_ADDRESS_ADDED); |
| 2041 } | 2055 } |
| 2042 | 2056 |
| 2043 return guid; | 2057 return guid; |
| 2044 } | 2058 } |
| 2045 | 2059 |
| 2046 } // namespace autofill | 2060 } // namespace autofill |
| OLD | NEW |