Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 35 #include "build/build_config.h" | 35 #include "build/build_config.h" |
| 36 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 36 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
| 37 #include "components/autofill/core/browser/autofill_client.h" | 37 #include "components/autofill/core/browser/autofill_client.h" |
| 38 #include "components/autofill/core/browser/autofill_data_model.h" | 38 #include "components/autofill/core/browser/autofill_data_model.h" |
| 39 #include "components/autofill/core/browser/autofill_experiments.h" | 39 #include "components/autofill/core/browser/autofill_experiments.h" |
| 40 #include "components/autofill/core/browser/autofill_external_delegate.h" | 40 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 41 #include "components/autofill/core/browser/autofill_field.h" | 41 #include "components/autofill/core/browser/autofill_field.h" |
| 42 #include "components/autofill/core/browser/autofill_manager_test_delegate.h" | 42 #include "components/autofill/core/browser/autofill_manager_test_delegate.h" |
| 43 #include "components/autofill/core/browser/autofill_metrics.h" | 43 #include "components/autofill/core/browser/autofill_metrics.h" |
| 44 #include "components/autofill/core/browser/autofill_profile.h" | 44 #include "components/autofill/core/browser/autofill_profile.h" |
| 45 #include "components/autofill/core/browser/autofill_profile_comparator.h" | |
| 45 #include "components/autofill/core/browser/autofill_type.h" | 46 #include "components/autofill/core/browser/autofill_type.h" |
| 46 #include "components/autofill/core/browser/country_names.h" | 47 #include "components/autofill/core/browser/country_names.h" |
| 47 #include "components/autofill/core/browser/credit_card.h" | 48 #include "components/autofill/core/browser/credit_card.h" |
| 48 #include "components/autofill/core/browser/field_types.h" | 49 #include "components/autofill/core/browser/field_types.h" |
| 49 #include "components/autofill/core/browser/form_structure.h" | 50 #include "components/autofill/core/browser/form_structure.h" |
| 50 #include "components/autofill/core/browser/personal_data_manager.h" | 51 #include "components/autofill/core/browser/personal_data_manager.h" |
| 51 #include "components/autofill/core/browser/phone_number.h" | 52 #include "components/autofill/core/browser/phone_number.h" |
| 52 #include "components/autofill/core/browser/phone_number_i18n.h" | 53 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 53 #include "components/autofill/core/browser/popup_item_ids.h" | 54 #include "components/autofill/core/browser/popup_item_ids.h" |
| 54 #include "components/autofill/core/browser/ui/save_card_bubble_controller.h" | 55 #include "components/autofill/core/browser/ui/save_card_bubble_controller.h" |
| (...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1034 void AutofillManager::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, | 1035 void AutofillManager::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, |
| 1035 const std::string& real_pan) { | 1036 const std::string& real_pan) { |
| 1036 DCHECK(full_card_request_); | 1037 DCHECK(full_card_request_); |
| 1037 full_card_request_->OnDidGetRealPan(result, real_pan); | 1038 full_card_request_->OnDidGetRealPan(result, real_pan); |
| 1038 } | 1039 } |
| 1039 | 1040 |
| 1040 void AutofillManager::OnDidGetUploadDetails( | 1041 void AutofillManager::OnDidGetUploadDetails( |
| 1041 AutofillClient::PaymentsRpcResult result, | 1042 AutofillClient::PaymentsRpcResult result, |
| 1042 const base::string16& context_token, | 1043 const base::string16& context_token, |
| 1043 std::unique_ptr<base::DictionaryValue> legal_message) { | 1044 std::unique_ptr<base::DictionaryValue> legal_message) { |
| 1044 // TODO(jdonnelly): Log duration. | 1045 int card_upload_decision_metrics; |
| 1045 if (result == AutofillClient::SUCCESS) { | 1046 if (result == AutofillClient::SUCCESS) { |
| 1046 // Do *not* call payments_client_->Prepare() here. We shouldn't send | 1047 // Do *not* call payments_client_->Prepare() here. We shouldn't send |
| 1047 // credentials until the user has explicitly accepted a prompt to upload. | 1048 // credentials until the user has explicitly accepted a prompt to upload. |
| 1048 upload_request_.context_token = context_token; | 1049 upload_request_.context_token = context_token; |
| 1049 user_did_accept_upload_prompt_ = false; | 1050 user_did_accept_upload_prompt_ = false; |
| 1050 client_->ConfirmSaveCreditCardToCloud( | 1051 client_->ConfirmSaveCreditCardToCloud( |
| 1051 upload_request_.card, std::move(legal_message), | 1052 upload_request_.card, std::move(legal_message), |
| 1052 should_cvc_be_requested_, | 1053 should_cvc_be_requested_, |
| 1053 base::Bind(&AutofillManager::OnUserDidAcceptUpload, | 1054 base::Bind(&AutofillManager::OnUserDidAcceptUpload, |
| 1054 weak_ptr_factory_.GetWeakPtr())); | 1055 weak_ptr_factory_.GetWeakPtr())); |
| 1055 client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUploadRiskData, | 1056 client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUploadRiskData, |
| 1056 weak_ptr_factory_.GetWeakPtr())); | 1057 weak_ptr_factory_.GetWeakPtr())); |
| 1057 AutofillMetrics::CardUploadDecisionMetric card_upload_decision_metric = | 1058 AutofillMetrics::LogCardUploadDecisionMetric( |
| 1058 should_cvc_be_requested_ ? AutofillMetrics::UPLOAD_OFFERED_NO_CVC | 1059 AutofillMetrics::UPLOAD_OFFERED); |
| 1059 : AutofillMetrics::UPLOAD_OFFERED; | 1060 card_upload_decision_metrics = 1 << AutofillMetrics::UPLOAD_OFFERED; |
| 1060 AutofillMetrics::LogCardUploadDecisionMetric(card_upload_decision_metric); | 1061 if (should_cvc_be_requested_) { |
| 1061 LogCardUploadDecisionUkm(card_upload_decision_metric); | 1062 AutofillMetrics::LogCardUploadDecisionMetric( |
| 1063 AutofillMetrics::UPLOAD_OFFERED_NO_CVC); | |
| 1064 card_upload_decision_metrics |= 1 | |
|
Steven Holte
2017/05/02 00:36:33
Are you always calling AutofillMetrics::LogCardUpl
csashi
2017/05/02 00:43:55
Done. Sebastien made same suggestion.
| |
| 1065 << AutofillMetrics::UPLOAD_OFFERED_NO_CVC; | |
| 1066 } | |
| 1062 } else { | 1067 } else { |
| 1063 // If the upload details request failed, fall back to a local save. The | 1068 // If the upload details request failed, fall back to a local save. The |
| 1064 // reasoning here is as follows: | 1069 // reasoning here is as follows: |
| 1065 // - This will sometimes fail intermittently, in which case it might be | 1070 // - This will sometimes fail intermittently, in which case it might be |
| 1066 // better to not fall back, because sometimes offering upload and sometimes | 1071 // better to not fall back, because sometimes offering upload and sometimes |
| 1067 // offering local save is a poor user experience. | 1072 // offering local save is a poor user experience. |
| 1068 // - However, in some cases, our local configuration limiting the feature to | 1073 // - However, in some cases, our local configuration limiting the feature to |
| 1069 // countries that Payments is known to support will not match Payments' own | 1074 // countries that Payments is known to support will not match Payments' own |
| 1070 // determination of what country the user is located in. In these cases, | 1075 // determination of what country the user is located in. In these cases, |
| 1071 // the upload details request will consistently fail and if we don't fall | 1076 // the upload details request will consistently fail and if we don't fall |
| 1072 // back to a local save then the user will never be offered any kind of | 1077 // back to a local save then the user will never be offered any kind of |
| 1073 // credit card save. | 1078 // credit card save. |
| 1074 client_->ConfirmSaveCreditCardLocally( | 1079 client_->ConfirmSaveCreditCardLocally( |
| 1075 upload_request_.card, | 1080 upload_request_.card, |
| 1076 base::Bind( | 1081 base::Bind( |
| 1077 base::IgnoreResult(&PersonalDataManager::SaveImportedCreditCard), | 1082 base::IgnoreResult(&PersonalDataManager::SaveImportedCreditCard), |
| 1078 base::Unretained(personal_data_), upload_request_.card)); | 1083 base::Unretained(personal_data_), upload_request_.card)); |
| 1079 AutofillMetrics::LogCardUploadDecisionMetric( | 1084 AutofillMetrics::LogCardUploadDecisionMetric( |
| 1085 AutofillMetrics::UPLOAD_NOT_OFFERED); | |
| 1086 AutofillMetrics::LogCardUploadDecisionMetric( | |
| 1080 AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED); | 1087 AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED); |
|
Jared Saul
2017/05/01 21:05:12
It feels kind of flaky that if anything fails (or
csashi
2017/05/02 00:43:55
Acknowledged. The best I could think of was to set
| |
| 1081 LogCardUploadDecisionUkm( | 1088 card_upload_decision_metrics = |
| 1082 AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED); | 1089 (1 << AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED) | |
| 1090 (1 << AutofillMetrics::UPLOAD_NOT_OFFERED); | |
| 1083 } | 1091 } |
| 1092 LogCardUploadDecisionsUkm(card_upload_decision_metrics); | |
| 1084 pending_upload_request_url_ = GURL(); | 1093 pending_upload_request_url_ = GURL(); |
| 1085 } | 1094 } |
| 1086 | 1095 |
| 1087 void AutofillManager::OnDidUploadCard(AutofillClient::PaymentsRpcResult result, | 1096 void AutofillManager::OnDidUploadCard(AutofillClient::PaymentsRpcResult result, |
| 1088 const std::string& server_id) { | 1097 const std::string& server_id) { |
| 1089 // We don't do anything user-visible if the upload attempt fails. | 1098 // We don't do anything user-visible if the upload attempt fails. |
| 1090 // If the upload succeeds, we will keep a copy of the card as a full server | 1099 // If the upload succeeds, we will keep a copy of the card as a full server |
| 1091 // card on the device. | 1100 // card on the device. |
| 1092 if (result == AutofillClient::SUCCESS && !server_id.empty()) { | 1101 if (result == AutofillClient::SUCCESS && !server_id.empty()) { |
| 1093 upload_request_.card.set_record_type(CreditCard::FULL_SERVER_CARD); | 1102 upload_request_.card.set_record_type(CreditCard::FULL_SERVER_CARD); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1250 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE && | 1259 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE && |
| 1251 IsValidCreditCardSecurityCode(field->value, | 1260 IsValidCreditCardSecurityCode(field->value, |
| 1252 upload_request_.card.type())) { | 1261 upload_request_.card.type())) { |
| 1253 upload_request_.cvc = field->value; | 1262 upload_request_.cvc = field->value; |
| 1254 break; | 1263 break; |
| 1255 } | 1264 } |
| 1256 } | 1265 } |
| 1257 | 1266 |
| 1258 // Upload requires that recently used or modified addresses meet the | 1267 // Upload requires that recently used or modified addresses meet the |
| 1259 // client-side validation rules. | 1268 // client-side validation rules. |
| 1260 autofill::AutofillMetrics::CardUploadDecisionMetric | |
| 1261 get_profiles_decision_metric = AutofillMetrics::UPLOAD_OFFERED; | |
| 1262 std::string rappor_metric_name; | 1269 std::string rappor_metric_name; |
| 1263 bool get_profiles_succeeded = | 1270 int upload_decision_metrics = GetProfilesForCreditCardUpload( |
| 1264 GetProfilesForCreditCardUpload(*imported_credit_card, | 1271 *imported_credit_card, &upload_request_.profiles, &rappor_metric_name); |
| 1265 &upload_request_.profiles, | |
| 1266 &get_profiles_decision_metric, | |
| 1267 &rappor_metric_name); | |
| 1268 | 1272 |
| 1269 pending_upload_request_url_ = GURL(submitted_form.source_url()); | 1273 pending_upload_request_url_ = GURL(submitted_form.source_url()); |
| 1270 | 1274 |
| 1271 // Both the CVC and address checks are done. Conform to the legacy order of | 1275 // Both the CVC and address checks are done. Conform to the legacy order of |
| 1272 // reporting on CVC then address. | 1276 // reporting on CVC then address. |
| 1273 should_cvc_be_requested_ = false; | 1277 should_cvc_be_requested_ = false; |
| 1274 if (upload_request_.cvc.empty()) { | 1278 if (upload_request_.cvc.empty()) { |
| 1275 if (IsAutofillUpstreamRequestCvcIfMissingExperimentEnabled()) { | 1279 should_cvc_be_requested_ = |
| 1276 should_cvc_be_requested_ = true; | 1280 (!upload_decision_metrics && |
| 1277 } else { | 1281 IsAutofillUpstreamRequestCvcIfMissingExperimentEnabled()); |
| 1282 if (!should_cvc_be_requested_) { | |
| 1278 AutofillMetrics::LogCardUploadDecisionMetric( | 1283 AutofillMetrics::LogCardUploadDecisionMetric( |
| 1279 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); | 1284 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); |
| 1280 LogCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); | 1285 upload_decision_metrics |= |
| 1281 pending_upload_request_url_ = GURL(); | 1286 (1 << AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); |
| 1282 CollectRapportSample(submitted_form.source_url(), | 1287 rappor_metric_name = "Autofill.CardUploadNotOfferedNoCvc"; |
| 1283 "Autofill.CardUploadNotOfferedNoCvc"); | |
| 1284 return; | |
| 1285 } | 1288 } |
| 1286 } | 1289 } |
| 1287 if (!get_profiles_succeeded) { | 1290 if (upload_decision_metrics) { |
| 1288 DCHECK(get_profiles_decision_metric != AutofillMetrics::UPLOAD_OFFERED); | |
| 1289 AutofillMetrics::LogCardUploadDecisionMetric( | 1291 AutofillMetrics::LogCardUploadDecisionMetric( |
| 1290 get_profiles_decision_metric); | 1292 AutofillMetrics::UPLOAD_NOT_OFFERED); |
| 1291 LogCardUploadDecisionUkm(get_profiles_decision_metric); | 1293 upload_decision_metrics |= 1 << AutofillMetrics::UPLOAD_NOT_OFFERED; |
| 1294 LogCardUploadDecisionsUkm(upload_decision_metrics); | |
| 1292 pending_upload_request_url_ = GURL(); | 1295 pending_upload_request_url_ = GURL(); |
| 1293 if (!rappor_metric_name.empty()) { | 1296 if (!rappor_metric_name.empty()) { |
| 1294 CollectRapportSample(submitted_form.source_url(), rappor_metric_name); | 1297 CollectRapporSample(submitted_form.source_url(), rappor_metric_name); |
| 1295 } | 1298 } |
| 1296 return; | 1299 return; |
| 1297 } | 1300 } |
| 1298 | 1301 |
| 1299 // All required data is available, start the upload process. | 1302 // All required data is available, start the upload process. |
| 1300 payments_client_->GetUploadDetails(upload_request_.profiles, app_locale_); | 1303 payments_client_->GetUploadDetails(upload_request_.profiles, app_locale_); |
| 1301 } | 1304 } |
| 1302 } | 1305 } |
| 1303 | 1306 |
| 1304 bool AutofillManager::GetProfilesForCreditCardUpload( | 1307 int AutofillManager::GetProfilesForCreditCardUpload( |
| 1305 const CreditCard& card, | 1308 const CreditCard& card, |
| 1306 std::vector<AutofillProfile>* profiles, | 1309 std::vector<AutofillProfile>* profiles, |
| 1307 autofill::AutofillMetrics::CardUploadDecisionMetric* | |
| 1308 address_upload_decision_metric, | |
| 1309 std::string* rappor_metric_name) const { | 1310 std::string* rappor_metric_name) const { |
| 1310 std::vector<AutofillProfile> candidate_profiles; | 1311 std::vector<AutofillProfile> candidate_profiles; |
| 1311 const base::Time now = AutofillClock::Now(); | 1312 const base::Time now = AutofillClock::Now(); |
| 1312 const base::TimeDelta fifteen_minutes = base::TimeDelta::FromMinutes(15); | 1313 const base::TimeDelta fifteen_minutes = base::TimeDelta::FromMinutes(15); |
| 1314 int upload_decision_metrics = 0; | |
| 1313 | 1315 |
| 1314 // First, collect all of the addresses used recently. | 1316 // First, collect all of the addresses used recently. |
| 1315 for (AutofillProfile* profile : personal_data_->GetProfiles()) { | 1317 for (AutofillProfile* profile : personal_data_->GetProfiles()) { |
| 1316 if ((now - profile->use_date()) < fifteen_minutes || | 1318 if ((now - profile->use_date()) < fifteen_minutes || |
| 1317 (now - profile->modification_date()) < fifteen_minutes) { | 1319 (now - profile->modification_date()) < fifteen_minutes) { |
| 1318 candidate_profiles.push_back(*profile); | 1320 candidate_profiles.push_back(*profile); |
| 1319 } | 1321 } |
| 1320 } | 1322 } |
| 1321 if (candidate_profiles.empty()) { | 1323 if (candidate_profiles.empty()) { |
| 1322 *address_upload_decision_metric = | 1324 AutofillMetrics::LogCardUploadDecisionMetric( |
| 1323 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS; | 1325 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS); |
| 1326 upload_decision_metrics |= | |
| 1327 (1 << AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS); | |
| 1324 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoAddress"; | 1328 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoAddress"; |
| 1325 return false; | |
| 1326 } | 1329 } |
| 1327 | 1330 |
| 1328 // If any of the names on the card or the addresses don't match (where | 1331 // If any of the names on the card or the addresses don't match (where |
| 1329 // matching is case insensitive and ignores middle initials if present), the | 1332 // matching is case insensitive and ignores middle initials if present), the |
| 1330 // candidate set is invalid. This matches the rules for name matching applied | 1333 // candidate set is invalid. This matches the rules for name matching applied |
| 1331 // server-side by Google Payments and ensures that we don't send upload | 1334 // server-side by Google Payments and ensures that we don't send upload |
| 1332 // requests that are guaranteed to fail. | 1335 // requests that are guaranteed to fail. |
| 1333 base::string16 verified_name; | 1336 base::string16 verified_name; |
| 1334 base::string16 card_name = | 1337 const base::string16 card_name = |
| 1335 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); | 1338 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); |
| 1336 if (!card_name.empty()) { | 1339 if (!card_name.empty()) { |
| 1337 verified_name = RemoveMiddleInitial(card_name); | 1340 verified_name = RemoveMiddleInitial(card_name); |
| 1338 } | 1341 } |
| 1339 for (const AutofillProfile& profile : candidate_profiles) { | 1342 for (const AutofillProfile& profile : candidate_profiles) { |
| 1340 base::string16 address_name = | 1343 const base::string16 address_name = |
| 1341 profile.GetInfo(AutofillType(NAME_FULL), app_locale_); | 1344 profile.GetInfo(AutofillType(NAME_FULL), app_locale_); |
| 1342 if (!address_name.empty()) { | 1345 if (!address_name.empty()) { |
| 1343 if (verified_name.empty()) { | 1346 if (verified_name.empty()) { |
| 1344 verified_name = RemoveMiddleInitial(address_name); | 1347 verified_name = RemoveMiddleInitial(address_name); |
| 1345 } else { | 1348 } else { |
| 1346 // TODO(crbug.com/590307): We only use ASCII case insensitivity here | 1349 // TODO(crbug.com/590307): We'll need to make the name comparison more |
| 1347 // because the feature is launching US-only and middle initials only | 1350 // sophisticated. |
| 1348 // make sense for Western-style names anyway. As we launch in more | |
| 1349 // countries, we'll need to make the name comparison more sophisticated. | |
| 1350 if (!base::EqualsCaseInsensitiveASCII( | 1351 if (!base::EqualsCaseInsensitiveASCII( |
| 1351 verified_name, RemoveMiddleInitial(address_name))) { | 1352 verified_name, RemoveMiddleInitial(address_name))) { |
| 1352 *address_upload_decision_metric = | 1353 if (!upload_decision_metrics) |
| 1353 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES; | 1354 *rappor_metric_name = |
| 1354 *rappor_metric_name = "Autofill.CardUploadNotOfferedConflictingNames"; | 1355 "Autofill.CardUploadNotOfferedConflictingNames"; |
| 1355 return false; | 1356 AutofillMetrics::LogCardUploadDecisionMetric( |
| 1357 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES); | |
| 1358 upload_decision_metrics |= | |
| 1359 (1 << AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES); | |
| 1360 break; | |
| 1356 } | 1361 } |
| 1357 } | 1362 } |
| 1358 } | 1363 } |
| 1359 } | 1364 } |
| 1360 // If neither the card nor any of the addresses have a name associated with | 1365 // If neither the card nor any of the addresses have a name associated with |
| 1361 // them, the candidate set is invalid. | 1366 // them, the candidate set is invalid. |
| 1362 if (verified_name.empty()) { | 1367 if (verified_name.empty()) { |
| 1363 *address_upload_decision_metric = | 1368 if (!upload_decision_metrics) |
| 1364 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME; | 1369 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoName"; |
| 1365 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoName"; | 1370 AutofillMetrics::LogCardUploadDecisionMetric( |
| 1366 return false; | 1371 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME); |
| 1372 upload_decision_metrics |= | |
| 1373 (1 << AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME); | |
| 1367 } | 1374 } |
| 1368 | 1375 |
| 1369 // If any of the candidate addresses have a non-empty zip that doesn't match | 1376 // If any of the candidate addresses have a non-empty zip that doesn't match |
| 1370 // any other non-empty zip, then the candidate set is invalid. | 1377 // any other non-empty zip, then the candidate set is invalid. |
| 1371 base::string16 verified_zip; | 1378 base::string16 verified_zip; |
| 1372 for (const AutofillProfile& profile : candidate_profiles) { | 1379 for (const AutofillProfile& profile : candidate_profiles) { |
| 1373 // TODO(jdonnelly): Use GetInfo instead of GetRawInfo once zip codes are | 1380 // TODO(jdonnelly): Use GetInfo instead of GetRawInfo once zip codes are |
| 1374 // canonicalized. See http://crbug.com/587465. | 1381 // canonicalized. See http://crbug.com/587465. |
| 1375 base::string16 zip = profile.GetRawInfo(ADDRESS_HOME_ZIP); | 1382 const base::string16 zip = profile.GetRawInfo(ADDRESS_HOME_ZIP); |
| 1376 if (!zip.empty()) { | 1383 if (!zip.empty()) { |
| 1377 if (verified_zip.empty()) { | 1384 if (verified_zip.empty()) { |
| 1378 verified_zip = zip; | 1385 verified_zip = zip; |
| 1379 } else { | 1386 } else { |
| 1380 // To compare two zips, we check to see if either is a prefix of the | 1387 // To compare two zips, we check to see if either is a prefix of the |
| 1381 // other. This allows us to consider a 5-digit zip and a zip+4 to be a | 1388 // other. This allows us to consider a 5-digit zip and a zip+4 to be a |
| 1382 // match if the first 5 digits are the same without hardcoding any | 1389 // match if the first 5 digits are the same without hardcoding any |
| 1383 // specifics of how postal codes are represented. (They can be numeric | 1390 // specifics of how postal codes are represented. (They can be numeric |
| 1384 // or alphanumeric and vary from 3 to 10 digits long by country. See | 1391 // or alphanumeric and vary from 3 to 10 digits long by country. See |
| 1385 // https://en.wikipedia.org/wiki/Postal_code#Presentation.) The Payments | 1392 // https://en.wikipedia.org/wiki/Postal_code#Presentation.) The Payments |
| 1386 // backend will apply a more sophisticated address-matching procedure. | 1393 // backend will apply a more sophisticated address-matching procedure. |
| 1387 // This check is simply meant to avoid offering upload in cases that are | 1394 // This check is simply meant to avoid offering upload in cases that are |
| 1388 // likely to fail. | 1395 // likely to fail. |
| 1389 if (!(StartsWith(verified_zip, zip, base::CompareCase::SENSITIVE) || | 1396 if (!(StartsWith(verified_zip, zip, base::CompareCase::SENSITIVE) || |
| 1390 StartsWith(zip, verified_zip, base::CompareCase::SENSITIVE))) { | 1397 StartsWith(zip, verified_zip, base::CompareCase::SENSITIVE))) { |
| 1391 *address_upload_decision_metric = | 1398 AutofillMetrics::LogCardUploadDecisionMetric( |
| 1392 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_ZIPS; | 1399 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_ZIPS); |
| 1393 return false; | 1400 upload_decision_metrics |= |
| 1401 (1 << AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_ZIPS); | |
| 1402 break; | |
| 1394 } | 1403 } |
| 1395 } | 1404 } |
| 1396 } | 1405 } |
| 1397 } | 1406 } |
| 1398 | 1407 |
| 1399 // If none of the candidate addresses have a zip, the candidate set is | 1408 // If none of the candidate addresses have a zip, the candidate set is |
| 1400 // invalid. | 1409 // invalid. |
| 1401 if (verified_zip.empty()) { | 1410 if (verified_zip.empty()) { |
| 1402 *address_upload_decision_metric = | 1411 AutofillMetrics::LogCardUploadDecisionMetric( |
| 1403 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE; | 1412 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); |
| 1404 return false; | 1413 upload_decision_metrics |= |
| 1414 (1 << AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); | |
| 1405 } | 1415 } |
| 1406 | 1416 |
| 1407 profiles->assign(candidate_profiles.begin(), candidate_profiles.end()); | 1417 if (!upload_decision_metrics) |
| 1408 return true; | 1418 profiles->assign(candidate_profiles.begin(), candidate_profiles.end()); |
| 1419 | |
| 1420 return upload_decision_metrics; | |
| 1409 } | 1421 } |
| 1410 | 1422 |
| 1411 void AutofillManager::CollectRapportSample(const GURL& source_url, | 1423 void AutofillManager::CollectRapporSample( |
| 1412 const std::string& metric_name) | 1424 const GURL& source_url, |
| 1413 const { | 1425 const std::string& metric_name) const { |
| 1414 if (source_url.is_valid() && client_->GetRapporServiceImpl()) { | 1426 if (source_url.is_valid() && client_->GetRapporServiceImpl()) { |
| 1415 rappor::SampleDomainAndRegistryFromGURL(client_->GetRapporServiceImpl(), | 1427 rappor::SampleDomainAndRegistryFromGURL(client_->GetRapporServiceImpl(), |
| 1416 metric_name, source_url); | 1428 metric_name, source_url); |
| 1417 } | 1429 } |
| 1418 } | 1430 } |
| 1419 | 1431 |
| 1420 // Note that |submitted_form| is passed as a pointer rather than as a reference | 1432 // Note that |submitted_form| is passed as a pointer rather than as a reference |
| 1421 // so that we can get memory management right across threads. Note also that we | 1433 // so that we can get memory management right across threads. Note also that we |
| 1422 // explicitly pass in all the time stamps of interest, as the cached ones might | 1434 // explicitly pass in all the time stamps of interest, as the cached ones might |
| 1423 // get reset before this method executes. | 1435 // get reset before this method executes. |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2255 } | 2267 } |
| 2256 if (i > 0) | 2268 if (i > 0) |
| 2257 fputs("Next oldest form:\n", file); | 2269 fputs("Next oldest form:\n", file); |
| 2258 } | 2270 } |
| 2259 fputs("\n", file); | 2271 fputs("\n", file); |
| 2260 | 2272 |
| 2261 fclose(file); | 2273 fclose(file); |
| 2262 } | 2274 } |
| 2263 #endif // ENABLE_FORM_DEBUG_DUMP | 2275 #endif // ENABLE_FORM_DEBUG_DUMP |
| 2264 | 2276 |
| 2265 void AutofillManager::LogCardUploadDecisionUkm( | 2277 void AutofillManager::LogCardUploadDecisionsUkm(int upload_decision_metrics) { |
| 2266 AutofillMetrics::CardUploadDecisionMetric upload_decision) { | 2278 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmService(), |
| 2267 AutofillMetrics::LogCardUploadDecisionUkm( | 2279 pending_upload_request_url_, |
| 2268 client_->GetUkmService(), pending_upload_request_url_, upload_decision); | 2280 upload_decision_metrics); |
| 2269 } | 2281 } |
| 2270 | 2282 |
| 2271 } // namespace autofill | 2283 } // namespace autofill |
| OLD | NEW |