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..55f373f147922ef3521ef0dd7ac9edc57da5d484 100644 |
--- a/chrome/browser/webdata/web_data_service.cc |
+++ b/chrome/browser/webdata/web_data_service.cc |
@@ -84,12 +84,13 @@ WebDataService::WebDataService() |
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) |
// if you do not want to instantiate WebDataService in your test. |
DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); |
+ |
+ wdr_mgr_.reset(new WebDataRequestManager()); |
} |
// static |
@@ -127,13 +128,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(); |
+ wdr_mgr_->CancelRequest(h); |
} |
content::NotificationSource WebDataService::GetNotificationSource() { |
@@ -157,25 +152,26 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, data); |
+ wdr_mgr_->RegisterRequest(request); |
dhollowa
2013/01/04 01:34:50
The common pattern here is:
(1) new GenericReque
Cait (Slow)
2013/01/04 22:59:29
Done.
|
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, wdr_mgr_->GetNextRequestHandle(), NULL, id); |
+ wdr_mgr_->RegisterRequest(request); |
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, wdr_mgr_->GetNextRequestHandle(), NULL, data); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::UpdateKeywordImpl, this, request)); |
} |
@@ -183,8 +179,8 @@ void WebDataService::UpdateKeyword(const TemplateURLData& data) { |
WebDataService::Handle WebDataService::GetKeywords( |
WebDataServiceConsumer* consumer) { |
WebDataRequest* request = |
- new WebDataRequest(this, GetNextRequestHandle(), consumer); |
- RegisterRequest(request); |
+ new WebDataRequest(this, wdr_mgr_->GetNextRequestHandle(), consumer); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetKeywordsImpl, this, request)); |
return request->GetHandle(); |
@@ -192,16 +188,16 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, url ? url->id() : 0); |
+ wdr_mgr_->RegisterRequest(request); |
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, wdr_mgr_->GetNextRequestHandle(), NULL, version); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, Bind(&WebDataService::SetBuiltinKeywordVersionImpl, |
this, request)); |
} |
@@ -215,9 +211,9 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, app_url, image); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::SetWebAppImageImpl, this, request)); |
} |
@@ -225,17 +221,19 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, app_url, |
+ has_all_images); |
+ wdr_mgr_->RegisterRequest(request); |
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, wdr_mgr_->GetNextRequestHandle(), NULL, app_url); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveWebAppImpl, this, request)); |
} |
@@ -244,8 +242,9 @@ 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, wdr_mgr_->GetNextRequestHandle(), consumer, app_url); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetWebAppImagesImpl, this, request)); |
return request->GetHandle(); |
@@ -260,8 +259,8 @@ WebDataService::Handle WebDataService::GetWebAppImages( |
void WebDataService::AddWebIntentService(const WebIntentServiceData& service) { |
GenericRequest<WebIntentServiceData>* request = |
new GenericRequest<WebIntentServiceData>( |
- this, GetNextRequestHandle(), NULL, service); |
- RegisterRequest(request); |
+ this, wdr_mgr_->GetNextRequestHandle(), NULL, service); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::AddWebIntentServiceImpl, this, request)); |
} |
@@ -270,8 +269,8 @@ void WebDataService::RemoveWebIntentService( |
const WebIntentServiceData& service) { |
GenericRequest<WebIntentServiceData>* request = |
new GenericRequest<WebIntentServiceData>( |
- this, GetNextRequestHandle(), NULL, service); |
- RegisterRequest(request); |
+ this, wdr_mgr_->GetNextRequestHandle(), NULL, service); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl, |
this, request)); |
} |
@@ -280,9 +279,10 @@ 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, wdr_mgr_->GetNextRequestHandle(), consumer, action); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetWebIntentServicesImpl, this, request)); |
return request->GetHandle(); |
@@ -292,9 +292,10 @@ 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, wdr_mgr_->GetNextRequestHandle(), consumer, service_url); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, Bind(&WebDataService::GetWebIntentServicesForURLImpl, |
this, request)); |
return request->GetHandle(); |
@@ -304,9 +305,10 @@ 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, wdr_mgr_->GetNextRequestHandle(), consumer, std::string()); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, Bind(&WebDataService::GetAllWebIntentServicesImpl, |
this, request)); |
return request->GetHandle(); |
@@ -316,8 +318,8 @@ void WebDataService::AddDefaultWebIntentService( |
const DefaultWebIntentService& service) { |
GenericRequest<DefaultWebIntentService>* request = |
new GenericRequest<DefaultWebIntentService>( |
- this, GetNextRequestHandle(), NULL, service); |
- RegisterRequest(request); |
+ this, wdr_mgr_->GetNextRequestHandle(), NULL, service); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this, |
request)); |
@@ -327,8 +329,8 @@ void WebDataService::RemoveDefaultWebIntentService( |
const DefaultWebIntentService& service) { |
GenericRequest<DefaultWebIntentService>* request = |
new GenericRequest<DefaultWebIntentService>( |
- this, GetNextRequestHandle(), NULL, service); |
- RegisterRequest(request); |
+ this, wdr_mgr_->GetNextRequestHandle(), NULL, service); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this, |
request)); |
@@ -338,8 +340,8 @@ void WebDataService::RemoveWebIntentServiceDefaults( |
const GURL& service_url) { |
GenericRequest<GURL>* request = |
new GenericRequest<GURL>( |
- this, GetNextRequestHandle(), NULL, service_url); |
- RegisterRequest(request); |
+ this, wdr_mgr_->GetNextRequestHandle(), NULL, service_url); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask( |
FROM_HERE, |
Bind(&WebDataService::RemoveWebIntentServiceDefaultsImpl, this, request)); |
@@ -350,8 +352,8 @@ WebDataService::Handle WebDataService::GetDefaultWebIntentServicesForAction( |
WebDataServiceConsumer* consumer) { |
DCHECK(consumer); |
GenericRequest<string16>* request = new GenericRequest<string16>( |
- this, GetNextRequestHandle(), consumer, action); |
- RegisterRequest(request); |
+ this, wdr_mgr_->GetNextRequestHandle(), consumer, action); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl, |
this, request)); |
@@ -362,8 +364,8 @@ WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices( |
WebDataServiceConsumer* consumer) { |
DCHECK(consumer); |
GenericRequest<std::string>* request = new GenericRequest<std::string>( |
- this, GetNextRequestHandle(), consumer, std::string()); |
- RegisterRequest(request); |
+ this, wdr_mgr_->GetNextRequestHandle(), consumer, std::string()); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl, |
this, request)); |
@@ -380,8 +382,8 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, service, token); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::SetTokenForServiceImpl, this, request)); |
} |
@@ -389,8 +391,8 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, std::string()); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveAllTokensImpl, this, request)); |
} |
@@ -401,8 +403,8 @@ WebDataService::Handle WebDataService::GetAllTokens( |
GenericRequest<std::string>* request = |
new GenericRequest<std::string>( |
- this, GetNextRequestHandle(), consumer, std::string()); |
- RegisterRequest(request); |
+ this, wdr_mgr_->GetNextRequestHandle(), consumer, std::string()); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetAllTokensImpl, this, request)); |
return request->GetHandle(); |
@@ -418,8 +420,8 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, fields); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::AddFormElementsImpl, this, request)); |
} |
@@ -428,8 +430,8 @@ 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, wdr_mgr_->GetNextRequestHandle(), consumer); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetFormValuesForElementNameImpl, |
this, request, name, prefix, limit)); |
@@ -439,12 +441,9 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, delete_begin, delete_end); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl, |
this, request)); |
@@ -452,8 +451,8 @@ void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, |
void WebDataService::RemoveExpiredFormElements() { |
WebDataRequest* request = |
- new WebDataRequest(this, GetNextRequestHandle(), NULL); |
- RegisterRequest(request); |
+ new WebDataRequest(this, wdr_mgr_->GetNextRequestHandle(), NULL); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveExpiredFormElementsImpl, |
this, request)); |
@@ -462,11 +461,9 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, name, value); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveFormValueForElementNameImpl, |
this, request)); |
@@ -475,8 +472,8 @@ void WebDataService::RemoveFormValueForElementName( |
void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { |
GenericRequest<AutofillProfile>* request = |
new GenericRequest<AutofillProfile>( |
- this, GetNextRequestHandle(), NULL, profile); |
- RegisterRequest(request); |
+ this, wdr_mgr_->GetNextRequestHandle(), NULL, profile); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::AddAutofillProfileImpl, this, request)); |
} |
@@ -484,8 +481,8 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, profile); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::UpdateAutofillProfileImpl, this, request)); |
} |
@@ -493,8 +490,8 @@ void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) { |
void WebDataService::RemoveAutofillProfile(const std::string& guid) { |
GenericRequest<std::string>* request = |
new GenericRequest<std::string>( |
- this, GetNextRequestHandle(), NULL, guid); |
- RegisterRequest(request); |
+ this, wdr_mgr_->GetNextRequestHandle(), NULL, guid); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveAutofillProfileImpl, this, request)); |
} |
@@ -502,8 +499,8 @@ 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, wdr_mgr_->GetNextRequestHandle(), consumer); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetAutofillProfilesImpl, this, request)); |
return request->GetHandle(); |
@@ -512,8 +509,8 @@ WebDataService::Handle WebDataService::GetAutofillProfiles( |
void WebDataService::EmptyMigrationTrash(bool notify_sync) { |
GenericRequest<bool>* request = |
new GenericRequest<bool>( |
- this, GetNextRequestHandle(), NULL, notify_sync); |
- RegisterRequest(request); |
+ this, wdr_mgr_->GetNextRequestHandle(), NULL, notify_sync); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::EmptyMigrationTrashImpl, this, request)); |
} |
@@ -521,8 +518,8 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, credit_card); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::AddCreditCardImpl, this, request)); |
} |
@@ -530,8 +527,8 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, credit_card); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::UpdateCreditCardImpl, this, request)); |
} |
@@ -539,8 +536,8 @@ void WebDataService::UpdateCreditCard(const CreditCard& credit_card) { |
void WebDataService::RemoveCreditCard(const std::string& guid) { |
GenericRequest<std::string>* request = |
new GenericRequest<std::string>( |
- this, GetNextRequestHandle(), NULL, guid); |
- RegisterRequest(request); |
+ this, wdr_mgr_->GetNextRequestHandle(), NULL, guid); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::RemoveCreditCardImpl, this, request)); |
} |
@@ -548,8 +545,8 @@ 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, wdr_mgr_->GetNextRequestHandle(), consumer); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, |
Bind(&WebDataService::GetCreditCardsImpl, this, request)); |
return request->GetHandle(); |
@@ -559,12 +556,10 @@ 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, wdr_mgr_->GetNextRequestHandle(), NULL, delete_begin, |
+ delete_end); |
+ wdr_mgr_->RegisterRequest(request); |
ScheduleTask(FROM_HERE, Bind( |
&WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, |
this, request)); |
@@ -597,49 +592,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; |
+ wdr_mgr_->RequestCompleted(h); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -746,11 +699,6 @@ void WebDataService::ScheduleCommit() { |
} |
} |
-int WebDataService::GetNextRequestHandle() { |
- base::AutoLock l(pending_lock_); |
- return ++next_request_handle_; |
-} |
- |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Keywords implementation. |
@@ -1461,56 +1409,3 @@ 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_; |
-} |
- |
-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::WebDataRequest::RequestComplete() { |
- message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted, |
- service_.get(), handle_)); |
-} |