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

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

Issue 2800853004: UKM that threads together multiple form interaction events. (Closed)
Patch Set: Moves UkmLogger as parameter to LogAutofillFormSubmittedState. 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
518 } 525 }
519 526
527 DCHECK(ukm_logger_);
528 if (ukm_logger_)
529 ukm_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE);
530
520 if (autofill_field->is_autofilled) { 531 if (autofill_field->is_autofilled) {
521 autofill_field->is_autofilled = false; 532 autofill_field->is_autofilled = false;
522 autofill_field->set_previously_autofilled(true); 533 autofill_field->set_previously_autofilled(true);
523 AutofillMetrics::LogUserHappinessMetric( 534 AutofillMetrics::LogUserHappinessMetric(
524 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD); 535 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD);
536 if (ukm_logger_)
537 ukm_logger_->LogUserHappinessMetric(
538 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD);
525 539
526 if (!user_did_edit_autofilled_field_) { 540 if (!user_did_edit_autofilled_field_) {
527 user_did_edit_autofilled_field_ = true; 541 user_did_edit_autofilled_field_ = true;
528 AutofillMetrics::LogUserHappinessMetric( 542 AutofillMetrics::LogUserHappinessMetric(
529 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE); 543 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE);
530 } 544 }
531 } 545 }
532 546
533 UpdateInitialInteractionTimestamp(timestamp); 547 UpdateInitialInteractionTimestamp(timestamp);
534 } 548 }
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 } 820 }
807 821
808 void AutofillManager::OnDidFillAutofillFormData(const FormData& form, 822 void AutofillManager::OnDidFillAutofillFormData(const FormData& form,
809 const TimeTicks& timestamp) { 823 const TimeTicks& timestamp) {
810 if (test_delegate_) 824 if (test_delegate_)
811 test_delegate_->DidFillFormData(); 825 test_delegate_->DidFillFormData();
812 826
813 UpdatePendingForm(form); 827 UpdatePendingForm(form);
814 828
815 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL); 829 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL);
830 DCHECK(ukm_logger_);
831 if (ukm_logger_)
832 ukm_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL);
816 if (!user_did_autofill_) { 833 if (!user_did_autofill_) {
817 user_did_autofill_ = true; 834 user_did_autofill_ = true;
818 AutofillMetrics::LogUserHappinessMetric( 835 AutofillMetrics::LogUserHappinessMetric(
819 AutofillMetrics::USER_DID_AUTOFILL_ONCE); 836 AutofillMetrics::USER_DID_AUTOFILL_ONCE);
820 } 837 }
821 838
822 UpdateInitialInteractionTimestamp(timestamp); 839 UpdateInitialInteractionTimestamp(timestamp);
823 } 840 }
824 841
825 void AutofillManager::DidShowSuggestions(bool is_new_popup, 842 void AutofillManager::DidShowSuggestions(bool is_new_popup,
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 1098
1082 void AutofillManager::OnFullCardRequestFailed() { 1099 void AutofillManager::OnFullCardRequestFailed() {
1083 driver_->RendererShouldClearPreviewedForm(); 1100 driver_->RendererShouldClearPreviewedForm();
1084 } 1101 }
1085 1102
1086 void AutofillManager::ShowUnmaskPrompt( 1103 void AutofillManager::ShowUnmaskPrompt(
1087 const CreditCard& card, 1104 const CreditCard& card,
1088 AutofillClient::UnmaskCardReason reason, 1105 AutofillClient::UnmaskCardReason reason,
1089 base::WeakPtr<CardUnmaskDelegate> delegate) { 1106 base::WeakPtr<CardUnmaskDelegate> delegate) {
1090 client_->ShowUnmaskPrompt(card, reason, delegate); 1107 client_->ShowUnmaskPrompt(card, reason, delegate);
1108 DCHECK(ukm_logger_);
1109 if (ukm_logger_)
1110 ukm_logger_->LogUnmaskPromptEvent(AutofillMetrics::UNMASK_PROMPT_SHOWN);
1091 } 1111 }
1092 1112
1093 void AutofillManager::OnUnmaskVerificationResult( 1113 void AutofillManager::OnUnmaskVerificationResult(
1094 AutofillClient::PaymentsRpcResult result) { 1114 AutofillClient::PaymentsRpcResult result) {
1095 client_->OnUnmaskVerificationResult(result); 1115 client_->OnUnmaskVerificationResult(result);
1096 } 1116 }
1097 1117
1098 void AutofillManager::OnUserDidAcceptUpload() { 1118 void AutofillManager::OnUserDidAcceptUpload() {
1099 user_did_accept_upload_prompt_ = true; 1119 user_did_accept_upload_prompt_ = true;
1100 if (!upload_request_.risk_data.empty()) { 1120 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 1391 // 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 1392 // 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 1393 // explicitly pass in all the time stamps of interest, as the cached ones might
1374 // get reset before this method executes. 1394 // get reset before this method executes.
1375 void AutofillManager::UploadFormDataAsyncCallback( 1395 void AutofillManager::UploadFormDataAsyncCallback(
1376 const FormStructure* submitted_form, 1396 const FormStructure* submitted_form,
1377 const TimeTicks& load_time, 1397 const TimeTicks& load_time,
1378 const TimeTicks& interaction_time, 1398 const TimeTicks& interaction_time,
1379 const TimeTicks& submission_time, 1399 const TimeTicks& submission_time,
1380 bool observed_submission) { 1400 bool observed_submission) {
1381 submitted_form->LogQualityMetrics(load_time, interaction_time, 1401 AutofillMetrics::AutofillFormSubmittedState state =
1382 submission_time, 1402 submitted_form->LogQualityMetrics(
1383 client_->GetRapporServiceImpl(), 1403 load_time, interaction_time, submission_time,
1384 did_show_suggestions_, observed_submission); 1404 client_->GetRapporServiceImpl(), did_show_suggestions_,
1405 observed_submission);
1406 if (state < AutofillMetrics::AUTOFILL_FORM_SUBMITTED_STATE_ENUM_SIZE) {
1407 DCHECK(ukm_logger_);
1408 if (ukm_logger_->url() != submitted_form->source_url()) {
1409 // TODO(csashi): Remove debug log.
1410 LOG(ERROR) << "source_url=" << submitted_form->source_url()
1411 << ", url=" << ukm_logger_->url();
1412 ukm_logger_->set_url(submitted_form->source_url());
1413 }
1414 AutofillMetrics::LogAutofillFormSubmittedState(state, ukm_logger_.get());
1415 }
1385 1416
1386 if (submitted_form->ShouldBeCrowdsourced()) 1417 if (submitted_form->ShouldBeCrowdsourced())
1387 UploadFormData(*submitted_form, observed_submission); 1418 UploadFormData(*submitted_form, observed_submission);
1388 } 1419 }
1389 1420
1390 void AutofillManager::UploadFormData(const FormStructure& submitted_form, 1421 void AutofillManager::UploadFormData(const FormStructure& submitted_form,
1391 bool observed_submission) { 1422 bool observed_submission) {
1392 if (!download_manager_) 1423 if (!download_manager_)
1393 return; 1424 return;
1394 1425
(...skipping 14 matching lines...) Expand all
1409 submitted_form, was_autofilled, non_empty_types, 1440 submitted_form, was_autofilled, non_empty_types,
1410 std::string() /* login_form_signature */, observed_submission); 1441 std::string() /* login_form_signature */, observed_submission);
1411 } 1442 }
1412 1443
1413 void AutofillManager::Reset() { 1444 void AutofillManager::Reset() {
1414 // Note that upload_request_ is not reset here because the prompt to 1445 // Note that upload_request_ is not reset here because the prompt to
1415 // save a card is shown after page navigation. 1446 // save a card is shown after page navigation.
1416 ProcessPendingFormForUpload(); 1447 ProcessPendingFormForUpload();
1417 DCHECK(!pending_form_data_); 1448 DCHECK(!pending_form_data_);
1418 form_structures_.clear(); 1449 form_structures_.clear();
1419 address_form_event_logger_.reset( 1450 ukm_logger_.reset(new AutofillMetrics::UkmLogger(client_->GetUkmService()));
1420 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)); 1451 address_form_event_logger_.reset(new AutofillMetrics::FormEventLogger(
1421 credit_card_form_event_logger_.reset( 1452 false /* is_for_credit_card */, ukm_logger_.get()));
1422 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)); 1453 credit_card_form_event_logger_.reset(new AutofillMetrics::FormEventLogger(
1454 true /* is_for_credit_card */, ukm_logger_.get()));
1423 #if defined(OS_ANDROID) || defined(OS_IOS) 1455 #if defined(OS_ANDROID) || defined(OS_IOS)
1424 autofill_assistant_.Reset(); 1456 autofill_assistant_.Reset();
1425 #endif 1457 #endif
1426 has_logged_autofill_enabled_ = false; 1458 has_logged_autofill_enabled_ = false;
1427 has_logged_address_suggestions_count_ = false; 1459 has_logged_address_suggestions_count_ = false;
1428 did_show_suggestions_ = false; 1460 did_show_suggestions_ = false;
1429 user_did_type_ = false; 1461 user_did_type_ = false;
1430 user_did_autofill_ = false; 1462 user_did_autofill_ = false;
1431 user_did_edit_autofilled_field_ = false; 1463 user_did_edit_autofilled_field_ = false;
1432 masked_card_ = CreditCard(); 1464 masked_card_ = CreditCard();
1433 unmasking_query_id_ = -1; 1465 unmasking_query_id_ = -1;
1434 unmasking_form_ = FormData(); 1466 unmasking_form_ = FormData();
1435 unmasking_field_ = FormFieldData(); 1467 unmasking_field_ = FormFieldData();
1436 forms_loaded_timestamps_.clear(); 1468 forms_loaded_timestamps_.clear();
1437 initial_interaction_timestamp_ = TimeTicks(); 1469 initial_interaction_timestamp_ = TimeTicks();
1438 external_delegate_->Reset(); 1470 external_delegate_->Reset();
1439 } 1471 }
1440 1472
1441 AutofillManager::AutofillManager(AutofillDriver* driver, 1473 AutofillManager::AutofillManager(AutofillDriver* driver,
1442 AutofillClient* client, 1474 AutofillClient* client,
1443 PersonalDataManager* personal_data) 1475 PersonalDataManager* personal_data)
1444 : driver_(driver), 1476 : driver_(driver),
1445 client_(client), 1477 client_(client),
1446 payments_client_( 1478 payments_client_(base::MakeUnique<payments::PaymentsClient>(
1447 new payments::PaymentsClient(driver->GetURLRequestContext(), this)), 1479 driver->GetURLRequestContext(),
1480 this)),
1448 app_locale_("en-US"), 1481 app_locale_("en-US"),
1449 personal_data_(personal_data), 1482 personal_data_(personal_data),
1450 autocomplete_history_manager_( 1483 autocomplete_history_manager_(
1451 new AutocompleteHistoryManager(driver, client)), 1484 base::MakeUnique<AutocompleteHistoryManager>(driver, client)),
1485 ukm_logger_(base::MakeUnique<AutofillMetrics::UkmLogger>(
1486 client->GetUkmService())),
1452 address_form_event_logger_( 1487 address_form_event_logger_(
1453 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)), 1488 base::MakeUnique<AutofillMetrics::FormEventLogger>(
1489 false /* is_for_credit_card */,
1490 ukm_logger_.get())),
1454 credit_card_form_event_logger_( 1491 credit_card_form_event_logger_(
1455 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)), 1492 base::MakeUnique<AutofillMetrics::FormEventLogger>(
1493 true /* is_for_credit_card */,
1494 ukm_logger_.get())),
1456 has_logged_autofill_enabled_(false), 1495 has_logged_autofill_enabled_(false),
1457 has_logged_address_suggestions_count_(false), 1496 has_logged_address_suggestions_count_(false),
1458 did_show_suggestions_(false), 1497 did_show_suggestions_(false),
1459 user_did_type_(false), 1498 user_did_type_(false),
1460 user_did_autofill_(false), 1499 user_did_autofill_(false),
1461 user_did_edit_autofilled_field_(false), 1500 user_did_edit_autofilled_field_(false),
1462 unmasking_query_id_(-1), 1501 unmasking_query_id_(-1),
1463 external_delegate_(NULL), 1502 external_delegate_(NULL),
1464 test_delegate_(NULL), 1503 test_delegate_(NULL),
1465 #if defined(OS_ANDROID) || defined(OS_IOS) 1504 #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 1711 // Note that this may invalidate |data_model|, particularly if it is a Mac
1673 // address book entry. 1712 // address book entry.
1674 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) 1713 if (action == AutofillDriver::FORM_DATA_ACTION_FILL)
1675 personal_data_->RecordUseOf(data_model); 1714 personal_data_->RecordUseOf(data_model);
1676 1715
1677 driver_->SendFormDataToRenderer(query_id, action, result); 1716 driver_->SendFormDataToRenderer(query_id, action, result);
1678 } 1717 }
1679 1718
1680 std::unique_ptr<FormStructure> AutofillManager::ValidateSubmittedForm( 1719 std::unique_ptr<FormStructure> AutofillManager::ValidateSubmittedForm(
1681 const FormData& form) { 1720 const FormData& form) {
1682 std::unique_ptr<FormStructure> submitted_form(new FormStructure(form)); 1721 std::unique_ptr<FormStructure> submitted_form(
1722 base::MakeUnique<FormStructure>(form));
1683 if (!ShouldUploadForm(*submitted_form)) 1723 if (!ShouldUploadForm(*submitted_form))
1684 return std::unique_ptr<FormStructure>(); 1724 return std::unique_ptr<FormStructure>();
1685 1725
1686 // Ignore forms not present in our cache. These are typically forms with 1726 // Ignore forms not present in our cache. These are typically forms with
1687 // wonky JavaScript that also makes them not auto-fillable. 1727 // wonky JavaScript that also makes them not auto-fillable.
1688 FormStructure* cached_submitted_form; 1728 FormStructure* cached_submitted_form;
1689 if (!FindCachedForm(form, &cached_submitted_form)) 1729 if (!FindCachedForm(form, &cached_submitted_form))
1690 return std::unique_ptr<FormStructure>(); 1730 return std::unique_ptr<FormStructure>();
1691 1731
1692 submitted_form->UpdateFromCache(*cached_submitted_form, false); 1732 submitted_form->UpdateFromCache(*cached_submitted_form, false);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 parse_form_start_time); 1913 parse_form_start_time);
1874 } 1914 }
1875 1915
1876 if (!queryable_forms.empty() && download_manager_) { 1916 if (!queryable_forms.empty() && download_manager_) {
1877 // Query the server if at least one of the forms was parsed. 1917 // Query the server if at least one of the forms was parsed.
1878 download_manager_->StartQueryRequest(queryable_forms); 1918 download_manager_->StartQueryRequest(queryable_forms);
1879 } 1919 }
1880 1920
1881 if (!queryable_forms.empty() || !non_queryable_forms.empty()) { 1921 if (!queryable_forms.empty() || !non_queryable_forms.empty()) {
1882 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED); 1922 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED);
1923
1924 // Log pending events, if any.
1925 ukm_logger_->LogUkm();
sebsg 2017/04/07 13:17:24 DCHECK(ukm_logger_)?
csashi 2017/04/09 19:17:26 I am creating ukm_logger_ in the constructor, so I
1926
1927 // If user submits a form, we set the key to the |submitted_form|'s
1928 // |source_url()|.
1929 ukm_logger_->set_url(forms[0].origin);
1930 ukm_logger_->LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED);
1883 #if defined(OS_IOS) 1931 #if defined(OS_IOS)
1884 // Log this from same location as AutofillMetrics::FORMS_LOADED to ensure 1932 // Log this from same location as AutofillMetrics::FORMS_LOADED to ensure
1885 // that KeyboardAccessoryButtonsIOS and UserHappiness UMA metrics will be 1933 // that KeyboardAccessoryButtonsIOS and UserHappiness UMA metrics will be
1886 // directly comparable. 1934 // directly comparable.
1887 KeyboardAccessoryMetricsLogger::OnFormsLoaded(); 1935 KeyboardAccessoryMetricsLogger::OnFormsLoaded();
1888 #endif 1936 #endif
1889 } 1937 }
1890 1938
1891 #if defined(OS_ANDROID) || defined(OS_IOS) 1939 #if defined(OS_ANDROID) || defined(OS_IOS)
1892 // When a credit card form is parsed and conditions are met, show an infobar 1940 // 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 } 2246 }
2199 #endif // ENABLE_FORM_DEBUG_DUMP 2247 #endif // ENABLE_FORM_DEBUG_DUMP
2200 2248
2201 void AutofillManager::LogCardUploadDecisionUkm( 2249 void AutofillManager::LogCardUploadDecisionUkm(
2202 AutofillMetrics::CardUploadDecisionMetric upload_decision) { 2250 AutofillMetrics::CardUploadDecisionMetric upload_decision) {
2203 AutofillMetrics::LogCardUploadDecisionUkm( 2251 AutofillMetrics::LogCardUploadDecisionUkm(
2204 client_->GetUkmService(), pending_upload_request_url_, upload_decision); 2252 client_->GetUkmService(), pending_upload_request_url_, upload_decision);
2205 } 2253 }
2206 2254
2207 } // namespace autofill 2255 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698