Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 int64 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 Loading... | |
| 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 TimeTicks::FromInternalValue(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 uint64 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 | |
| 393 // timestamp. | |
| 394 base::TimeTicks interaction_time = TimeTicks::FromInternalValue(timestamp); | |
| 395 if (initial_interaction_timestamp_.is_null() || | |
| 396 interaction_time < initial_interaction_timestamp_) { | |
| 397 initial_interaction_timestamp_ = interaction_time; | |
| 398 } | |
| 386 } | 399 } |
| 387 | 400 |
| 388 void AutofillManager::OnQueryFormFieldAutofill( | 401 void AutofillManager::OnQueryFormFieldAutofill( |
| 389 int query_id, | 402 int query_id, |
| 390 const webkit_glue::FormData& form, | 403 const webkit_glue::FormData& form, |
| 391 const webkit_glue::FormField& field) { | 404 const webkit_glue::FormField& field) { |
| 392 std::vector<string16> values; | 405 std::vector<string16> values; |
| 393 std::vector<string16> labels; | 406 std::vector<string16> labels; |
| 394 std::vector<string16> icons; | 407 std::vector<string16> icons; |
| 395 std::vector<int> unique_ids; | 408 std::vector<int> unique_ids; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 } | 638 } |
| 626 | 639 |
| 627 void AutofillManager::OnDidPreviewAutofillFormData() { | 640 void AutofillManager::OnDidPreviewAutofillFormData() { |
| 628 NotificationService::current()->Notify( | 641 NotificationService::current()->Notify( |
| 629 chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA, | 642 chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA, |
| 630 Source<RenderViewHost>(tab_contents()->render_view_host()), | 643 Source<RenderViewHost>(tab_contents()->render_view_host()), |
| 631 NotificationService::NoDetails()); | 644 NotificationService::NoDetails()); |
| 632 } | 645 } |
| 633 | 646 |
| 634 | 647 |
| 635 void AutofillManager::OnDidFillAutofillFormData() { | 648 void AutofillManager::OnDidFillAutofillFormData(uint64 timestamp) { |
| 636 NotificationService::current()->Notify( | 649 NotificationService::current()->Notify( |
| 637 chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA, | 650 chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA, |
| 638 Source<RenderViewHost>(tab_contents()->render_view_host()), | 651 Source<RenderViewHost>(tab_contents()->render_view_host()), |
| 639 NotificationService::NoDetails()); | 652 NotificationService::NoDetails()); |
| 640 | 653 |
| 641 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL); | 654 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL); |
| 642 if (!user_did_autofill_) { | 655 if (!user_did_autofill_) { |
| 643 user_did_autofill_ = true; | 656 user_did_autofill_ = true; |
| 644 metric_logger_->LogUserHappinessMetric( | 657 metric_logger_->LogUserHappinessMetric( |
| 645 AutofillMetrics::USER_DID_AUTOFILL_ONCE); | 658 AutofillMetrics::USER_DID_AUTOFILL_ONCE); |
| 646 } | 659 } |
| 660 | |
| 661 // Messages might arrive out of order, so always remember the earliest | |
| 662 // timestamp. | |
| 663 base::TimeTicks interaction_time = TimeTicks::FromInternalValue(timestamp); | |
| 664 if (initial_interaction_timestamp_.is_null() || | |
| 665 interaction_time < initial_interaction_timestamp_) { | |
| 666 initial_interaction_timestamp_ = interaction_time; | |
| 667 } | |
| 647 } | 668 } |
| 648 | 669 |
| 649 void AutofillManager::OnDidShowAutofillSuggestions(bool is_new_popup) { | 670 void AutofillManager::OnDidShowAutofillSuggestions(bool is_new_popup) { |
| 650 NotificationService::current()->Notify( | 671 NotificationService::current()->Notify( |
| 651 chrome::NOTIFICATION_AUTOFILL_DID_SHOW_SUGGESTIONS, | 672 chrome::NOTIFICATION_AUTOFILL_DID_SHOW_SUGGESTIONS, |
| 652 Source<RenderViewHost>(tab_contents()->render_view_host()), | 673 Source<RenderViewHost>(tab_contents()->render_view_host()), |
| 653 NotificationService::NoDetails()); | 674 NotificationService::NoDetails()); |
| 654 | 675 |
| 655 if (is_new_popup) { | 676 if (is_new_popup) { |
| 656 metric_logger_->LogUserHappinessMetric(AutofillMetrics::SUGGESTIONS_SHOWN); | 677 metric_logger_->LogUserHappinessMetric(AutofillMetrics::SUGGESTIONS_SHOWN); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 } | 788 } |
| 768 | 789 |
| 769 void AutofillManager::Reset() { | 790 void AutofillManager::Reset() { |
| 770 form_structures_.reset(); | 791 form_structures_.reset(); |
| 771 has_logged_autofill_enabled_ = false; | 792 has_logged_autofill_enabled_ = false; |
| 772 has_logged_address_suggestions_count_ = false; | 793 has_logged_address_suggestions_count_ = false; |
| 773 did_show_suggestions_ = false; | 794 did_show_suggestions_ = false; |
| 774 user_did_type_ = false; | 795 user_did_type_ = false; |
| 775 user_did_autofill_ = false; | 796 user_did_autofill_ = false; |
| 776 user_did_edit_autofilled_field_ = false; | 797 user_did_edit_autofilled_field_ = false; |
| 798 initial_interaction_timestamp_ = TimeTicks::FromInternalValue(0); | |
|
jar (doing other things)
2011/08/31 17:02:21
This seems strange that you are supplying a specif
Ilya Sherman
2011/08/31 21:56:23
Done.
| |
| 777 } | 799 } |
| 778 | 800 |
| 779 AutofillManager::AutofillManager(TabContentsWrapper* tab_contents, | 801 AutofillManager::AutofillManager(TabContentsWrapper* tab_contents, |
| 780 PersonalDataManager* personal_data) | 802 PersonalDataManager* personal_data) |
| 781 : TabContentsObserver(tab_contents->tab_contents()), | 803 : TabContentsObserver(tab_contents->tab_contents()), |
| 782 tab_contents_wrapper_(tab_contents), | 804 tab_contents_wrapper_(tab_contents), |
| 783 personal_data_(personal_data), | 805 personal_data_(personal_data), |
| 784 download_manager_(NULL), | 806 download_manager_(NULL), |
| 785 disable_download_manager_requests_(true), | 807 disable_download_manager_requests_(true), |
| 786 metric_logger_(new AutofillMetrics), | 808 metric_logger_(new AutofillMetrics), |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1143 void AutofillManager::UnpackGUIDs(int id, | 1165 void AutofillManager::UnpackGUIDs(int id, |
| 1144 GUIDPair* cc_guid, | 1166 GUIDPair* cc_guid, |
| 1145 GUIDPair* profile_guid) { | 1167 GUIDPair* profile_guid) { |
| 1146 int cc_id = id >> std::numeric_limits<unsigned short>::digits & | 1168 int cc_id = id >> std::numeric_limits<unsigned short>::digits & |
| 1147 std::numeric_limits<unsigned short>::max(); | 1169 std::numeric_limits<unsigned short>::max(); |
| 1148 int profile_id = id & std::numeric_limits<unsigned short>::max(); | 1170 int profile_id = id & std::numeric_limits<unsigned short>::max(); |
| 1149 | 1171 |
| 1150 *cc_guid = IDToGUID(cc_id); | 1172 *cc_guid = IDToGUID(cc_id); |
| 1151 *profile_guid = IDToGUID(profile_id); | 1173 *profile_guid = IDToGUID(profile_id); |
| 1152 } | 1174 } |
| OLD | NEW |