Chromium Code Reviews| Index: chrome/browser/autofill/personal_data_manager.cc |
| diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc |
| index 4e861982274bc7587e7e8a2ab3a5871b48855050..9b1cc0a0cfcb1af9868b8fc8f68f44dced9a24b0 100644 |
| --- a/chrome/browser/autofill/personal_data_manager.cc |
| +++ b/chrome/browser/autofill/personal_data_manager.cc |
| @@ -23,9 +23,6 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/sync/profile_sync_service.h" |
| #include "chrome/browser/sync/profile_sync_service_factory.h" |
| -#include "chrome/browser/webdata/autofill_entry.h" |
| -#include "chrome/browser/webdata/web_data_service.h" |
| -#include "chrome/browser/webdata/web_data_service_factory.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/pref_names.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -127,7 +124,7 @@ PersonalDataManager::~PersonalDataManager() { |
| } |
| void PersonalDataManager::OnWebDataServiceRequestDone( |
| - WebDataService::Handle h, |
| + WebDataServiceBase::Handle h, |
| const WDTypedResult* result) { |
| DCHECK(pending_profiles_query_ || pending_creditcards_query_); |
| @@ -172,11 +169,10 @@ void PersonalDataManager::OnWebDataServiceRequestDone( |
| if (sync_service && (!sync_service->HasSyncSetupCompleted() || |
| !PrefServiceBase::ForProfile(profile_)->GetBoolean( |
| prefs::kSyncAutofill))) { |
| - scoped_refptr<WebDataService> web_data_service = |
| - WebDataServiceFactory::GetForProfile(profile_, |
| - Profile::EXPLICIT_ACCESS); |
| - if (web_data_service) |
| - web_data_service->RemoveExpiredFormElements(); |
| + scoped_ref<AutofillWebDataService> service = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (service) |
| + service->RemoveExpiredFormElements(); |
| } |
| } |
| } |
| @@ -201,9 +197,9 @@ void PersonalDataManager::OnStateChanged() { |
| if (!profile_ || profile_->IsOffTheRecord()) |
| return; |
| - scoped_refptr<WebDataService> web_data_service = |
| - WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| - if (!web_data_service.get()) { |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
|
dhollowa
2012/09/07 16:04:01
|service| or |data_service|? And elsewhere.
|
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) { |
| NOTREACHED(); |
| return; |
| } |
| @@ -214,7 +210,7 @@ void PersonalDataManager::OnStateChanged() { |
| return; |
| if (sync_service->ShouldPushChanges()) { |
| - web_data_service->EmptyMigrationTrash(true); |
| + autofill_data->EmptyMigrationTrash(true); |
| sync_service->RemoveObserver(this); |
| } |
| } |
| @@ -229,12 +225,12 @@ void PersonalDataManager::Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); |
| - scoped_refptr<WebDataService> web_data_service = |
| - content::Source<WebDataService>(source).ptr(); |
| - DCHECK(web_data_service.get() && |
| - web_data_service.get() == WebDataServiceFactory::GetForProfile( |
| - profile_, Profile::EXPLICIT_ACCESS).get()); |
| + scoped_refptr<WebDataServiceBase> notification_source = |
| + content::Source<WebDataServiceBase>(source).ptr(); |
| + |
| + DCHECK(autofill_data_.get() && |
|
dhollowa
2012/09/07 16:04:01
Compile error with |autofill_data_|?
|
| + autofill_data_->NotificationSource() == notification_source); |
| Refresh(); |
| } |
| @@ -367,9 +363,9 @@ void PersonalDataManager::AddProfile(const AutofillProfile& profile) { |
| if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
| return; |
| - scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
| - profile_, Profile::EXPLICIT_ACCESS); |
| - if (!wds.get()) |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) |
| return; |
| // Don't add a duplicate. |
| @@ -377,7 +373,7 @@ void PersonalDataManager::AddProfile(const AutofillProfile& profile) { |
| return; |
| // Add the new profile to the web database. |
| - wds->AddAutofillProfile(profile); |
| + autofill_data->AddAutofillProfile(profile); |
| // Refresh our local cache and send notifications to observers. |
| Refresh(); |
| @@ -395,13 +391,13 @@ void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { |
| return; |
| } |
| - scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
| - profile_, Profile::EXPLICIT_ACCESS); |
| - if (!wds.get()) |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) |
| return; |
| // Make the update. |
| - wds->UpdateAutofillProfile(profile); |
| + autofill_data->UpdateAutofillProfile(profile); |
| // Refresh our local cache and send notifications to observers. |
| Refresh(); |
| @@ -414,13 +410,13 @@ void PersonalDataManager::RemoveProfile(const std::string& guid) { |
| if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) |
| return; |
| - scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
| - profile_, Profile::EXPLICIT_ACCESS); |
| - if (!wds.get()) |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) |
| return; |
| // Remove the profile. |
| - wds->RemoveAutofillProfile(guid); |
| + autofill_data->RemoveAutofillProfile(guid); |
| // Refresh our local cache and send notifications to observers. |
| Refresh(); |
| @@ -446,9 +442,9 @@ void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { |
| if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
| return; |
| - scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
| - profile_, Profile::EXPLICIT_ACCESS); |
| - if (!wds.get()) |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) |
| return; |
| // Don't add a duplicate. |
| @@ -456,7 +452,7 @@ void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { |
| return; |
| // Add the new credit card to the web database. |
| - wds->AddCreditCard(credit_card); |
| + autofill_data->AddCreditCard(credit_card); |
| // Refresh our local cache and send notifications to observers. |
| Refresh(); |
| @@ -474,13 +470,13 @@ void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { |
| return; |
| } |
| - scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
| - profile_, Profile::EXPLICIT_ACCESS); |
| - if (!wds.get()) |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) |
| return; |
| // Make the update. |
| - wds->UpdateCreditCard(credit_card); |
| + autofill_data->UpdateCreditCard(credit_card); |
| // Refresh our local cache and send notifications to observers. |
| Refresh(); |
| @@ -493,13 +489,13 @@ void PersonalDataManager::RemoveCreditCard(const std::string& guid) { |
| if (!FindByGUID<CreditCard>(credit_cards_, guid)) |
| return; |
| - scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
| - profile_, Profile::EXPLICIT_ACCESS); |
| - if (!wds.get()) |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) |
| return; |
| // Remove the credit card. |
| - wds->RemoveCreditCard(guid); |
| + autofill_data->RemoveCreditCard(guid); |
| // Refresh our local cache and send notifications to observers. |
| Refresh(); |
| @@ -583,18 +579,19 @@ void PersonalDataManager::Init(Profile* profile) { |
| metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); |
| // WebDataService may not be available in tests. |
| - scoped_refptr<WebDataService> web_data_service = |
| - WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| - if (!web_data_service.get()) |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) |
| return; |
| LoadProfiles(); |
| LoadCreditCards(); |
| + // TODO(joi): How to handle? |
| notification_registrar_.Add( |
| this, |
| chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, |
| - content::Source<WebDataService>(web_data_service)); |
| + content::Source<WebDataServiceBase>(web_data_service)); |
| } |
| bool PersonalDataManager::IsAutofillEnabled() const { |
| @@ -679,9 +676,9 @@ void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { |
| address_of<AutofillProfile>); |
| AutofillProfile::AdjustInferredLabels(&profile_pointers); |
| - scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
| - profile_, Profile::EXPLICIT_ACCESS); |
| - if (!wds.get()) |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) |
| return; |
| // Any profiles that are not in the new profile list should be removed from |
| @@ -690,14 +687,14 @@ void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { |
| web_profiles_.begin(); |
| iter != web_profiles_.end(); ++iter) { |
| if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) |
| - wds->RemoveAutofillProfile((*iter)->guid()); |
| + autofill_data->RemoveAutofillProfile((*iter)->guid()); |
| } |
| // Update the web database with the existing profiles. |
| for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); |
| iter != profiles->end(); ++iter) { |
| if (FindByGUID<AutofillProfile>(web_profiles_, iter->guid())) |
| - wds->UpdateAutofillProfile(*iter); |
| + autofill_data->UpdateAutofillProfile(*iter); |
| } |
| // Add the new profiles to the web database. Don't add a duplicate. |
| @@ -705,7 +702,7 @@ void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { |
| iter != profiles->end(); ++iter) { |
| if (!FindByGUID<AutofillProfile>(web_profiles_, iter->guid()) && |
| !FindByContents(web_profiles_, *iter)) |
| - wds->AddAutofillProfile(*iter); |
| + autofill_data->AddAutofillProfile(*iter); |
| } |
| // Copy in the new profiles. |
| @@ -731,9 +728,9 @@ void PersonalDataManager::SetCreditCards( |
| std::mem_fun_ref(&CreditCard::IsEmpty)), |
| credit_cards->end()); |
| - scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
| - profile_, Profile::EXPLICIT_ACCESS); |
| - if (!wds.get()) |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) |
| return; |
| // Any credit cards that are not in the new credit card list should be |
| @@ -741,14 +738,14 @@ void PersonalDataManager::SetCreditCards( |
| for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); |
| iter != credit_cards_.end(); ++iter) { |
| if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) |
| - wds->RemoveCreditCard((*iter)->guid()); |
| + autofill_data->RemoveCreditCard((*iter)->guid()); |
| } |
| // Update the web database with the existing credit cards. |
| for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
| iter != credit_cards->end(); ++iter) { |
| if (FindByGUID<CreditCard>(credit_cards_, iter->guid())) |
| - wds->UpdateCreditCard(*iter); |
| + autofill_data->UpdateCreditCard(*iter); |
| } |
| // Add the new credit cards to the web database. Don't add a duplicate. |
| @@ -756,7 +753,7 @@ void PersonalDataManager::SetCreditCards( |
| iter != credit_cards->end(); ++iter) { |
| if (!FindByGUID<CreditCard>(credit_cards_, iter->guid()) && |
| !FindByContents(credit_cards_, *iter)) |
| - wds->AddCreditCard(*iter); |
| + autofill_data->AddCreditCard(*iter); |
| } |
| // Copy in the new credit cards. |
| @@ -771,16 +768,16 @@ void PersonalDataManager::SetCreditCards( |
| } |
| void PersonalDataManager::LoadProfiles() { |
| - scoped_refptr<WebDataService> web_data_service = |
| - WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| - if (!web_data_service.get()) { |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) { |
| NOTREACHED(); |
| return; |
| } |
| CancelPendingQuery(&pending_profiles_query_); |
| - pending_profiles_query_ = web_data_service->GetAutofillProfiles(this); |
| + pending_profiles_query_ = autofill_data->GetAutofillProfiles(this); |
| } |
| // Win and Linux implementations do nothing. Mac implementation fills in the |
| @@ -791,19 +788,19 @@ void PersonalDataManager::LoadAuxiliaryProfiles() const { |
| #endif |
| void PersonalDataManager::LoadCreditCards() { |
| - scoped_refptr<WebDataService> web_data_service = |
| - WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| - if (!web_data_service.get()) { |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) { |
| NOTREACHED(); |
| return; |
| } |
| CancelPendingQuery(&pending_creditcards_query_); |
| - pending_creditcards_query_ = web_data_service->GetCreditCards(this); |
| + pending_creditcards_query_ = autofill_data->GetCreditCards(this); |
| } |
| -void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, |
| +void PersonalDataManager::ReceiveLoadedProfiles(WebDataServiceBase::Handle h, |
| const WDTypedResult* result) { |
| DCHECK_EQ(pending_profiles_query_, h); |
| @@ -824,7 +821,7 @@ void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, |
| } |
| void PersonalDataManager::ReceiveLoadedCreditCards( |
| - WebDataService::Handle h, const WDTypedResult* result) { |
| + WebDataServiceBase::Handle h, const WDTypedResult* result) { |
| DCHECK_EQ(pending_creditcards_query_, h); |
| pending_creditcards_query_ = 0; |
| @@ -840,16 +837,16 @@ void PersonalDataManager::ReceiveLoadedCreditCards( |
| } |
| } |
| -void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) { |
| +void PersonalDataManager::CancelPendingQuery( |
| + WebDataServiceBase::Handle* handle) { |
| if (*handle) { |
| - scoped_refptr<WebDataService> web_data_service = |
| - WebDataServiceFactory::GetForProfile(profile_, |
| - Profile::EXPLICIT_ACCESS); |
| - if (!web_data_service.get()) { |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) { |
| NOTREACHED(); |
| return; |
| } |
| - web_data_service->CancelRequest(*handle); |
| + autofill_data->CancelRequest(*handle); |
| } |
| *handle = 0; |
| } |
| @@ -913,9 +910,9 @@ void PersonalDataManager::EmptyMigrationTrash() { |
| if (!profile_ || profile_->IsOffTheRecord()) |
| return; |
| - scoped_refptr<WebDataService> web_data_service = |
| - WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| - if (!web_data_service.get()) { |
| + scoped_ptr<AutofillWebDataService> autofill_data = |
| + AutofillWebDataService::ForContext(profile_); |
| + if (!autofill_data.get()) { |
| NOTREACHED(); |
| return; |
| } |
| @@ -926,9 +923,9 @@ void PersonalDataManager::EmptyMigrationTrash() { |
| return; |
| if (!sync_service->HasSyncSetupCompleted()) { |
| - web_data_service->EmptyMigrationTrash(false); |
| + autofill_data->EmptyMigrationTrash(false); |
| } else if (sync_service->ShouldPushChanges()) { |
| - web_data_service->EmptyMigrationTrash(true); |
| + autofill_data->EmptyMigrationTrash(true); |
| } else { |
| // Install ourself as a listener so we can empty the trash once the |
| // sync service becomes available. |