diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-20 21:57:13 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-20 21:57:13 +0000 |
commit | 693d828b212b0c072c108a4530434aeeb6554845 (patch) | |
tree | 4166ac193b8dd5faf007ae3bf29c00404b58f7f5 /chrome | |
parent | eb54a569a3683b10f1d0f8548177d29a3b4ef9be (diff) | |
download | chromium_src-693d828b212b0c072c108a4530434aeeb6554845.zip chromium_src-693d828b212b0c072c108a4530434aeeb6554845.tar.gz chromium_src-693d828b212b0c072c108a4530434aeeb6554845.tar.bz2 |
Hook up AutoFill profile DB handling in WebDataService.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/552072
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36684 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/webdata/web_data_service.cc | 93 | ||||
-rw-r--r-- | chrome/browser/webdata/web_data_service.h | 38 |
2 files changed, 123 insertions, 8 deletions
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc index d25492b..3601b8b 100644 --- a/chrome/browser/webdata/web_data_service.cc +++ b/chrome/browser/webdata/web_data_service.cc @@ -7,6 +7,7 @@ #include "base/message_loop.h" #include "base/task.h" #include "base/thread.h" +#include "chrome/browser/autofill/autofill_profile.h" #include "chrome/browser/webdata/autofill_change.h" #include "chrome/browser/webdata/autofill_entry.h" #include "chrome/browser/webdata/web_database.h" @@ -139,6 +140,49 @@ void WebDataService::RemoveFormValueForElementName( request)); } +void WebDataService::AddAutoFillProfile(const AutoFillProfile& profile) { + GenericRequest<AutoFillProfile>* request = + new GenericRequest<AutoFillProfile>( + this, GetNextRequestHandle(), NULL, profile); + RegisterRequest(request); + ScheduleTask(NewRunnableMethod(this, + &WebDataService::AddAutoFillProfileImpl, + request)); +} + +void WebDataService::UpdateAutoFillProfile(const AutoFillProfile& profile) { + GenericRequest<AutoFillProfile>* request = + new GenericRequest<AutoFillProfile>( + this, GetNextRequestHandle(), NULL, profile); + RegisterRequest(request); + ScheduleTask(NewRunnableMethod(this, + &WebDataService::UpdateAutoFillProfileImpl, + request)); +} + +void WebDataService::RemoveAutoFillProfile(const AutoFillProfile& profile) { + GenericRequest<AutoFillProfile>* request = + new GenericRequest<AutoFillProfile>( + this, GetNextRequestHandle(), NULL, profile); + RegisterRequest(request); + ScheduleTask(NewRunnableMethod(this, + &WebDataService::RemoveAutoFillProfileImpl, + request)); +} + +WebDataService::Handle WebDataService::GetAutoFillProfileForLabel( + const string16& label, WebDataServiceConsumer* consumer) { + WebDataRequest* request = + new WebDataRequest(this, GetNextRequestHandle(), consumer); + RegisterRequest(request); + ScheduleTask( + NewRunnableMethod(this, + &WebDataService::GetAutoFillProfileForLabelImpl, + request, + label)); + return request->GetHandle(); +} + void WebDataService::RequestCompleted(Handle h) { pending_lock_.Acquire(); RequestMap::iterator i = pending_requests_.find(h); @@ -665,6 +709,55 @@ void WebDataService::RemoveFormValueForElementNameImpl( request->RequestComplete(); } +void WebDataService::AddAutoFillProfileImpl( + GenericRequest<AutoFillProfile>* request) { + InitializeDatabaseIfNecessary(); + if (db_ && !request->IsCancelled()) { + const AutoFillProfile& profile = request->GetArgument(); + if (!db_->AddAutoFillProfile(profile)) + NOTREACHED(); + ScheduleCommit(); + } + request->RequestComplete(); +} + +void WebDataService::UpdateAutoFillProfileImpl( + GenericRequest<AutoFillProfile>* request) { + InitializeDatabaseIfNecessary(); + if (db_ && !request->IsCancelled()) { + const AutoFillProfile& profile = request->GetArgument(); + if (!db_->UpdateAutoFillProfile(profile)) + NOTREACHED(); + ScheduleCommit(); + } + request->RequestComplete(); +} + +void WebDataService::RemoveAutoFillProfileImpl( + GenericRequest<AutoFillProfile>* request) { + InitializeDatabaseIfNecessary(); + if (db_ && !request->IsCancelled()) { + const AutoFillProfile& profile = request->GetArgument(); + if (!db_->RemoveAutoFillProfile(profile)) + NOTREACHED(); + ScheduleCommit(); + } + request->RequestComplete(); +} + +void WebDataService::GetAutoFillProfileForLabelImpl(WebDataRequest* request, + const string16& label) { + InitializeDatabaseIfNecessary(); + if (db_ && !request->IsCancelled()) { + AutoFillProfile* profile; + db_->GetAutoFillProfileForLabel(label, &profile); + request->SetResult( + new WDResult<AutoFillProfile>(AUTOFILL_PROFILE_RESULT, *profile)); + delete profile; + } + request->RequestComplete(); +} + //////////////////////////////////////////////////////////////////////////////// // // Web Apps implementation. diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h index 4421b71..9ab3c01 100644 --- a/chrome/browser/webdata/web_data_service.h +++ b/chrome/browser/webdata/web_data_service.h @@ -18,6 +18,7 @@ #include "webkit/glue/form_field.h" class AutofillChange; +class AutoFillProfile; #if defined(OS_WIN) struct IE7PasswordInfo; #endif @@ -53,16 +54,17 @@ struct PasswordForm; // Result types // typedef enum { - BOOL_RESULT = 1, // WDResult<bool> - KEYWORDS_RESULT, // WDResult<WDKeywordsResult> - INT64_RESULT, // WDResult<int64> - PASSWORD_RESULT, // WDResult<std::vector<PasswordForm*>> + BOOL_RESULT = 1, // WDResult<bool> + KEYWORDS_RESULT, // WDResult<WDKeywordsResult> + INT64_RESULT, // WDResult<int64> + PASSWORD_RESULT, // WDResult<std::vector<PasswordForm*>> #if defined(OS_WIN) - PASSWORD_IE7_RESULT, // WDResult<IE7PasswordInfo> + PASSWORD_IE7_RESULT, // WDResult<IE7PasswordInfo> #endif - WEB_APP_IMAGES, // WDResult<WDAppImagesResult> - AUTOFILL_VALUE_RESULT, // WDResult<std::vector<string16>> - AUTOFILL_CHANGES, // WDResult<std::vector<AutofillChange>> + WEB_APP_IMAGES, // WDResult<WDAppImagesResult> + AUTOFILL_VALUE_RESULT, // WDResult<std::vector<string16>> + AUTOFILL_CHANGES, // WDResult<std::vector<AutofillChange>> + AUTOFILL_PROFILE_RESULT // WDResult<AutoFillProfile> } WDResultType; typedef std::vector<AutofillChange> AutofillChangeList; @@ -405,6 +407,21 @@ class WebDataService void RemoveFormValueForElementName(const string16& name, const string16& value); + // Schedules a task to add an AutoFill profile to the web database. + void AddAutoFillProfile(const AutoFillProfile& profile); + + // Schedules a task to update an AutoFill profile in the web database. + void UpdateAutoFillProfile(const AutoFillProfile& profile); + + // Schedules a task to remove an AutoFill profile from the web database. + void RemoveAutoFillProfile(const AutoFillProfile& profile); + + // Initiates the request for an AutoFill profile with label |label. The + // method OnWebDataServiceRequestDone of |consumer| gets called back when the + // request is finished, with the profile included in the argument |result|. + Handle GetAutoFillProfileForLabel(const string16& label, + WebDataServiceConsumer* consumer); + // Testing #ifdef UNIT_TEST void set_failed_init(bool value) { failed_init_ = value; } @@ -497,6 +514,11 @@ class WebDataService GenericRequest2<base::Time, base::Time>* request); void RemoveFormValueForElementNameImpl( GenericRequest2<string16, string16>* request); + void AddAutoFillProfileImpl(GenericRequest<AutoFillProfile>* request); + void UpdateAutoFillProfileImpl(GenericRequest<AutoFillProfile>* request); + void RemoveAutoFillProfileImpl(GenericRequest<AutoFillProfile>* request); + void GetAutoFillProfileForLabelImpl(WebDataRequest* request, + const string16& label); ////////////////////////////////////////////////////////////////////////////// // |