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 48f93212778d07c66ce2cecfa41ddc92066ef085..2ef08637bfc75bead032e74e35224f4d9e8ad98d 100644 |
--- a/chrome/browser/webdata/web_data_service.cc |
+++ b/chrome/browser/webdata/web_data_service.cc |
@@ -80,11 +80,11 @@ WDKeywordsResult::~WDKeywordsResult() {} |
WebDataService::WebDataService() |
: is_running_(false), |
db_(NULL), |
+ request_manager_(new WebDataRequestManager()), |
autocomplete_syncable_service_(NULL), |
autofill_profile_syncable_service_(NULL), |
failed_init_(false), |
should_commit_(false), |
- next_request_handle_(1), |
main_loop_(MessageLoop::current()) { |
// WebDataService requires DB thread if instantiated. |
// Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) |
@@ -127,13 +127,7 @@ void WebDataService::UnloadDatabase() { |
} |
void WebDataService::CancelRequest(Handle h) { |
- base::AutoLock l(pending_lock_); |
- RequestMap::iterator i = pending_requests_.find(h); |
- if (i == pending_requests_.end()) { |
- NOTREACHED() << "Canceling a nonexistent web data service request"; |
- return; |
- } |
- i->second->Cancel(); |
+ request_manager_->CancelRequest(h); |
} |
content::NotificationSource WebDataService::GetNotificationSource() { |
@@ -157,25 +151,22 @@ WebDatabase* WebDataService::GetDatabase() { |
void WebDataService::AddKeyword(const TemplateURLData& data) { |
GenericRequest<TemplateURLData>* request = |
- new GenericRequest<TemplateURLData>(this, GetNextRequestHandle(), NULL, |
- data); |
- RegisterRequest(request); |
+ new GenericRequest<TemplateURLData>( |
+ this, NULL, request_manager_, data); |
ScheduleTask(FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, request)); |
} |
void WebDataService::RemoveKeyword(TemplateURLID id) { |
GenericRequest<TemplateURLID>* request = |
- new GenericRequest<TemplateURLID>(this, GetNextRequestHandle(), NULL, id); |
- RegisterRequest(request); |
+ new GenericRequest<TemplateURLID>(this, NULL, request_manager_, id); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveKeywordImpl, this, request)); |
} |
void WebDataService::UpdateKeyword(const TemplateURLData& data) { |
GenericRequest<TemplateURLData>* request = |
- new GenericRequest<TemplateURLData>(this, GetNextRequestHandle(), NULL, |
- data); |
- RegisterRequest(request); |
+ new GenericRequest<TemplateURLData>( |
+ this, NULL, request_manager_, data); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::UpdateKeywordImpl, this, request)); |
} |
@@ -183,8 +174,7 @@ void WebDataService::UpdateKeyword(const TemplateURLData& data) { |
WebDataService::Handle WebDataService::GetKeywords( |
WebDataServiceConsumer* consumer) { |
WebDataRequest* request = |
- new WebDataRequest(this, GetNextRequestHandle(), consumer); |
- RegisterRequest(request); |
+ new WebDataRequest(this, consumer, request_manager_); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetKeywordsImpl, this, request)); |
return request->GetHandle(); |
@@ -192,16 +182,14 @@ WebDataService::Handle WebDataService::GetKeywords( |
void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) { |
GenericRequest<TemplateURLID>* request = new GenericRequest<TemplateURLID>( |
- this, GetNextRequestHandle(), NULL, url ? url->id() : 0); |
- RegisterRequest(request); |
+ this, NULL, request_manager_, url ? url->id() : 0); |
ScheduleTask(FROM_HERE, Bind(&WebDataService::SetDefaultSearchProviderImpl, |
this, request)); |
} |
void WebDataService::SetBuiltinKeywordVersion(int version) { |
- GenericRequest<int>* request = |
- new GenericRequest<int>(this, GetNextRequestHandle(), NULL, version); |
- RegisterRequest(request); |
+ GenericRequest<int>* request = new GenericRequest<int>( |
+ this, NULL, request_manager_, version); |
ScheduleTask(FROM_HERE, Bind(&WebDataService::SetBuiltinKeywordVersionImpl, |
this, request)); |
} |
@@ -215,9 +203,8 @@ void WebDataService::SetBuiltinKeywordVersion(int version) { |
void WebDataService::SetWebAppImage(const GURL& app_url, |
const SkBitmap& image) { |
GenericRequest2<GURL, SkBitmap>* request = |
- new GenericRequest2<GURL, SkBitmap>(this, GetNextRequestHandle(), |
- NULL, app_url, image); |
- RegisterRequest(request); |
+ new GenericRequest2<GURL, SkBitmap>( |
+ this, NULL, request_manager_, app_url, image); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::SetWebAppImageImpl, this, request)); |
} |
@@ -225,17 +212,15 @@ void WebDataService::SetWebAppImage(const GURL& app_url, |
void WebDataService::SetWebAppHasAllImages(const GURL& app_url, |
bool has_all_images) { |
GenericRequest2<GURL, bool>* request = |
- new GenericRequest2<GURL, bool>(this, GetNextRequestHandle(), |
- NULL, app_url, has_all_images); |
- RegisterRequest(request); |
+ new GenericRequest2<GURL, bool>( |
+ this, NULL, request_manager_, app_url, has_all_images); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, request)); |
} |
void WebDataService::RemoveWebApp(const GURL& app_url) { |
GenericRequest<GURL>* request = |
- new GenericRequest<GURL>(this, GetNextRequestHandle(), NULL, app_url); |
- RegisterRequest(request); |
+ new GenericRequest<GURL>(this, NULL, request_manager_, app_url); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveWebAppImpl, this, request)); |
} |
@@ -244,8 +229,7 @@ WebDataService::Handle WebDataService::GetWebAppImages( |
const GURL& app_url, |
WebDataServiceConsumer* consumer) { |
GenericRequest<GURL>* request = |
- new GenericRequest<GURL>(this, GetNextRequestHandle(), consumer, app_url); |
- RegisterRequest(request); |
+ new GenericRequest<GURL>(this, consumer, request_manager_, app_url); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetWebAppImagesImpl, this, request)); |
return request->GetHandle(); |
@@ -260,8 +244,7 @@ WebDataService::Handle WebDataService::GetWebAppImages( |
void WebDataService::AddWebIntentService(const WebIntentServiceData& service) { |
GenericRequest<WebIntentServiceData>* request = |
new GenericRequest<WebIntentServiceData>( |
- this, GetNextRequestHandle(), NULL, service); |
- RegisterRequest(request); |
+ this, NULL, request_manager_, service); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::AddWebIntentServiceImpl, this, request)); |
} |
@@ -270,8 +253,7 @@ void WebDataService::RemoveWebIntentService( |
const WebIntentServiceData& service) { |
GenericRequest<WebIntentServiceData>* request = |
new GenericRequest<WebIntentServiceData>( |
- this, GetNextRequestHandle(), NULL, service); |
- RegisterRequest(request); |
+ this, NULL, request_manager_, service); |
ScheduleTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl, |
this, request)); |
} |
@@ -280,9 +262,9 @@ WebDataService::Handle WebDataService::GetWebIntentServicesForAction( |
const string16& action, |
WebDataServiceConsumer* consumer) { |
DCHECK(consumer); |
- GenericRequest<string16>* request = new GenericRequest<string16>( |
- this, GetNextRequestHandle(), consumer, action); |
- RegisterRequest(request); |
+ GenericRequest<string16>* request = |
+ new GenericRequest<string16>( |
+ this, consumer, request_manager_, action); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetWebIntentServicesImpl, this, request)); |
return request->GetHandle(); |
@@ -292,9 +274,9 @@ WebDataService::Handle WebDataService::GetWebIntentServicesForURL( |
const string16& service_url, |
WebDataServiceConsumer* consumer) { |
DCHECK(consumer); |
- GenericRequest<string16>* request = new GenericRequest<string16>( |
- this, GetNextRequestHandle(), consumer, service_url); |
- RegisterRequest(request); |
+ GenericRequest<string16>* request = |
+ new GenericRequest<string16>( |
+ this, consumer, request_manager_, service_url); |
ScheduleTask(FROM_HERE, Bind(&WebDataService::GetWebIntentServicesForURLImpl, |
this, request)); |
return request->GetHandle(); |
@@ -304,9 +286,9 @@ WebDataService::Handle WebDataService::GetWebIntentServicesForURL( |
WebDataService::Handle WebDataService::GetAllWebIntentServices( |
WebDataServiceConsumer* consumer) { |
DCHECK(consumer); |
- GenericRequest<std::string>* request = new GenericRequest<std::string>( |
- this, GetNextRequestHandle(), consumer, std::string()); |
- RegisterRequest(request); |
+ 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(); |
@@ -316,8 +298,7 @@ void WebDataService::AddDefaultWebIntentService( |
const DefaultWebIntentService& service) { |
GenericRequest<DefaultWebIntentService>* request = |
new GenericRequest<DefaultWebIntentService>( |
- this, GetNextRequestHandle(), NULL, service); |
- RegisterRequest(request); |
+ this, NULL, request_manager_, service); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this, |
request)); |
@@ -327,8 +308,7 @@ void WebDataService::RemoveDefaultWebIntentService( |
const DefaultWebIntentService& service) { |
GenericRequest<DefaultWebIntentService>* request = |
new GenericRequest<DefaultWebIntentService>( |
- this, GetNextRequestHandle(), NULL, service); |
- RegisterRequest(request); |
+ this, NULL, request_manager_, service); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this, |
request)); |
@@ -337,9 +317,7 @@ void WebDataService::RemoveDefaultWebIntentService( |
void WebDataService::RemoveWebIntentServiceDefaults( |
const GURL& service_url) { |
GenericRequest<GURL>* request = |
- new GenericRequest<GURL>( |
- this, GetNextRequestHandle(), NULL, service_url); |
- RegisterRequest(request); |
+ new GenericRequest<GURL>(this, NULL, request_manager_, service_url); |
ScheduleTask( |
FROM_HERE, |
Bind(&WebDataService::RemoveWebIntentServiceDefaultsImpl, this, request)); |
@@ -350,8 +328,7 @@ WebDataService::Handle WebDataService::GetDefaultWebIntentServicesForAction( |
WebDataServiceConsumer* consumer) { |
DCHECK(consumer); |
GenericRequest<string16>* request = new GenericRequest<string16>( |
- this, GetNextRequestHandle(), consumer, action); |
- RegisterRequest(request); |
+ this, consumer, request_manager_, action); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl, |
this, request)); |
@@ -362,8 +339,7 @@ WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices( |
WebDataServiceConsumer* consumer) { |
DCHECK(consumer); |
GenericRequest<std::string>* request = new GenericRequest<std::string>( |
- this, GetNextRequestHandle(), consumer, std::string()); |
- RegisterRequest(request); |
+ this, consumer, request_manager_, std::string()); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl, |
this, request)); |
@@ -380,8 +356,7 @@ void WebDataService::SetTokenForService(const std::string& service, |
const std::string& token) { |
GenericRequest2<std::string, std::string>* request = |
new GenericRequest2<std::string, std::string>( |
- this, GetNextRequestHandle(), NULL, service, token); |
- RegisterRequest(request); |
+ this, NULL, request_manager_, service, token); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::SetTokenForServiceImpl, this, request)); |
} |
@@ -389,8 +364,7 @@ void WebDataService::SetTokenForService(const std::string& service, |
void WebDataService::RemoveAllTokens() { |
GenericRequest<std::string>* request = |
new GenericRequest<std::string>( |
- this, GetNextRequestHandle(), NULL, std::string()); |
- RegisterRequest(request); |
+ this, NULL, request_manager_, std::string()); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveAllTokensImpl, this, request)); |
} |
@@ -401,8 +375,7 @@ WebDataService::Handle WebDataService::GetAllTokens( |
GenericRequest<std::string>* request = |
new GenericRequest<std::string>( |
- this, GetNextRequestHandle(), consumer, std::string()); |
- RegisterRequest(request); |
+ this, consumer, request_manager_, std::string()); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetAllTokensImpl, this, request)); |
return request->GetHandle(); |
@@ -418,8 +391,7 @@ void WebDataService::AddFormFields( |
const std::vector<FormFieldData>& fields) { |
GenericRequest<std::vector<FormFieldData> >* request = |
new GenericRequest<std::vector<FormFieldData> >( |
- this, GetNextRequestHandle(), NULL, fields); |
- RegisterRequest(request); |
+ this, NULL, request_manager_, fields); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::AddFormElementsImpl, this, request)); |
} |
@@ -428,8 +400,7 @@ WebDataService::Handle WebDataService::GetFormValuesForElementName( |
const string16& name, const string16& prefix, int limit, |
WebDataServiceConsumer* consumer) { |
WebDataRequest* request = |
- new WebDataRequest(this, GetNextRequestHandle(), consumer); |
- RegisterRequest(request); |
+ new WebDataRequest(this, consumer, request_manager_); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetFormValuesForElementNameImpl, |
this, request, name, prefix, limit)); |
@@ -439,12 +410,8 @@ WebDataService::Handle WebDataService::GetFormValuesForElementName( |
void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, |
const Time& delete_end) { |
GenericRequest2<Time, Time>* request = |
- new GenericRequest2<Time, Time>(this, |
- GetNextRequestHandle(), |
- NULL, |
- delete_begin, |
- delete_end); |
- RegisterRequest(request); |
+ new GenericRequest2<Time, Time>( |
+ this, NULL, request_manager_, delete_begin, delete_end); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl, |
this, request)); |
@@ -452,8 +419,7 @@ void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, |
void WebDataService::RemoveExpiredFormElements() { |
WebDataRequest* request = |
- new WebDataRequest(this, GetNextRequestHandle(), NULL); |
- RegisterRequest(request); |
+ new WebDataRequest(this, NULL, request_manager_); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveExpiredFormElementsImpl, |
this, request)); |
@@ -462,11 +428,8 @@ void WebDataService::RemoveExpiredFormElements() { |
void WebDataService::RemoveFormValueForElementName( |
const string16& name, const string16& value) { |
GenericRequest2<string16, string16>* request = |
- new GenericRequest2<string16, string16>(this, |
- GetNextRequestHandle(), |
- NULL, |
- name, value); |
- RegisterRequest(request); |
+ new GenericRequest2<string16, string16>( |
+ this, NULL, request_manager_, name, value); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveFormValueForElementNameImpl, |
this, request)); |
@@ -475,8 +438,7 @@ void WebDataService::RemoveFormValueForElementName( |
void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { |
GenericRequest<AutofillProfile>* request = |
new GenericRequest<AutofillProfile>( |
- this, GetNextRequestHandle(), NULL, profile); |
- RegisterRequest(request); |
+ this, NULL, request_manager_, profile); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::AddAutofillProfileImpl, this, request)); |
} |
@@ -484,17 +446,14 @@ void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { |
void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) { |
GenericRequest<AutofillProfile>* request = |
new GenericRequest<AutofillProfile>( |
- this, GetNextRequestHandle(), NULL, profile); |
- RegisterRequest(request); |
+ this, NULL, request_manager_, profile); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::UpdateAutofillProfileImpl, this, request)); |
} |
void WebDataService::RemoveAutofillProfile(const std::string& guid) { |
GenericRequest<std::string>* request = |
- new GenericRequest<std::string>( |
- this, GetNextRequestHandle(), NULL, guid); |
- RegisterRequest(request); |
+ new GenericRequest<std::string>(this, NULL, request_manager_, guid); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveAutofillProfileImpl, this, request)); |
} |
@@ -502,8 +461,7 @@ void WebDataService::RemoveAutofillProfile(const std::string& guid) { |
WebDataService::Handle WebDataService::GetAutofillProfiles( |
WebDataServiceConsumer* consumer) { |
WebDataRequest* request = |
- new WebDataRequest(this, GetNextRequestHandle(), consumer); |
- RegisterRequest(request); |
+ new WebDataRequest(this, consumer, request_manager_); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetAutofillProfilesImpl, this, request)); |
return request->GetHandle(); |
@@ -511,9 +469,7 @@ WebDataService::Handle WebDataService::GetAutofillProfiles( |
void WebDataService::EmptyMigrationTrash(bool notify_sync) { |
GenericRequest<bool>* request = |
- new GenericRequest<bool>( |
- this, GetNextRequestHandle(), NULL, notify_sync); |
- RegisterRequest(request); |
+ new GenericRequest<bool>(this, NULL, request_manager_, notify_sync); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::EmptyMigrationTrashImpl, this, request)); |
} |
@@ -521,8 +477,7 @@ void WebDataService::EmptyMigrationTrash(bool notify_sync) { |
void WebDataService::AddCreditCard(const CreditCard& credit_card) { |
GenericRequest<CreditCard>* request = |
new GenericRequest<CreditCard>( |
- this, GetNextRequestHandle(), NULL, credit_card); |
- RegisterRequest(request); |
+ this, NULL, request_manager_, credit_card); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::AddCreditCardImpl, this, request)); |
} |
@@ -530,17 +485,14 @@ void WebDataService::AddCreditCard(const CreditCard& credit_card) { |
void WebDataService::UpdateCreditCard(const CreditCard& credit_card) { |
GenericRequest<CreditCard>* request = |
new GenericRequest<CreditCard>( |
- this, GetNextRequestHandle(), NULL, credit_card); |
- RegisterRequest(request); |
+ this, NULL, request_manager_, credit_card); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::UpdateCreditCardImpl, this, request)); |
} |
void WebDataService::RemoveCreditCard(const std::string& guid) { |
GenericRequest<std::string>* request = |
- new GenericRequest<std::string>( |
- this, GetNextRequestHandle(), NULL, guid); |
- RegisterRequest(request); |
+ new GenericRequest<std::string>(this, NULL, request_manager_, guid); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveCreditCardImpl, this, request)); |
} |
@@ -548,8 +500,7 @@ void WebDataService::RemoveCreditCard(const std::string& guid) { |
WebDataService::Handle WebDataService::GetCreditCards( |
WebDataServiceConsumer* consumer) { |
WebDataRequest* request = |
- new WebDataRequest(this, GetNextRequestHandle(), consumer); |
- RegisterRequest(request); |
+ new WebDataRequest(this, consumer, request_manager_); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetCreditCardsImpl, this, request)); |
return request->GetHandle(); |
@@ -559,12 +510,8 @@ void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
const Time& delete_begin, |
const Time& delete_end) { |
GenericRequest2<Time, Time>* request = |
- new GenericRequest2<Time, Time>(this, |
- GetNextRequestHandle(), |
- NULL, |
- delete_begin, |
- delete_end); |
- RegisterRequest(request); |
+ new GenericRequest2<Time, Time>( |
+ this, NULL, request_manager_, delete_begin, delete_end); |
ScheduleTask(FROM_HERE, Bind( |
&WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, |
this, request)); |
@@ -597,49 +544,7 @@ bool WebDataService::InitWithPath(const FilePath& path) { |
} |
void WebDataService::RequestCompleted(Handle h) { |
- pending_lock_.Acquire(); |
- RequestMap::iterator i = pending_requests_.find(h); |
- if (i == pending_requests_.end()) { |
- NOTREACHED() << "Request completed called for an unknown request"; |
- pending_lock_.Release(); |
- return; |
- } |
- |
- // Take ownership of the request object and remove it from the map. |
- scoped_ptr<WebDataRequest> request(i->second); |
- pending_requests_.erase(i); |
- pending_lock_.Release(); |
- |
- // Notify the consumer if needed. |
- WebDataServiceConsumer* consumer = NULL; |
- if (!request->IsCancelled(&consumer) && consumer) { |
- consumer->OnWebDataServiceRequestDone(request->GetHandle(), |
- request->GetResult()); |
- } else { |
- // Nobody is taken ownership of the result, either because it is cancelled |
- // or there is no consumer. Destroy results that require special handling. |
- WDTypedResult const *result = request->GetResult(); |
- if (result) { |
- if (result->GetType() == AUTOFILL_PROFILES_RESULT) { |
- const WDResult<std::vector<AutofillProfile*> >* r = |
- static_cast<const WDResult<std::vector<AutofillProfile*> >*>( |
- result); |
- std::vector<AutofillProfile*> profiles = r->GetValue(); |
- STLDeleteElements(&profiles); |
- } else if (result->GetType() == AUTOFILL_CREDITCARDS_RESULT) { |
- const WDResult<std::vector<CreditCard*> >* r = |
- static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
- |
- std::vector<CreditCard*> credit_cards = r->GetValue(); |
- STLDeleteElements(&credit_cards); |
- } |
- } |
- } |
-} |
- |
-void WebDataService::RegisterRequest(WebDataRequest* request) { |
- base::AutoLock l(pending_lock_); |
- pending_requests_[request->GetHandle()] = request; |
+ request_manager_->RequestCompleted(h); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -746,11 +651,6 @@ void WebDataService::ScheduleCommit() { |
} |
} |
-int WebDataService::GetNextRequestHandle() { |
- base::AutoLock l(pending_lock_); |
- return ++next_request_handle_; |
-} |
- |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Keywords implementation. |
@@ -759,7 +659,7 @@ int WebDataService::GetNextRequestHandle() { |
void WebDataService::AddKeywordImpl(GenericRequest<TemplateURLData>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
db_->GetKeywordTable()->AddKeyword(request->arg()); |
ScheduleCommit(); |
} |
@@ -768,7 +668,7 @@ void WebDataService::AddKeywordImpl(GenericRequest<TemplateURLData>* request) { |
void WebDataService::RemoveKeywordImpl(GenericRequest<TemplateURLID>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
DCHECK(request->arg()); |
db_->GetKeywordTable()->RemoveKeyword(request->arg()); |
ScheduleCommit(); |
@@ -779,7 +679,7 @@ void WebDataService::RemoveKeywordImpl(GenericRequest<TemplateURLID>* request) { |
void WebDataService::UpdateKeywordImpl( |
GenericRequest<TemplateURLData>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
if (!db_->GetKeywordTable()->UpdateKeyword(request->arg())) { |
NOTREACHED(); |
return; |
@@ -791,7 +691,7 @@ void WebDataService::UpdateKeywordImpl( |
void WebDataService::GetKeywordsImpl(WebDataRequest* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
WDKeywordsResult result; |
db_->GetKeywordTable()->GetKeywords(&result.keywords); |
result.default_search_provider_id = |
@@ -807,7 +707,7 @@ void WebDataService::GetKeywordsImpl(WebDataRequest* request) { |
void WebDataService::SetDefaultSearchProviderImpl( |
GenericRequest<TemplateURLID>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
if (!db_->GetKeywordTable()->SetDefaultSearchProviderID(request->arg())) { |
NOTREACHED(); |
return; |
@@ -820,7 +720,7 @@ void WebDataService::SetDefaultSearchProviderImpl( |
void WebDataService::SetBuiltinKeywordVersionImpl( |
GenericRequest<int>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
if (!db_->GetKeywordTable()->SetBuiltinKeywordVersion(request->arg())) { |
NOTREACHED(); |
return; |
@@ -839,7 +739,7 @@ void WebDataService::SetBuiltinKeywordVersionImpl( |
void WebDataService::SetWebAppImageImpl( |
GenericRequest2<GURL, SkBitmap>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
db_->GetWebAppsTable()->SetWebAppImage( |
request->arg1(), request->arg2()); |
ScheduleCommit(); |
@@ -850,7 +750,7 @@ void WebDataService::SetWebAppImageImpl( |
void WebDataService::SetWebAppHasAllImagesImpl( |
GenericRequest2<GURL, bool>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
db_->GetWebAppsTable()->SetWebAppHasAllImages(request->arg1(), |
request->arg2()); |
ScheduleCommit(); |
@@ -860,7 +760,7 @@ void WebDataService::SetWebAppHasAllImagesImpl( |
void WebDataService::RemoveWebAppImpl(GenericRequest<GURL>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
db_->GetWebAppsTable()->RemoveWebApp(request->arg()); |
ScheduleCommit(); |
} |
@@ -869,7 +769,7 @@ void WebDataService::RemoveWebAppImpl(GenericRequest<GURL>* request) { |
void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
WDAppImagesResult result; |
result.has_all_images = |
db_->GetWebAppsTable()->GetWebAppHasAllImages(request->arg()); |
@@ -889,7 +789,7 @@ void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) { |
void WebDataService::RemoveWebIntentServiceImpl( |
GenericRequest<WebIntentServiceData>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
const WebIntentServiceData& service = request->arg(); |
db_->GetWebIntentsTable()->RemoveWebIntentService(service); |
ScheduleCommit(); |
@@ -900,7 +800,7 @@ void WebDataService::RemoveWebIntentServiceImpl( |
void WebDataService::AddWebIntentServiceImpl( |
GenericRequest<WebIntentServiceData>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
const WebIntentServiceData& service = request->arg(); |
db_->GetWebIntentsTable()->SetWebIntentService(service); |
ScheduleCommit(); |
@@ -912,7 +812,7 @@ void WebDataService::AddWebIntentServiceImpl( |
void WebDataService::GetWebIntentServicesImpl( |
GenericRequest<string16>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
std::vector<WebIntentServiceData> result; |
db_->GetWebIntentsTable()->GetWebIntentServicesForAction(request->arg(), |
&result); |
@@ -925,7 +825,7 @@ void WebDataService::GetWebIntentServicesImpl( |
void WebDataService::GetWebIntentServicesForURLImpl( |
GenericRequest<string16>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
std::vector<WebIntentServiceData> result; |
db_->GetWebIntentsTable()->GetWebIntentServicesForURL( |
request->arg(), &result); |
@@ -939,7 +839,7 @@ void WebDataService::GetWebIntentServicesForURLImpl( |
void WebDataService::GetAllWebIntentServicesImpl( |
GenericRequest<std::string>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
std::vector<WebIntentServiceData> result; |
db_->GetWebIntentsTable()->GetAllWebIntentServices(&result); |
request->SetResult( |
@@ -952,7 +852,7 @@ void WebDataService::GetAllWebIntentServicesImpl( |
void WebDataService::AddDefaultWebIntentServiceImpl( |
GenericRequest<DefaultWebIntentService>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
const DefaultWebIntentService& service = request->arg(); |
db_->GetWebIntentsTable()->SetDefaultService(service); |
ScheduleCommit(); |
@@ -963,7 +863,7 @@ void WebDataService::AddDefaultWebIntentServiceImpl( |
void WebDataService::RemoveDefaultWebIntentServiceImpl( |
GenericRequest<DefaultWebIntentService>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
const DefaultWebIntentService& service = request->arg(); |
db_->GetWebIntentsTable()->RemoveDefaultService(service); |
ScheduleCommit(); |
@@ -974,7 +874,7 @@ void WebDataService::RemoveDefaultWebIntentServiceImpl( |
void WebDataService::RemoveWebIntentServiceDefaultsImpl( |
GenericRequest<GURL>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
const GURL& service_url = request->arg(); |
db_->GetWebIntentsTable()->RemoveServiceDefaults(service_url); |
ScheduleCommit(); |
@@ -985,7 +885,7 @@ void WebDataService::RemoveWebIntentServiceDefaultsImpl( |
void WebDataService::GetDefaultWebIntentServicesForActionImpl( |
GenericRequest<string16>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
std::vector<DefaultWebIntentService> result; |
db_->GetWebIntentsTable()->GetDefaultServices( |
request->arg(), &result); |
@@ -999,7 +899,7 @@ void WebDataService::GetDefaultWebIntentServicesForActionImpl( |
void WebDataService::GetAllDefaultWebIntentServicesImpl( |
GenericRequest<std::string>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
std::vector<DefaultWebIntentService> result; |
db_->GetWebIntentsTable()->GetAllDefaultServices(&result); |
request->SetResult( |
@@ -1019,7 +919,7 @@ void WebDataService::GetAllDefaultWebIntentServicesImpl( |
void WebDataService::RemoveAllTokensImpl( |
GenericRequest<std::string>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
if (db_->GetTokenServiceTable()->RemoveAllTokens()) { |
ScheduleCommit(); |
} |
@@ -1030,7 +930,7 @@ void WebDataService::RemoveAllTokensImpl( |
void WebDataService::SetTokenForServiceImpl( |
GenericRequest2<std::string, std::string>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
if (db_->GetTokenServiceTable()->SetTokenForService( |
request->arg1(), request->arg2())) { |
ScheduleCommit(); |
@@ -1043,7 +943,7 @@ void WebDataService::SetTokenForServiceImpl( |
void WebDataService::GetAllTokensImpl( |
GenericRequest<std::string>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
std::map<std::string, std::string> map; |
db_->GetTokenServiceTable()->GetAllTokens(&map); |
request->SetResult( |
@@ -1061,7 +961,7 @@ void WebDataService::GetAllTokensImpl( |
void WebDataService::AddFormElementsImpl( |
GenericRequest<std::vector<FormFieldData> >* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
AutofillChangeList changes; |
if (!db_->GetAutofillTable()->AddFormFieldValues( |
request->arg(), &changes)) { |
@@ -1087,7 +987,7 @@ void WebDataService::AddFormElementsImpl( |
void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request, |
const string16& name, const string16& prefix, int limit) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
std::vector<string16> values; |
db_->GetAutofillTable()->GetFormValuesForElementName( |
name, prefix, &values, limit); |
@@ -1100,7 +1000,7 @@ void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request, |
void WebDataService::RemoveFormElementsAddedBetweenImpl( |
GenericRequest2<Time, Time>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
AutofillChangeList changes; |
if (db_->GetAutofillTable()->RemoveFormElementsAddedBetween( |
request->arg1(), request->arg2(), &changes)) { |
@@ -1124,7 +1024,7 @@ void WebDataService::RemoveFormElementsAddedBetweenImpl( |
void WebDataService::RemoveExpiredFormElementsImpl(WebDataRequest* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
AutofillChangeList changes; |
if (db_->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { |
if (!changes.empty()) { |
@@ -1148,7 +1048,7 @@ void WebDataService::RemoveExpiredFormElementsImpl(WebDataRequest* request) { |
void WebDataService::RemoveFormValueForElementNameImpl( |
GenericRequest2<string16, string16>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
const string16& name = request->arg1(); |
const string16& value = request->arg2(); |
@@ -1173,7 +1073,7 @@ void WebDataService::RemoveFormValueForElementNameImpl( |
void WebDataService::AddAutofillProfileImpl( |
GenericRequest<AutofillProfile>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
const AutofillProfile& profile = request->arg(); |
if (!db_->GetAutofillTable()->AddAutofillProfile(profile)) { |
NOTREACHED(); |
@@ -1195,7 +1095,7 @@ void WebDataService::AddAutofillProfileImpl( |
void WebDataService::UpdateAutofillProfileImpl( |
GenericRequest<AutofillProfile>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
const AutofillProfile& profile = request->arg(); |
// Only perform the update if the profile exists. It is currently |
@@ -1229,7 +1129,7 @@ void WebDataService::UpdateAutofillProfileImpl( |
void WebDataService::RemoveAutofillProfileImpl( |
GenericRequest<std::string>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
const std::string& guid = request->arg(); |
AutofillProfile* profile = NULL; |
@@ -1257,12 +1157,13 @@ void WebDataService::RemoveAutofillProfileImpl( |
void WebDataService::GetAutofillProfilesImpl(WebDataRequest* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
std::vector<AutofillProfile*> profiles; |
db_->GetAutofillTable()->GetAutofillProfiles(&profiles); |
request->SetResult( |
new WDResult<std::vector<AutofillProfile*> >(AUTOFILL_PROFILES_RESULT, |
- profiles)); |
+ base::Bind(&WebDataService::DestroyAutofillProfileResult, |
+ base::Unretained(this)), profiles)); |
} |
request->RequestComplete(); |
} |
@@ -1270,7 +1171,7 @@ void WebDataService::GetAutofillProfilesImpl(WebDataRequest* request) { |
void WebDataService::EmptyMigrationTrashImpl( |
GenericRequest<bool>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
bool notify_sync = request->arg(); |
if (notify_sync) { |
std::vector<std::string> guids; |
@@ -1321,7 +1222,7 @@ void WebDataService::EmptyMigrationTrashImpl( |
void WebDataService::AddCreditCardImpl( |
GenericRequest<CreditCard>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
const CreditCard& credit_card = request->arg(); |
if (!db_->GetAutofillTable()->AddCreditCard(credit_card)) { |
NOTREACHED(); |
@@ -1343,7 +1244,7 @@ void WebDataService::AddCreditCardImpl( |
void WebDataService::UpdateCreditCardImpl( |
GenericRequest<CreditCard>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
const CreditCard& credit_card = request->arg(); |
// It is currently valid to try to update a missing profile. We simply drop |
@@ -1376,7 +1277,7 @@ void WebDataService::UpdateCreditCardImpl( |
void WebDataService::RemoveCreditCardImpl( |
GenericRequest<std::string>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
const std::string& guid = request->arg(); |
if (!db_->GetAutofillTable()->RemoveCreditCard(guid)) { |
NOTREACHED(); |
@@ -1397,12 +1298,13 @@ void WebDataService::RemoveCreditCardImpl( |
void WebDataService::GetCreditCardsImpl(WebDataRequest* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
std::vector<CreditCard*> credit_cards; |
db_->GetAutofillTable()->GetCreditCards(&credit_cards); |
request->SetResult( |
new WDResult<std::vector<CreditCard*> >(AUTOFILL_CREDITCARDS_RESULT, |
- credit_cards)); |
+ base::Bind(&WebDataService::DestroyAutofillCreditCardResult, |
+ base::Unretained(this)), credit_cards)); |
} |
request->RequestComplete(); |
} |
@@ -1410,7 +1312,7 @@ void WebDataService::GetCreditCardsImpl(WebDataRequest* request) { |
void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( |
GenericRequest2<Time, Time>* request) { |
InitializeDatabaseIfNecessary(); |
- if (db_ && !request->IsCancelled(NULL)) { |
+ if (db_ && !request->IsCancelled()) { |
std::vector<std::string> profile_guids; |
std::vector<std::string> credit_card_guids; |
if (db_->GetAutofillTable()-> |
@@ -1462,55 +1364,20 @@ AutocompleteSyncableService* WebDataService::GetAutocompleteSyncableService() |
return autocomplete_syncable_service_; |
} |
- |
-//////////////////////////////////////////////////////////////////////////////// |
-// |
-// WebDataRequest implementation. |
-// |
-//////////////////////////////////////////////////////////////////////////////// |
- |
-WebDataService::WebDataRequest::WebDataRequest(WebDataService* service, |
- Handle handle, |
- WebDataServiceConsumer* consumer) |
- : service_(service), |
- handle_(handle), |
- cancelled_(false), |
- consumer_(consumer), |
- result_(NULL) { |
- message_loop_ = MessageLoop::current(); |
-} |
- |
-WebDataService::WebDataRequest::~WebDataRequest() { |
- delete result_; |
+void WebDataService::DestroyAutofillProfileResult(const WDTypedResult* result) { |
+ DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); |
+ const WDResult<std::vector<AutofillProfile*> >* r = |
+ static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); |
+ std::vector<AutofillProfile*> profiles = r->GetValue(); |
+ STLDeleteElements(&profiles); |
} |
-WebDataService::Handle WebDataService::WebDataRequest::GetHandle() const { |
- return handle_; |
-} |
- |
-bool WebDataService::WebDataRequest::IsCancelled( |
- WebDataServiceConsumer** consumer) const { |
- base::AutoLock l(cancel_lock_); |
- if (consumer) |
- *consumer = consumer_; |
- return cancelled_; |
-} |
- |
-void WebDataService::WebDataRequest::Cancel() { |
- base::AutoLock l(cancel_lock_); |
- cancelled_ = true; |
- consumer_ = NULL; |
-} |
- |
-void WebDataService::WebDataRequest::SetResult(WDTypedResult* r) { |
- result_ = r; |
-} |
- |
-const WDTypedResult* WebDataService::WebDataRequest::GetResult() const { |
- return result_; |
-} |
+void WebDataService::DestroyAutofillCreditCardResult( |
+ const WDTypedResult* result) { |
+ DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
+ const WDResult<std::vector<CreditCard*> >* r = |
+ static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
-void WebDataService::WebDataRequest::RequestComplete() { |
- message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted, |
- service_.get(), handle_)); |
+ std::vector<CreditCard*> credit_cards = r->GetValue(); |
+ STLDeleteElements(&credit_cards); |
} |