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

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

Issue 2789843004: [Payments] Upload card UI now has a CVC prompt (Closed)
Patch Set: Attempt to fix memory leak Created 3 years, 8 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_type.h" 45 #include "components/autofill/core/browser/autofill_type.h"
46 #include "components/autofill/core/browser/country_names.h" 46 #include "components/autofill/core/browser/country_names.h"
47 #include "components/autofill/core/browser/credit_card.h" 47 #include "components/autofill/core/browser/credit_card.h"
48 #include "components/autofill/core/browser/field_types.h" 48 #include "components/autofill/core/browser/field_types.h"
49 #include "components/autofill/core/browser/form_structure.h" 49 #include "components/autofill/core/browser/form_structure.h"
50 #include "components/autofill/core/browser/personal_data_manager.h" 50 #include "components/autofill/core/browser/personal_data_manager.h"
51 #include "components/autofill/core/browser/phone_number.h" 51 #include "components/autofill/core/browser/phone_number.h"
52 #include "components/autofill/core/browser/phone_number_i18n.h" 52 #include "components/autofill/core/browser/phone_number_i18n.h"
53 #include "components/autofill/core/browser/popup_item_ids.h" 53 #include "components/autofill/core/browser/popup_item_ids.h"
54 #include "components/autofill/core/browser/ui/save_card_bubble_controller.h"
54 #include "components/autofill/core/browser/validation.h" 55 #include "components/autofill/core/browser/validation.h"
55 #include "components/autofill/core/common/autofill_clock.h" 56 #include "components/autofill/core/common/autofill_clock.h"
56 #include "components/autofill/core/common/autofill_constants.h" 57 #include "components/autofill/core/common/autofill_constants.h"
57 #include "components/autofill/core/common/autofill_data_validation.h" 58 #include "components/autofill/core/common/autofill_data_validation.h"
58 #include "components/autofill/core/common/autofill_pref_names.h" 59 #include "components/autofill/core/common/autofill_pref_names.h"
59 #include "components/autofill/core/common/autofill_util.h" 60 #include "components/autofill/core/common/autofill_util.h"
60 #include "components/autofill/core/common/form_data.h" 61 #include "components/autofill/core/common/form_data.h"
61 #include "components/autofill/core/common/form_data_predictions.h" 62 #include "components/autofill/core/common/form_data_predictions.h"
62 #include "components/autofill/core/common/form_field_data.h" 63 #include "components/autofill/core/common/form_field_data.h"
63 #include "components/autofill/core/common/password_form_fill_data.h" 64 #include "components/autofill/core/common/password_form_fill_data.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)), 228 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)),
228 credit_card_form_event_logger_( 229 credit_card_form_event_logger_(
229 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)), 230 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)),
230 has_logged_autofill_enabled_(false), 231 has_logged_autofill_enabled_(false),
231 has_logged_address_suggestions_count_(false), 232 has_logged_address_suggestions_count_(false),
232 did_show_suggestions_(false), 233 did_show_suggestions_(false),
233 user_did_type_(false), 234 user_did_type_(false),
234 user_did_autofill_(false), 235 user_did_autofill_(false),
235 user_did_edit_autofilled_field_(false), 236 user_did_edit_autofilled_field_(false),
236 user_did_accept_upload_prompt_(false), 237 user_did_accept_upload_prompt_(false),
238 should_cvc_be_requested_(false),
237 external_delegate_(NULL), 239 external_delegate_(NULL),
238 test_delegate_(NULL), 240 test_delegate_(NULL),
239 #if defined(OS_ANDROID) || defined(OS_IOS) 241 #if defined(OS_ANDROID) || defined(OS_IOS)
240 autofill_assistant_(this), 242 autofill_assistant_(this),
241 #endif 243 #endif
242 weak_ptr_factory_(this) { 244 weak_ptr_factory_(this) {
243 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { 245 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) {
244 download_manager_.reset(new AutofillDownloadManager(driver, this)); 246 download_manager_.reset(new AutofillDownloadManager(driver, this));
245 } 247 }
246 CountryNames::SetLocaleString(app_locale_); 248 CountryNames::SetLocaleString(app_locale_);
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 const base::string16& context_token, 1028 const base::string16& context_token,
1027 std::unique_ptr<base::DictionaryValue> legal_message) { 1029 std::unique_ptr<base::DictionaryValue> legal_message) {
1028 // TODO(jdonnelly): Log duration. 1030 // TODO(jdonnelly): Log duration.
1029 if (result == AutofillClient::SUCCESS) { 1031 if (result == AutofillClient::SUCCESS) {
1030 // Do *not* call payments_client_->Prepare() here. We shouldn't send 1032 // Do *not* call payments_client_->Prepare() here. We shouldn't send
1031 // credentials until the user has explicitly accepted a prompt to upload. 1033 // credentials until the user has explicitly accepted a prompt to upload.
1032 upload_request_.context_token = context_token; 1034 upload_request_.context_token = context_token;
1033 user_did_accept_upload_prompt_ = false; 1035 user_did_accept_upload_prompt_ = false;
1034 client_->ConfirmSaveCreditCardToCloud( 1036 client_->ConfirmSaveCreditCardToCloud(
1035 upload_request_.card, std::move(legal_message), 1037 upload_request_.card, std::move(legal_message),
1038 should_cvc_be_requested_,
1036 base::Bind(&AutofillManager::OnUserDidAcceptUpload, 1039 base::Bind(&AutofillManager::OnUserDidAcceptUpload,
1037 weak_ptr_factory_.GetWeakPtr())); 1040 weak_ptr_factory_.GetWeakPtr()));
1038 client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUploadRiskData, 1041 client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUploadRiskData,
1039 weak_ptr_factory_.GetWeakPtr())); 1042 weak_ptr_factory_.GetWeakPtr()));
1040 AutofillMetrics::LogCardUploadDecisionMetric( 1043 AutofillMetrics::CardUploadDecisionMetric card_upload_decision_metric =
1041 AutofillMetrics::UPLOAD_OFFERED); 1044 should_cvc_be_requested_ ? AutofillMetrics::UPLOAD_OFFERED_NO_CVC
1042 LogCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); 1045 : AutofillMetrics::UPLOAD_OFFERED;
1046 AutofillMetrics::LogCardUploadDecisionMetric(card_upload_decision_metric);
1047 LogCardUploadDecisionUkm(card_upload_decision_metric);
1043 } else { 1048 } else {
1044 // If the upload details request failed, fall back to a local save. The 1049 // If the upload details request failed, fall back to a local save. The
1045 // reasoning here is as follows: 1050 // reasoning here is as follows:
1046 // - This will sometimes fail intermittently, in which case it might be 1051 // - This will sometimes fail intermittently, in which case it might be
1047 // better to not fall back, because sometimes offering upload and sometimes 1052 // better to not fall back, because sometimes offering upload and sometimes
1048 // offering local save is a poor user experience. 1053 // offering local save is a poor user experience.
1049 // - However, in some cases, our local configuration limiting the feature to 1054 // - However, in some cases, our local configuration limiting the feature to
1050 // countries that Payments is known to support will not match Payments' own 1055 // countries that Payments is known to support will not match Payments' own
1051 // determination of what country the user is located in. In these cases, 1056 // determination of what country the user is located in. In these cases,
1052 // the upload details request will consistently fail and if we don't fall 1057 // the upload details request will consistently fail and if we don't fall
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 1097
1093 void AutofillManager::OnUnmaskVerificationResult( 1098 void AutofillManager::OnUnmaskVerificationResult(
1094 AutofillClient::PaymentsRpcResult result) { 1099 AutofillClient::PaymentsRpcResult result) {
1095 client_->OnUnmaskVerificationResult(result); 1100 client_->OnUnmaskVerificationResult(result);
1096 } 1101 }
1097 1102
1098 void AutofillManager::OnUserDidAcceptUpload() { 1103 void AutofillManager::OnUserDidAcceptUpload() {
1099 user_did_accept_upload_prompt_ = true; 1104 user_did_accept_upload_prompt_ = true;
1100 if (!upload_request_.risk_data.empty()) { 1105 if (!upload_request_.risk_data.empty()) {
1101 upload_request_.app_locale = app_locale_; 1106 upload_request_.app_locale = app_locale_;
1107 #if !defined(OS_ANDROID)
Evan Stade 2017/04/12 15:21:31 still necessary?
Jared Saul 2017/04/12 22:49:21 Don't think so. Removed, thanks.
1108 // If the upload request does not have card CVC, populate it with the
1109 // value provided by the user:
1110 if (upload_request_.cvc.empty()) {
1111 DCHECK(client_->GetSaveCardBubbleController());
1112 upload_request_.cvc =
1113 client_->GetSaveCardBubbleController()->GetCvcEnteredByUser();
1114 }
1115 #endif
1102 payments_client_->UploadCard(upload_request_); 1116 payments_client_->UploadCard(upload_request_);
1103 } 1117 }
1104 } 1118 }
1105 1119
1106 void AutofillManager::OnDidGetUploadRiskData(const std::string& risk_data) { 1120 void AutofillManager::OnDidGetUploadRiskData(const std::string& risk_data) {
1107 upload_request_.risk_data = risk_data; 1121 upload_request_.risk_data = risk_data;
1108 if (user_did_accept_upload_prompt_) { 1122 if (user_did_accept_upload_prompt_) {
1109 upload_request_.app_locale = app_locale_; 1123 upload_request_.app_locale = app_locale_;
1124 #if !defined(OS_ANDROID)
Evan Stade 2017/04/12 15:21:31 still necessary?
Jared Saul 2017/04/12 22:49:22 Done.
1125 // If the upload request does not have card CVC, populate it with the
1126 // value provided by the user:
1127 if (upload_request_.cvc.empty()) {
1128 DCHECK(client_->GetSaveCardBubbleController());
1129 upload_request_.cvc =
1130 client_->GetSaveCardBubbleController()->GetCvcEnteredByUser();
1131 }
1132 #endif
1110 payments_client_->UploadCard(upload_request_); 1133 payments_client_->UploadCard(upload_request_);
1111 } 1134 }
1112 } 1135 }
1113 1136
1114 void AutofillManager::OnDidEndTextFieldEditing() { 1137 void AutofillManager::OnDidEndTextFieldEditing() {
1115 external_delegate_->DidEndTextFieldEditing(); 1138 external_delegate_->DidEndTextFieldEditing();
1116 } 1139 }
1117 1140
1118 bool AutofillManager::IsAutofillEnabled() const { 1141 bool AutofillManager::IsAutofillEnabled() const {
1119 return ::autofill::IsAutofillEnabled(client_->GetPrefs()); 1142 return ::autofill::IsAutofillEnabled(client_->GetPrefs());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 upload_request_.card = *imported_credit_card; 1215 upload_request_.card = *imported_credit_card;
1193 1216
1194 // In order to prompt the user to upload their card, we must have both: 1217 // In order to prompt the user to upload their card, we must have both:
1195 // 1) Card with CVC 1218 // 1) Card with CVC
1196 // 2) 1+ recently-used or modified addresses that meet the client-side 1219 // 2) 1+ recently-used or modified addresses that meet the client-side
1197 // validation rules 1220 // validation rules
1198 // Here we perform both checks before returning or logging anything, 1221 // Here we perform both checks before returning or logging anything,
1199 // because if only one of the two is missing, it may be fixable. 1222 // because if only one of the two is missing, it may be fixable.
1200 1223
1201 // Check for a CVC to determine whether we can prompt the user to upload 1224 // Check for a CVC to determine whether we can prompt the user to upload
1202 // their card. If no CVC is present, do nothing. We could fall back to a 1225 // their card. If no CVC is present and the experiment is off, do nothing.
1203 // local save but we believe that sometimes offering upload and sometimes 1226 // We could fall back to a local save but we believe that sometimes offering
1204 // offering local save is a confusing user experience. 1227 // upload and sometimes offering local save is a confusing user experience.
1228 // If no CVC and the experiment is on, request CVC from the user in the
1229 // bubble and save using the provided value.
1205 for (const auto& field : submitted_form) { 1230 for (const auto& field : submitted_form) {
1206 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE && 1231 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE &&
1207 IsValidCreditCardSecurityCode(field->value, 1232 IsValidCreditCardSecurityCode(field->value,
1208 upload_request_.card.type())) { 1233 upload_request_.card.type())) {
1209 upload_request_.cvc = field->value; 1234 upload_request_.cvc = field->value;
1210 break; 1235 break;
1211 } 1236 }
1212 } 1237 }
1213 1238
1214 // Upload requires that recently used or modified addresses meet the 1239 // Upload requires that recently used or modified addresses meet the
1215 // client-side validation rules. 1240 // client-side validation rules.
1216 autofill::AutofillMetrics::CardUploadDecisionMetric 1241 autofill::AutofillMetrics::CardUploadDecisionMetric
1217 get_profiles_decision_metric = AutofillMetrics::UPLOAD_OFFERED; 1242 get_profiles_decision_metric = AutofillMetrics::UPLOAD_OFFERED;
1218 std::string rappor_metric_name; 1243 std::string rappor_metric_name;
1219 bool get_profiles_succeeded = 1244 bool get_profiles_succeeded =
1220 GetProfilesForCreditCardUpload(*imported_credit_card, 1245 GetProfilesForCreditCardUpload(*imported_credit_card,
1221 &upload_request_.profiles, 1246 &upload_request_.profiles,
1222 &get_profiles_decision_metric, 1247 &get_profiles_decision_metric,
1223 &rappor_metric_name); 1248 &rappor_metric_name);
1224 1249
1225 pending_upload_request_url_ = GURL(submitted_form.source_url()); 1250 pending_upload_request_url_ = GURL(submitted_form.source_url());
1226 1251
1227 // Both the CVC and address checks are done. Conform to the legacy order of 1252 // Both the CVC and address checks are done. Conform to the legacy order of
1228 // reporting on CVC then address. 1253 // reporting on CVC then address.
1254 should_cvc_be_requested_ = false;
1229 if (upload_request_.cvc.empty()) { 1255 if (upload_request_.cvc.empty()) {
1230 AutofillMetrics::LogCardUploadDecisionMetric( 1256 if (IsAutofillUpstreamRequestCvcIfMissingExperimentEnabled()) {
1231 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); 1257 should_cvc_be_requested_ = true;
1232 LogCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); 1258 } else {
1233 pending_upload_request_url_ = GURL(); 1259 AutofillMetrics::LogCardUploadDecisionMetric(
1234 CollectRapportSample(submitted_form.source_url(), 1260 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC);
1235 "Autofill.CardUploadNotOfferedNoCvc"); 1261 LogCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC);
1236 return; 1262 pending_upload_request_url_ = GURL();
1263 CollectRapportSample(submitted_form.source_url(),
1264 "Autofill.CardUploadNotOfferedNoCvc");
1265 return;
1266 }
1237 } 1267 }
1238 if (!get_profiles_succeeded) { 1268 if (!get_profiles_succeeded) {
1239 DCHECK(get_profiles_decision_metric != AutofillMetrics::UPLOAD_OFFERED); 1269 DCHECK(get_profiles_decision_metric != AutofillMetrics::UPLOAD_OFFERED);
1240 AutofillMetrics::LogCardUploadDecisionMetric( 1270 AutofillMetrics::LogCardUploadDecisionMetric(
1241 get_profiles_decision_metric); 1271 get_profiles_decision_metric);
1242 LogCardUploadDecisionUkm(get_profiles_decision_metric); 1272 LogCardUploadDecisionUkm(get_profiles_decision_metric);
1243 pending_upload_request_url_ = GURL(); 1273 pending_upload_request_url_ = GURL();
1244 if (!rappor_metric_name.empty()) { 1274 if (!rappor_metric_name.empty()) {
1245 CollectRapportSample(submitted_form.source_url(), rappor_metric_name); 1275 CollectRapportSample(submitted_form.source_url(), rappor_metric_name);
1246 } 1276 }
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 } 2228 }
2199 #endif // ENABLE_FORM_DEBUG_DUMP 2229 #endif // ENABLE_FORM_DEBUG_DUMP
2200 2230
2201 void AutofillManager::LogCardUploadDecisionUkm( 2231 void AutofillManager::LogCardUploadDecisionUkm(
2202 AutofillMetrics::CardUploadDecisionMetric upload_decision) { 2232 AutofillMetrics::CardUploadDecisionMetric upload_decision) {
2203 AutofillMetrics::LogCardUploadDecisionUkm( 2233 AutofillMetrics::LogCardUploadDecisionUkm(
2204 client_->GetUkmService(), pending_upload_request_url_, upload_decision); 2234 client_->GetUkmService(), pending_upload_request_url_, upload_decision);
2205 } 2235 }
2206 2236
2207 } // namespace autofill 2237 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698