| 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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 if (is_off_the_record_ || !database_.get()) | 474 if (is_off_the_record_ || !database_.get()) |
| 475 return; | 475 return; |
| 476 | 476 |
| 477 CreditCard* credit_card = GetCreditCardByGUID(data_model.guid()); | 477 CreditCard* credit_card = GetCreditCardByGUID(data_model.guid()); |
| 478 if (credit_card) { | 478 if (credit_card) { |
| 479 credit_card->RecordAndLogUse(); | 479 credit_card->RecordAndLogUse(); |
| 480 | 480 |
| 481 if (credit_card->record_type() == CreditCard::LOCAL_CARD) | 481 if (credit_card->record_type() == CreditCard::LOCAL_CARD) |
| 482 database_->UpdateCreditCard(*credit_card); | 482 database_->UpdateCreditCard(*credit_card); |
| 483 else | 483 else |
| 484 database_->UpdateServerCardUsageStats(*credit_card); | 484 database_->UpdateServerCardMetadata(*credit_card); |
| 485 | 485 |
| 486 Refresh(); | 486 Refresh(); |
| 487 return; | 487 return; |
| 488 } | 488 } |
| 489 | 489 |
| 490 AutofillProfile* profile = GetProfileByGUID(data_model.guid()); | 490 AutofillProfile* profile = GetProfileByGUID(data_model.guid()); |
| 491 if (profile) { | 491 if (profile) { |
| 492 profile->RecordAndLogUse(); | 492 profile->RecordAndLogUse(); |
| 493 | 493 |
| 494 if (profile->record_type() == AutofillProfile::LOCAL_PROFILE) | 494 if (profile->record_type() == AutofillProfile::LOCAL_PROFILE) |
| 495 database_->UpdateAutofillProfile(*profile); | 495 database_->UpdateAutofillProfile(*profile); |
| 496 else if (profile->record_type() == AutofillProfile::SERVER_PROFILE) | 496 else if (profile->record_type() == AutofillProfile::SERVER_PROFILE) |
| 497 database_->UpdateServerAddressUsageStats(*profile); | 497 database_->UpdateServerAddressMetadata(*profile); |
| 498 | 498 |
| 499 Refresh(); | 499 Refresh(); |
| 500 } | 500 } |
| 501 } | 501 } |
| 502 | 502 |
| 503 void PersonalDataManager::AddProfile(const AutofillProfile& profile) { | 503 void PersonalDataManager::AddProfile(const AutofillProfile& profile) { |
| 504 if (is_off_the_record_) | 504 if (is_off_the_record_) |
| 505 return; | 505 return; |
| 506 | 506 |
| 507 if (profile.IsEmpty(app_locale_)) | 507 if (profile.IsEmpty(app_locale_)) |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 database_->MaskServerCreditCard(credit_card.server_id()); | 642 database_->MaskServerCreditCard(credit_card.server_id()); |
| 643 } | 643 } |
| 644 | 644 |
| 645 Refresh(); | 645 Refresh(); |
| 646 } | 646 } |
| 647 | 647 |
| 648 void PersonalDataManager::UpdateServerCardMetadata( | 648 void PersonalDataManager::UpdateServerCardMetadata( |
| 649 const CreditCard& credit_card) { | 649 const CreditCard& credit_card) { |
| 650 DCHECK_NE(CreditCard::LOCAL_CARD, credit_card.record_type()); | 650 DCHECK_NE(CreditCard::LOCAL_CARD, credit_card.record_type()); |
| 651 | 651 |
| 652 if (!database_.get()) | 652 if (is_off_the_record_ || !database_.get()) |
| 653 return; | 653 return; |
| 654 | 654 |
| 655 CreditCard* existing_credit_card = nullptr; | 655 database_->UpdateServerCardMetadata(credit_card); |
| 656 for (auto& server_card : server_credit_cards_) { | |
| 657 if (credit_card.server_id() == server_card->server_id()) { | |
| 658 existing_credit_card = server_card.get(); | |
| 659 break; | |
| 660 } | |
| 661 } | |
| 662 if (!existing_credit_card | |
| 663 || existing_credit_card->billing_address_id() == | |
| 664 credit_card.billing_address_id()) { | |
| 665 return; | |
| 666 } | |
| 667 | |
| 668 existing_credit_card->set_billing_address_id( | |
| 669 credit_card.billing_address_id()); | |
| 670 database_->UpdateServerCardBillingAddress(*existing_credit_card); | |
| 671 | 656 |
| 672 Refresh(); | 657 Refresh(); |
| 673 } | 658 } |
| 674 | 659 |
| 675 void PersonalDataManager::ResetFullServerCard(const std::string& guid) { | 660 void PersonalDataManager::ResetFullServerCard(const std::string& guid) { |
| 676 for (const auto& card : server_credit_cards_) { | 661 for (const auto& card : server_credit_cards_) { |
| 677 if (card->guid() == guid) { | 662 if (card->guid() == guid) { |
| 678 DCHECK_EQ(card->record_type(), CreditCard::FULL_SERVER_CARD); | 663 DCHECK_EQ(card->record_type(), CreditCard::FULL_SERVER_CARD); |
| 679 CreditCard card_copy = *card; | 664 CreditCard card_copy = *card; |
| 680 card_copy.set_record_type(CreditCard::MASKED_SERVER_CARD); | 665 card_copy.set_record_type(CreditCard::MASKED_SERVER_CARD); |
| (...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1861 } | 1846 } |
| 1862 | 1847 |
| 1863 // If the card was modified, apply the changes to the database. | 1848 // If the card was modified, apply the changes to the database. |
| 1864 if (was_modified) { | 1849 if (was_modified) { |
| 1865 database_->UpdateCreditCard(*credit_card); | 1850 database_->UpdateCreditCard(*credit_card); |
| 1866 } | 1851 } |
| 1867 } | 1852 } |
| 1868 } | 1853 } |
| 1869 | 1854 |
| 1870 } // namespace autofill | 1855 } // namespace autofill |
| OLD | NEW |