| 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_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 19 #include "base/containers/adapters.h" | 19 #include "base/containers/adapters.h" |
| 20 #include "base/feature_list.h" | 20 #include "base/feature_list.h" |
| 21 #include "base/files/file_util.h" | 21 #include "base/files/file_util.h" |
| 22 #include "base/guid.h" | 22 #include "base/guid.h" |
| 23 #include "base/logging.h" | 23 #include "base/logging.h" |
| 24 #include "base/memory/ptr_util.h" |
| 24 #include "base/message_loop/message_loop.h" | 25 #include "base/message_loop/message_loop.h" |
| 25 #include "base/path_service.h" | 26 #include "base/path_service.h" |
| 26 #include "base/strings/string16.h" | 27 #include "base/strings/string16.h" |
| 27 #include "base/strings/string_number_conversions.h" | 28 #include "base/strings/string_number_conversions.h" |
| 28 #include "base/strings/string_split.h" | 29 #include "base/strings/string_split.h" |
| 29 #include "base/strings/string_util.h" | 30 #include "base/strings/string_util.h" |
| 30 #include "base/strings/utf_string_conversions.h" | 31 #include "base/strings/utf_string_conversions.h" |
| 31 #include "base/threading/sequenced_worker_pool.h" | 32 #include "base/threading/sequenced_worker_pool.h" |
| 32 #include "base/threading/thread_restrictions.h" | 33 #include "base/threading/thread_restrictions.h" |
| 33 #include "build/build_config.h" | 34 #include "build/build_config.h" |
| (...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 | 873 |
| 873 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name, | 874 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name, |
| 874 const base::string16& value) { | 875 const base::string16& value) { |
| 875 autocomplete_history_manager_->OnRemoveAutocompleteEntry(name, value); | 876 autocomplete_history_manager_->OnRemoveAutocompleteEntry(name, value); |
| 876 } | 877 } |
| 877 | 878 |
| 878 bool AutofillManager::IsShowingUnmaskPrompt() { | 879 bool AutofillManager::IsShowingUnmaskPrompt() { |
| 879 return full_card_request_ && full_card_request_->IsGettingFullCard(); | 880 return full_card_request_ && full_card_request_->IsGettingFullCard(); |
| 880 } | 881 } |
| 881 | 882 |
| 882 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() { | 883 const std::vector<std::unique_ptr<FormStructure>>& |
| 883 return form_structures_.get(); | 884 AutofillManager::GetFormStructures() { |
| 885 return form_structures_; |
| 884 } | 886 } |
| 885 | 887 |
| 886 payments::FullCardRequest* AutofillManager::GetOrCreateFullCardRequest() { | 888 payments::FullCardRequest* AutofillManager::GetOrCreateFullCardRequest() { |
| 887 if (!full_card_request_) { | 889 if (!full_card_request_) { |
| 888 full_card_request_.reset(new payments::FullCardRequest( | 890 full_card_request_.reset(new payments::FullCardRequest( |
| 889 client_, payments_client_.get(), personal_data_)); | 891 client_, payments_client_.get(), personal_data_)); |
| 890 } | 892 } |
| 891 | 893 |
| 892 return full_card_request_.get(); | 894 return full_card_request_.get(); |
| 893 } | 895 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 907 } | 909 } |
| 908 | 910 |
| 909 void AutofillManager::OnLoadedServerPredictions( | 911 void AutofillManager::OnLoadedServerPredictions( |
| 910 std::string response, | 912 std::string response, |
| 911 const std::vector<std::string>& form_signatures) { | 913 const std::vector<std::string>& form_signatures) { |
| 912 // We obtain the current valid FormStructures represented by | 914 // We obtain the current valid FormStructures represented by |
| 913 // |form_signatures|. We invert both lists because most recent forms are at | 915 // |form_signatures|. We invert both lists because most recent forms are at |
| 914 // the end of the list (and reverse the resulting pointer vector). | 916 // the end of the list (and reverse the resulting pointer vector). |
| 915 std::vector<FormStructure*> queried_forms; | 917 std::vector<FormStructure*> queried_forms; |
| 916 for (const std::string& signature : base::Reversed(form_signatures)) { | 918 for (const std::string& signature : base::Reversed(form_signatures)) { |
| 917 for (FormStructure* cur_form : base::Reversed(form_structures_)) { | 919 for (auto& cur_form : base::Reversed(form_structures_)) { |
| 918 if (cur_form->FormSignatureAsStr() == signature) { | 920 if (cur_form->FormSignatureAsStr() == signature) { |
| 919 queried_forms.push_back(cur_form); | 921 queried_forms.push_back(cur_form.get()); |
| 920 break; | 922 break; |
| 921 } | 923 } |
| 922 } | 924 } |
| 923 } | 925 } |
| 924 std::reverse(queried_forms.begin(), queried_forms.end()); | 926 std::reverse(queried_forms.begin(), queried_forms.end()); |
| 925 | 927 |
| 926 // If there are no current forms corresponding to the queried signatures, drop | 928 // If there are no current forms corresponding to the queried signatures, drop |
| 927 // the query response. | 929 // the query response. |
| 928 if (queried_forms.empty()) | 930 if (queried_forms.empty()) |
| 929 return; | 931 return; |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 | 1582 |
| 1581 bool AutofillManager::FindCachedForm(const FormData& form, | 1583 bool AutofillManager::FindCachedForm(const FormData& form, |
| 1582 FormStructure** form_structure) const { | 1584 FormStructure** form_structure) const { |
| 1583 // Find the FormStructure that corresponds to |form|. | 1585 // Find the FormStructure that corresponds to |form|. |
| 1584 // Scan backward through the cached |form_structures_|, as updated versions of | 1586 // Scan backward through the cached |form_structures_|, as updated versions of |
| 1585 // forms are added to the back of the list, whereas original versions of these | 1587 // forms are added to the back of the list, whereas original versions of these |
| 1586 // forms might appear toward the beginning of the list. The communication | 1588 // forms might appear toward the beginning of the list. The communication |
| 1587 // protocol with the crowdsourcing server does not permit us to discard the | 1589 // protocol with the crowdsourcing server does not permit us to discard the |
| 1588 // original versions of the forms. | 1590 // original versions of the forms. |
| 1589 *form_structure = NULL; | 1591 *form_structure = NULL; |
| 1590 for (FormStructure* cur_form : base::Reversed(form_structures_)) { | 1592 for (auto& cur_form : base::Reversed(form_structures_)) { |
| 1591 if (*cur_form == form) { | 1593 if (*cur_form == form) { |
| 1592 *form_structure = cur_form; | 1594 *form_structure = cur_form.get(); |
| 1593 | 1595 |
| 1594 // The same form might be cached with multiple field counts: in some | 1596 // The same form might be cached with multiple field counts: in some |
| 1595 // cases, non-autofillable fields are filtered out, whereas in other cases | 1597 // cases, non-autofillable fields are filtered out, whereas in other cases |
| 1596 // they are not. To avoid thrashing the cache, keep scanning until we | 1598 // they are not. To avoid thrashing the cache, keep scanning until we |
| 1597 // find a cached version with the same number of fields, if there is one. | 1599 // find a cached version with the same number of fields, if there is one. |
| 1598 if (cur_form->field_count() == form.fields.size()) | 1600 if (cur_form->field_count() == form.fields.size()) |
| 1599 break; | 1601 break; |
| 1600 } | 1602 } |
| 1601 } | 1603 } |
| 1602 | 1604 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 for (size_t i = 0; !needs_update && i < cached_form->field_count(); ++i) | 1669 for (size_t i = 0; !needs_update && i < cached_form->field_count(); ++i) |
| 1668 needs_update = !cached_form->field(i)->SameFieldAs(live_form.fields[i]); | 1670 needs_update = !cached_form->field(i)->SameFieldAs(live_form.fields[i]); |
| 1669 | 1671 |
| 1670 if (!needs_update) | 1672 if (!needs_update) |
| 1671 return true; | 1673 return true; |
| 1672 | 1674 |
| 1673 if (form_structures_.size() >= kMaxFormCacheSize) | 1675 if (form_structures_.size() >= kMaxFormCacheSize) |
| 1674 return false; | 1676 return false; |
| 1675 | 1677 |
| 1676 // Add the new or updated form to our cache. | 1678 // Add the new or updated form to our cache. |
| 1677 form_structures_.push_back(new FormStructure(live_form)); | 1679 form_structures_.push_back(base::MakeUnique<FormStructure>(live_form)); |
| 1678 *updated_form = *form_structures_.rbegin(); | 1680 *updated_form = form_structures_.rbegin()->get(); |
| 1679 (*updated_form)->DetermineHeuristicTypes(); | 1681 (*updated_form)->DetermineHeuristicTypes(); |
| 1680 | 1682 |
| 1681 // If we have cached data, propagate it to the updated form. | 1683 // If we have cached data, propagate it to the updated form. |
| 1682 if (cached_form) { | 1684 if (cached_form) { |
| 1683 std::map<base::string16, const AutofillField*> cached_fields; | 1685 std::map<base::string16, const AutofillField*> cached_fields; |
| 1684 for (size_t i = 0; i < cached_form->field_count(); ++i) { | 1686 for (size_t i = 0; i < cached_form->field_count(); ++i) { |
| 1685 const AutofillField* field = cached_form->field(i); | 1687 const AutofillField* field = cached_form->field(i); |
| 1686 cached_fields[field->unique_name()] = field; | 1688 cached_fields[field->unique_name()] = field; |
| 1687 } | 1689 } |
| 1688 | 1690 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1757 | 1759 |
| 1758 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { | 1760 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { |
| 1759 if (forms.empty()) | 1761 if (forms.empty()) |
| 1760 return; | 1762 return; |
| 1761 | 1763 |
| 1762 std::vector<FormStructure*> non_queryable_forms; | 1764 std::vector<FormStructure*> non_queryable_forms; |
| 1763 std::vector<FormStructure*> queryable_forms; | 1765 std::vector<FormStructure*> queryable_forms; |
| 1764 for (const FormData& form : forms) { | 1766 for (const FormData& form : forms) { |
| 1765 const auto parse_form_start_time = base::TimeTicks::Now(); | 1767 const auto parse_form_start_time = base::TimeTicks::Now(); |
| 1766 | 1768 |
| 1767 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); | 1769 std::unique_ptr<FormStructure> form_structure = |
| 1770 base::MakeUnique<FormStructure>(form); |
| 1768 form_structure->ParseFieldTypesFromAutocompleteAttributes(); | 1771 form_structure->ParseFieldTypesFromAutocompleteAttributes(); |
| 1769 if (!form_structure->ShouldBeParsed()) | 1772 if (!form_structure->ShouldBeParsed()) |
| 1770 continue; | 1773 continue; |
| 1771 | 1774 |
| 1772 form_structure->DetermineHeuristicTypes(); | 1775 form_structure->DetermineHeuristicTypes(); |
| 1773 | 1776 |
| 1774 // Ownership is transferred to |form_structures_| which maintains it until | 1777 // Ownership is transferred to |form_structures_| which maintains it until |
| 1775 // the manager is Reset() or destroyed. It is safe to use references below | 1778 // the manager is Reset() or destroyed. It is safe to use references below |
| 1776 // as long as receivers don't take ownership. | 1779 // as long as receivers don't take ownership. |
| 1777 form_structures_.push_back(std::move(form_structure)); | 1780 form_structures_.push_back(std::move(form_structure)); |
| 1778 | 1781 |
| 1779 if (form_structures_.back()->ShouldBeCrowdsourced()) | 1782 if (form_structures_.back()->ShouldBeCrowdsourced()) |
| 1780 queryable_forms.push_back(form_structures_.back()); | 1783 queryable_forms.push_back(form_structures_.back().get()); |
| 1781 else | 1784 else |
| 1782 non_queryable_forms.push_back(form_structures_.back()); | 1785 non_queryable_forms.push_back(form_structures_.back().get()); |
| 1783 | 1786 |
| 1784 AutofillMetrics::LogParseFormTiming(base::TimeTicks::Now() - | 1787 AutofillMetrics::LogParseFormTiming(base::TimeTicks::Now() - |
| 1785 parse_form_start_time); | 1788 parse_form_start_time); |
| 1786 } | 1789 } |
| 1787 | 1790 |
| 1788 if (!queryable_forms.empty() && download_manager_) { | 1791 if (!queryable_forms.empty() && download_manager_) { |
| 1789 // Query the server if at least one of the forms was parsed. | 1792 // Query the server if at least one of the forms was parsed. |
| 1790 download_manager_->StartQueryRequest(queryable_forms); | 1793 download_manager_->StartQueryRequest(queryable_forms); |
| 1791 } | 1794 } |
| 1792 | 1795 |
| 1793 if (!queryable_forms.empty() || !non_queryable_forms.empty()) { | 1796 if (!queryable_forms.empty() || !non_queryable_forms.empty()) { |
| 1794 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED); | 1797 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED); |
| 1795 #if defined(OS_IOS) | 1798 #if defined(OS_IOS) |
| 1796 // Log this from same location as AutofillMetrics::FORMS_LOADED to ensure | 1799 // Log this from same location as AutofillMetrics::FORMS_LOADED to ensure |
| 1797 // that KeyboardAccessoryButtonsIOS and UserHappiness UMA metrics will be | 1800 // that KeyboardAccessoryButtonsIOS and UserHappiness UMA metrics will be |
| 1798 // directly comparable. | 1801 // directly comparable. |
| 1799 KeyboardAccessoryMetricsLogger::OnFormsLoaded(); | 1802 KeyboardAccessoryMetricsLogger::OnFormsLoaded(); |
| 1800 #endif | 1803 #endif |
| 1801 } | 1804 } |
| 1802 | 1805 |
| 1803 #if defined(OS_ANDROID) || defined(OS_IOS) | 1806 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 1804 // When a credit card form is parsed and conditions are met, show an infobar | 1807 // When a credit card form is parsed and conditions are met, show an infobar |
| 1805 // prompt for credit card assisted filling. Upon accepting the infobar, the | 1808 // prompt for credit card assisted filling. Upon accepting the infobar, the |
| 1806 // form will automatically be filled with the user's information through this | 1809 // form will automatically be filled with the user's information through this |
| 1807 // class' FillCreditCardForm(). | 1810 // class' FillCreditCardForm(). |
| 1808 if (autofill_assistant_.CanShowCreditCardAssist(form_structures_.get())) { | 1811 if (autofill_assistant_.CanShowCreditCardAssist(form_structures_)) { |
| 1809 const std::vector<CreditCard*> cards = | 1812 const std::vector<CreditCard*> cards = |
| 1810 personal_data_->GetCreditCardsToSuggest(); | 1813 personal_data_->GetCreditCardsToSuggest(); |
| 1811 // Expired cards are last in the sorted order, so if the first one is | 1814 // Expired cards are last in the sorted order, so if the first one is |
| 1812 // expired, they all are. | 1815 // expired, they all are. |
| 1813 if (!cards.empty() && !cards.front()->IsExpired(base::Time::Now())) | 1816 if (!cards.empty() && !cards.front()->IsExpired(base::Time::Now())) |
| 1814 autofill_assistant_.ShowAssistForCreditCard(*cards.front()); | 1817 autofill_assistant_.ShowAssistForCreditCard(*cards.front()); |
| 1815 } | 1818 } |
| 1816 #endif | 1819 #endif |
| 1817 | 1820 |
| 1818 // For the |non_queryable_forms|, we have all the field type info we're ever | 1821 // For the |non_queryable_forms|, we have all the field type info we're ever |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2084 if (i > 0) | 2087 if (i > 0) |
| 2085 fputs("Next oldest form:\n", file); | 2088 fputs("Next oldest form:\n", file); |
| 2086 } | 2089 } |
| 2087 fputs("\n", file); | 2090 fputs("\n", file); |
| 2088 | 2091 |
| 2089 fclose(file); | 2092 fclose(file); |
| 2090 } | 2093 } |
| 2091 #endif // ENABLE_FORM_DEBUG_DUMP | 2094 #endif // ENABLE_FORM_DEBUG_DUMP |
| 2092 | 2095 |
| 2093 } // namespace autofill | 2096 } // namespace autofill |
| OLD | NEW |