Chromium Code Reviews| Index: chrome/browser/webdata/web_data_service.cc |
| diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc |
| index 685b5f375968ddf44b3c2b9f09e1f6c15dabd563..fb6e2be34a1d54b83879f73ef79546f850aff497 100644 |
| --- a/chrome/browser/webdata/web_data_service.cc |
| +++ b/chrome/browser/webdata/web_data_service.cc |
| @@ -149,48 +149,37 @@ WebDatabase* WebDataService::GetDatabase() { |
| ////////////////////////////////////////////////////////////////////////////// |
| void WebDataService::AddKeyword(const TemplateURLData& data) { |
| - GenericRequest<TemplateURLData>* request = |
| - new GenericRequest<TemplateURLData>( |
| - this, NULL, &request_manager_, data); |
| - ScheduleTask(FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, request)); |
| + ScheduleDBTask( |
| + FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, data)); |
| } |
| void WebDataService::RemoveKeyword(TemplateURLID id) { |
| - GenericRequest<TemplateURLID>* request = |
| - new GenericRequest<TemplateURLID>(this, NULL, &request_manager_, id); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::RemoveKeywordImpl, this, request)); |
| + ScheduleDBTask( |
| + FROM_HERE, Bind(&WebDataService::RemoveKeywordImpl, this, id)); |
| } |
| void WebDataService::UpdateKeyword(const TemplateURLData& data) { |
| - GenericRequest<TemplateURLData>* request = |
| - new GenericRequest<TemplateURLData>( |
| - this, NULL, &request_manager_, data); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::UpdateKeywordImpl, this, request)); |
| + ScheduleDBTask( |
| + FROM_HERE, Bind(&WebDataService::UpdateKeywordImpl, this, data)); |
| } |
| WebDataService::Handle WebDataService::GetKeywords( |
| - WebDataServiceConsumer* consumer) { |
| - WebDataRequest* request = |
| - new WebDataRequest(this, consumer, &request_manager_); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::GetKeywordsImpl, this, request)); |
| - return request->GetHandle(); |
| + WebDataServiceConsumer* consumer) { |
| + WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| + Bind(&WebDataService::GetKeywordsImpl, this), |
| + consumer); |
| + return handle; |
| } |
| void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) { |
| - GenericRequest<TemplateURLID>* request = new GenericRequest<TemplateURLID>( |
| - this, NULL, &request_manager_, url ? url->id() : 0); |
| - ScheduleTask(FROM_HERE, Bind(&WebDataService::SetDefaultSearchProviderImpl, |
| - this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::SetDefaultSearchProviderImpl, this, |
| + url ? url->id() : 0)); |
| } |
| void WebDataService::SetBuiltinKeywordVersion(int version) { |
| - GenericRequest<int>* request = new GenericRequest<int>( |
| - this, NULL, &request_manager_, version); |
| - ScheduleTask(FROM_HERE, Bind(&WebDataService::SetBuiltinKeywordVersionImpl, |
| - this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::SetBuiltinKeywordVersionImpl, this, version)); |
| } |
| ////////////////////////////////////////////////////////////////////////////// |
| @@ -201,37 +190,28 @@ void WebDataService::SetBuiltinKeywordVersion(int version) { |
| void WebDataService::SetWebAppImage(const GURL& app_url, |
| const SkBitmap& image) { |
| - GenericRequest2<GURL, SkBitmap>* request = |
| - new GenericRequest2<GURL, SkBitmap>( |
| - this, NULL, &request_manager_, app_url, image); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::SetWebAppImageImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::SetWebAppImageImpl, this, app_url, image)); |
| } |
| void WebDataService::SetWebAppHasAllImages(const GURL& app_url, |
| bool has_all_images) { |
| - GenericRequest2<GURL, bool>* request = |
| - new GenericRequest2<GURL, bool>( |
| - this, NULL, &request_manager_, app_url, has_all_images); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, app_url, |
| + has_all_images)); |
| } |
| void WebDataService::RemoveWebApp(const GURL& app_url) { |
| - GenericRequest<GURL>* request = |
| - new GenericRequest<GURL>(this, NULL, &request_manager_, app_url); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::RemoveWebAppImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::RemoveWebAppImpl, this, app_url)); |
| } |
| WebDataService::Handle WebDataService::GetWebAppImages( |
| const GURL& app_url, |
| WebDataServiceConsumer* consumer) { |
| - GenericRequest<GURL>* request = |
| - new GenericRequest<GURL>(this, consumer, &request_manager_, app_url); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::GetWebAppImagesImpl, this, request)); |
| - return request->GetHandle(); |
| + WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
|
erikwright (departed)
2013/01/10 19:48:10
is there a reason for the local variable?
Cait (Slow)
2013/01/11 19:40:39
Done.
|
| + Bind(&WebDataService::GetWebAppImagesImpl, this, app_url), consumer); |
| + return handle; |
| } |
| ////////////////////////////////////////////////////////////////////////////// |
| @@ -241,108 +221,82 @@ WebDataService::Handle WebDataService::GetWebAppImages( |
| ////////////////////////////////////////////////////////////////////////////// |
| void WebDataService::AddWebIntentService(const WebIntentServiceData& service) { |
| - GenericRequest<WebIntentServiceData>* request = |
| - new GenericRequest<WebIntentServiceData>( |
| - this, NULL, &request_manager_, service); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::AddWebIntentServiceImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::AddWebIntentServiceImpl, this, service)); |
| } |
| void WebDataService::RemoveWebIntentService( |
| const WebIntentServiceData& service) { |
| - GenericRequest<WebIntentServiceData>* request = |
| - new GenericRequest<WebIntentServiceData>( |
| - this, NULL, &request_manager_, service); |
| - ScheduleTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl, |
| - this, request)); |
| + ScheduleDBTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl, |
| + this, service)); |
| } |
| WebDataService::Handle WebDataService::GetWebIntentServicesForAction( |
| const string16& action, |
| WebDataServiceConsumer* consumer) { |
| DCHECK(consumer); |
|
erikwright (departed)
2013/01/10 19:48:10
How about putting a DCHECK like this inside Schedu
Cait (Slow)
2013/01/11 19:40:39
Done.
|
| - GenericRequest<string16>* request = |
| - new GenericRequest<string16>( |
| - this, consumer, &request_manager_, action); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::GetWebIntentServicesImpl, this, request)); |
| - return request->GetHandle(); |
| + WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| + Bind(&WebDataService::GetWebIntentServicesImpl, this, action), |
| + consumer); |
| + return handle; |
| } |
| WebDataService::Handle WebDataService::GetWebIntentServicesForURL( |
| const string16& service_url, |
| WebDataServiceConsumer* consumer) { |
| DCHECK(consumer); |
| - GenericRequest<string16>* request = |
| - new GenericRequest<string16>( |
| - this, consumer, &request_manager_, service_url); |
| - ScheduleTask(FROM_HERE, Bind(&WebDataService::GetWebIntentServicesForURLImpl, |
| - this, request)); |
| - return request->GetHandle(); |
| + WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| + Bind(&WebDataService::GetWebIntentServicesForURLImpl, this, service_url), |
| + consumer); |
| + return handle; |
| } |
| WebDataService::Handle WebDataService::GetAllWebIntentServices( |
| WebDataServiceConsumer* consumer) { |
| - DCHECK(consumer); |
| - GenericRequest<std::string>* request = |
| - new GenericRequest<std::string>( |
| - this, consumer, &request_manager_, std::string()); |
| - ScheduleTask(FROM_HERE, Bind(&WebDataService::GetAllWebIntentServicesImpl, |
| - this, request)); |
| - return request->GetHandle(); |
| +DCHECK(consumer); |
| + WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| + Bind(&WebDataService::GetAllWebIntentServicesImpl, this), consumer); |
| + return handle; |
| } |
| void WebDataService::AddDefaultWebIntentService( |
| const DefaultWebIntentService& service) { |
| - GenericRequest<DefaultWebIntentService>* request = |
| - new GenericRequest<DefaultWebIntentService>( |
| - this, NULL, &request_manager_, service); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this, |
| - request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this, service)); |
| } |
| void WebDataService::RemoveDefaultWebIntentService( |
| const DefaultWebIntentService& service) { |
| - GenericRequest<DefaultWebIntentService>* request = |
| - new GenericRequest<DefaultWebIntentService>( |
| - this, NULL, &request_manager_, service); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this, |
| - request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this, service)); |
| } |
| void WebDataService::RemoveWebIntentServiceDefaults( |
| const GURL& service_url) { |
| - GenericRequest<GURL>* request = |
| - new GenericRequest<GURL>(this, NULL, &request_manager_, service_url); |
| - ScheduleTask( |
| - FROM_HERE, |
| - Bind(&WebDataService::RemoveWebIntentServiceDefaultsImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::RemoveWebIntentServiceDefaultsImpl, this, |
| + service_url)); |
| } |
| WebDataService::Handle WebDataService::GetDefaultWebIntentServicesForAction( |
| const string16& action, |
| WebDataServiceConsumer* consumer) { |
| DCHECK(consumer); |
| - GenericRequest<string16>* request = new GenericRequest<string16>( |
| - this, consumer, &request_manager_, action); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl, |
| - this, request)); |
| - return request->GetHandle(); |
| + WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| + Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl, this, |
| + action), |
| + consumer); |
| + return handle; |
| } |
| WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices( |
| WebDataServiceConsumer* consumer) { |
| DCHECK(consumer); |
| - GenericRequest<std::string>* request = new GenericRequest<std::string>( |
| - this, consumer, &request_manager_, std::string()); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl, |
| - this, request)); |
| - return request->GetHandle(); |
| + WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| + Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl, this), |
| + consumer); |
| + return handle; |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -353,31 +307,20 @@ WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices( |
| void WebDataService::SetTokenForService(const std::string& service, |
| const std::string& token) { |
| - GenericRequest2<std::string, std::string>* request = |
| - new GenericRequest2<std::string, std::string>( |
| - this, NULL, &request_manager_, service, token); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::SetTokenForServiceImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::SetTokenForServiceImpl, this, service, token)); |
| } |
| void WebDataService::RemoveAllTokens() { |
| - GenericRequest<std::string>* request = |
| - new GenericRequest<std::string>( |
| - this, NULL, &request_manager_, std::string()); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::RemoveAllTokensImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, Bind(&WebDataService::RemoveAllTokensImpl, this)); |
| } |
| // Null on failure. Success is WDResult<std::string> |
| WebDataService::Handle WebDataService::GetAllTokens( |
| WebDataServiceConsumer* consumer) { |
| - |
| - GenericRequest<std::string>* request = |
| - new GenericRequest<std::string>( |
| - this, consumer, &request_manager_, std::string()); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::GetAllTokensImpl, this, request)); |
| - return request->GetHandle(); |
| + WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| + Bind(&WebDataService::GetAllTokensImpl, this), consumer); |
| + return handle; |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -388,132 +331,94 @@ WebDataService::Handle WebDataService::GetAllTokens( |
| void WebDataService::AddFormFields( |
| const std::vector<FormFieldData>& fields) { |
| - GenericRequest<std::vector<FormFieldData> >* request = |
| - new GenericRequest<std::vector<FormFieldData> >( |
| - this, NULL, &request_manager_, fields); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::AddFormElementsImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::AddFormElementsImpl, this, fields)); |
| } |
| WebDataService::Handle WebDataService::GetFormValuesForElementName( |
| const string16& name, const string16& prefix, int limit, |
| WebDataServiceConsumer* consumer) { |
| - WebDataRequest* request = |
| - new WebDataRequest(this, consumer, &request_manager_); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::GetFormValuesForElementNameImpl, |
| - this, request, name, prefix, limit)); |
| - return request->GetHandle(); |
| + WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| + Bind(&WebDataService::GetFormValuesForElementNameImpl, |
| + this, name, prefix, limit), |
| + consumer); |
| + return handle; |
| } |
| void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, |
| const Time& delete_end) { |
| - GenericRequest2<Time, Time>* request = |
| - new GenericRequest2<Time, Time>( |
| - this, NULL, &request_manager_, delete_begin, delete_end); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl, |
| - this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl, |
| + this, delete_begin, delete_end)); |
| } |
| void WebDataService::RemoveExpiredFormElements() { |
| - WebDataRequest* request = |
| - new WebDataRequest(this, NULL, &request_manager_); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::RemoveExpiredFormElementsImpl, |
| - this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::RemoveExpiredFormElementsImpl, this)); |
| } |
| void WebDataService::RemoveFormValueForElementName( |
| const string16& name, const string16& value) { |
| - GenericRequest2<string16, string16>* request = |
| - new GenericRequest2<string16, string16>( |
| - this, NULL, &request_manager_, name, value); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::RemoveFormValueForElementNameImpl, |
| - this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::RemoveFormValueForElementNameImpl, |
| + this, name, value)); |
| } |
| void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { |
| - GenericRequest<AutofillProfile>* request = |
| - new GenericRequest<AutofillProfile>( |
| - this, NULL, &request_manager_, profile); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::AddAutofillProfileImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::AddAutofillProfileImpl, this, profile)); |
| } |
| void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) { |
| - GenericRequest<AutofillProfile>* request = |
| - new GenericRequest<AutofillProfile>( |
| - this, NULL, &request_manager_, profile); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::UpdateAutofillProfileImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::UpdateAutofillProfileImpl, this, profile)); |
| } |
| void WebDataService::RemoveAutofillProfile(const std::string& guid) { |
| - GenericRequest<std::string>* request = |
| - new GenericRequest<std::string>(this, NULL, &request_manager_, guid); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::RemoveAutofillProfileImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::RemoveAutofillProfileImpl, this, guid)); |
| } |
| WebDataService::Handle WebDataService::GetAutofillProfiles( |
| WebDataServiceConsumer* consumer) { |
| - WebDataRequest* request = |
| - new WebDataRequest(this, consumer, &request_manager_); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::GetAutofillProfilesImpl, this, request)); |
| - return request->GetHandle(); |
| + WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| + Bind(&WebDataService::GetAutofillProfilesImpl, this), consumer); |
| + return handle; |
| } |
| void WebDataService::EmptyMigrationTrash(bool notify_sync) { |
| - GenericRequest<bool>* request = |
| - new GenericRequest<bool>(this, NULL, &request_manager_, notify_sync); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::EmptyMigrationTrashImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::EmptyMigrationTrashImpl, this, notify_sync)); |
| } |
| void WebDataService::AddCreditCard(const CreditCard& credit_card) { |
| - GenericRequest<CreditCard>* request = |
| - new GenericRequest<CreditCard>( |
| - this, NULL, &request_manager_, credit_card); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::AddCreditCardImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::AddCreditCardImpl, this, credit_card)); |
| } |
| void WebDataService::UpdateCreditCard(const CreditCard& credit_card) { |
| - GenericRequest<CreditCard>* request = |
| - new GenericRequest<CreditCard>( |
| - this, NULL, &request_manager_, credit_card); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::UpdateCreditCardImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::UpdateCreditCardImpl, this, credit_card)); |
| } |
| void WebDataService::RemoveCreditCard(const std::string& guid) { |
| - GenericRequest<std::string>* request = |
| - new GenericRequest<std::string>(this, NULL, &request_manager_, guid); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::RemoveCreditCardImpl, this, request)); |
| + ScheduleDBTask(FROM_HERE, |
| + Bind(&WebDataService::RemoveCreditCardImpl, this, guid)); |
| } |
| WebDataService::Handle WebDataService::GetCreditCards( |
| WebDataServiceConsumer* consumer) { |
| - WebDataRequest* request = |
| - new WebDataRequest(this, consumer, &request_manager_); |
| - ScheduleTask(FROM_HERE, |
| - Bind(&WebDataService::GetCreditCardsImpl, this, request)); |
| - return request->GetHandle(); |
| + WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| + Bind(&WebDataService::GetCreditCardsImpl, this), consumer); |
| + return handle; |
| } |
| void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
| const Time& delete_begin, |
| const Time& delete_end) { |
| - GenericRequest2<Time, Time>* request = |
| - new GenericRequest2<Time, Time>( |
| - this, NULL, &request_manager_, delete_begin, delete_end); |
| - ScheduleTask(FROM_HERE, Bind( |
| + ScheduleDBTask(FROM_HERE, Bind( |
| &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, |
| - this, request)); |
| + this, delete_begin, delete_end)); |
| } |
| WebDataService::~WebDataService() { |
| @@ -643,90 +548,109 @@ void WebDataService::ScheduleTask(const tracked_objects::Location& from_here, |
| NOTREACHED() << "Task scheduled after Shutdown()"; |
| } |
| -void WebDataService::ScheduleCommit() { |
| - if (should_commit_ == false) { |
| - should_commit_ = true; |
| - ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this)); |
| +void WebDataService::ScheduleDBTask( |
| + const tracked_objects::Location& from_here, |
| + const base::Closure& task) { |
| + WebDataRequest* request = new WebDataRequest(this, NULL, |
|
erikwright (departed)
2013/01/10 19:48:10
wrap after '=' or '('
erikwright (departed)
2013/01/10 19:48:10
Your changes here and in your previous CL reveal t
Cait (Slow)
2013/01/11 19:40:39
Ownership gap is fixed in https://codereview.chrom
Cait (Slow)
2013/01/11 19:40:39
Done.
|
| + &request_manager_); |
| + if (is_running_) { |
| + BrowserThread::PostTask(BrowserThread::DB, from_here, |
| + base::Bind(&WebDataService::DBTaskWrapper, this, task, request)); |
| + } else { |
| + NOTREACHED() << "Task scheduled after Shutdown()"; |
| } |
| } |
| -//////////////////////////////////////////////////////////////////////////////// |
| -// |
| -// Keywords implementation. |
| -// |
| -//////////////////////////////////////////////////////////////////////////////// |
| +WebDataService::Handle WebDataService::ScheduleDBTaskWithResult( |
| + const tracked_objects::Location& from_here, |
| + const ResultTask& task, |
| + WebDataServiceConsumer* consumer) { |
| + WebDataRequest* request = new WebDataRequest(this, consumer, |
| + &request_manager_); |
| + if (is_running_) { |
| + BrowserThread::PostTask(BrowserThread::DB, from_here, |
| + base::Bind(&WebDataService::DBResultTaskWrapper, this, task, request)); |
| + } else { |
| + NOTREACHED() << "Task scheduled after Shutdown()"; |
| + } |
| + return request->GetHandle(); |
| +} |
| -void WebDataService::AddKeywordImpl(GenericRequest<TemplateURLData>* request) { |
| +void WebDataService::DBTaskWrapper(const base::Closure& task, |
| + WebDataRequest* request) { |
| InitializeDatabaseIfNecessary(); |
| if (db_ && !request->IsCancelled()) { |
| - db_->GetKeywordTable()->AddKeyword(request->arg()); |
| - ScheduleCommit(); |
| + task.Run(); |
| } |
| request->RequestComplete(); |
| } |
| -void WebDataService::RemoveKeywordImpl(GenericRequest<TemplateURLID>* request) { |
| +void WebDataService::DBResultTaskWrapper(const ResultTask& task, |
| + WebDataRequest* request) { |
| InitializeDatabaseIfNecessary(); |
| if (db_ && !request->IsCancelled()) { |
| - DCHECK(request->arg()); |
| - db_->GetKeywordTable()->RemoveKeyword(request->arg()); |
| - ScheduleCommit(); |
| + WDTypedResult* result = task.Run(); |
| + request->SetResult(result); |
| } |
| request->RequestComplete(); |
| } |
| -void WebDataService::UpdateKeywordImpl( |
| - GenericRequest<TemplateURLData>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - if (!db_->GetKeywordTable()->UpdateKeyword(request->arg())) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - ScheduleCommit(); |
| +void WebDataService::ScheduleCommit() { |
| + if (should_commit_ == false) { |
| + should_commit_ = true; |
| + ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this)); |
|
erikwright (departed)
2013/01/10 19:48:10
Is this now the only caller of ScheduleTask? If so
Cait (Slow)
2013/01/11 19:40:39
It's actually called in 5 places (init'ing and shu
|
| } |
| - request->RequestComplete(); |
| } |
| -void WebDataService::GetKeywordsImpl(WebDataRequest* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - WDKeywordsResult result; |
| - db_->GetKeywordTable()->GetKeywords(&result.keywords); |
| - result.default_search_provider_id = |
| - db_->GetKeywordTable()->GetDefaultSearchProviderID(); |
| - result.builtin_keyword_version = |
| - db_->GetKeywordTable()->GetBuiltinKeywordVersion(); |
| - request->SetResult( |
| - new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result)); |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// |
| +// Keywords implementation. |
| +// |
| +//////////////////////////////////////////////////////////////////////////////// |
| + |
| +void WebDataService::AddKeywordImpl(const TemplateURLData& data) { |
| + db_->GetKeywordTable()->AddKeyword(data); |
| + ScheduleCommit(); |
| +} |
| + |
| +void WebDataService::RemoveKeywordImpl(TemplateURLID id) { |
| + DCHECK(id); |
| + db_->GetKeywordTable()->RemoveKeyword(id); |
| + ScheduleCommit(); |
| +} |
| + |
| +void WebDataService::UpdateKeywordImpl(const TemplateURLData& data) { |
| + if (!db_->GetKeywordTable()->UpdateKeyword(data)) { |
| + NOTREACHED(); |
| + return; |
| } |
| - request->RequestComplete(); |
| + ScheduleCommit(); |
| } |
| -void WebDataService::SetDefaultSearchProviderImpl( |
| - GenericRequest<TemplateURLID>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - if (!db_->GetKeywordTable()->SetDefaultSearchProviderID(request->arg())) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - ScheduleCommit(); |
| +WDTypedResult* WebDataService::GetKeywordsImpl() { |
| + WDKeywordsResult result; |
| + db_->GetKeywordTable()->GetKeywords(&result.keywords); |
| + result.default_search_provider_id = |
| + db_->GetKeywordTable()->GetDefaultSearchProviderID(); |
| + result.builtin_keyword_version = |
| + db_->GetKeywordTable()->GetBuiltinKeywordVersion(); |
| + return new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result); |
| +} |
| + |
| +void WebDataService::SetDefaultSearchProviderImpl(TemplateURLID id) { |
| + if (!db_->GetKeywordTable()->SetDefaultSearchProviderID(id)) { |
| + NOTREACHED(); |
| + return; |
| } |
| - request->RequestComplete(); |
| + ScheduleCommit(); |
| } |
| -void WebDataService::SetBuiltinKeywordVersionImpl( |
| - GenericRequest<int>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - if (!db_->GetKeywordTable()->SetBuiltinKeywordVersion(request->arg())) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - ScheduleCommit(); |
| +void WebDataService::SetBuiltinKeywordVersionImpl(int version) { |
| + if (!db_->GetKeywordTable()->SetBuiltinKeywordVersion(version)) { |
| + NOTREACHED(); |
| + return; |
| } |
| - request->RequestComplete(); |
| + ScheduleCommit(); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -736,47 +660,28 @@ void WebDataService::SetBuiltinKeywordVersionImpl( |
| //////////////////////////////////////////////////////////////////////////////// |
| void WebDataService::SetWebAppImageImpl( |
| - GenericRequest2<GURL, SkBitmap>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - db_->GetWebAppsTable()->SetWebAppImage( |
| - request->arg1(), request->arg2()); |
| - ScheduleCommit(); |
| - } |
| - request->RequestComplete(); |
| + const GURL& app_url, const SkBitmap& image) { |
| + db_->GetWebAppsTable()->SetWebAppImage(app_url, image); |
| + ScheduleCommit(); |
| } |
| void WebDataService::SetWebAppHasAllImagesImpl( |
| - GenericRequest2<GURL, bool>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - db_->GetWebAppsTable()->SetWebAppHasAllImages(request->arg1(), |
| - request->arg2()); |
| - ScheduleCommit(); |
| - } |
| - request->RequestComplete(); |
| + const GURL& app_url, bool has_all_images) { |
| + db_->GetWebAppsTable()->SetWebAppHasAllImages(app_url, has_all_images); |
| + ScheduleCommit(); |
| } |
| -void WebDataService::RemoveWebAppImpl(GenericRequest<GURL>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - db_->GetWebAppsTable()->RemoveWebApp(request->arg()); |
| - ScheduleCommit(); |
| - } |
| - request->RequestComplete(); |
| +void WebDataService::RemoveWebAppImpl(const GURL& app_url) { |
| + db_->GetWebAppsTable()->RemoveWebApp(app_url); |
| + ScheduleCommit(); |
| } |
| -void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - WDAppImagesResult result; |
| - result.has_all_images = |
| - db_->GetWebAppsTable()->GetWebAppHasAllImages(request->arg()); |
| - db_->GetWebAppsTable()->GetWebAppImages(request->arg(), &result.images); |
| - request->SetResult( |
| - new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result)); |
| - } |
| - request->RequestComplete(); |
| +WDTypedResult* WebDataService::GetWebAppImagesImpl(const GURL& app_url) { |
|
erikwright (departed)
2013/01/10 19:48:10
The new style is to return scoped_ptr<WDTypedResul
Cait (Slow)
2013/01/11 19:40:39
Done.
|
| + WDAppImagesResult result; |
| + result.has_all_images = |
| + db_->GetWebAppsTable()->GetWebAppHasAllImages(app_url); |
| + db_->GetWebAppsTable()->GetWebAppImages(app_url, &result.images); |
| + return new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -786,126 +691,72 @@ void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) { |
| //////////////////////////////////////////////////////////////////////////////// |
| void WebDataService::RemoveWebIntentServiceImpl( |
| - GenericRequest<WebIntentServiceData>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - const WebIntentServiceData& service = request->arg(); |
| - db_->GetWebIntentsTable()->RemoveWebIntentService(service); |
| - ScheduleCommit(); |
| - } |
| - request->RequestComplete(); |
| + const webkit_glue::WebIntentServiceData& service) { |
| + db_->GetWebIntentsTable()->RemoveWebIntentService(service); |
| + ScheduleCommit(); |
| } |
| void WebDataService::AddWebIntentServiceImpl( |
| - GenericRequest<WebIntentServiceData>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - const WebIntentServiceData& service = request->arg(); |
| - db_->GetWebIntentsTable()->SetWebIntentService(service); |
| - ScheduleCommit(); |
| - } |
| - request->RequestComplete(); |
| + const webkit_glue::WebIntentServiceData& service) { |
| + db_->GetWebIntentsTable()->SetWebIntentService(service); |
| + ScheduleCommit(); |
| } |
| -void WebDataService::GetWebIntentServicesImpl( |
| - GenericRequest<string16>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - std::vector<WebIntentServiceData> result; |
| - db_->GetWebIntentsTable()->GetWebIntentServicesForAction(request->arg(), |
| - &result); |
| - request->SetResult(new WDResult<std::vector<WebIntentServiceData> >( |
| - WEB_INTENTS_RESULT, result)); |
| - } |
| - request->RequestComplete(); |
| +WDTypedResult* WebDataService::GetWebIntentServicesImpl( |
| + const string16& action) { |
| + std::vector<WebIntentServiceData> result; |
| + db_->GetWebIntentsTable()->GetWebIntentServicesForAction(action, &result); |
| + return new WDResult<std::vector<WebIntentServiceData> >( |
| + WEB_INTENTS_RESULT, result); |
| } |
| -void WebDataService::GetWebIntentServicesForURLImpl( |
| - GenericRequest<string16>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - std::vector<WebIntentServiceData> result; |
| - db_->GetWebIntentsTable()->GetWebIntentServicesForURL( |
| - request->arg(), &result); |
| - request->SetResult( |
| - new WDResult<std::vector<WebIntentServiceData> >( |
| - WEB_INTENTS_RESULT, result)); |
| - } |
| - request->RequestComplete(); |
| +WDTypedResult* WebDataService::GetWebIntentServicesForURLImpl( |
| + const string16& service_url) { |
| + std::vector<WebIntentServiceData> result; |
| + db_->GetWebIntentsTable()->GetWebIntentServicesForURL(service_url, &result); |
| + return new WDResult<std::vector<WebIntentServiceData> >( |
| + WEB_INTENTS_RESULT, result); |
| } |
| -void WebDataService::GetAllWebIntentServicesImpl( |
| - GenericRequest<std::string>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - std::vector<WebIntentServiceData> result; |
| - db_->GetWebIntentsTable()->GetAllWebIntentServices(&result); |
| - request->SetResult( |
| - new WDResult<std::vector<WebIntentServiceData> >( |
| - WEB_INTENTS_RESULT, result)); |
| - } |
| - request->RequestComplete(); |
| +WDTypedResult* WebDataService::GetAllWebIntentServicesImpl() { |
| + std::vector<WebIntentServiceData> result; |
| + db_->GetWebIntentsTable()->GetAllWebIntentServices(&result); |
| + return new WDResult<std::vector<WebIntentServiceData> >( |
| + WEB_INTENTS_RESULT, result); |
| } |
| void WebDataService::AddDefaultWebIntentServiceImpl( |
| - GenericRequest<DefaultWebIntentService>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - const DefaultWebIntentService& service = request->arg(); |
| - db_->GetWebIntentsTable()->SetDefaultService(service); |
| - ScheduleCommit(); |
| - } |
| - request->RequestComplete(); |
| + const DefaultWebIntentService& service) { |
| + db_->GetWebIntentsTable()->SetDefaultService(service); |
| + ScheduleCommit(); |
| } |
| void WebDataService::RemoveDefaultWebIntentServiceImpl( |
| - GenericRequest<DefaultWebIntentService>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - const DefaultWebIntentService& service = request->arg(); |
| - db_->GetWebIntentsTable()->RemoveDefaultService(service); |
| - ScheduleCommit(); |
| - } |
| - request->RequestComplete(); |
| + const DefaultWebIntentService& service) { |
| + db_->GetWebIntentsTable()->RemoveDefaultService(service); |
| + ScheduleCommit(); |
| } |
| void WebDataService::RemoveWebIntentServiceDefaultsImpl( |
| - GenericRequest<GURL>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - const GURL& service_url = request->arg(); |
| - db_->GetWebIntentsTable()->RemoveServiceDefaults(service_url); |
| - ScheduleCommit(); |
| - } |
| - request->RequestComplete(); |
| + const GURL& service_url) { |
| + db_->GetWebIntentsTable()->RemoveServiceDefaults(service_url); |
| + ScheduleCommit(); |
| } |
| -void WebDataService::GetDefaultWebIntentServicesForActionImpl( |
| - GenericRequest<string16>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - std::vector<DefaultWebIntentService> result; |
| - db_->GetWebIntentsTable()->GetDefaultServices( |
| - request->arg(), &result); |
| - request->SetResult( |
| - new WDResult<std::vector<DefaultWebIntentService> >( |
| - WEB_INTENTS_DEFAULTS_RESULT, result)); |
| - } |
| - request->RequestComplete(); |
| +WDTypedResult* WebDataService::GetDefaultWebIntentServicesForActionImpl( |
| + const string16& action) { |
| + std::vector<DefaultWebIntentService> result; |
| + db_->GetWebIntentsTable()->GetDefaultServices(action, &result); |
| + return new WDResult<std::vector<DefaultWebIntentService> >( |
| + WEB_INTENTS_DEFAULTS_RESULT, result); |
| } |
| -void WebDataService::GetAllDefaultWebIntentServicesImpl( |
| - GenericRequest<std::string>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - std::vector<DefaultWebIntentService> result; |
| - db_->GetWebIntentsTable()->GetAllDefaultServices(&result); |
| - request->SetResult( |
| - new WDResult<std::vector<DefaultWebIntentService> >( |
| - WEB_INTENTS_DEFAULTS_RESULT, result)); |
| - } |
| - request->RequestComplete(); |
| +WDTypedResult* WebDataService::GetAllDefaultWebIntentServicesImpl() { |
| + std::vector<DefaultWebIntentService> result; |
| + db_->GetWebIntentsTable()->GetAllDefaultServices(&result); |
| + return new WDResult<std::vector<DefaultWebIntentService> >( |
| + WEB_INTENTS_DEFAULTS_RESULT, result); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -914,41 +765,23 @@ void WebDataService::GetAllDefaultWebIntentServicesImpl( |
| // |
| //////////////////////////////////////////////////////////////////////////////// |
| -// argument std::string is unused |
| -void WebDataService::RemoveAllTokensImpl( |
| - GenericRequest<std::string>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - if (db_->GetTokenServiceTable()->RemoveAllTokens()) { |
| - ScheduleCommit(); |
| - } |
| +void WebDataService::RemoveAllTokensImpl() { |
| + if (db_->GetTokenServiceTable()->RemoveAllTokens()) { |
| + ScheduleCommit(); |
| } |
| - request->RequestComplete(); |
| } |
| -void WebDataService::SetTokenForServiceImpl( |
| - GenericRequest2<std::string, std::string>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - if (db_->GetTokenServiceTable()->SetTokenForService( |
| - request->arg1(), request->arg2())) { |
| - ScheduleCommit(); |
| - } |
| +void WebDataService::SetTokenForServiceImpl(const std::string& service, |
| + const std::string& token) { |
| + if (db_->GetTokenServiceTable()->SetTokenForService(service, token)) { |
| + ScheduleCommit(); |
| } |
| - request->RequestComplete(); |
| } |
| -// argument is unused |
| -void WebDataService::GetAllTokensImpl( |
| - GenericRequest<std::string>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - std::map<std::string, std::string> map; |
| - db_->GetTokenServiceTable()->GetAllTokens(&map); |
| - request->SetResult( |
| - new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); |
| - } |
| - request->RequestComplete(); |
| +WDTypedResult* WebDataService::GetAllTokensImpl() { |
| + std::map<std::string, std::string> map; |
| + db_->GetTokenServiceTable()->GetAllTokens(&map); |
| + return new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -958,393 +791,298 @@ void WebDataService::GetAllTokensImpl( |
| //////////////////////////////////////////////////////////////////////////////// |
| void WebDataService::AddFormElementsImpl( |
| - GenericRequest<std::vector<FormFieldData> >* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - AutofillChangeList changes; |
| - if (!db_->GetAutofillTable()->AddFormFieldValues( |
| - request->arg(), &changes)) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - request->SetResult( |
| - new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); |
| - ScheduleCommit(); |
| - |
| - // Post the notifications including the list of affected keys. |
| - // This is sent here so that work resulting from this notification will be |
| - // done on the DB thread, and not the UI thread. |
| - content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| - content::Source<WebDataService>(this), |
| - content::Details<AutofillChangeList>(&changes)); |
| + const std::vector<FormFieldData>& fields) { |
| + AutofillChangeList changes; |
| + if (!db_->GetAutofillTable()->AddFormFieldValues(fields, &changes)) { |
| + NOTREACHED(); |
| + return; |
| } |
| + ScheduleCommit(); |
| - request->RequestComplete(); |
| + // Post the notifications including the list of affected keys. |
| + // This is sent here so that work resulting from this notification will be |
| + // done on the DB thread, and not the UI thread. |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| + content::Source<WebDataService>(this), |
| + content::Details<AutofillChangeList>(&changes)); |
| } |
| -void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request, |
| - const string16& name, const string16& prefix, int limit) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - std::vector<string16> values; |
| - db_->GetAutofillTable()->GetFormValuesForElementName( |
| - name, prefix, &values, limit); |
| - request->SetResult( |
| - new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); |
| - } |
| - request->RequestComplete(); |
| +WDTypedResult* WebDataService::GetFormValuesForElementNameImpl( |
| + const string16& name, const string16& prefix, int limit) { |
| + std::vector<string16> values; |
| + db_->GetAutofillTable()->GetFormValuesForElementName( |
| + name, prefix, &values, limit); |
| + return new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values); |
| } |
| void WebDataService::RemoveFormElementsAddedBetweenImpl( |
| - GenericRequest2<Time, Time>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - AutofillChangeList changes; |
| - if (db_->GetAutofillTable()->RemoveFormElementsAddedBetween( |
| - request->arg1(), request->arg2(), &changes)) { |
| - if (!changes.empty()) { |
| - request->SetResult( |
| - new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); |
| - |
| - // Post the notifications including the list of affected keys. |
| - // This is sent here so that work resulting from this notification |
| - // will be done on the DB thread, and not the UI thread. |
| - content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| - content::Source<WebDataService>(this), |
| - content::Details<AutofillChangeList>(&changes)); |
| - } |
| - ScheduleCommit(); |
| - } |
| - } |
| - request->RequestComplete(); |
| -} |
| - |
| -void WebDataService::RemoveExpiredFormElementsImpl(WebDataRequest* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - AutofillChangeList changes; |
| - if (db_->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { |
| - if (!changes.empty()) { |
| - request->SetResult( |
| - new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); |
| - |
| - // Post the notifications including the list of affected keys. |
| - // This is sent here so that work resulting from this notification |
| - // will be done on the DB thread, and not the UI thread. |
| - content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| - content::Source<WebDataService>(this), |
| - content::Details<AutofillChangeList>(&changes)); |
| - } |
| - ScheduleCommit(); |
| + const base::Time& delete_begin, const base::Time& delete_end) { |
| + AutofillChangeList changes; |
| + if (db_->GetAutofillTable()->RemoveFormElementsAddedBetween( |
| + delete_begin, delete_end, &changes)) { |
| + if (!changes.empty()) { |
| + // Post the notifications including the list of affected keys. |
| + // This is sent here so that work resulting from this notification |
| + // will be done on the DB thread, and not the UI thread. |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| + content::Source<WebDataService>(this), |
| + content::Details<AutofillChangeList>(&changes)); |
| } |
| + ScheduleCommit(); |
| } |
| - request->RequestComplete(); |
| } |
| -void WebDataService::RemoveFormValueForElementNameImpl( |
| - GenericRequest2<string16, string16>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - const string16& name = request->arg1(); |
| - const string16& value = request->arg2(); |
| - |
| - if (db_->GetAutofillTable()->RemoveFormElement(name, value)) { |
| - AutofillChangeList changes; |
| - changes.push_back(AutofillChange(AutofillChange::REMOVE, |
| - AutofillKey(name, value))); |
| - request->SetResult( |
| - new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); |
| - ScheduleCommit(); |
| +void WebDataService::RemoveExpiredFormElementsImpl() { |
| + AutofillChangeList changes; |
| + if (db_->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { |
| + if (!changes.empty()) { |
| // Post the notifications including the list of affected keys. |
| + // This is sent here so that work resulting from this notification |
| + // will be done on the DB thread, and not the UI thread. |
| content::NotificationService::current()->Notify( |
| chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| content::Source<WebDataService>(this), |
| content::Details<AutofillChangeList>(&changes)); |
| } |
| + ScheduleCommit(); |
| } |
| - request->RequestComplete(); |
| } |
| -void WebDataService::AddAutofillProfileImpl( |
| - GenericRequest<AutofillProfile>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - const AutofillProfile& profile = request->arg(); |
| - if (!db_->GetAutofillTable()->AddAutofillProfile(profile)) { |
| - NOTREACHED(); |
| - return; |
| - } |
| +void WebDataService::RemoveFormValueForElementNameImpl( |
| + const string16& name, const string16& value) { |
| + |
| + if (db_->GetAutofillTable()->RemoveFormElement(name, value)) { |
| + AutofillChangeList changes; |
| + changes.push_back(AutofillChange(AutofillChange::REMOVE, |
| + AutofillKey(name, value))); |
| ScheduleCommit(); |
| - // Send GUID-based notification. |
| - AutofillProfileChange change(AutofillProfileChange::ADD, |
| - profile.guid(), &profile); |
| + // Post the notifications including the list of affected keys. |
| content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| + chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| content::Source<WebDataService>(this), |
| - content::Details<AutofillProfileChange>(&change)); |
| + content::Details<AutofillChangeList>(&changes)); |
| } |
| - request->RequestComplete(); |
| } |
| -void WebDataService::UpdateAutofillProfileImpl( |
| - GenericRequest<AutofillProfile>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - const AutofillProfile& profile = request->arg(); |
| - |
| - // Only perform the update if the profile exists. It is currently |
| - // valid to try to update a missing profile. We simply drop the write and |
| - // the caller will detect this on the next refresh. |
| - AutofillProfile* original_profile = NULL; |
| - if (!db_->GetAutofillTable()->GetAutofillProfile(profile.guid(), |
| - &original_profile)) { |
| - request->RequestComplete(); |
| - return; |
| - } |
| - scoped_ptr<AutofillProfile> scoped_profile(original_profile); |
| +void WebDataService::AddAutofillProfileImpl(const AutofillProfile& profile) { |
| + if (!db_->GetAutofillTable()->AddAutofillProfile(profile)) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + ScheduleCommit(); |
| - if (!db_->GetAutofillTable()->UpdateAutofillProfileMulti(profile)) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - ScheduleCommit(); |
| + // Send GUID-based notification. |
| + AutofillProfileChange change(AutofillProfileChange::ADD, |
| + profile.guid(), &profile); |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| + content::Source<WebDataService>(this), |
| + content::Details<AutofillProfileChange>(&change)); |
| +} |
| - // Send GUID-based notification. |
| - AutofillProfileChange change(AutofillProfileChange::UPDATE, |
| - profile.guid(), &profile); |
| - content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| - content::Source<WebDataService>(this), |
| - content::Details<AutofillProfileChange>(&change)); |
| +void WebDataService::UpdateAutofillProfileImpl(const AutofillProfile& profile) { |
| + // Only perform the update if the profile exists. It is currently |
| + // valid to try to update a missing profile. We simply drop the write and |
| + // the caller will detect this on the next refresh. |
| + AutofillProfile* original_profile = NULL; |
| + if (!db_->GetAutofillTable()->GetAutofillProfile(profile.guid(), |
| + &original_profile)) { |
| + return; |
| } |
| - request->RequestComplete(); |
| -} |
| + scoped_ptr<AutofillProfile> scoped_profile(original_profile); |
| -void WebDataService::RemoveAutofillProfileImpl( |
| - GenericRequest<std::string>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - const std::string& guid = request->arg(); |
| + if (!db_->GetAutofillTable()->UpdateAutofillProfileMulti(profile)) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + ScheduleCommit(); |
| - AutofillProfile* profile = NULL; |
| - if (!db_->GetAutofillTable()->GetAutofillProfile(guid, &profile)) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - scoped_ptr<AutofillProfile> scoped_profile(profile); |
| + // Send GUID-based notification. |
| + AutofillProfileChange change(AutofillProfileChange::UPDATE, |
| + profile.guid(), &profile); |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| + content::Source<WebDataService>(this), |
| + content::Details<AutofillProfileChange>(&change)); |
| +} |
| - if (!db_->GetAutofillTable()->RemoveAutofillProfile(guid)) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - ScheduleCommit(); |
| +void WebDataService::RemoveAutofillProfileImpl(const std::string& guid) { |
| + AutofillProfile* profile = NULL; |
| + if (!db_->GetAutofillTable()->GetAutofillProfile(guid, &profile)) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + scoped_ptr<AutofillProfile> scoped_profile(profile); |
| - // Send GUID-based notification. |
| - AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); |
| - content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| - content::Source<WebDataService>(this), |
| - content::Details<AutofillProfileChange>(&change)); |
| + if (!db_->GetAutofillTable()->RemoveAutofillProfile(guid)) { |
| + NOTREACHED(); |
| + return; |
| } |
| - request->RequestComplete(); |
| + ScheduleCommit(); |
| + |
| + // Send GUID-based notification. |
| + AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| + content::Source<WebDataService>(this), |
| + content::Details<AutofillProfileChange>(&change)); |
| } |
| -void WebDataService::GetAutofillProfilesImpl(WebDataRequest* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - std::vector<AutofillProfile*> profiles; |
| - db_->GetAutofillTable()->GetAutofillProfiles(&profiles); |
| - request->SetResult( |
| - new WDResult<std::vector<AutofillProfile*> >(AUTOFILL_PROFILES_RESULT, |
| - base::Bind(&WebDataService::DestroyAutofillProfileResult, |
| - base::Unretained(this)), profiles)); |
| - } |
| - request->RequestComplete(); |
| +WDTypedResult* WebDataService::GetAutofillProfilesImpl() { |
| + std::vector<AutofillProfile*> profiles; |
| + db_->GetAutofillTable()->GetAutofillProfiles(&profiles); |
| + return new WDResult<std::vector<AutofillProfile*> >(AUTOFILL_PROFILES_RESULT, |
| + base::Bind(&WebDataService::DestroyAutofillProfileResult, |
| + base::Unretained(this)), profiles); |
| } |
| -void WebDataService::EmptyMigrationTrashImpl( |
| - GenericRequest<bool>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - bool notify_sync = request->arg(); |
| - if (notify_sync) { |
| - std::vector<std::string> guids; |
| - if (!db_->GetAutofillTable()->GetAutofillProfilesInTrash(&guids)) { |
| - NOTREACHED(); |
| - return; |
| - } |
| +void WebDataService::EmptyMigrationTrashImpl(bool notify_sync) { |
| + if (notify_sync) { |
| + std::vector<std::string> guids; |
| + if (!db_->GetAutofillTable()->GetAutofillProfilesInTrash(&guids)) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + for (std::vector<std::string>::const_iterator iter = guids.begin(); |
| + iter != guids.end(); ++iter) { |
| + // Send GUID-based notification. |
| + AutofillProfileChange change(AutofillProfileChange::REMOVE, |
| + *iter, NULL); |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| + content::Source<WebDataService>(this), |
| + content::Details<AutofillProfileChange>(&change)); |
| + } |
| - for (std::vector<std::string>::const_iterator iter = guids.begin(); |
| - iter != guids.end(); ++iter) { |
| - // Send GUID-based notification. |
| - AutofillProfileChange change(AutofillProfileChange::REMOVE, |
| - *iter, NULL); |
| + // If we trashed any profiles they may have been merged, so send out |
| + // update notifications as well. |
| + if (!guids.empty()) { |
| + std::vector<AutofillProfile*> profiles; |
| + db_->GetAutofillTable()->GetAutofillProfiles(&profiles); |
| + for (std::vector<AutofillProfile*>::const_iterator |
| + iter = profiles.begin(); |
| + iter != profiles.end(); ++iter) { |
| + AutofillProfileChange change(AutofillProfileChange::UPDATE, |
| + (*iter)->guid(), *iter); |
| content::NotificationService::current()->Notify( |
| chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| content::Source<WebDataService>(this), |
| content::Details<AutofillProfileChange>(&change)); |
| } |
| - |
| - // If we trashed any profiles they may have been merged, so send out |
| - // update notifications as well. |
| - if (!guids.empty()) { |
| - std::vector<AutofillProfile*> profiles; |
| - db_->GetAutofillTable()->GetAutofillProfiles(&profiles); |
| - for (std::vector<AutofillProfile*>::const_iterator |
| - iter = profiles.begin(); |
| - iter != profiles.end(); ++iter) { |
| - AutofillProfileChange change(AutofillProfileChange::UPDATE, |
| - (*iter)->guid(), *iter); |
| - content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| - content::Source<WebDataService>(this), |
| - content::Details<AutofillProfileChange>(&change)); |
| - } |
| - STLDeleteElements(&profiles); |
| - } |
| + STLDeleteElements(&profiles); |
| } |
| + } |
| - if (!db_->GetAutofillTable()->EmptyAutofillProfilesTrash()) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - ScheduleCommit(); |
| + if (!db_->GetAutofillTable()->EmptyAutofillProfilesTrash()) { |
| + NOTREACHED(); |
| + return; |
| } |
| - request->RequestComplete(); |
| + ScheduleCommit(); |
| } |
| -void WebDataService::AddCreditCardImpl( |
| - GenericRequest<CreditCard>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - const CreditCard& credit_card = request->arg(); |
| - if (!db_->GetAutofillTable()->AddCreditCard(credit_card)) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - ScheduleCommit(); |
| - |
| - // Send GUID-based notification. |
| - AutofillCreditCardChange change(AutofillCreditCardChange::ADD, |
| - credit_card.guid(), &credit_card); |
| - content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| - content::Source<WebDataService>(this), |
| - content::Details<AutofillCreditCardChange>(&change)); |
| +void WebDataService::AddCreditCardImpl(const CreditCard& credit_card) { |
| + if (!db_->GetAutofillTable()->AddCreditCard(credit_card)) { |
| + NOTREACHED(); |
| + return; |
| } |
| - request->RequestComplete(); |
| -} |
| + ScheduleCommit(); |
| -void WebDataService::UpdateCreditCardImpl( |
| - GenericRequest<CreditCard>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - const CreditCard& credit_card = request->arg(); |
| - |
| - // It is currently valid to try to update a missing profile. We simply drop |
| - // the write and the caller will detect this on the next refresh. |
| - CreditCard* original_credit_card = NULL; |
| - if (!db_->GetAutofillTable()->GetCreditCard(credit_card.guid(), |
| - &original_credit_card)) { |
| - request->RequestComplete(); |
| - return; |
| - } |
| - scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); |
| + // Send GUID-based notification. |
| + AutofillCreditCardChange change(AutofillCreditCardChange::ADD, |
| + credit_card.guid(), &credit_card); |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| + content::Source<WebDataService>(this), |
| + content::Details<AutofillCreditCardChange>(&change)); |
| +} |
| - if (!db_->GetAutofillTable()->UpdateCreditCard(credit_card)) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - ScheduleCommit(); |
| +void WebDataService::UpdateCreditCardImpl(const CreditCard& credit_card) { |
| + // It is currently valid to try to update a missing profile. We simply drop |
| + // the write and the caller will detect this on the next refresh. |
| + CreditCard* original_credit_card = NULL; |
| + if (!db_->GetAutofillTable()->GetCreditCard(credit_card.guid(), |
| + &original_credit_card)) { |
| + return; |
| + } |
| + scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); |
| - // Send GUID-based notification. |
| - AutofillCreditCardChange change(AutofillCreditCardChange::UPDATE, |
| - credit_card.guid(), &credit_card); |
| - content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| - content::Source<WebDataService>(this), |
| - content::Details<AutofillCreditCardChange>(&change)); |
| + if (!db_->GetAutofillTable()->UpdateCreditCard(credit_card)) { |
| + NOTREACHED(); |
| + return; |
| } |
| - request->RequestComplete(); |
| -} |
| + ScheduleCommit(); |
| -void WebDataService::RemoveCreditCardImpl( |
| - GenericRequest<std::string>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - const std::string& guid = request->arg(); |
| - if (!db_->GetAutofillTable()->RemoveCreditCard(guid)) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - ScheduleCommit(); |
| + // Send GUID-based notification. |
| + AutofillCreditCardChange change(AutofillCreditCardChange::UPDATE, |
| + credit_card.guid(), &credit_card); |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| + content::Source<WebDataService>(this), |
| + content::Details<AutofillCreditCardChange>(&change)); |
| +} |
| - // Send GUID-based notification. |
| - AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, guid, |
| - NULL); |
| - content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| - content::Source<WebDataService>(this), |
| - content::Details<AutofillCreditCardChange>(&change)); |
| +void WebDataService::RemoveCreditCardImpl(const std::string& guid) { |
| + if (!db_->GetAutofillTable()->RemoveCreditCard(guid)) { |
| + NOTREACHED(); |
| + return; |
| } |
| - request->RequestComplete(); |
| + ScheduleCommit(); |
| + |
| + // Send GUID-based notification. |
| + AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, guid, |
| + NULL); |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| + content::Source<WebDataService>(this), |
| + content::Details<AutofillCreditCardChange>(&change)); |
| } |
| -void WebDataService::GetCreditCardsImpl(WebDataRequest* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - std::vector<CreditCard*> credit_cards; |
| - db_->GetAutofillTable()->GetCreditCards(&credit_cards); |
| - request->SetResult( |
| - new WDResult<std::vector<CreditCard*> >(AUTOFILL_CREDITCARDS_RESULT, |
| - base::Bind(&WebDataService::DestroyAutofillCreditCardResult, |
| - base::Unretained(this)), credit_cards)); |
| - } |
| - request->RequestComplete(); |
| +WDTypedResult* WebDataService::GetCreditCardsImpl() { |
| + std::vector<CreditCard*> credit_cards; |
| + db_->GetAutofillTable()->GetCreditCards(&credit_cards); |
| + return new WDResult<std::vector<CreditCard*> >(AUTOFILL_CREDITCARDS_RESULT, |
| + base::Bind(&WebDataService::DestroyAutofillCreditCardResult, |
| + base::Unretained(this)), credit_cards); |
| } |
| void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( |
| - GenericRequest2<Time, Time>* request) { |
| - InitializeDatabaseIfNecessary(); |
| - if (db_ && !request->IsCancelled()) { |
| - std::vector<std::string> profile_guids; |
| - std::vector<std::string> credit_card_guids; |
| - if (db_->GetAutofillTable()-> |
| - RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
| - request->arg1(), |
| - request->arg2(), |
| - &profile_guids, |
| - &credit_card_guids)) { |
| - for (std::vector<std::string>::iterator iter = profile_guids.begin(); |
| - iter != profile_guids.end(); ++iter) { |
| - AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, |
| - NULL); |
| - content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| - content::Source<WebDataService>(this), |
| - content::Details<AutofillProfileChange>(&change)); |
| - } |
| + const base::Time& delete_begin, const base::Time& delete_end) { |
| + std::vector<std::string> profile_guids; |
| + std::vector<std::string> credit_card_guids; |
| + if (db_->GetAutofillTable()-> |
| + RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
| + delete_begin, |
| + delete_end, |
| + &profile_guids, |
| + &credit_card_guids)) { |
| + for (std::vector<std::string>::iterator iter = profile_guids.begin(); |
| + iter != profile_guids.end(); ++iter) { |
| + AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, |
| + NULL); |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| + content::Source<WebDataService>(this), |
| + content::Details<AutofillProfileChange>(&change)); |
| + } |
| - for (std::vector<std::string>::iterator iter = credit_card_guids.begin(); |
| - iter != credit_card_guids.end(); ++iter) { |
| - AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, |
| - *iter, NULL); |
| - content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| - content::Source<WebDataService>(this), |
| - content::Details<AutofillCreditCardChange>(&change)); |
| - } |
| - // Note: It is the caller's responsibility to post notifications for any |
| - // changes, e.g. by calling the Refresh() method of PersonalDataManager. |
| - ScheduleCommit(); |
| + for (std::vector<std::string>::iterator iter = credit_card_guids.begin(); |
| + iter != credit_card_guids.end(); ++iter) { |
| + AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, |
| + *iter, NULL); |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| + content::Source<WebDataService>(this), |
| + content::Details<AutofillCreditCardChange>(&change)); |
| } |
| + // Note: It is the caller's responsibility to post notifications for any |
| + // changes, e.g. by calling the Refresh() method of PersonalDataManager. |
| + ScheduleCommit(); |
| } |
| - request->RequestComplete(); |
| } |
| AutofillProfileSyncableService* |