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

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

Issue 14096009: [Autofill] Split off AutofillDataModel as a subclass of FormData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Android compile Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/autofill_manager.h" 5 #include "components/autofill/browser/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>
11 #include <set> 11 #include <set>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/guid.h" 16 #include "base/guid.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/prefs/pref_service.h" 18 #include "base/prefs/pref_service.h"
19 #include "base/string16.h" 19 #include "base/string16.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/threading/sequenced_worker_pool.h" 21 #include "base/threading/sequenced_worker_pool.h"
22 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
23 #include "components/autofill/browser/autocheckout/whitelist_manager.h" 23 #include "components/autofill/browser/autocheckout/whitelist_manager.h"
24 #include "components/autofill/browser/autocheckout_manager.h" 24 #include "components/autofill/browser/autocheckout_manager.h"
25 #include "components/autofill/browser/autocomplete_history_manager.h" 25 #include "components/autofill/browser/autocomplete_history_manager.h"
26 #include "components/autofill/browser/autofill_data_model.h"
26 #include "components/autofill/browser/autofill_external_delegate.h" 27 #include "components/autofill/browser/autofill_external_delegate.h"
27 #include "components/autofill/browser/autofill_field.h" 28 #include "components/autofill/browser/autofill_field.h"
28 #include "components/autofill/browser/autofill_manager_delegate.h" 29 #include "components/autofill/browser/autofill_manager_delegate.h"
29 #include "components/autofill/browser/autofill_manager_test_delegate.h" 30 #include "components/autofill/browser/autofill_manager_test_delegate.h"
30 #include "components/autofill/browser/autofill_metrics.h" 31 #include "components/autofill/browser/autofill_metrics.h"
31 #include "components/autofill/browser/autofill_profile.h" 32 #include "components/autofill/browser/autofill_profile.h"
32 #include "components/autofill/browser/autofill_type.h" 33 #include "components/autofill/browser/autofill_type.h"
33 #include "components/autofill/browser/credit_card.h" 34 #include "components/autofill/browser/credit_card.h"
34 #include "components/autofill/browser/form_structure.h" 35 #include "components/autofill/browser/form_structure.h"
35 #include "components/autofill/browser/password_generator.h" 36 #include "components/autofill/browser/password_generator.h"
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 // renderer. 606 // renderer.
606 autocomplete_history_manager_.OnGetAutocompleteSuggestions( 607 autocomplete_history_manager_.OnGetAutocompleteSuggestions(
607 query_id, field.name, field.value, values, labels, icons, unique_ids); 608 query_id, field.name, field.value, values, labels, icons, unique_ids);
608 } 609 }
609 610
610 void AutofillManager::OnFillAutofillFormData(int query_id, 611 void AutofillManager::OnFillAutofillFormData(int query_id,
611 const FormData& form, 612 const FormData& form,
612 const FormFieldData& field, 613 const FormFieldData& field,
613 int unique_id) { 614 int unique_id) {
614 RenderViewHost* host = NULL; 615 RenderViewHost* host = NULL;
615 const FormGroup* form_group = NULL; 616 const AutofillDataModel* data_model = NULL;
616 size_t variant = 0; 617 size_t variant = 0;
617 FormStructure* form_structure = NULL; 618 FormStructure* form_structure = NULL;
618 AutofillField* autofill_field = NULL; 619 AutofillField* autofill_field = NULL;
619 // NOTE: GetHost may invalidate |form_group| because it causes the 620 // NOTE: GetHost may invalidate |data_model| because it causes the
620 // PersonalDataManager to reload Mac address book entries. Thus it must 621 // PersonalDataManager to reload Mac address book entries. Thus it must
621 // come before GetProfileOrCreditCard. 622 // come before GetProfileOrCreditCard.
622 if (!GetHost(&host) || 623 if (!GetHost(&host) ||
623 !GetProfileOrCreditCard(unique_id, &form_group, &variant) || 624 !GetProfileOrCreditCard(unique_id, &data_model, &variant) ||
624 !GetCachedFormAndField(form, field, &form_structure, &autofill_field)) 625 !GetCachedFormAndField(form, field, &form_structure, &autofill_field))
625 return; 626 return;
626 627
627 DCHECK(host); 628 DCHECK(host);
628 DCHECK(form_structure); 629 DCHECK(form_structure);
629 DCHECK(autofill_field); 630 DCHECK(autofill_field);
630 631
631 FormData result = form; 632 FormData result = form;
632 633
633 // If the relevant section is auto-filled, we should fill |field| but not the 634 // If the relevant section is auto-filled, we should fill |field| but not the
634 // rest of the form. 635 // rest of the form.
635 if (SectionIsAutofilled(*form_structure, form, autofill_field->section())) { 636 if (SectionIsAutofilled(*form_structure, form, autofill_field->section())) {
636 for (std::vector<FormFieldData>::iterator iter = result.fields.begin(); 637 for (std::vector<FormFieldData>::iterator iter = result.fields.begin();
637 iter != result.fields.end(); ++iter) { 638 iter != result.fields.end(); ++iter) {
638 if ((*iter) == field) { 639 if ((*iter) == field) {
639 form_group->FillFormField( 640 data_model->FillFormField(
640 *autofill_field, variant, app_locale_, &(*iter)); 641 *autofill_field, variant, app_locale_, &(*iter));
641 // Mark the cached field as autofilled, so that we can detect when a 642 // Mark the cached field as autofilled, so that we can detect when a
642 // user edits an autofilled field (for metrics). 643 // user edits an autofilled field (for metrics).
643 autofill_field->is_autofilled = true; 644 autofill_field->is_autofilled = true;
644 break; 645 break;
645 } 646 }
646 } 647 }
647 648
648 host->Send(new AutofillMsg_FormDataFilled(host->GetRoutingID(), query_id, 649 host->Send(new AutofillMsg_FormDataFilled(host->GetRoutingID(), query_id,
649 result)); 650 result));
(...skipping 17 matching lines...) Expand all
667 // If the field being filled is either 668 // If the field being filled is either
668 // (a) the field that the user initiated the fill from, or 669 // (a) the field that the user initiated the fill from, or
669 // (b) part of the same logical unit, e.g. name or phone number, 670 // (b) part of the same logical unit, e.g. name or phone number,
670 // then take the multi-profile "variant" into account. 671 // then take the multi-profile "variant" into account.
671 // Otherwise fill with the default (zeroth) variant. 672 // Otherwise fill with the default (zeroth) variant.
672 size_t use_variant = 0; 673 size_t use_variant = 0;
673 if (result.fields[i] == field || 674 if (result.fields[i] == field ||
674 field_group_type == initiating_group_type) { 675 field_group_type == initiating_group_type) {
675 use_variant = variant; 676 use_variant = variant;
676 } 677 }
677 form_group->FillFormField(*cached_field, 678 data_model->FillFormField(*cached_field,
678 use_variant, 679 use_variant,
679 app_locale_, 680 app_locale_,
680 &result.fields[i]); 681 &result.fields[i]);
681 // Mark the cached field as autofilled, so that we can detect when a user 682 // Mark the cached field as autofilled, so that we can detect when a user
682 // edits an autofilled field (for metrics). 683 // edits an autofilled field (for metrics).
683 form_structure->field(i)->is_autofilled = true; 684 form_structure->field(i)->is_autofilled = true;
684 } 685 }
685 } 686 }
686 687
687 autofilled_form_signatures_.push_front(form_structure->FormSignature()); 688 autofilled_form_signatures_.push_front(form_structure->FormSignature());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 void AutofillManager::OnShowPasswordGenerationPopup( 742 void AutofillManager::OnShowPasswordGenerationPopup(
742 const gfx::Rect& bounds, 743 const gfx::Rect& bounds,
743 int max_length, 744 int max_length,
744 const content::PasswordForm& form) { 745 const content::PasswordForm& form) {
745 password_generator_.reset(new autofill::PasswordGenerator(max_length)); 746 password_generator_.reset(new autofill::PasswordGenerator(max_length));
746 manager_delegate_->ShowPasswordGenerationBubble( 747 manager_delegate_->ShowPasswordGenerationBubble(
747 bounds, form, password_generator_.get()); 748 bounds, form, password_generator_.get());
748 } 749 }
749 750
750 void AutofillManager::RemoveAutofillProfileOrCreditCard(int unique_id) { 751 void AutofillManager::RemoveAutofillProfileOrCreditCard(int unique_id) {
751 const FormGroup* form_group = NULL; 752 const AutofillDataModel* data_model = NULL;
752 size_t variant = 0; 753 size_t variant = 0;
753 if (!GetProfileOrCreditCard(unique_id, &form_group, &variant)) { 754 if (!GetProfileOrCreditCard(unique_id, &data_model, &variant)) {
754 NOTREACHED(); 755 NOTREACHED();
755 return; 756 return;
756 } 757 }
757 758
758 // TODO(csharp): If we are dealing with a variant only the variant should 759 // TODO(csharp): If we are dealing with a variant only the variant should
759 // be deleted, instead of doing nothing. 760 // be deleted, instead of doing nothing.
760 // http://crbug.com/124211 761 // http://crbug.com/124211
761 if (variant != 0) 762 if (variant != 0)
762 return; 763 return;
763 764
764 personal_data_->RemoveByGUID(form_group->GetGUID()); 765 personal_data_->RemoveByGUID(data_model->guid());
765 } 766 }
766 767
767 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name, 768 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name,
768 const base::string16& value) { 769 const base::string16& value) {
769 autocomplete_history_manager_.OnRemoveAutocompleteEntry(name, value); 770 autocomplete_history_manager_.OnRemoveAutocompleteEntry(name, value);
770 } 771 }
771 772
772 content::WebContents* AutofillManager::GetWebContents() const { 773 content::WebContents* AutofillManager::GetWebContents() const {
773 return web_contents(); 774 return web_contents();
774 } 775 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 1054
1054 *host = web_contents()->GetRenderViewHost(); 1055 *host = web_contents()->GetRenderViewHost();
1055 if (!*host) 1056 if (!*host)
1056 return false; 1057 return false;
1057 1058
1058 return true; 1059 return true;
1059 } 1060 }
1060 1061
1061 bool AutofillManager::GetProfileOrCreditCard( 1062 bool AutofillManager::GetProfileOrCreditCard(
1062 int unique_id, 1063 int unique_id,
1063 const FormGroup** form_group, 1064 const AutofillDataModel** data_model,
1064 size_t* variant) const { 1065 size_t* variant) const {
1065 // Unpack the |unique_id| into component parts. 1066 // Unpack the |unique_id| into component parts.
1066 GUIDPair credit_card_guid; 1067 GUIDPair credit_card_guid;
1067 GUIDPair profile_guid; 1068 GUIDPair profile_guid;
1068 UnpackGUIDs(unique_id, &credit_card_guid, &profile_guid); 1069 UnpackGUIDs(unique_id, &credit_card_guid, &profile_guid);
1069 DCHECK(!base::IsValidGUID(credit_card_guid.first) || 1070 DCHECK(!base::IsValidGUID(credit_card_guid.first) ||
1070 !base::IsValidGUID(profile_guid.first)); 1071 !base::IsValidGUID(profile_guid.first));
1071 1072
1072 // Find the profile that matches the |profile_guid|, if one is specified. 1073 // Find the profile that matches the |profile_guid|, if one is specified.
1073 // Otherwise find the credit card that matches the |credit_card_guid|, 1074 // Otherwise find the credit card that matches the |credit_card_guid|,
1074 // if specified. 1075 // if specified.
1075 if (base::IsValidGUID(profile_guid.first)) { 1076 if (base::IsValidGUID(profile_guid.first)) {
1076 *form_group = personal_data_->GetProfileByGUID(profile_guid.first); 1077 *data_model = personal_data_->GetProfileByGUID(profile_guid.first);
1077 *variant = profile_guid.second; 1078 *variant = profile_guid.second;
1078 } else if (base::IsValidGUID(credit_card_guid.first)) { 1079 } else if (base::IsValidGUID(credit_card_guid.first)) {
1079 *form_group = 1080 *data_model = personal_data_->GetCreditCardByGUID(credit_card_guid.first);
1080 personal_data_->GetCreditCardByGUID(credit_card_guid.first);
1081 *variant = credit_card_guid.second; 1081 *variant = credit_card_guid.second;
1082 } 1082 }
1083 1083
1084 return !!*form_group; 1084 return !!*data_model;
1085 } 1085 }
1086 1086
1087 bool AutofillManager::FindCachedForm(const FormData& form, 1087 bool AutofillManager::FindCachedForm(const FormData& form,
1088 FormStructure** form_structure) const { 1088 FormStructure** form_structure) const {
1089 // Find the FormStructure that corresponds to |form|. 1089 // Find the FormStructure that corresponds to |form|.
1090 // Scan backward through the cached |form_structures_|, as updated versions of 1090 // Scan backward through the cached |form_structures_|, as updated versions of
1091 // forms are added to the back of the list, whereas original versions of these 1091 // forms are added to the back of the list, whereas original versions of these
1092 // forms might appear toward the beginning of the list. The communication 1092 // forms might appear toward the beginning of the list. The communication
1093 // protocol with the crowdsourcing server does not permit us to discard the 1093 // protocol with the crowdsourcing server does not permit us to discard the
1094 // original versions of the forms. 1094 // original versions of the forms.
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 1349
1350 void AutofillManager::UpdateInitialInteractionTimestamp( 1350 void AutofillManager::UpdateInitialInteractionTimestamp(
1351 const TimeTicks& interaction_timestamp) { 1351 const TimeTicks& interaction_timestamp) {
1352 if (initial_interaction_timestamp_.is_null() || 1352 if (initial_interaction_timestamp_.is_null() ||
1353 interaction_timestamp < initial_interaction_timestamp_) { 1353 interaction_timestamp < initial_interaction_timestamp_) {
1354 initial_interaction_timestamp_ = interaction_timestamp; 1354 initial_interaction_timestamp_ = interaction_timestamp;
1355 } 1355 }
1356 } 1356 }
1357 1357
1358 } // namespace autofill 1358 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/autofill_manager.h ('k') | components/autofill/browser/autofill_profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698