Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: components/autofill/core/browser/autofill_manager.cc

Issue 2403773002: Remove stl_util's STLDeleteContainerPointers from autofill. (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 870
870 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name, 871 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name,
871 const base::string16& value) { 872 const base::string16& value) {
872 autocomplete_history_manager_->OnRemoveAutocompleteEntry(name, value); 873 autocomplete_history_manager_->OnRemoveAutocompleteEntry(name, value);
873 } 874 }
874 875
875 bool AutofillManager::IsShowingUnmaskPrompt() { 876 bool AutofillManager::IsShowingUnmaskPrompt() {
876 return full_card_request_ && full_card_request_->IsGettingFullCard(); 877 return full_card_request_ && full_card_request_->IsGettingFullCard();
877 } 878 }
878 879
879 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() { 880 const std::vector<std::unique_ptr<FormStructure>>&
880 return form_structures_.get(); 881 AutofillManager::GetFormStructures() {
882 return form_structures_;
881 } 883 }
882 884
883 payments::FullCardRequest* AutofillManager::GetOrCreateFullCardRequest() { 885 payments::FullCardRequest* AutofillManager::GetOrCreateFullCardRequest() {
884 if (!full_card_request_) { 886 if (!full_card_request_) {
885 full_card_request_.reset(new payments::FullCardRequest( 887 full_card_request_.reset(new payments::FullCardRequest(
886 client_, payments_client_.get(), personal_data_)); 888 client_, payments_client_.get(), personal_data_));
887 } 889 }
888 890
889 return full_card_request_.get(); 891 return full_card_request_.get();
890 } 892 }
(...skipping 13 matching lines...) Expand all
904 } 906 }
905 907
906 void AutofillManager::OnLoadedServerPredictions( 908 void AutofillManager::OnLoadedServerPredictions(
907 std::string response, 909 std::string response,
908 const std::vector<std::string>& form_signatures) { 910 const std::vector<std::string>& form_signatures) {
909 // We obtain the current valid FormStructures represented by 911 // We obtain the current valid FormStructures represented by
910 // |form_signatures|. We invert both lists because most recent forms are at 912 // |form_signatures|. We invert both lists because most recent forms are at
911 // the end of the list (and reverse the resulting pointer vector). 913 // the end of the list (and reverse the resulting pointer vector).
912 std::vector<FormStructure*> queried_forms; 914 std::vector<FormStructure*> queried_forms;
913 for (const std::string& signature : base::Reversed(form_signatures)) { 915 for (const std::string& signature : base::Reversed(form_signatures)) {
914 for (FormStructure* cur_form : base::Reversed(form_structures_)) { 916 for (auto& cur_form : base::Reversed(form_structures_)) {
915 if (cur_form->FormSignatureAsStr() == signature) { 917 if (cur_form->FormSignatureAsStr() == signature) {
916 queried_forms.push_back(cur_form); 918 queried_forms.push_back(cur_form.get());
917 break; 919 break;
918 } 920 }
919 } 921 }
920 } 922 }
921 std::reverse(queried_forms.begin(), queried_forms.end()); 923 std::reverse(queried_forms.begin(), queried_forms.end());
922 924
923 // If there are no current forms corresponding to the queried signatures, drop 925 // If there are no current forms corresponding to the queried signatures, drop
924 // the query response. 926 // the query response.
925 if (queried_forms.empty()) 927 if (queried_forms.empty())
926 return; 928 return;
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 1579
1578 bool AutofillManager::FindCachedForm(const FormData& form, 1580 bool AutofillManager::FindCachedForm(const FormData& form,
1579 FormStructure** form_structure) const { 1581 FormStructure** form_structure) const {
1580 // Find the FormStructure that corresponds to |form|. 1582 // Find the FormStructure that corresponds to |form|.
1581 // Scan backward through the cached |form_structures_|, as updated versions of 1583 // Scan backward through the cached |form_structures_|, as updated versions of
1582 // forms are added to the back of the list, whereas original versions of these 1584 // forms are added to the back of the list, whereas original versions of these
1583 // forms might appear toward the beginning of the list. The communication 1585 // forms might appear toward the beginning of the list. The communication
1584 // protocol with the crowdsourcing server does not permit us to discard the 1586 // protocol with the crowdsourcing server does not permit us to discard the
1585 // original versions of the forms. 1587 // original versions of the forms.
1586 *form_structure = NULL; 1588 *form_structure = NULL;
1587 for (FormStructure* cur_form : base::Reversed(form_structures_)) { 1589 for (auto& cur_form : base::Reversed(form_structures_)) {
1588 if (*cur_form == form) { 1590 if (*cur_form == form) {
1589 *form_structure = cur_form; 1591 *form_structure = cur_form.get();
1590 1592
1591 // The same form might be cached with multiple field counts: in some 1593 // The same form might be cached with multiple field counts: in some
1592 // cases, non-autofillable fields are filtered out, whereas in other cases 1594 // cases, non-autofillable fields are filtered out, whereas in other cases
1593 // they are not. To avoid thrashing the cache, keep scanning until we 1595 // they are not. To avoid thrashing the cache, keep scanning until we
1594 // find a cached version with the same number of fields, if there is one. 1596 // find a cached version with the same number of fields, if there is one.
1595 if (cur_form->field_count() == form.fields.size()) 1597 if (cur_form->field_count() == form.fields.size())
1596 break; 1598 break;
1597 } 1599 }
1598 } 1600 }
1599 1601
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 for (size_t i = 0; !needs_update && i < cached_form->field_count(); ++i) 1666 for (size_t i = 0; !needs_update && i < cached_form->field_count(); ++i)
1665 needs_update = !cached_form->field(i)->SameFieldAs(live_form.fields[i]); 1667 needs_update = !cached_form->field(i)->SameFieldAs(live_form.fields[i]);
1666 1668
1667 if (!needs_update) 1669 if (!needs_update)
1668 return true; 1670 return true;
1669 1671
1670 if (form_structures_.size() >= kMaxFormCacheSize) 1672 if (form_structures_.size() >= kMaxFormCacheSize)
1671 return false; 1673 return false;
1672 1674
1673 // Add the new or updated form to our cache. 1675 // Add the new or updated form to our cache.
1674 form_structures_.push_back(new FormStructure(live_form)); 1676 form_structures_.push_back(base::MakeUnique<FormStructure>(live_form));
1675 *updated_form = *form_structures_.rbegin(); 1677 *updated_form = form_structures_.rbegin()->get();
1676 (*updated_form)->DetermineHeuristicTypes(); 1678 (*updated_form)->DetermineHeuristicTypes();
1677 1679
1678 // If we have cached data, propagate it to the updated form. 1680 // If we have cached data, propagate it to the updated form.
1679 if (cached_form) { 1681 if (cached_form) {
1680 std::map<base::string16, const AutofillField*> cached_fields; 1682 std::map<base::string16, const AutofillField*> cached_fields;
1681 for (size_t i = 0; i < cached_form->field_count(); ++i) { 1683 for (size_t i = 0; i < cached_form->field_count(); ++i) {
1682 const AutofillField* field = cached_form->field(i); 1684 const AutofillField* field = cached_form->field(i);
1683 cached_fields[field->unique_name()] = field; 1685 cached_fields[field->unique_name()] = field;
1684 } 1686 }
1685 1687
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 1756
1755 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { 1757 void AutofillManager::ParseForms(const std::vector<FormData>& forms) {
1756 if (forms.empty()) 1758 if (forms.empty())
1757 return; 1759 return;
1758 1760
1759 std::vector<FormStructure*> non_queryable_forms; 1761 std::vector<FormStructure*> non_queryable_forms;
1760 std::vector<FormStructure*> queryable_forms; 1762 std::vector<FormStructure*> queryable_forms;
1761 for (const FormData& form : forms) { 1763 for (const FormData& form : forms) {
1762 const auto parse_form_start_time = base::TimeTicks::Now(); 1764 const auto parse_form_start_time = base::TimeTicks::Now();
1763 1765
1764 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); 1766 std::unique_ptr<FormStructure> form_structure =
1767 base::MakeUnique<FormStructure>(form);
1765 form_structure->ParseFieldTypesFromAutocompleteAttributes(); 1768 form_structure->ParseFieldTypesFromAutocompleteAttributes();
1766 if (!form_structure->ShouldBeParsed()) 1769 if (!form_structure->ShouldBeParsed())
1767 continue; 1770 continue;
1768 1771
1769 form_structure->DetermineHeuristicTypes(); 1772 form_structure->DetermineHeuristicTypes();
1770 1773
1771 // Ownership is transferred to |form_structures_| which maintains it until 1774 // Ownership is transferred to |form_structures_| which maintains it until
1772 // the manager is Reset() or destroyed. It is safe to use references below 1775 // the manager is Reset() or destroyed. It is safe to use references below
1773 // as long as receivers don't take ownership. 1776 // as long as receivers don't take ownership.
1774 form_structures_.push_back(std::move(form_structure)); 1777 form_structures_.push_back(std::move(form_structure));
1775 1778
1776 if (form_structures_.back()->ShouldBeCrowdsourced()) 1779 if (form_structures_.back()->ShouldBeCrowdsourced())
1777 queryable_forms.push_back(form_structures_.back()); 1780 queryable_forms.push_back(form_structures_.back().get());
1778 else 1781 else
1779 non_queryable_forms.push_back(form_structures_.back()); 1782 non_queryable_forms.push_back(form_structures_.back().get());
1780 1783
1781 AutofillMetrics::LogParseFormTiming(base::TimeTicks::Now() - 1784 AutofillMetrics::LogParseFormTiming(base::TimeTicks::Now() -
1782 parse_form_start_time); 1785 parse_form_start_time);
1783 } 1786 }
1784 1787
1785 if (!queryable_forms.empty() && download_manager_) { 1788 if (!queryable_forms.empty() && download_manager_) {
1786 // Query the server if at least one of the forms was parsed. 1789 // Query the server if at least one of the forms was parsed.
1787 download_manager_->StartQueryRequest(queryable_forms); 1790 download_manager_->StartQueryRequest(queryable_forms);
1788 } 1791 }
1789 1792
1790 if (!queryable_forms.empty() || !non_queryable_forms.empty()) { 1793 if (!queryable_forms.empty() || !non_queryable_forms.empty()) {
1791 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED); 1794 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED);
1792 #if defined(OS_IOS) 1795 #if defined(OS_IOS)
1793 // Log this from same location as AutofillMetrics::FORMS_LOADED to ensure 1796 // Log this from same location as AutofillMetrics::FORMS_LOADED to ensure
1794 // that KeyboardAccessoryButtonsIOS and UserHappiness UMA metrics will be 1797 // that KeyboardAccessoryButtonsIOS and UserHappiness UMA metrics will be
1795 // directly comparable. 1798 // directly comparable.
1796 KeyboardAccessoryMetricsLogger::OnFormsLoaded(); 1799 KeyboardAccessoryMetricsLogger::OnFormsLoaded();
1797 #endif 1800 #endif
1798 } 1801 }
1799 1802
1800 #if defined(OS_ANDROID) || defined(OS_IOS) 1803 #if defined(OS_ANDROID) || defined(OS_IOS)
1801 // When a credit card form is parsed and conditions are met, show an infobar 1804 // When a credit card form is parsed and conditions are met, show an infobar
1802 // prompt for credit card assisted filling. Upon accepting the infobar, the 1805 // prompt for credit card assisted filling. Upon accepting the infobar, the
1803 // form will automatically be filled with the user's information through this 1806 // form will automatically be filled with the user's information through this
1804 // class' FillCreditCardForm(). 1807 // class' FillCreditCardForm().
1805 if (autofill_assistant_.CanShowCreditCardAssist(form_structures_.get())) { 1808 if (autofill_assistant_.CanShowCreditCardAssist(form_structures_)) {
1806 const std::vector<CreditCard*> cards = 1809 const std::vector<CreditCard*> cards =
1807 personal_data_->GetCreditCardsToSuggest(); 1810 personal_data_->GetCreditCardsToSuggest();
1808 // Expired cards are last in the sorted order, so if the first one is 1811 // Expired cards are last in the sorted order, so if the first one is
1809 // expired, they all are. 1812 // expired, they all are.
1810 if (!cards.empty() && !cards.front()->IsExpired(base::Time::Now())) 1813 if (!cards.empty() && !cards.front()->IsExpired(base::Time::Now()))
1811 autofill_assistant_.ShowAssistForCreditCard(*cards.front()); 1814 autofill_assistant_.ShowAssistForCreditCard(*cards.front());
1812 } 1815 }
1813 #endif 1816 #endif
1814 1817
1815 // For the |non_queryable_forms|, we have all the field type info we're ever 1818 // 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
2081 if (i > 0) 2084 if (i > 0)
2082 fputs("Next oldest form:\n", file); 2085 fputs("Next oldest form:\n", file);
2083 } 2086 }
2084 fputs("\n", file); 2087 fputs("\n", file);
2085 2088
2086 fclose(file); 2089 fclose(file);
2087 } 2090 }
2088 #endif // ENABLE_FORM_DEBUG_DUMP 2091 #endif // ENABLE_FORM_DEBUG_DUMP
2089 2092
2090 } // namespace autofill 2093 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698