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

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

Issue 2800853004: UKM that threads together multiple form interaction events. (Closed)
Patch Set: Updates unit tests. 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 } // namespace 211 } // namespace
212 212
213 AutofillManager::AutofillManager( 213 AutofillManager::AutofillManager(
214 AutofillDriver* driver, 214 AutofillDriver* driver,
215 AutofillClient* client, 215 AutofillClient* client,
216 const std::string& app_locale, 216 const std::string& app_locale,
217 AutofillDownloadManagerState enable_download_manager) 217 AutofillDownloadManagerState enable_download_manager)
218 : driver_(driver), 218 : driver_(driver),
219 client_(client), 219 client_(client),
220 payments_client_( 220 payments_client_(base::MakeUnique<payments::PaymentsClient>(
221 new payments::PaymentsClient(driver->GetURLRequestContext(), this)), 221 driver->GetURLRequestContext(),
222 this)),
222 app_locale_(app_locale), 223 app_locale_(app_locale),
223 personal_data_(client->GetPersonalDataManager()), 224 personal_data_(client->GetPersonalDataManager()),
224 autocomplete_history_manager_( 225 autocomplete_history_manager_(
225 new AutocompleteHistoryManager(driver, client)), 226 base::MakeUnique<AutocompleteHistoryManager>(driver, client)),
227 ukm_logger_(base::MakeUnique<AutofillMetrics::UkmLogger>(
228 client->GetUkmService())),
226 address_form_event_logger_( 229 address_form_event_logger_(
227 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)), 230 base::MakeUnique<AutofillMetrics::FormEventLogger>(
231 false /* is_for_credit_card */,
232 ukm_logger_.get())),
228 credit_card_form_event_logger_( 233 credit_card_form_event_logger_(
229 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)), 234 base::MakeUnique<AutofillMetrics::FormEventLogger>(
235 true /* is_for_credit_card */,
236 ukm_logger_.get())),
230 has_logged_autofill_enabled_(false), 237 has_logged_autofill_enabled_(false),
231 has_logged_address_suggestions_count_(false), 238 has_logged_address_suggestions_count_(false),
232 did_show_suggestions_(false), 239 did_show_suggestions_(false),
233 user_did_type_(false), 240 user_did_type_(false),
234 user_did_autofill_(false), 241 user_did_autofill_(false),
235 user_did_edit_autofilled_field_(false), 242 user_did_edit_autofilled_field_(false),
236 user_did_accept_upload_prompt_(false), 243 user_did_accept_upload_prompt_(false),
237 external_delegate_(NULL), 244 external_delegate_(NULL),
238 test_delegate_(NULL), 245 test_delegate_(NULL),
239 #if defined(OS_ANDROID) || defined(OS_IOS) 246 #if defined(OS_ANDROID) || defined(OS_IOS)
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 FormStructure* form_structure = NULL; 515 FormStructure* form_structure = NULL;
509 AutofillField* autofill_field = NULL; 516 AutofillField* autofill_field = NULL;
510 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) 517 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field))
511 return; 518 return;
512 519
513 UpdatePendingForm(form); 520 UpdatePendingForm(form);
514 521
515 if (!user_did_type_) { 522 if (!user_did_type_) {
516 user_did_type_ = true; 523 user_did_type_ = true;
517 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE); 524 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE);
525 ukm_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE);
518 } 526 }
519 527
520 if (autofill_field->is_autofilled) { 528 if (autofill_field->is_autofilled) {
521 autofill_field->is_autofilled = false; 529 autofill_field->is_autofilled = false;
522 autofill_field->set_previously_autofilled(true); 530 autofill_field->set_previously_autofilled(true);
523 AutofillMetrics::LogUserHappinessMetric( 531 AutofillMetrics::LogUserHappinessMetric(
524 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD); 532 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD);
533 ukm_logger_->LogUserHappinessMetric(
534 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD);
525 535
526 if (!user_did_edit_autofilled_field_) { 536 if (!user_did_edit_autofilled_field_) {
527 user_did_edit_autofilled_field_ = true; 537 user_did_edit_autofilled_field_ = true;
528 AutofillMetrics::LogUserHappinessMetric( 538 AutofillMetrics::LogUserHappinessMetric(
529 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE); 539 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE);
530 } 540 }
531 } 541 }
532 542
533 UpdateInitialInteractionTimestamp(timestamp); 543 UpdateInitialInteractionTimestamp(timestamp);
534 } 544 }
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 } 816 }
807 817
808 void AutofillManager::OnDidFillAutofillFormData(const FormData& form, 818 void AutofillManager::OnDidFillAutofillFormData(const FormData& form,
809 const TimeTicks& timestamp) { 819 const TimeTicks& timestamp) {
810 if (test_delegate_) 820 if (test_delegate_)
811 test_delegate_->DidFillFormData(); 821 test_delegate_->DidFillFormData();
812 822
813 UpdatePendingForm(form); 823 UpdatePendingForm(form);
814 824
815 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL); 825 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL);
826 ukm_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL);
816 if (!user_did_autofill_) { 827 if (!user_did_autofill_) {
817 user_did_autofill_ = true; 828 user_did_autofill_ = true;
818 AutofillMetrics::LogUserHappinessMetric( 829 AutofillMetrics::LogUserHappinessMetric(
819 AutofillMetrics::USER_DID_AUTOFILL_ONCE); 830 AutofillMetrics::USER_DID_AUTOFILL_ONCE);
820 } 831 }
821 832
822 UpdateInitialInteractionTimestamp(timestamp); 833 UpdateInitialInteractionTimestamp(timestamp);
823 } 834 }
824 835
825 void AutofillManager::DidShowSuggestions(bool is_new_popup, 836 void AutofillManager::DidShowSuggestions(bool is_new_popup,
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 1092
1082 void AutofillManager::OnFullCardRequestFailed() { 1093 void AutofillManager::OnFullCardRequestFailed() {
1083 driver_->RendererShouldClearPreviewedForm(); 1094 driver_->RendererShouldClearPreviewedForm();
1084 } 1095 }
1085 1096
1086 void AutofillManager::ShowUnmaskPrompt( 1097 void AutofillManager::ShowUnmaskPrompt(
1087 const CreditCard& card, 1098 const CreditCard& card,
1088 AutofillClient::UnmaskCardReason reason, 1099 AutofillClient::UnmaskCardReason reason,
1089 base::WeakPtr<CardUnmaskDelegate> delegate) { 1100 base::WeakPtr<CardUnmaskDelegate> delegate) {
1090 client_->ShowUnmaskPrompt(card, reason, delegate); 1101 client_->ShowUnmaskPrompt(card, reason, delegate);
1102 ukm_logger_->LogUnmaskPromptEvent(AutofillMetrics::UNMASK_PROMPT_SHOWN);
1091 } 1103 }
1092 1104
1093 void AutofillManager::OnUnmaskVerificationResult( 1105 void AutofillManager::OnUnmaskVerificationResult(
1094 AutofillClient::PaymentsRpcResult result) { 1106 AutofillClient::PaymentsRpcResult result) {
1095 client_->OnUnmaskVerificationResult(result); 1107 client_->OnUnmaskVerificationResult(result);
1096 } 1108 }
1097 1109
1098 void AutofillManager::OnUserDidAcceptUpload() { 1110 void AutofillManager::OnUserDidAcceptUpload() {
1099 user_did_accept_upload_prompt_ = true; 1111 user_did_accept_upload_prompt_ = true;
1100 if (!upload_request_.risk_data.empty()) { 1112 if (!upload_request_.risk_data.empty()) {
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 // Note that |submitted_form| is passed as a pointer rather than as a reference 1383 // Note that |submitted_form| is passed as a pointer rather than as a reference
1372 // so that we can get memory management right across threads. Note also that we 1384 // so that we can get memory management right across threads. Note also that we
1373 // explicitly pass in all the time stamps of interest, as the cached ones might 1385 // explicitly pass in all the time stamps of interest, as the cached ones might
1374 // get reset before this method executes. 1386 // get reset before this method executes.
1375 void AutofillManager::UploadFormDataAsyncCallback( 1387 void AutofillManager::UploadFormDataAsyncCallback(
1376 const FormStructure* submitted_form, 1388 const FormStructure* submitted_form,
1377 const TimeTicks& load_time, 1389 const TimeTicks& load_time,
1378 const TimeTicks& interaction_time, 1390 const TimeTicks& interaction_time,
1379 const TimeTicks& submission_time, 1391 const TimeTicks& submission_time,
1380 bool observed_submission) { 1392 bool observed_submission) {
1381 submitted_form->LogQualityMetrics(load_time, interaction_time, 1393 AutofillMetrics::AutofillFormSubmittedState state =
1382 submission_time, 1394 submitted_form->LogQualityMetrics(
1383 client_->GetRapporServiceImpl(), 1395 load_time, interaction_time, submission_time,
1384 did_show_suggestions_, observed_submission); 1396 client_->GetRapporServiceImpl(), did_show_suggestions_,
1397 observed_submission);
1398 if (state < AutofillMetrics::AUTOFILL_FORM_SUBMITTED_STATE_ENUM_SIZE) {
sebsg 2017/04/10 19:20:19 Do we expect that this is ever bigger than max? If
csashi 2017/04/10 20:15:57 Done.
1399 if (ukm_logger_->url() != submitted_form->source_url())
1400 ukm_logger_->set_url(submitted_form->source_url());
1401 AutofillMetrics::LogAutofillFormSubmittedState(state, ukm_logger_.get());
1402 }
1385 1403
1386 if (submitted_form->ShouldBeCrowdsourced()) 1404 if (submitted_form->ShouldBeCrowdsourced())
1387 UploadFormData(*submitted_form, observed_submission); 1405 UploadFormData(*submitted_form, observed_submission);
1388 } 1406 }
1389 1407
1390 void AutofillManager::UploadFormData(const FormStructure& submitted_form, 1408 void AutofillManager::UploadFormData(const FormStructure& submitted_form,
1391 bool observed_submission) { 1409 bool observed_submission) {
1392 if (!download_manager_) 1410 if (!download_manager_)
1393 return; 1411 return;
1394 1412
(...skipping 14 matching lines...) Expand all
1409 submitted_form, was_autofilled, non_empty_types, 1427 submitted_form, was_autofilled, non_empty_types,
1410 std::string() /* login_form_signature */, observed_submission); 1428 std::string() /* login_form_signature */, observed_submission);
1411 } 1429 }
1412 1430
1413 void AutofillManager::Reset() { 1431 void AutofillManager::Reset() {
1414 // Note that upload_request_ is not reset here because the prompt to 1432 // Note that upload_request_ is not reset here because the prompt to
1415 // save a card is shown after page navigation. 1433 // save a card is shown after page navigation.
1416 ProcessPendingFormForUpload(); 1434 ProcessPendingFormForUpload();
1417 DCHECK(!pending_form_data_); 1435 DCHECK(!pending_form_data_);
1418 form_structures_.clear(); 1436 form_structures_.clear();
1419 address_form_event_logger_.reset( 1437 ukm_logger_.reset(new AutofillMetrics::UkmLogger(client_->GetUkmService()));
1420 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)); 1438 address_form_event_logger_.reset(new AutofillMetrics::FormEventLogger(
1421 credit_card_form_event_logger_.reset( 1439 false /* is_for_credit_card */, ukm_logger_.get()));
1422 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)); 1440 credit_card_form_event_logger_.reset(new AutofillMetrics::FormEventLogger(
1441 true /* is_for_credit_card */, ukm_logger_.get()));
1423 #if defined(OS_ANDROID) || defined(OS_IOS) 1442 #if defined(OS_ANDROID) || defined(OS_IOS)
1424 autofill_assistant_.Reset(); 1443 autofill_assistant_.Reset();
1425 #endif 1444 #endif
1426 has_logged_autofill_enabled_ = false; 1445 has_logged_autofill_enabled_ = false;
1427 has_logged_address_suggestions_count_ = false; 1446 has_logged_address_suggestions_count_ = false;
1428 did_show_suggestions_ = false; 1447 did_show_suggestions_ = false;
1429 user_did_type_ = false; 1448 user_did_type_ = false;
1430 user_did_autofill_ = false; 1449 user_did_autofill_ = false;
1431 user_did_edit_autofilled_field_ = false; 1450 user_did_edit_autofilled_field_ = false;
1432 masked_card_ = CreditCard(); 1451 masked_card_ = CreditCard();
1433 unmasking_query_id_ = -1; 1452 unmasking_query_id_ = -1;
1434 unmasking_form_ = FormData(); 1453 unmasking_form_ = FormData();
1435 unmasking_field_ = FormFieldData(); 1454 unmasking_field_ = FormFieldData();
1436 forms_loaded_timestamps_.clear(); 1455 forms_loaded_timestamps_.clear();
1437 initial_interaction_timestamp_ = TimeTicks(); 1456 initial_interaction_timestamp_ = TimeTicks();
1438 external_delegate_->Reset(); 1457 external_delegate_->Reset();
1439 } 1458 }
1440 1459
1441 AutofillManager::AutofillManager(AutofillDriver* driver, 1460 AutofillManager::AutofillManager(AutofillDriver* driver,
1442 AutofillClient* client, 1461 AutofillClient* client,
1443 PersonalDataManager* personal_data) 1462 PersonalDataManager* personal_data)
1444 : driver_(driver), 1463 : driver_(driver),
1445 client_(client), 1464 client_(client),
1446 payments_client_( 1465 payments_client_(base::MakeUnique<payments::PaymentsClient>(
1447 new payments::PaymentsClient(driver->GetURLRequestContext(), this)), 1466 driver->GetURLRequestContext(),
1467 this)),
1448 app_locale_("en-US"), 1468 app_locale_("en-US"),
1449 personal_data_(personal_data), 1469 personal_data_(personal_data),
1450 autocomplete_history_manager_( 1470 autocomplete_history_manager_(
1451 new AutocompleteHistoryManager(driver, client)), 1471 base::MakeUnique<AutocompleteHistoryManager>(driver, client)),
1472 ukm_logger_(base::MakeUnique<AutofillMetrics::UkmLogger>(
1473 client->GetUkmService())),
1452 address_form_event_logger_( 1474 address_form_event_logger_(
1453 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)), 1475 base::MakeUnique<AutofillMetrics::FormEventLogger>(
1476 false /* is_for_credit_card */,
1477 ukm_logger_.get())),
1454 credit_card_form_event_logger_( 1478 credit_card_form_event_logger_(
1455 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)), 1479 base::MakeUnique<AutofillMetrics::FormEventLogger>(
1480 true /* is_for_credit_card */,
1481 ukm_logger_.get())),
1456 has_logged_autofill_enabled_(false), 1482 has_logged_autofill_enabled_(false),
1457 has_logged_address_suggestions_count_(false), 1483 has_logged_address_suggestions_count_(false),
1458 did_show_suggestions_(false), 1484 did_show_suggestions_(false),
1459 user_did_type_(false), 1485 user_did_type_(false),
1460 user_did_autofill_(false), 1486 user_did_autofill_(false),
1461 user_did_edit_autofilled_field_(false), 1487 user_did_edit_autofilled_field_(false),
1462 unmasking_query_id_(-1), 1488 unmasking_query_id_(-1),
1463 external_delegate_(NULL), 1489 external_delegate_(NULL),
1464 test_delegate_(NULL), 1490 test_delegate_(NULL),
1465 #if defined(OS_ANDROID) || defined(OS_IOS) 1491 #if defined(OS_ANDROID) || defined(OS_IOS)
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 // Note that this may invalidate |data_model|, particularly if it is a Mac 1698 // Note that this may invalidate |data_model|, particularly if it is a Mac
1673 // address book entry. 1699 // address book entry.
1674 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) 1700 if (action == AutofillDriver::FORM_DATA_ACTION_FILL)
1675 personal_data_->RecordUseOf(data_model); 1701 personal_data_->RecordUseOf(data_model);
1676 1702
1677 driver_->SendFormDataToRenderer(query_id, action, result); 1703 driver_->SendFormDataToRenderer(query_id, action, result);
1678 } 1704 }
1679 1705
1680 std::unique_ptr<FormStructure> AutofillManager::ValidateSubmittedForm( 1706 std::unique_ptr<FormStructure> AutofillManager::ValidateSubmittedForm(
1681 const FormData& form) { 1707 const FormData& form) {
1682 std::unique_ptr<FormStructure> submitted_form(new FormStructure(form)); 1708 std::unique_ptr<FormStructure> submitted_form(
1709 base::MakeUnique<FormStructure>(form));
1683 if (!ShouldUploadForm(*submitted_form)) 1710 if (!ShouldUploadForm(*submitted_form))
1684 return std::unique_ptr<FormStructure>(); 1711 return std::unique_ptr<FormStructure>();
1685 1712
1686 // Ignore forms not present in our cache. These are typically forms with 1713 // Ignore forms not present in our cache. These are typically forms with
1687 // wonky JavaScript that also makes them not auto-fillable. 1714 // wonky JavaScript that also makes them not auto-fillable.
1688 FormStructure* cached_submitted_form; 1715 FormStructure* cached_submitted_form;
1689 if (!FindCachedForm(form, &cached_submitted_form)) 1716 if (!FindCachedForm(form, &cached_submitted_form))
1690 return std::unique_ptr<FormStructure>(); 1717 return std::unique_ptr<FormStructure>();
1691 1718
1692 submitted_form->UpdateFromCache(*cached_submitted_form, false); 1719 submitted_form->UpdateFromCache(*cached_submitted_form, false);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 parse_form_start_time); 1900 parse_form_start_time);
1874 } 1901 }
1875 1902
1876 if (!queryable_forms.empty() && download_manager_) { 1903 if (!queryable_forms.empty() && download_manager_) {
1877 // Query the server if at least one of the forms was parsed. 1904 // Query the server if at least one of the forms was parsed.
1878 download_manager_->StartQueryRequest(queryable_forms); 1905 download_manager_->StartQueryRequest(queryable_forms);
1879 } 1906 }
1880 1907
1881 if (!queryable_forms.empty() || !non_queryable_forms.empty()) { 1908 if (!queryable_forms.empty() || !non_queryable_forms.empty()) {
1882 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED); 1909 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED);
1910
1911 // Log pending events, if any.
1912 ukm_logger_->LogUkm();
1913
1914 // If user submits a form later, we set the key to the |submitted_form|'s
sebsg 2017/04/10 19:20:19 I would reformulate to something like, setup the u
csashi 2017/04/10 20:15:57 Done.
1915 // |source_url()|.
1916 ukm_logger_->set_url(forms[0].origin);
1917 ukm_logger_->LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED);
1883 #if defined(OS_IOS) 1918 #if defined(OS_IOS)
1884 // Log this from same location as AutofillMetrics::FORMS_LOADED to ensure 1919 // Log this from same location as AutofillMetrics::FORMS_LOADED to ensure
1885 // that KeyboardAccessoryButtonsIOS and UserHappiness UMA metrics will be 1920 // that KeyboardAccessoryButtonsIOS and UserHappiness UMA metrics will be
1886 // directly comparable. 1921 // directly comparable.
1887 KeyboardAccessoryMetricsLogger::OnFormsLoaded(); 1922 KeyboardAccessoryMetricsLogger::OnFormsLoaded();
1888 #endif 1923 #endif
1889 } 1924 }
1890 1925
1891 #if defined(OS_ANDROID) || defined(OS_IOS) 1926 #if defined(OS_ANDROID) || defined(OS_IOS)
1892 // When a credit card form is parsed and conditions are met, show an infobar 1927 // When a credit card form is parsed and conditions are met, show an infobar
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 } 2233 }
2199 #endif // ENABLE_FORM_DEBUG_DUMP 2234 #endif // ENABLE_FORM_DEBUG_DUMP
2200 2235
2201 void AutofillManager::LogCardUploadDecisionUkm( 2236 void AutofillManager::LogCardUploadDecisionUkm(
2202 AutofillMetrics::CardUploadDecisionMetric upload_decision) { 2237 AutofillMetrics::CardUploadDecisionMetric upload_decision) {
2203 AutofillMetrics::LogCardUploadDecisionUkm( 2238 AutofillMetrics::LogCardUploadDecisionUkm(
2204 client_->GetUkmService(), pending_upload_request_url_, upload_decision); 2239 client_->GetUkmService(), pending_upload_request_url_, upload_decision);
2205 } 2240 }
2206 2241
2207 } // namespace autofill 2242 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698