| 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 | |
| 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 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 if ((now - profile->use_date()) < fifteen_minutes || | 1305 if ((now - profile->use_date()) < fifteen_minutes || |
| 1329 (now - profile->modification_date()) < fifteen_minutes) { | 1306 (now - profile->modification_date()) < fifteen_minutes) { |
| 1330 candidate_profiles.push_back(*profile); | 1307 candidate_profiles.push_back(*profile); |
| 1331 } | 1308 } |
| 1332 } | 1309 } |
| 1333 if (candidate_profiles.empty()) { | 1310 if (candidate_profiles.empty()) { |
| 1334 upload_decision_metrics |= AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS; | 1311 upload_decision_metrics |= AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS; |
| 1335 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoAddress"; | 1312 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoAddress"; |
| 1336 } | 1313 } |
| 1337 | 1314 |
| 1338 // If any of the names on the card or the addresses don't match (where | 1315 // If any of the names on the card or the addresses don't match the |
| 1339 // matching is case insensitive and ignores middle initials if present), the | |
| 1340 // candidate set is invalid. This matches the rules for name matching applied | 1316 // candidate set is invalid. This matches the rules for name matching applied |
| 1341 // server-side by Google Payments and ensures that we don't send upload | 1317 // server-side by Google Payments and ensures that we don't send upload |
| 1342 // requests that are guaranteed to fail. | 1318 // requests that are guaranteed to fail. |
| 1343 base::string16 verified_name; | |
| 1344 const base::string16 card_name = | 1319 const base::string16 card_name = |
| 1345 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); | 1320 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); |
| 1346 if (!card_name.empty()) { | 1321 base::string16 verified_name; |
| 1347 verified_name = RemoveMiddleInitial(card_name); | 1322 if (candidate_profiles.empty()) { |
| 1348 } | 1323 verified_name = card_name; |
| 1349 for (const AutofillProfile& profile : candidate_profiles) { | 1324 } else { |
| 1350 const base::string16 address_name = | 1325 AutofillProfileComparator comparator(app_locale_); |
| 1351 profile.GetInfo(AutofillType(NAME_FULL), app_locale_); | 1326 verified_name = comparator.NormalizeForComparison(card_name); |
| 1352 if (!address_name.empty()) { | 1327 for (const AutofillProfile& profile : candidate_profiles) { |
| 1353 if (verified_name.empty()) { | 1328 const base::string16 address_name = comparator.NormalizeForComparison( |
| 1354 verified_name = RemoveMiddleInitial(address_name); | 1329 profile.GetInfo(AutofillType(NAME_FULL), app_locale_)); |
| 1355 } else { | 1330 if (!address_name.empty()) { |
| 1356 // TODO(crbug.com/590307): We'll need to make the name comparison more | 1331 if (verified_name.empty() || |
| 1357 // sophisticated. | 1332 comparator.IsNameVariantOf(address_name, verified_name)) { |
| 1358 if (!base::EqualsCaseInsensitiveASCII( | 1333 verified_name = address_name; |
| 1359 verified_name, RemoveMiddleInitial(address_name))) { | 1334 } else if (!comparator.IsNameVariantOf(verified_name, address_name)) { |
| 1360 if (!upload_decision_metrics) | 1335 if (!upload_decision_metrics) |
| 1361 *rappor_metric_name = | 1336 *rappor_metric_name = |
| 1362 "Autofill.CardUploadNotOfferedConflictingNames"; | 1337 "Autofill.CardUploadNotOfferedConflictingNames"; |
| 1363 upload_decision_metrics |= | 1338 upload_decision_metrics |= |
| 1364 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES; | 1339 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES; |
| 1365 break; | 1340 break; |
| 1366 } | 1341 } |
| 1367 } | 1342 } |
| 1368 } | 1343 } |
| 1369 } | 1344 } |
| 1345 |
| 1370 // If neither the card nor any of the addresses have a name associated with | 1346 // If neither the card nor any of the addresses have a name associated with |
| 1371 // them, the candidate set is invalid. | 1347 // them, the candidate set is invalid. |
| 1372 if (verified_name.empty()) { | 1348 if (verified_name.empty()) { |
| 1373 if (!upload_decision_metrics) | 1349 if (!upload_decision_metrics) |
| 1374 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoName"; | 1350 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoName"; |
| 1375 upload_decision_metrics |= AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME; | 1351 upload_decision_metrics |= AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME; |
| 1376 } | 1352 } |
| 1377 | 1353 |
| 1378 // If any of the candidate addresses have a non-empty zip that doesn't match | 1354 // If any of the candidate addresses have a non-empty zip that doesn't match |
| 1379 // any other non-empty zip, then the candidate set is invalid. | 1355 // any other non-empty zip, then the candidate set is invalid. |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2271 #endif // ENABLE_FORM_DEBUG_DUMP | 2247 #endif // ENABLE_FORM_DEBUG_DUMP |
| 2272 | 2248 |
| 2273 void AutofillManager::LogCardUploadDecisions(int upload_decision_metrics) { | 2249 void AutofillManager::LogCardUploadDecisions(int upload_decision_metrics) { |
| 2274 AutofillMetrics::LogCardUploadDecisionMetrics(upload_decision_metrics); | 2250 AutofillMetrics::LogCardUploadDecisionMetrics(upload_decision_metrics); |
| 2275 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmService(), | 2251 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmService(), |
| 2276 pending_upload_request_url_, | 2252 pending_upload_request_url_, |
| 2277 upload_decision_metrics); | 2253 upload_decision_metrics); |
| 2278 } | 2254 } |
| 2279 | 2255 |
| 2280 } // namespace autofill | 2256 } // namespace autofill |
| OLD | NEW |