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

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

Issue 2110563002: Use AutofillProfileComparator in place of ad-hoc merge logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@merge
Patch Set: Rebase Created 4 years, 5 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/form_group.h" 5 #include "components/autofill/core/browser/form_group.h"
6 6
7 #include "components/autofill/core/browser/autofill_profile.h" 7 #include "components/autofill/core/browser/autofill_profile.h"
8 #include "components/autofill/core/browser/autofill_profile_comparator.h"
8 #include "components/autofill/core/browser/autofill_type.h" 9 #include "components/autofill/core/browser/autofill_type.h"
9 #include "components/autofill/core/common/autofill_l10n_util.h" 10 #include "components/autofill/core/common/autofill_l10n_util.h"
10 11
11 namespace autofill { 12 namespace autofill {
12 13
13 void FormGroup::GetMatchingTypes(const base::string16& text, 14 void FormGroup::GetMatchingTypes(const base::string16& text,
14 const std::string& app_locale, 15 const std::string& app_locale,
15 ServerFieldTypeSet* matching_types) const { 16 ServerFieldTypeSet* matching_types) const {
16 if (text.empty()) { 17 if (text.empty()) {
17 matching_types->insert(EMPTY_TYPE); 18 matching_types->insert(EMPTY_TYPE);
18 return; 19 return;
19 } 20 }
20 21
21 base::string16 canonicalized_text = 22 AutofillProfileComparator comparator(app_locale);
22 AutofillProfile::CanonicalizeProfileString(text); 23 base::string16 canonicalized_text = comparator.NormalizeForComparison(text);
24
23 if (canonicalized_text.empty()) 25 if (canonicalized_text.empty())
24 return; 26 return;
25 27
26 // TODO(crbug.com/574086): Investigate whether to use |app_locale| in case
27 // insensitive comparisons.
28 l10n::CaseInsensitiveCompare compare;
29 ServerFieldTypeSet types; 28 ServerFieldTypeSet types;
30 GetSupportedTypes(&types); 29 GetSupportedTypes(&types);
31 for (const auto& type : types) { 30 for (const auto& type : types) {
32 if (compare.StringsEqual(canonicalized_text, 31 base::string16 candidate_text = comparator.NormalizeForComparison(
33 AutofillProfile::CanonicalizeProfileString( 32 GetInfo(AutofillType(type), app_locale));
34 GetInfo(AutofillType(type), app_locale)))) 33 if (canonicalized_text == candidate_text)
35 matching_types->insert(type); 34 matching_types->insert(type);
36 } 35 }
37 } 36 }
38 37
39 void FormGroup::GetNonEmptyTypes(const std::string& app_locale, 38 void FormGroup::GetNonEmptyTypes(const std::string& app_locale,
40 ServerFieldTypeSet* non_empty_types) const { 39 ServerFieldTypeSet* non_empty_types) const {
41 ServerFieldTypeSet types; 40 ServerFieldTypeSet types;
42 GetSupportedTypes(&types); 41 GetSupportedTypes(&types);
43 for (const auto& type : types) { 42 for (const auto& type : types) {
44 if (!GetInfo(AutofillType(type), app_locale).empty()) 43 if (!GetInfo(AutofillType(type), app_locale).empty())
45 non_empty_types->insert(type); 44 non_empty_types->insert(type);
46 } 45 }
47 } 46 }
48 47
49 base::string16 FormGroup::GetInfo(const AutofillType& type, 48 base::string16 FormGroup::GetInfo(const AutofillType& type,
50 const std::string& app_locale) const { 49 const std::string& app_locale) const {
51 return GetRawInfo(type.GetStorableType()); 50 return GetRawInfo(type.GetStorableType());
52 } 51 }
53 52
54 bool FormGroup::SetInfo(const AutofillType& type, 53 bool FormGroup::SetInfo(const AutofillType& type,
55 const base::string16& value, 54 const base::string16& value,
56 const std::string& app_locale) { 55 const std::string& app_locale) {
57 SetRawInfo(type.GetStorableType(), value); 56 SetRawInfo(type.GetStorableType(), value);
58 return true; 57 return true;
59 } 58 }
60 59
61 } // namespace autofill 60 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/contact_info.cc ('k') | components/autofill/core/browser/personal_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698