diff options
author | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-08 13:43:51 +0000 |
---|---|---|
committer | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-08 13:43:51 +0000 |
commit | a39aa53a7acabb03a86a5be5c663d6ae47215440 (patch) | |
tree | e304aa2f39c6103bf75d151c41730f43d9111b1a /chrome/browser/autocomplete_history_manager.cc | |
parent | a5e04eafb781ce5739ab08398bc7ded7ed512116 (diff) | |
download | chromium_src-a39aa53a7acabb03a86a5be5c663d6ae47215440.zip chromium_src-a39aa53a7acabb03a86a5be5c663d6ae47215440.tar.gz chromium_src-a39aa53a7acabb03a86a5be5c663d6ae47215440.tar.bz2 |
Backing this out to see if it fixes the failures on the two windows bots (landed about when they started).
Revert 49030 - AutoFill: Don't save credit card numbers from Autocomplete to the WebDB.
BUG=8026
TEST=AutocompleteHistoryManagerTest
Review URL: http://codereview.chromium.org/2676003
TBR=jhawkins@chromium.org
Review URL: http://codereview.chromium.org/2748002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49164 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete_history_manager.cc')
-rw-r--r-- | chrome/browser/autocomplete_history_manager.cc | 95 |
1 files changed, 45 insertions, 50 deletions
diff --git a/chrome/browser/autocomplete_history_manager.cc b/chrome/browser/autocomplete_history_manager.cc index d94f920..e5d96a7 100644 --- a/chrome/browser/autocomplete_history_manager.cc +++ b/chrome/browser/autocomplete_history_manager.cc @@ -6,9 +6,7 @@ #include <vector> -#include "base/string16.h" #include "base/string_util.h" -#include "chrome/browser/autofill/credit_card.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" @@ -18,56 +16,75 @@ using webkit_glue::FormData; -namespace { - // Limit on the number of suggestions to appear in the pop-up menu under an // text input element in a form. -const int kMaxAutocompleteMenuItems = 6; - -// The separator characters for credit card values. -const string16 kCreditCardSeparators = ASCIIToUTF16(" -"); - -} // namespace +static const int kMaxAutofillMenuItems = 6; AutocompleteHistoryManager::AutocompleteHistoryManager( TabContents* tab_contents) : tab_contents_(tab_contents), pending_query_handle_(0), query_id_(0) { - DCHECK(tab_contents); - - profile_ = tab_contents_->profile(); - DCHECK(profile_); - - web_data_service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); - DCHECK(web_data_service_); - - autofill_enabled_.Init(prefs::kAutoFillEnabled, profile_->GetPrefs(), NULL); + form_autofill_enabled_.Init(prefs::kAutoFillEnabled, + profile()->GetPrefs(), NULL); } AutocompleteHistoryManager::~AutocompleteHistoryManager() { CancelPendingQuery(); } +void AutocompleteHistoryManager::CancelPendingQuery() { + if (pending_query_handle_) { + SendSuggestions(NULL); + WebDataService* web_data_service = + profile()->GetWebDataService(Profile::EXPLICIT_ACCESS); + if (!web_data_service) { + NOTREACHED(); + return; + } + web_data_service->CancelRequest(pending_query_handle_); + } + pending_query_handle_ = 0; +} + +Profile* AutocompleteHistoryManager::profile() { + return tab_contents_->profile(); +} + void AutocompleteHistoryManager::FormSubmitted(const FormData& form) { StoreFormEntriesInWebDatabase(form); } bool AutocompleteHistoryManager::GetAutocompleteSuggestions( int query_id, const string16& name, const string16& prefix) { - if (!*autofill_enabled_) + if (!*form_autofill_enabled_) return false; + WebDataService* web_data_service = + profile()->GetWebDataService(Profile::EXPLICIT_ACCESS); + if (!web_data_service) { + NOTREACHED(); + return false; + } + CancelPendingQuery(); query_id_ = query_id; - pending_query_handle_ = web_data_service_->GetFormValuesForElementName( - name, prefix, kMaxAutocompleteMenuItems, this); + + pending_query_handle_ = web_data_service->GetFormValuesForElementName( + name, prefix, kMaxAutofillMenuItems, this); return true; } void AutocompleteHistoryManager::RemoveAutocompleteEntry( const string16& name, const string16& value) { - web_data_service_->RemoveFormValueForElementName(name, value); + WebDataService* web_data_service = + profile()->GetWebDataService(Profile::EXPLICIT_ACCESS); + if (!web_data_service) { + NOTREACHED(); + return; + } + + web_data_service->RemoveFormValueForElementName(name, value); } void AutocompleteHistoryManager::OnWebDataServiceRequestDone( @@ -76,7 +93,7 @@ void AutocompleteHistoryManager::OnWebDataServiceRequestDone( DCHECK(pending_query_handle_); pending_query_handle_ = 0; - if (*autofill_enabled_) { + if (*form_autofill_enabled_) { DCHECK(result); SendSuggestions(result); } else { @@ -84,57 +101,35 @@ void AutocompleteHistoryManager::OnWebDataServiceRequestDone( } } -AutocompleteHistoryManager::AutocompleteHistoryManager( - Profile* profile, WebDataService* wds) : tab_contents_(NULL), - profile_(profile), - web_data_service_(wds), - pending_query_handle_(0), - query_id_(0) { - autofill_enabled_.Init( - prefs::kAutoFillEnabled, profile_->GetPrefs(), NULL); -} - -void AutocompleteHistoryManager::CancelPendingQuery() { - if (pending_query_handle_) { - SendSuggestions(NULL); - web_data_service_->CancelRequest(pending_query_handle_); - } - pending_query_handle_ = 0; -} - void AutocompleteHistoryManager::StoreFormEntriesInWebDatabase( const FormData& form) { - if (!*autofill_enabled_) + if (!*form_autofill_enabled_) return; - if (profile_->IsOffTheRecord()) + if (profile()->IsOffTheRecord()) return; // We put the following restriction on stored FormFields: // - non-empty name // - non-empty value // - text field - // - value is not a credit card number std::vector<webkit_glue::FormField> values; for (std::vector<webkit_glue::FormField>::const_iterator iter = form.fields.begin(); iter != form.fields.end(); ++iter) { if (!iter->value().empty() && !iter->name().empty() && - iter->form_control_type() == ASCIIToUTF16("text") && - !CreditCard::IsCreditCardNumber(iter->value())) + iter->form_control_type() == ASCIIToUTF16("text")) values.push_back(*iter); } - if (!values.empty()) - web_data_service_->AddFormFields(values); + profile()->GetWebDataService(Profile::EXPLICIT_ACCESS)->AddFormFields(values); } void AutocompleteHistoryManager::SendSuggestions(const WDTypedResult* result) { RenderViewHost* host = tab_contents_->render_view_host(); if (!host) return; - if (result) { DCHECK(result->GetType() == AUTOFILL_VALUE_RESULT); const WDResult<std::vector<string16> >* autofill_result = |