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

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

Issue 13928035: WIP Component build of autofill Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make windows compiling Created 7 years, 8 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: components/autofill/browser/personal_data_manager.cc
diff --git a/components/autofill/browser/personal_data_manager.cc b/components/autofill/browser/personal_data_manager.cc
index 481ca2468d0efa7ac663d0d3788a9b7ccc28cc6b..c8f75eb38328a35f0d3f53cc750e9eeff293fe93 100644
--- a/components/autofill/browser/personal_data_manager.cc
+++ b/components/autofill/browser/personal_data_manager.cc
@@ -139,21 +139,21 @@ PersonalDataManager::PersonalDataManager(const std::string& app_locale)
metric_logger_(new AutofillMetrics),
has_logged_profile_count_(false) {}
-void PersonalDataManager::Init(BrowserContext* browser_context) {
+void PersonalDataManager::Init(BrowserContext* browser_context,
+ AutofillWebDataService* autofill_webdata) {
browser_context_ = browser_context;
metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled());
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
-
// WebDataService may not be available in tests.
- if (!autofill_data.get())
+ if (!autofill_webdata)
return;
+ autofill_webdata_ = autofill_webdata;
+
LoadProfiles();
LoadCreditCards();
- autofill_data->AddObserver(this);
+ autofill_webdata_->AddObserver(this);
}
PersonalDataManager::~PersonalDataManager() {
@@ -163,10 +163,8 @@ PersonalDataManager::~PersonalDataManager() {
if (!browser_context_)
return;
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (autofill_data.get())
- autofill_data->RemoveObserver(this);
+ if (autofill_webdata_.get())
+ autofill_webdata_->RemoveObserver(this);
}
void PersonalDataManager::OnWebDataServiceRequestDone(
@@ -365,9 +363,7 @@ void PersonalDataManager::AddProfile(const AutofillProfile& profile) {
if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid()))
return;
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ if (!autofill_webdata_.get())
return;
// Don't add a duplicate.
@@ -375,7 +371,7 @@ void PersonalDataManager::AddProfile(const AutofillProfile& profile) {
return;
// Add the new profile to the web database.
- autofill_data->AddAutofillProfile(profile);
+ autofill_webdata_->AddAutofillProfile(profile);
// Refresh our local cache and send notifications to observers.
Refresh();
@@ -393,13 +389,11 @@ void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) {
return;
}
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ if (!autofill_webdata_.get())
return;
// Make the update.
- autofill_data->UpdateAutofillProfile(profile);
+ autofill_webdata_->UpdateAutofillProfile(profile);
// Refresh our local cache and send notifications to observers.
Refresh();
@@ -426,9 +420,7 @@ void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) {
if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid()))
return;
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ if (!autofill_webdata_.get())
return;
// Don't add a duplicate.
@@ -436,7 +428,7 @@ void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) {
return;
// Add the new credit card to the web database.
- autofill_data->AddCreditCard(credit_card);
+ autofill_webdata_->AddCreditCard(credit_card);
// Refresh our local cache and send notifications to observers.
Refresh();
@@ -454,13 +446,11 @@ void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) {
return;
}
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ if (!autofill_webdata_.get())
return;
// Make the update.
- autofill_data->UpdateCreditCard(credit_card);
+ autofill_webdata_->UpdateCreditCard(credit_card);
// Refresh our local cache and send notifications to observers.
Refresh();
@@ -476,15 +466,13 @@ void PersonalDataManager::RemoveByGUID(const std::string& guid) {
if (!is_credit_card && !is_profile)
return;
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ if (!autofill_webdata_.get())
return;
if (is_credit_card)
- autofill_data->RemoveCreditCard(guid);
+ autofill_webdata_->RemoveCreditCard(guid);
else
- autofill_data->RemoveAutofillProfile(guid);
+ autofill_webdata_->RemoveAutofillProfile(guid);
// Refresh our local cache and send notifications to observers.
Refresh();
@@ -757,9 +745,7 @@ void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) {
address_of<AutofillProfile>);
AutofillProfile::AdjustInferredLabels(&profile_pointers);
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ if (!autofill_webdata_.get())
return;
// Any profiles that are not in the new profile list should be removed from
@@ -768,14 +754,14 @@ void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) {
web_profiles_.begin();
iter != web_profiles_.end(); ++iter) {
if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid()))
- autofill_data->RemoveAutofillProfile((*iter)->guid());
+ autofill_webdata_->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()))
- autofill_data->UpdateAutofillProfile(*iter);
+ autofill_webdata_->UpdateAutofillProfile(*iter);
}
// Add the new profiles to the web database. Don't add a duplicate.
@@ -783,7 +769,7 @@ void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) {
iter != profiles->end(); ++iter) {
if (!FindByGUID<AutofillProfile>(web_profiles_, iter->guid()) &&
!FindByContents(web_profiles_, *iter))
- autofill_data->AddAutofillProfile(*iter);
+ autofill_webdata_->AddAutofillProfile(*iter);
}
// Copy in the new profiles.
@@ -811,9 +797,7 @@ void PersonalDataManager::SetCreditCards(
it++;
}
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ if (!autofill_webdata_.get())
return;
// Any credit cards that are not in the new credit card list should be
@@ -821,14 +805,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()))
- autofill_data->RemoveCreditCard((*iter)->guid());
+ autofill_webdata_->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()))
- autofill_data->UpdateCreditCard(*iter);
+ autofill_webdata_->UpdateCreditCard(*iter);
}
// Add the new credit cards to the web database. Don't add a duplicate.
@@ -836,7 +820,7 @@ void PersonalDataManager::SetCreditCards(
iter != credit_cards->end(); ++iter) {
if (!FindByGUID<CreditCard>(credit_cards_, iter->guid()) &&
!FindByContents(credit_cards_, *iter))
- autofill_data->AddCreditCard(*iter);
+ autofill_webdata_->AddCreditCard(*iter);
}
// Copy in the new credit cards.
@@ -851,16 +835,14 @@ void PersonalDataManager::SetCreditCards(
}
void PersonalDataManager::LoadProfiles() {
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get()) {
+ if (!autofill_webdata_.get()) {
NOTREACHED();
return;
}
CancelPendingQuery(&pending_profiles_query_);
- pending_profiles_query_ = autofill_data->GetAutofillProfiles(this);
+ pending_profiles_query_ = autofill_webdata_->GetAutofillProfiles(this);
}
// Win and Linux implementations do nothing. Mac and Android implementations
@@ -871,16 +853,14 @@ void PersonalDataManager::LoadAuxiliaryProfiles() {
#endif
void PersonalDataManager::LoadCreditCards() {
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get()) {
+ if (!autofill_webdata_.get()) {
NOTREACHED();
return;
}
CancelPendingQuery(&pending_creditcards_query_);
- pending_creditcards_query_ = autofill_data->GetCreditCards(this);
+ pending_creditcards_query_ = autofill_webdata_->GetCreditCards(this);
}
void PersonalDataManager::ReceiveLoadedProfiles(WebDataServiceBase::Handle h,
@@ -922,13 +902,11 @@ void PersonalDataManager::ReceiveLoadedCreditCards(
void PersonalDataManager::CancelPendingQuery(
WebDataServiceBase::Handle* handle) {
if (*handle) {
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get()) {
+ if (!autofill_webdata_.get()) {
NOTREACHED();
return;
}
- autofill_data->CancelRequest(*handle);
+ autofill_webdata_->CancelRequest(*handle);
}
*handle = 0;
}

Powered by Google App Engine
This is Rietveld 408576698