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

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

Issue 2894333002: Pass active_chrome_experiments in payments RPC. (Closed)
Patch Set: Adds feature to active_chrome_experiments only if feature was triggered. 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
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 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 } 1278 }
1279 } else if (is_valid_cvc && 1279 } else if (is_valid_cvc &&
1280 field->Type().GetStorableType() == UNKNOWN_TYPE) { 1280 field->Type().GetStorableType() == UNKNOWN_TYPE) {
1281 found_cvc_value_in_non_cvc_field_ = true; 1281 found_cvc_value_in_non_cvc_field_ = true;
1282 } 1282 }
1283 } 1283 }
1284 1284
1285 // Upload requires that recently used or modified addresses meet the 1285 // Upload requires that recently used or modified addresses meet the
1286 // client-side validation rules. 1286 // client-side validation rules.
1287 std::string rappor_metric_name; 1287 std::string rappor_metric_name;
1288 int upload_decision_metrics = GetProfilesForCreditCardUpload( 1288 int upload_decision_metrics = SetProfilesForCreditCardUpload(
1289 *imported_credit_card, &upload_request_.profiles, &rappor_metric_name); 1289 *imported_credit_card, &upload_request_, &rappor_metric_name);
1290 1290
1291 pending_upload_request_url_ = GURL(submitted_form.source_url()); 1291 pending_upload_request_url_ = GURL(submitted_form.source_url());
1292 1292
1293 should_cvc_be_requested_ = false; 1293 should_cvc_be_requested_ = false;
1294 if (upload_request_.cvc.empty()) { 1294 if (upload_request_.cvc.empty()) {
1295 should_cvc_be_requested_ = 1295 should_cvc_be_requested_ =
1296 (!upload_decision_metrics && 1296 (!upload_decision_metrics &&
1297 IsAutofillUpstreamRequestCvcIfMissingExperimentEnabled()); 1297 IsAutofillUpstreamRequestCvcIfMissingExperimentEnabled());
1298 if (!should_cvc_be_requested_) { 1298 if (should_cvc_be_requested_) {
1299 upload_request_.active_experiments.push_back(
1300 kAutofillUpstreamRequestCvcIfMissing.name);
1301 } else {
1299 upload_decision_metrics |= GetCVCCardUploadDecisionMetric(); 1302 upload_decision_metrics |= GetCVCCardUploadDecisionMetric();
1300 rappor_metric_name = "Autofill.CardUploadNotOfferedNoCvc"; 1303 rappor_metric_name = "Autofill.CardUploadNotOfferedNoCvc";
1301 } 1304 }
1302 } 1305 }
1303 if (upload_decision_metrics) { 1306 if (upload_decision_metrics) {
1304 LogCardUploadDecisions(upload_decision_metrics); 1307 LogCardUploadDecisions(upload_decision_metrics);
1305 pending_upload_request_url_ = GURL(); 1308 pending_upload_request_url_ = GURL();
1306 if (!rappor_metric_name.empty()) { 1309 if (!rappor_metric_name.empty()) {
1307 CollectRapporSample(submitted_form.source_url(), rappor_metric_name); 1310 CollectRapporSample(submitted_form.source_url(), rappor_metric_name);
1308 } 1311 }
1309 return; 1312 return;
1310 } 1313 }
1311 1314
1312 // All required data is available, start the upload process. 1315 // All required data is available, start the upload process.
1313 payments_client_->GetUploadDetails(upload_request_.profiles, app_locale_); 1316 payments_client_->GetUploadDetails(upload_request_.profiles,
1317 upload_request_.active_experiments,
1318 app_locale_);
1314 } 1319 }
1315 } 1320 }
1316 1321
1317 AutofillMetrics::CardUploadDecisionMetric 1322 AutofillMetrics::CardUploadDecisionMetric
1318 AutofillManager::GetCVCCardUploadDecisionMetric() const { 1323 AutofillManager::GetCVCCardUploadDecisionMetric() const {
1319 if (found_cvc_field_) 1324 if (found_cvc_field_)
1320 return found_value_in_cvc_field_ ? AutofillMetrics::INVALID_CVC_VALUE 1325 return found_value_in_cvc_field_ ? AutofillMetrics::INVALID_CVC_VALUE
1321 : AutofillMetrics::CVC_VALUE_NOT_FOUND; 1326 : AutofillMetrics::CVC_VALUE_NOT_FOUND;
1322 else 1327 else
1323 return found_cvc_value_in_non_cvc_field_ 1328 return found_cvc_value_in_non_cvc_field_
1324 ? AutofillMetrics::FOUND_POSSIBLE_CVC_VALUE_IN_NON_CVC_FIELD 1329 ? AutofillMetrics::FOUND_POSSIBLE_CVC_VALUE_IN_NON_CVC_FIELD
1325 : AutofillMetrics::CVC_FIELD_NOT_FOUND; 1330 : AutofillMetrics::CVC_FIELD_NOT_FOUND;
1326 } 1331 }
1327 1332
1328 int AutofillManager::GetProfilesForCreditCardUpload( 1333 int AutofillManager::SetProfilesForCreditCardUpload(
1329 const CreditCard& card, 1334 const CreditCard& card,
1330 std::vector<AutofillProfile>* profiles, 1335 payments::PaymentsClient::UploadRequestDetails* upload_request,
1331 std::string* rappor_metric_name) const { 1336 std::string* rappor_metric_name) const {
1332 std::vector<AutofillProfile> candidate_profiles; 1337 std::vector<AutofillProfile> candidate_profiles;
1333 const base::Time now = AutofillClock::Now(); 1338 const base::Time now = AutofillClock::Now();
1334 const base::TimeDelta fifteen_minutes = base::TimeDelta::FromMinutes(15); 1339 const base::TimeDelta fifteen_minutes = base::TimeDelta::FromMinutes(15);
1335 int upload_decision_metrics = 0; 1340 int upload_decision_metrics = 0;
1336 bool has_profile = false; 1341 bool has_profile = false;
1337 bool has_modified_profile = false; 1342 bool has_modified_profile = false;
1338 1343
1339 // First, collect all of the addresses used or modified recently. 1344 // First, collect all of the addresses used or modified recently.
1340 for (AutofillProfile* profile : personal_data_->GetProfiles()) { 1345 for (AutofillProfile* profile : personal_data_->GetProfiles()) {
1341 has_profile = true; 1346 has_profile = true;
1342 if ((now - profile->modification_date()) < fifteen_minutes) { 1347 if ((now - profile->modification_date()) < fifteen_minutes) {
1343 has_modified_profile = true; 1348 has_modified_profile = true;
1344 candidate_profiles.push_back(*profile); 1349 candidate_profiles.push_back(*profile);
1345 } else if ((now - profile->use_date()) < fifteen_minutes) { 1350 } else if ((now - profile->use_date()) < fifteen_minutes) {
1346 candidate_profiles.push_back(*profile); 1351 candidate_profiles.push_back(*profile);
1347 } 1352 }
1348 } 1353 }
1349 1354
1350 AutofillMetrics::LogHasModifiedProfileOnCreditCardFormSubmission( 1355 AutofillMetrics::LogHasModifiedProfileOnCreditCardFormSubmission(
1351 has_modified_profile); 1356 has_modified_profile);
1352 1357
1353 // If there are no recently used or modified profiles and experiment to use 1358 // If there are no recently used or modified profiles and experiment to use
1354 // profiles that were not recently is enabled, collect the profiles that were 1359 // profiles that were not recently is enabled, collect the profiles that were
1355 // not recently used but used within the maximum time specified in the 1360 // not recently used but used within the maximum time specified in the
1356 // experiment. 1361 // experiment.
1357 if (candidate_profiles.empty()) { 1362 if (candidate_profiles.empty()) {
1358 const base::TimeDelta max_time_since_use = 1363 const base::TimeDelta max_time_since_use =
1359 GetMaxTimeSinceAutofillProfileUseForCardUpload(); 1364 GetMaxTimeSinceAutofillProfileUseForCardUpload();
1360 if (!max_time_since_use.is_zero()) 1365 if (!max_time_since_use.is_zero()) {
1361 for (AutofillProfile* profile : personal_data_->GetProfiles()) 1366 for (AutofillProfile* profile : personal_data_->GetProfiles())
1362 if ((now - profile->modification_date()) < max_time_since_use || 1367 if ((now - profile->modification_date()) < max_time_since_use ||
1363 (now - profile->use_date()) < max_time_since_use) 1368 (now - profile->use_date()) < max_time_since_use)
1364 candidate_profiles.push_back(*profile); 1369 candidate_profiles.push_back(*profile);
1370 if (!candidate_profiles.empty())
1371 upload_request->active_experiments.push_back(
1372 kAutofillUpstreamUseNotRecentlyUsedAutofillProfile.name);
1373 }
1365 } 1374 }
1366 1375
1367 if (candidate_profiles.empty()) { 1376 if (candidate_profiles.empty()) {
1368 upload_decision_metrics |= 1377 upload_decision_metrics |=
1369 has_profile 1378 has_profile
1370 ? AutofillMetrics::UPLOAD_NOT_OFFERED_NO_RECENTLY_USED_ADDRESS 1379 ? AutofillMetrics::UPLOAD_NOT_OFFERED_NO_RECENTLY_USED_ADDRESS
1371 : AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS_PROFILE; 1380 : AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS_PROFILE;
1372 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoAddress"; 1381 *rappor_metric_name = "Autofill.CardUploadNotOfferedNoAddress";
1373 } 1382 }
1374 1383
1375 // If any of the names on the card or the addresses don't match the 1384 // If any of the names on the card or the addresses don't match the
1376 // candidate set is invalid. This matches the rules for name matching applied 1385 // candidate set is invalid. This matches the rules for name matching applied
1377 // server-side by Google Payments and ensures that we don't send upload 1386 // server-side by Google Payments and ensures that we don't send upload
1378 // requests that are guaranteed to fail. 1387 // requests that are guaranteed to fail.
1379 const base::string16 card_name = 1388 const base::string16 card_name =
1380 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); 1389 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_);
1381 base::string16 verified_name; 1390 base::string16 verified_name;
1382 if (candidate_profiles.empty()) { 1391 if (candidate_profiles.empty()) {
1383 verified_name = card_name; 1392 verified_name = card_name;
1384 } else { 1393 } else {
1385 bool found_conflicting_names = false; 1394 bool found_conflicting_names = false;
1386 if (base::FeatureList::IsEnabled( 1395 if (base::FeatureList::IsEnabled(
1387 kAutofillUpstreamUseAutofillProfileComparatorForName)) { 1396 kAutofillUpstreamUseAutofillProfileComparatorForName)) {
1397 upload_request->active_experiments.push_back(
1398 kAutofillUpstreamUseAutofillProfileComparatorForName.name);
1388 AutofillProfileComparator comparator(app_locale_); 1399 AutofillProfileComparator comparator(app_locale_);
1389 verified_name = comparator.NormalizeForComparison(card_name); 1400 verified_name = comparator.NormalizeForComparison(card_name);
1390 for (const AutofillProfile& profile : candidate_profiles) { 1401 for (const AutofillProfile& profile : candidate_profiles) {
1391 const base::string16 address_name = comparator.NormalizeForComparison( 1402 const base::string16 address_name = comparator.NormalizeForComparison(
1392 profile.GetInfo(AutofillType(NAME_FULL), app_locale_)); 1403 profile.GetInfo(AutofillType(NAME_FULL), app_locale_));
1393 if (address_name.empty()) 1404 if (address_name.empty())
1394 continue; 1405 continue;
1395 if (verified_name.empty() || 1406 if (verified_name.empty() ||
1396 comparator.IsNameVariantOf(address_name, verified_name)) { 1407 comparator.IsNameVariantOf(address_name, verified_name)) {
1397 verified_name = address_name; 1408 verified_name = address_name;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 } 1472 }
1462 } 1473 }
1463 } 1474 }
1464 1475
1465 // If none of the candidate addresses have a zip, the candidate set is 1476 // If none of the candidate addresses have a zip, the candidate set is
1466 // invalid. 1477 // invalid.
1467 if (verified_zip.empty() && !candidate_profiles.empty()) 1478 if (verified_zip.empty() && !candidate_profiles.empty())
1468 upload_decision_metrics |= AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE; 1479 upload_decision_metrics |= AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE;
1469 1480
1470 if (!upload_decision_metrics) { 1481 if (!upload_decision_metrics) {
1471 profiles->assign(candidate_profiles.begin(), candidate_profiles.end()); 1482 upload_request->profiles.assign(candidate_profiles.begin(),
1483 candidate_profiles.end());
1472 if (!has_modified_profile) 1484 if (!has_modified_profile)
1473 for (const AutofillProfile& profile : candidate_profiles) 1485 for (const AutofillProfile& profile : candidate_profiles)
1474 UMA_HISTOGRAM_COUNTS_1000( 1486 UMA_HISTOGRAM_COUNTS_1000(
1475 "Autofill.DaysSincePreviousUseAtSubmission.Profile", 1487 "Autofill.DaysSincePreviousUseAtSubmission.Profile",
1476 (profile.use_date() - profile.previous_use_date()).InDays()); 1488 (profile.use_date() - profile.previous_use_date()).InDays());
1477 } 1489 }
1478 return upload_decision_metrics; 1490 return upload_decision_metrics;
1479 } 1491 }
1480 1492
1481 void AutofillManager::CollectRapporSample( 1493 void AutofillManager::CollectRapporSample(
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
2334 #endif // ENABLE_FORM_DEBUG_DUMP 2346 #endif // ENABLE_FORM_DEBUG_DUMP
2335 2347
2336 void AutofillManager::LogCardUploadDecisions(int upload_decision_metrics) { 2348 void AutofillManager::LogCardUploadDecisions(int upload_decision_metrics) {
2337 AutofillMetrics::LogCardUploadDecisionMetrics(upload_decision_metrics); 2349 AutofillMetrics::LogCardUploadDecisionMetrics(upload_decision_metrics);
2338 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmService(), 2350 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmService(),
2339 pending_upload_request_url_, 2351 pending_upload_request_url_,
2340 upload_decision_metrics); 2352 upload_decision_metrics);
2341 } 2353 }
2342 2354
2343 } // namespace autofill 2355 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.h ('k') | components/autofill/core/browser/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698