Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1830)

Unified Diff: chrome/browser/autofill/personal_data_manager.cc

Issue 10908065: Introduce a couple of abstract bases for WebDataService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..cd73880e34ab568f92f3e09fcc9b99994a00c2f6 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,11 @@ 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_refptr<WebDataServiceBase> service =
+ WebDataServiceBase::ForProfile(profile_);
+ if (service) {
dhollowa 2012/09/04 21:53:52 nit: no need for {} with single-line if-body.
Jói 2012/09/06 01:17:27 Done.
+ AutofillWebData::ForService(service)->RemoveExpiredFormElements();
+ }
}
}
}
@@ -201,8 +198,8 @@ void PersonalDataManager::OnStateChanged() {
if (!profile_ || profile_->IsOffTheRecord())
return;
- scoped_refptr<WebDataService> web_data_service =
- WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
+ scoped_refptr<WebDataServiceBase> web_data_service =
+ WebDataServiceBase::ForProfile(profile_);
if (!web_data_service.get()) {
NOTREACHED();
return;
@@ -214,7 +211,7 @@ void PersonalDataManager::OnStateChanged() {
return;
if (sync_service->ShouldPushChanges()) {
- web_data_service->EmptyMigrationTrash(true);
+ AutofillWebData::ForService(web_data_service)->EmptyMigrationTrash(true);
sync_service->RemoveObserver(this);
}
}
@@ -229,12 +226,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();
+ scoped_refptr<WebDataServiceBase> web_data_service =
+ content::Source<WebDataServiceBase>(source).ptr();
DCHECK(web_data_service.get() &&
- web_data_service.get() == WebDataServiceFactory::GetForProfile(
- profile_, Profile::EXPLICIT_ACCESS).get());
+ web_data_service.get() == WebDataServiceBase::ForProfile(
+ profile_).get());
Refresh();
}
@@ -367,8 +364,8 @@ void PersonalDataManager::AddProfile(const AutofillProfile& profile) {
if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid()))
return;
- scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
- profile_, Profile::EXPLICIT_ACCESS);
+ scoped_refptr<WebDataServiceBase> wds =
dhollowa 2012/09/04 21:53:52 Maybe some helpers like |autofill_data()| and |web
Jói 2012/09/06 01:17:27 Will look at this once we've finished discussing h
+ WebDataServiceBase::ForProfile(profile_);
if (!wds.get())
return;
@@ -377,7 +374,7 @@ void PersonalDataManager::AddProfile(const AutofillProfile& profile) {
return;
// Add the new profile to the web database.
- wds->AddAutofillProfile(profile);
+ AutofillWebData::ForService(wds)->AddAutofillProfile(profile);
// Refresh our local cache and send notifications to observers.
Refresh();
@@ -395,13 +392,13 @@ void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) {
return;
}
- scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
- profile_, Profile::EXPLICIT_ACCESS);
+ scoped_refptr<WebDataServiceBase> wds =
+ WebDataServiceBase::ForProfile(profile_);
if (!wds.get())
return;
// Make the update.
- wds->UpdateAutofillProfile(profile);
+ AutofillWebData::ForService(wds)->UpdateAutofillProfile(profile);
// Refresh our local cache and send notifications to observers.
Refresh();
@@ -414,13 +411,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);
+ scoped_refptr<WebDataServiceBase> wds =
+ WebDataServiceBase::ForProfile(profile_);
if (!wds.get())
return;
// Remove the profile.
- wds->RemoveAutofillProfile(guid);
+ AutofillWebData::ForService(wds)->RemoveAutofillProfile(guid);
// Refresh our local cache and send notifications to observers.
Refresh();
@@ -446,8 +443,8 @@ 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);
+ scoped_refptr<WebDataServiceBase> wds =
+ WebDataServiceBase::ForProfile(profile_);
if (!wds.get())
return;
@@ -456,7 +453,7 @@ void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) {
return;
// Add the new credit card to the web database.
- wds->AddCreditCard(credit_card);
+ AutofillWebData::ForService(wds)->AddCreditCard(credit_card);
// Refresh our local cache and send notifications to observers.
Refresh();
@@ -474,13 +471,13 @@ void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) {
return;
}
- scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
- profile_, Profile::EXPLICIT_ACCESS);
+ scoped_refptr<WebDataServiceBase> wds =
+ WebDataServiceBase::ForProfile(profile_);
if (!wds.get())
return;
// Make the update.
- wds->UpdateCreditCard(credit_card);
+ AutofillWebData::ForService(wds)->UpdateCreditCard(credit_card);
// Refresh our local cache and send notifications to observers.
Refresh();
@@ -493,13 +490,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);
+ scoped_refptr<WebDataServiceBase> wds =
+ WebDataServiceBase::ForProfile(profile_);
if (!wds.get())
return;
// Remove the credit card.
- wds->RemoveCreditCard(guid);
+ AutofillWebData::ForService(wds)->RemoveCreditCard(guid);
// Refresh our local cache and send notifications to observers.
Refresh();
@@ -583,8 +580,8 @@ 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);
+ scoped_refptr<WebDataServiceBase> web_data_service =
+ WebDataServiceBase::ForProfile(profile_);
if (!web_data_service.get())
return;
@@ -594,7 +591,7 @@ void PersonalDataManager::Init(Profile* profile) {
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,10 +676,11 @@ void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) {
address_of<AutofillProfile>);
AutofillProfile::AdjustInferredLabels(&profile_pointers);
- scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
- profile_, Profile::EXPLICIT_ACCESS);
+ scoped_refptr<WebDataServiceBase> wds =
+ WebDataServiceBase::ForProfile(profile_);
if (!wds.get())
return;
+ AutofillWebData* autofill_data = AutofillWebData::ForService(wds);
// Any profiles that are not in the new profile list should be removed from
// the web database.
@@ -690,14 +688,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 +703,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,24 +729,25 @@ void PersonalDataManager::SetCreditCards(
std::mem_fun_ref(&CreditCard::IsEmpty)),
credit_cards->end());
- scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
- profile_, Profile::EXPLICIT_ACCESS);
+ scoped_refptr<WebDataServiceBase> wds =
+ WebDataServiceBase::ForProfile(profile_);
if (!wds.get())
return;
+ AutofillWebData* autofill_data = AutofillWebData::ForService(wds);
// Any credit cards that are not in the new credit card list should be
// removed.
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 +755,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,8 +770,8 @@ void PersonalDataManager::SetCreditCards(
}
void PersonalDataManager::LoadProfiles() {
- scoped_refptr<WebDataService> web_data_service =
- WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
+ scoped_refptr<WebDataServiceBase> web_data_service =
+ WebDataServiceBase::ForProfile(profile_);
if (!web_data_service.get()) {
NOTREACHED();
return;
@@ -780,7 +779,8 @@ void PersonalDataManager::LoadProfiles() {
CancelPendingQuery(&pending_profiles_query_);
- pending_profiles_query_ = web_data_service->GetAutofillProfiles(this);
+ pending_profiles_query_ = AutofillWebData::ForService(
+ web_data_service)->GetAutofillProfiles(this);
}
// Win and Linux implementations do nothing. Mac implementation fills in the
@@ -791,8 +791,8 @@ void PersonalDataManager::LoadAuxiliaryProfiles() const {
#endif
void PersonalDataManager::LoadCreditCards() {
- scoped_refptr<WebDataService> web_data_service =
- WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
+ scoped_refptr<WebDataServiceBase> web_data_service =
+ WebDataServiceBase::ForProfile(profile_);
if (!web_data_service.get()) {
NOTREACHED();
return;
@@ -800,10 +800,11 @@ void PersonalDataManager::LoadCreditCards() {
CancelPendingQuery(&pending_creditcards_query_);
- pending_creditcards_query_ = web_data_service->GetCreditCards(this);
+ pending_creditcards_query_ = AutofillWebData::ForService(
+ web_data_service)->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 +825,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,11 +841,11 @@ 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);
+ scoped_refptr<WebDataServiceBase> web_data_service =
+ WebDataServiceBase::ForProfile(profile_);
if (!web_data_service.get()) {
NOTREACHED();
return;
@@ -913,8 +914,8 @@ void PersonalDataManager::EmptyMigrationTrash() {
if (!profile_ || profile_->IsOffTheRecord())
return;
- scoped_refptr<WebDataService> web_data_service =
- WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
+ scoped_refptr<WebDataServiceBase> web_data_service =
+ WebDataServiceBase::ForProfile(profile_);
if (!web_data_service.get()) {
NOTREACHED();
return;
@@ -925,10 +926,12 @@ void PersonalDataManager::EmptyMigrationTrash() {
if (!sync_service)
return;
+ AutofillWebData* autofill_data =
+ AutofillWebData::ForService(web_data_service);
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.

Powered by Google App Engine
This is Rietveld 408576698