| 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 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 const std::unordered_map<std::string, std::string>& guids_merge_map) { | 1813 const std::unordered_map<std::string, std::string>& guids_merge_map) { |
| 1814 /* Here is an example of what the graph might look like. | 1814 /* Here is an example of what the graph might look like. |
| 1815 | 1815 |
| 1816 A -> B | 1816 A -> B |
| 1817 \ | 1817 \ |
| 1818 -> E | 1818 -> E |
| 1819 / | 1819 / |
| 1820 C -> D | 1820 C -> D |
| 1821 */ | 1821 */ |
| 1822 | 1822 |
| 1823 for (auto& credit_card : local_credit_cards_) { | 1823 for (auto& credit_card : GetCreditCards()) { |
| 1824 // If the credit card is not associated with a billing address, skip it. | 1824 // If the credit card is not associated with a billing address, skip it. |
| 1825 if (credit_card->billing_address_id().empty()) | 1825 if (credit_card->billing_address_id().empty()) |
| 1826 break; | 1826 break; |
| 1827 | 1827 |
| 1828 // If the billing address profile associated with the card has been merged, | 1828 // If the billing address profile associated with the card has been merged, |
| 1829 // replace it by the id of the profile in which it was merged. Repeat the | 1829 // replace it by the id of the profile in which it was merged. Repeat the |
| 1830 // process until the billing address has not been merged into another one. | 1830 // process until the billing address has not been merged into another one. |
| 1831 std::unordered_map<std::string, std::string>::size_type nb_guid_changes = 0; | 1831 std::unordered_map<std::string, std::string>::size_type nb_guid_changes = 0; |
| 1832 bool was_modified = false; | 1832 bool was_modified = false; |
| 1833 auto it = guids_merge_map.find(credit_card->billing_address_id()); | 1833 auto it = guids_merge_map.find(credit_card->billing_address_id()); |
| 1834 while (it != guids_merge_map.end()) { | 1834 while (it != guids_merge_map.end()) { |
| 1835 was_modified = true; | 1835 was_modified = true; |
| 1836 credit_card->set_billing_address_id(it->second); | 1836 credit_card->set_billing_address_id(it->second); |
| 1837 it = guids_merge_map.find(credit_card->billing_address_id()); | 1837 it = guids_merge_map.find(credit_card->billing_address_id()); |
| 1838 | 1838 |
| 1839 // Out of abundance of caution. | 1839 // Out of abundance of caution. |
| 1840 if (nb_guid_changes > guids_merge_map.size()) { | 1840 if (nb_guid_changes > guids_merge_map.size()) { |
| 1841 NOTREACHED(); | 1841 NOTREACHED(); |
| 1842 // Cancel the changes for that card. | 1842 // Cancel the changes for that card. |
| 1843 was_modified = false; | 1843 was_modified = false; |
| 1844 break; | 1844 break; |
| 1845 } | 1845 } |
| 1846 } | 1846 } |
| 1847 | 1847 |
| 1848 // If the card was modified, apply the changes to the database. | 1848 // If the card was modified, apply the changes to the database. |
| 1849 if (was_modified) { | 1849 if (was_modified) { |
| 1850 database_->UpdateCreditCard(*credit_card); | 1850 if (credit_card->record_type() == CreditCard::LOCAL_CARD) |
| 1851 database_->UpdateCreditCard(*credit_card); |
| 1852 else |
| 1853 database_->UpdateServerCardMetadata(*credit_card); |
| 1851 } | 1854 } |
| 1852 } | 1855 } |
| 1853 } | 1856 } |
| 1854 | 1857 |
| 1855 } // namespace autofill | 1858 } // namespace autofill |
| OLD | NEW |