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

Side by Side Diff: chrome/browser/autofill/autofill_manager.cc

Issue 7740070: Add metrics to measure time elapsed between form load and form submission with or without Autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Serialize in all the right places Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/autofill/autofill_manager.h" 5 #include "chrome/browser/autofill/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "content/common/notification_service.h" 44 #include "content/common/notification_service.h"
45 #include "content/common/notification_source.h" 45 #include "content/common/notification_source.h"
46 #include "googleurl/src/gurl.h" 46 #include "googleurl/src/gurl.h"
47 #include "grit/generated_resources.h" 47 #include "grit/generated_resources.h"
48 #include "ipc/ipc_message_macros.h" 48 #include "ipc/ipc_message_macros.h"
49 #include "ui/base/l10n/l10n_util.h" 49 #include "ui/base/l10n/l10n_util.h"
50 #include "webkit/glue/form_data.h" 50 #include "webkit/glue/form_data.h"
51 #include "webkit/glue/form_data_predictions.h" 51 #include "webkit/glue/form_data_predictions.h"
52 #include "webkit/glue/form_field.h" 52 #include "webkit/glue/form_field.h"
53 53
54 using base::TimeTicks;
54 using switches::kEnableAutofillFeedback; 55 using switches::kEnableAutofillFeedback;
55 using webkit_glue::FormData; 56 using webkit_glue::FormData;
56 using webkit_glue::FormDataPredictions; 57 using webkit_glue::FormDataPredictions;
57 using webkit_glue::FormField; 58 using webkit_glue::FormField;
58 59
59 namespace { 60 namespace {
60 61
61 // We only send a fraction of the forms to upload server. 62 // We only send a fraction of the forms to upload server.
62 // The rate for positive/negative matches potentially could be different. 63 // The rate for positive/negative matches potentially could be different.
63 const double kAutofillPositiveUploadRateDefaultValue = 0.20; 64 const double kAutofillPositiveUploadRateDefaultValue = 0.20;
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidFillAutofillFormData, 296 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidFillAutofillFormData,
296 OnDidFillAutofillFormData) 297 OnDidFillAutofillFormData)
297 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidShowAutofillSuggestions, 298 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidShowAutofillSuggestions,
298 OnDidShowAutofillSuggestions) 299 OnDidShowAutofillSuggestions)
299 IPC_MESSAGE_UNHANDLED(handled = false) 300 IPC_MESSAGE_UNHANDLED(handled = false)
300 IPC_END_MESSAGE_MAP() 301 IPC_END_MESSAGE_MAP()
301 302
302 return handled; 303 return handled;
303 } 304 }
304 305
305 void AutofillManager::OnFormSubmitted(const FormData& form) { 306 void AutofillManager::OnFormSubmitted(const FormData& form,
307 const TimeTicks& timestamp) {
306 // Let AutoComplete know as well. 308 // Let AutoComplete know as well.
307 tab_contents_wrapper_->autocomplete_history_manager()->OnFormSubmitted(form); 309 tab_contents_wrapper_->autocomplete_history_manager()->OnFormSubmitted(form);
308 310
309 if (!IsAutofillEnabled()) 311 if (!IsAutofillEnabled())
310 return; 312 return;
311 313
312 if (tab_contents()->browser_context()->IsOffTheRecord()) 314 if (tab_contents()->browser_context()->IsOffTheRecord())
313 return; 315 return;
314 316
315 // Don't save data that was submitted through JavaScript. 317 // Don't save data that was submitted through JavaScript.
(...skipping 12 matching lines...) Expand all
328 FormStructure* cached_submitted_form; 330 FormStructure* cached_submitted_form;
329 if (!FindCachedForm(form, &cached_submitted_form)) 331 if (!FindCachedForm(form, &cached_submitted_form))
330 return; 332 return;
331 submitted_form.UpdateFromCache(*cached_submitted_form); 333 submitted_form.UpdateFromCache(*cached_submitted_form);
332 334
333 // Only upload server statistics and UMA metrics if at least some local data 335 // Only upload server statistics and UMA metrics if at least some local data
334 // is available to use as a baseline. 336 // is available to use as a baseline.
335 if (!personal_data_->profiles().empty() || 337 if (!personal_data_->profiles().empty() ||
336 !personal_data_->credit_cards().empty()) { 338 !personal_data_->credit_cards().empty()) {
337 DeterminePossibleFieldTypesForUpload(&submitted_form); 339 DeterminePossibleFieldTypesForUpload(&submitted_form);
338 submitted_form.LogQualityMetrics(*metric_logger_); 340 submitted_form.LogQualityMetrics(*metric_logger_,
341 initial_interaction_timestamp_,
342 timestamp);
339 343
340 if (submitted_form.ShouldBeCrowdsourced()) 344 if (submitted_form.ShouldBeCrowdsourced())
341 UploadFormData(submitted_form); 345 UploadFormData(submitted_form);
342 } 346 }
343 347
344 if (!submitted_form.IsAutofillable(true)) 348 if (!submitted_form.IsAutofillable(true))
345 return; 349 return;
346 350
347 ImportFormData(submitted_form); 351 ImportFormData(submitted_form);
348 } 352 }
349 353
350 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms) { 354 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms) {
351 bool enabled = IsAutofillEnabled(); 355 bool enabled = IsAutofillEnabled();
352 if (!has_logged_autofill_enabled_) { 356 if (!has_logged_autofill_enabled_) {
353 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled); 357 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled);
354 has_logged_autofill_enabled_ = true; 358 has_logged_autofill_enabled_ = true;
355 } 359 }
356 360
357 if (!enabled) 361 if (!enabled)
358 return; 362 return;
359 363
360 ParseForms(forms); 364 ParseForms(forms);
361 } 365 }
362 366
363 void AutofillManager::OnTextFieldDidChange(const FormData& form, 367 void AutofillManager::OnTextFieldDidChange(const FormData& form,
364 const FormField& field) { 368 const FormField& field,
369 const TimeTicks& timestamp) {
365 FormStructure* form_structure = NULL; 370 FormStructure* form_structure = NULL;
366 AutofillField* autofill_field = NULL; 371 AutofillField* autofill_field = NULL;
367 if (!FindCachedFormAndField(form, field, &form_structure, &autofill_field)) 372 if (!FindCachedFormAndField(form, field, &form_structure, &autofill_field))
368 return; 373 return;
369 374
370 if (!user_did_type_) { 375 if (!user_did_type_) {
371 user_did_type_ = true; 376 user_did_type_ = true;
372 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE); 377 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE);
373 } 378 }
374 379
375 if (autofill_field->is_autofilled) { 380 if (autofill_field->is_autofilled) {
376 autofill_field->is_autofilled = false; 381 autofill_field->is_autofilled = false;
377 metric_logger_->LogUserHappinessMetric( 382 metric_logger_->LogUserHappinessMetric(
378 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD); 383 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD);
379 384
380 if (!user_did_edit_autofilled_field_) { 385 if (!user_did_edit_autofilled_field_) {
381 user_did_edit_autofilled_field_ = true; 386 user_did_edit_autofilled_field_ = true;
382 metric_logger_->LogUserHappinessMetric( 387 metric_logger_->LogUserHappinessMetric(
383 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE); 388 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE);
384 } 389 }
385 } 390 }
391
392 // Messages might arrive out of order, so always remember the earliest
dhollowa 2011/08/31 22:40:52 This code repeats below. Pull out into utility fu
Ilya Sherman 2011/08/31 23:21:32 Done.
393 // timestamp.
394 if (initial_interaction_timestamp_.is_null() ||
395 timestamp < initial_interaction_timestamp_) {
396 initial_interaction_timestamp_ = timestamp;
397 }
386 } 398 }
387 399
388 void AutofillManager::OnQueryFormFieldAutofill( 400 void AutofillManager::OnQueryFormFieldAutofill(
389 int query_id, 401 int query_id,
390 const webkit_glue::FormData& form, 402 const webkit_glue::FormData& form,
391 const webkit_glue::FormField& field) { 403 const webkit_glue::FormField& field) {
392 std::vector<string16> values; 404 std::vector<string16> values;
393 std::vector<string16> labels; 405 std::vector<string16> labels;
394 std::vector<string16> icons; 406 std::vector<string16> icons;
395 std::vector<int> unique_ids; 407 std::vector<int> unique_ids;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 } 637 }
626 638
627 void AutofillManager::OnDidPreviewAutofillFormData() { 639 void AutofillManager::OnDidPreviewAutofillFormData() {
628 NotificationService::current()->Notify( 640 NotificationService::current()->Notify(
629 chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA, 641 chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA,
630 Source<RenderViewHost>(tab_contents()->render_view_host()), 642 Source<RenderViewHost>(tab_contents()->render_view_host()),
631 NotificationService::NoDetails()); 643 NotificationService::NoDetails());
632 } 644 }
633 645
634 646
635 void AutofillManager::OnDidFillAutofillFormData() { 647 void AutofillManager::OnDidFillAutofillFormData(const TimeTicks& timestamp) {
636 NotificationService::current()->Notify( 648 NotificationService::current()->Notify(
637 chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA, 649 chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA,
638 Source<RenderViewHost>(tab_contents()->render_view_host()), 650 Source<RenderViewHost>(tab_contents()->render_view_host()),
639 NotificationService::NoDetails()); 651 NotificationService::NoDetails());
640 652
641 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL); 653 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL);
642 if (!user_did_autofill_) { 654 if (!user_did_autofill_) {
643 user_did_autofill_ = true; 655 user_did_autofill_ = true;
644 metric_logger_->LogUserHappinessMetric( 656 metric_logger_->LogUserHappinessMetric(
645 AutofillMetrics::USER_DID_AUTOFILL_ONCE); 657 AutofillMetrics::USER_DID_AUTOFILL_ONCE);
646 } 658 }
659
660 // Messages might arrive out of order, so always remember the earliest
661 // timestamp.
662 if (initial_interaction_timestamp_.is_null() ||
663 timestamp < initial_interaction_timestamp_) {
664 initial_interaction_timestamp_ = timestamp;
665 }
647 } 666 }
648 667
649 void AutofillManager::OnDidShowAutofillSuggestions(bool is_new_popup) { 668 void AutofillManager::OnDidShowAutofillSuggestions(bool is_new_popup) {
650 NotificationService::current()->Notify( 669 NotificationService::current()->Notify(
651 chrome::NOTIFICATION_AUTOFILL_DID_SHOW_SUGGESTIONS, 670 chrome::NOTIFICATION_AUTOFILL_DID_SHOW_SUGGESTIONS,
652 Source<RenderViewHost>(tab_contents()->render_view_host()), 671 Source<RenderViewHost>(tab_contents()->render_view_host()),
653 NotificationService::NoDetails()); 672 NotificationService::NoDetails());
654 673
655 if (is_new_popup) { 674 if (is_new_popup) {
656 metric_logger_->LogUserHappinessMetric(AutofillMetrics::SUGGESTIONS_SHOWN); 675 metric_logger_->LogUserHappinessMetric(AutofillMetrics::SUGGESTIONS_SHOWN);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 } 786 }
768 787
769 void AutofillManager::Reset() { 788 void AutofillManager::Reset() {
770 form_structures_.reset(); 789 form_structures_.reset();
771 has_logged_autofill_enabled_ = false; 790 has_logged_autofill_enabled_ = false;
772 has_logged_address_suggestions_count_ = false; 791 has_logged_address_suggestions_count_ = false;
773 did_show_suggestions_ = false; 792 did_show_suggestions_ = false;
774 user_did_type_ = false; 793 user_did_type_ = false;
775 user_did_autofill_ = false; 794 user_did_autofill_ = false;
776 user_did_edit_autofilled_field_ = false; 795 user_did_edit_autofilled_field_ = false;
796 initial_interaction_timestamp_ = TimeTicks();
777 } 797 }
778 798
779 AutofillManager::AutofillManager(TabContentsWrapper* tab_contents, 799 AutofillManager::AutofillManager(TabContentsWrapper* tab_contents,
780 PersonalDataManager* personal_data) 800 PersonalDataManager* personal_data)
781 : TabContentsObserver(tab_contents->tab_contents()), 801 : TabContentsObserver(tab_contents->tab_contents()),
782 tab_contents_wrapper_(tab_contents), 802 tab_contents_wrapper_(tab_contents),
783 personal_data_(personal_data), 803 personal_data_(personal_data),
784 download_manager_(NULL), 804 download_manager_(NULL),
785 disable_download_manager_requests_(true), 805 disable_download_manager_requests_(true),
786 metric_logger_(new AutofillMetrics), 806 metric_logger_(new AutofillMetrics),
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 void AutofillManager::UnpackGUIDs(int id, 1163 void AutofillManager::UnpackGUIDs(int id,
1144 GUIDPair* cc_guid, 1164 GUIDPair* cc_guid,
1145 GUIDPair* profile_guid) { 1165 GUIDPair* profile_guid) {
1146 int cc_id = id >> std::numeric_limits<unsigned short>::digits & 1166 int cc_id = id >> std::numeric_limits<unsigned short>::digits &
1147 std::numeric_limits<unsigned short>::max(); 1167 std::numeric_limits<unsigned short>::max();
1148 int profile_id = id & std::numeric_limits<unsigned short>::max(); 1168 int profile_id = id & std::numeric_limits<unsigned short>::max();
1149 1169
1150 *cc_guid = IDToGUID(cc_id); 1170 *cc_guid = IDToGUID(cc_id);
1151 *profile_guid = IDToGUID(profile_id); 1171 *profile_guid = IDToGUID(profile_id);
1152 } 1172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698