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

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

Issue 2864483005: Uses AutofillProfileComparator to compare profile names. (Closed)
Patch Set: Uses AutofillProfileComparator to compare profile names. Created 3 years, 7 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
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 base::string16 SanitizeCreditCardFieldValue(const base::string16& value) { 116 base::string16 SanitizeCreditCardFieldValue(const base::string16& value) {
117 base::string16 sanitized; 117 base::string16 sanitized;
118 base::TrimWhitespace(value, base::TRIM_ALL, &sanitized); 118 base::TrimWhitespace(value, base::TRIM_ALL, &sanitized);
119 // Some sites have ____-____-____-____ in their credit card number fields, for 119 // Some sites have ____-____-____-____ in their credit card number fields, for
120 // example. 120 // example.
121 base::ReplaceChars(sanitized, base::ASCIIToUTF16("-_"), 121 base::ReplaceChars(sanitized, base::ASCIIToUTF16("-_"),
122 base::ASCIIToUTF16(""), &sanitized); 122 base::ASCIIToUTF16(""), &sanitized);
123 return sanitized; 123 return sanitized;
124 } 124 }
125 125
126 // If |name| consists of three whitespace-separated parts and the second of the
127 // three parts is a single character or a single character followed by a period,
128 // returns the result of joining the first and third parts with a space.
129 // Otherwise, returns |name|.
130 //
131 // Note that a better way to do this would be to use SplitName from
132 // src/components/autofill/core/browser/contact_info.cc. However, for now we
133 // want the logic of which variations of names are considered to be the same to
134 // exactly match the logic applied on the Payments server.
135 base::string16 RemoveMiddleInitial(const base::string16& name) {
136 std::vector<base::StringPiece16> parts =
137 base::SplitStringPiece(name, base::kWhitespaceUTF16,
138 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
139 if (parts.size() == 3 && (parts[1].length() == 1 ||
140 (parts[1].length() == 2 &&
141 base::EndsWith(parts[1], base::ASCIIToUTF16("."),
142 base::CompareCase::SENSITIVE)))) {
143 parts.erase(parts.begin() + 1);
144 return base::JoinString(parts, base::ASCIIToUTF16(" "));
145 }
146 return name;
147 }
148
149 // Returns whether the |field| is predicted as being any kind of name. 126 // Returns whether the |field| is predicted as being any kind of name.
150 bool IsNameType(const AutofillField& field) { 127 bool IsNameType(const AutofillField& field) {
151 return field.Type().group() == NAME || field.Type().group() == NAME_BILLING || 128 return field.Type().group() == NAME || field.Type().group() == NAME_BILLING ||
152 field.Type().GetStorableType() == CREDIT_CARD_NAME_FULL || 129 field.Type().GetStorableType() == CREDIT_CARD_NAME_FULL ||
153 field.Type().GetStorableType() == CREDIT_CARD_NAME_FIRST || 130 field.Type().GetStorableType() == CREDIT_CARD_NAME_FIRST ||
154 field.Type().GetStorableType() == CREDIT_CARD_NAME_LAST; 131 field.Type().GetStorableType() == CREDIT_CARD_NAME_LAST;
155 } 132 }
156 133
157 // Selects the right name type from the |old_types| to insert into the 134 // Selects the right name type from the |old_types| to insert into the
158 // |new_types| based on |is_credit_card|. 135 // |new_types| based on |is_credit_card|.
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 if ((now - profile->use_date()) < fifteen_minutes || 1282 if ((now - profile->use_date()) < fifteen_minutes ||
1306 (now - profile->modification_date()) < fifteen_minutes) { 1283 (now - profile->modification_date()) < fifteen_minutes) {
1307 candidate_profiles.push_back(*profile); 1284 candidate_profiles.push_back(*profile);
1308 } 1285 }
1309 } 1286 }
1310 if (candidate_profiles.empty()) { 1287 if (candidate_profiles.empty()) {
1311 upload_decision_metrics |= AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS; 1288 upload_decision_metrics |= AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS;
1312 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoAddress"; 1289 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoAddress";
1313 } 1290 }
1314 1291
1315 // If any of the names on the card or the addresses don't match (where 1292 // If any of the names on the card or the addresses don't match the
1316 // matching is case insensitive and ignores middle initials if present), the
1317 // candidate set is invalid. This matches the rules for name matching applied 1293 // candidate set is invalid. This matches the rules for name matching applied
1318 // server-side by Google Payments and ensures that we don't send upload 1294 // server-side by Google Payments and ensures that we don't send upload
1319 // requests that are guaranteed to fail. 1295 // requests that are guaranteed to fail.
1320 base::string16 verified_name;
1321 const base::string16 card_name = 1296 const base::string16 card_name =
1322 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); 1297 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_);
1323 if (!card_name.empty()) { 1298 base::string16 verified_name;
1324 verified_name = RemoveMiddleInitial(card_name); 1299 if (candidate_profiles.empty()) {
1325 } 1300 verified_name = card_name;
1326 for (const AutofillProfile& profile : candidate_profiles) { 1301 } else {
1327 const base::string16 address_name = 1302 AutofillProfileComparator comparator(app_locale_);
1328 profile.GetInfo(AutofillType(NAME_FULL), app_locale_); 1303 verified_name = comparator.NormalizeForComparison(card_name);
1329 if (!address_name.empty()) { 1304 for (const AutofillProfile& profile : candidate_profiles) {
1330 if (verified_name.empty()) { 1305 const base::string16 address_name = comparator.NormalizeForComparison(
1331 verified_name = RemoveMiddleInitial(address_name); 1306 profile.GetInfo(AutofillType(NAME_FULL), app_locale_));
1332 } else { 1307 if (!address_name.empty()) {
1333 // TODO(crbug.com/590307): We'll need to make the name comparison more 1308 if (verified_name.empty() ||
1334 // sophisticated. 1309 comparator.IsNameVariantOf(address_name, verified_name)) {
1335 if (!base::EqualsCaseInsensitiveASCII( 1310 verified_name = address_name;
1336 verified_name, RemoveMiddleInitial(address_name))) { 1311 } else if (!comparator.IsNameVariantOf(verified_name, address_name)) {
Roger McFarlane (Chromium) 2017/05/05 16:05:30 Would it be helpful to add the bidirectional name
csashi 2017/05/05 16:22:30 I prefer the current version because I would like
1337 if (!upload_decision_metrics) 1312 if (!upload_decision_metrics)
1338 *rappor_metric_name = 1313 *rappor_metric_name =
1339 "Autofill.CardUploadNotOfferedConflictingNames"; 1314 "Autofill.CardUploadNotOfferedConflictingNames";
1340 upload_decision_metrics |= 1315 upload_decision_metrics |=
1341 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES; 1316 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES;
1342 break; 1317 break;
1343 } 1318 }
1344 } 1319 }
1345 } 1320 }
1346 } 1321 }
1322
1347 // If neither the card nor any of the addresses have a name associated with 1323 // If neither the card nor any of the addresses have a name associated with
1348 // them, the candidate set is invalid. 1324 // them, the candidate set is invalid.
1349 if (verified_name.empty()) { 1325 if (verified_name.empty()) {
1350 if (!upload_decision_metrics) 1326 if (!upload_decision_metrics)
1351 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoName"; 1327 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoName";
1352 upload_decision_metrics |= AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME; 1328 upload_decision_metrics |= AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME;
1353 } 1329 }
1354 1330
1355 // If any of the candidate addresses have a non-empty zip that doesn't match 1331 // If any of the candidate addresses have a non-empty zip that doesn't match
1356 // any other non-empty zip, then the candidate set is invalid. 1332 // any other non-empty zip, then the candidate set is invalid.
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 #endif // ENABLE_FORM_DEBUG_DUMP 2224 #endif // ENABLE_FORM_DEBUG_DUMP
2249 2225
2250 void AutofillManager::LogCardUploadDecisions(int upload_decision_metrics) { 2226 void AutofillManager::LogCardUploadDecisions(int upload_decision_metrics) {
2251 AutofillMetrics::LogCardUploadDecisionMetrics(upload_decision_metrics); 2227 AutofillMetrics::LogCardUploadDecisionMetrics(upload_decision_metrics);
2252 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmService(), 2228 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmService(),
2253 pending_upload_request_url_, 2229 pending_upload_request_url_,
2254 upload_decision_metrics); 2230 upload_decision_metrics);
2255 } 2231 }
2256 2232
2257 } // namespace autofill 2233 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698