| 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> |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 126 // Returns whether the |field| is predicted as being any kind of name. | 149 // Returns whether the |field| is predicted as being any kind of name. |
| 127 bool IsNameType(const AutofillField& field) { | 150 bool IsNameType(const AutofillField& field) { |
| 128 return field.Type().group() == NAME || field.Type().group() == NAME_BILLING || | 151 return field.Type().group() == NAME || field.Type().group() == NAME_BILLING || |
| 129 field.Type().GetStorableType() == CREDIT_CARD_NAME_FULL || | 152 field.Type().GetStorableType() == CREDIT_CARD_NAME_FULL || |
| 130 field.Type().GetStorableType() == CREDIT_CARD_NAME_FIRST || | 153 field.Type().GetStorableType() == CREDIT_CARD_NAME_FIRST || |
| 131 field.Type().GetStorableType() == CREDIT_CARD_NAME_LAST; | 154 field.Type().GetStorableType() == CREDIT_CARD_NAME_LAST; |
| 132 } | 155 } |
| 133 | 156 |
| 134 // Selects the right name type from the |old_types| to insert into the | 157 // Selects the right name type from the |old_types| to insert into the |
| 135 // |new_types| based on |is_credit_card|. | 158 // |new_types| based on |is_credit_card|. |
| (...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 // If any of the names on the card or the addresses don't match the | 1341 // If any of the names on the card or the addresses don't match the |
| 1319 // candidate set is invalid. This matches the rules for name matching applied | 1342 // candidate set is invalid. This matches the rules for name matching applied |
| 1320 // server-side by Google Payments and ensures that we don't send upload | 1343 // server-side by Google Payments and ensures that we don't send upload |
| 1321 // requests that are guaranteed to fail. | 1344 // requests that are guaranteed to fail. |
| 1322 const base::string16 card_name = | 1345 const base::string16 card_name = |
| 1323 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); | 1346 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); |
| 1324 base::string16 verified_name; | 1347 base::string16 verified_name; |
| 1325 if (candidate_profiles.empty()) { | 1348 if (candidate_profiles.empty()) { |
| 1326 verified_name = card_name; | 1349 verified_name = card_name; |
| 1327 } else { | 1350 } else { |
| 1328 AutofillProfileComparator comparator(app_locale_); | 1351 bool found_conflicting_names = false; |
| 1329 verified_name = comparator.NormalizeForComparison(card_name); | 1352 if (base::FeatureList::IsEnabled( |
| 1330 for (const AutofillProfile& profile : candidate_profiles) { | 1353 kAutofillUpstreamUseAutofillProfileComparatorForName)) { |
| 1331 const base::string16 address_name = comparator.NormalizeForComparison( | 1354 AutofillProfileComparator comparator(app_locale_); |
| 1332 profile.GetInfo(AutofillType(NAME_FULL), app_locale_)); | 1355 verified_name = comparator.NormalizeForComparison(card_name); |
| 1333 if (!address_name.empty()) { | 1356 for (const AutofillProfile& profile : candidate_profiles) { |
| 1357 const base::string16 address_name = comparator.NormalizeForComparison( |
| 1358 profile.GetInfo(AutofillType(NAME_FULL), app_locale_)); |
| 1359 if (address_name.empty()) |
| 1360 continue; |
| 1334 if (verified_name.empty() || | 1361 if (verified_name.empty() || |
| 1335 comparator.IsNameVariantOf(address_name, verified_name)) { | 1362 comparator.IsNameVariantOf(address_name, verified_name)) { |
| 1336 verified_name = address_name; | 1363 verified_name = address_name; |
| 1337 } else if (!comparator.IsNameVariantOf(verified_name, address_name)) { | 1364 } else if (!comparator.IsNameVariantOf(verified_name, address_name)) { |
| 1338 if (!upload_decision_metrics) | 1365 found_conflicting_names = true; |
| 1339 *rappor_metric_name = | 1366 break; |
| 1340 "Autofill.CardUploadNotOfferedConflictingNames"; | 1367 } |
| 1341 upload_decision_metrics |= | 1368 } |
| 1342 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES; | 1369 } else { |
| 1370 verified_name = RemoveMiddleInitial(card_name); |
| 1371 for (const AutofillProfile& profile : candidate_profiles) { |
| 1372 const base::string16 address_name = RemoveMiddleInitial( |
| 1373 profile.GetInfo(AutofillType(NAME_FULL), app_locale_)); |
| 1374 if (address_name.empty()) |
| 1375 continue; |
| 1376 if (verified_name.empty()) { |
| 1377 verified_name = address_name; |
| 1378 } else if (!base::EqualsCaseInsensitiveASCII(verified_name, |
| 1379 address_name)) { |
| 1380 found_conflicting_names = true; |
| 1343 break; | 1381 break; |
| 1344 } | 1382 } |
| 1345 } | 1383 } |
| 1346 } | 1384 } |
| 1385 if (found_conflicting_names) { |
| 1386 if (!upload_decision_metrics) |
| 1387 *rappor_metric_name = "Autofill.CardUploadNotOfferedConflictingNames"; |
| 1388 upload_decision_metrics |= |
| 1389 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES; |
| 1390 } |
| 1347 } | 1391 } |
| 1348 | 1392 |
| 1349 // If neither the card nor any of the addresses have a name associated with | 1393 // If neither the card nor any of the addresses have a name associated with |
| 1350 // them, the candidate set is invalid. | 1394 // them, the candidate set is invalid. |
| 1351 if (verified_name.empty()) { | 1395 if (verified_name.empty()) { |
| 1352 if (!upload_decision_metrics) | 1396 if (!upload_decision_metrics) |
| 1353 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoName"; | 1397 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoName"; |
| 1354 upload_decision_metrics |= AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME; | 1398 upload_decision_metrics |= AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME; |
| 1355 } | 1399 } |
| 1356 | 1400 |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2250 #endif // ENABLE_FORM_DEBUG_DUMP | 2294 #endif // ENABLE_FORM_DEBUG_DUMP |
| 2251 | 2295 |
| 2252 void AutofillManager::LogCardUploadDecisions(int upload_decision_metrics) { | 2296 void AutofillManager::LogCardUploadDecisions(int upload_decision_metrics) { |
| 2253 AutofillMetrics::LogCardUploadDecisionMetrics(upload_decision_metrics); | 2297 AutofillMetrics::LogCardUploadDecisionMetrics(upload_decision_metrics); |
| 2254 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmService(), | 2298 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmService(), |
| 2255 pending_upload_request_url_, | 2299 pending_upload_request_url_, |
| 2256 upload_decision_metrics); | 2300 upload_decision_metrics); |
| 2257 } | 2301 } |
| 2258 | 2302 |
| 2259 } // namespace autofill | 2303 } // namespace autofill |
| OLD | NEW |