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 cd73880e34ab568f92f3e09fcc9b99994a00c2f6..303b1fc12d5bc685417df7f4361942af105f7907 100644 |
| --- a/chrome/browser/autofill/personal_data_manager.cc |
| +++ b/chrome/browser/autofill/personal_data_manager.cc |
| @@ -28,6 +28,8 @@ |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/notification_source.h" |
| +using content::BrowserContext; |
| + |
| namespace { |
| template<typename T> |
| @@ -165,12 +167,14 @@ void PersonalDataManager::OnWebDataServiceRequestDone( |
| // If sync is not set, cull older entries of the autocomplete. Otherwise, |
| // the entries will be culled when sync is connected. |
| ProfileSyncService* sync_service = |
| - ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
| + ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| + static_cast<Profile*>(browser_context_)); |
| if (sync_service && (!sync_service->HasSyncSetupCompleted() || |
| - !PrefServiceBase::ForProfile(profile_)->GetBoolean( |
| - prefs::kSyncAutofill))) { |
| + !PrefServiceBase::ForContext( |
| + browser_context_)->GetBoolean( |
| + prefs::kSyncAutofill))) { |
| scoped_refptr<WebDataServiceBase> service = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (service) { |
| AutofillWebData::ForService(service)->RemoveExpiredFormElements(); |
| } |
| @@ -195,18 +199,19 @@ void PersonalDataManager::RemoveObserver( |
| // changes. This method, |OnStateChange| acts as a deferred call to |
| // |EmptyMigrationTrash| once the sync service becomes available. |
| void PersonalDataManager::OnStateChanged() { |
| - if (!profile_ || profile_->IsOffTheRecord()) |
| + if (!browser_context_ || browser_context_->IsOffTheRecord()) |
| return; |
| scoped_refptr<WebDataServiceBase> web_data_service = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!web_data_service.get()) { |
| NOTREACHED(); |
| return; |
| } |
| ProfileSyncService* sync_service = |
| - ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
| + ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| + static_cast<Profile*>(browser_context_)); |
| if (!sync_service) |
| return; |
| @@ -230,8 +235,8 @@ void PersonalDataManager::Observe(int type, |
| content::Source<WebDataServiceBase>(source).ptr(); |
| DCHECK(web_data_service.get() && |
| - web_data_service.get() == WebDataServiceBase::ForProfile( |
| - profile_).get()); |
| + web_data_service.get() == WebDataServiceBase::ForContext( |
| + browser_context_).get()); |
| Refresh(); |
| } |
| @@ -354,7 +359,7 @@ bool PersonalDataManager::ImportFormData( |
| } |
| void PersonalDataManager::AddProfile(const AutofillProfile& profile) { |
| - if (profile_->IsOffTheRecord()) |
| + if (browser_context_->IsOffTheRecord()) |
| return; |
| if (profile.IsEmpty()) |
| @@ -365,7 +370,7 @@ void PersonalDataManager::AddProfile(const AutofillProfile& profile) { |
| return; |
| scoped_refptr<WebDataServiceBase> wds = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!wds.get()) |
| return; |
| @@ -381,7 +386,7 @@ void PersonalDataManager::AddProfile(const AutofillProfile& profile) { |
| } |
| void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { |
| - if (profile_->IsOffTheRecord()) |
| + if (browser_context_->IsOffTheRecord()) |
| return; |
| if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
| @@ -393,7 +398,7 @@ void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { |
| } |
| scoped_refptr<WebDataServiceBase> wds = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!wds.get()) |
| return; |
| @@ -405,14 +410,14 @@ void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { |
| } |
| void PersonalDataManager::RemoveProfile(const std::string& guid) { |
| - if (profile_->IsOffTheRecord()) |
| + if (browser_context_->IsOffTheRecord()) |
| return; |
| if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) |
| return; |
| scoped_refptr<WebDataServiceBase> wds = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!wds.get()) |
| return; |
| @@ -434,7 +439,7 @@ AutofillProfile* PersonalDataManager::GetProfileByGUID( |
| } |
| void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { |
| - if (profile_->IsOffTheRecord()) |
| + if (browser_context_->IsOffTheRecord()) |
| return; |
| if (credit_card.IsEmpty()) |
| @@ -444,7 +449,7 @@ void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { |
| return; |
| scoped_refptr<WebDataServiceBase> wds = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!wds.get()) |
| return; |
| @@ -460,7 +465,7 @@ void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { |
| } |
| void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { |
| - if (profile_->IsOffTheRecord()) |
| + if (browser_context_->IsOffTheRecord()) |
| return; |
| if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
| @@ -472,7 +477,7 @@ void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { |
| } |
| scoped_refptr<WebDataServiceBase> wds = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!wds.get()) |
| return; |
| @@ -484,14 +489,14 @@ void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { |
| } |
| void PersonalDataManager::RemoveCreditCard(const std::string& guid) { |
| - if (profile_->IsOffTheRecord()) |
| + if (browser_context_->IsOffTheRecord()) |
| return; |
| if (!FindByGUID<CreditCard>(credit_cards_, guid)) |
| return; |
| scoped_refptr<WebDataServiceBase> wds = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!wds.get()) |
| return; |
| @@ -530,9 +535,9 @@ bool PersonalDataManager::IsDataLoaded() const { |
| } |
| const std::vector<AutofillProfile*>& PersonalDataManager::profiles() const { |
| - // |profile_| is NULL in AutofillManagerTest. |
| - bool auxiliary_profiles_enabled = profile_ ? |
| - PrefServiceBase::ForProfile(profile_)->GetBoolean( |
| + // |browser_context_| is NULL in AutofillManagerTest. |
| + bool auxiliary_profiles_enabled = browser_context_ ? |
| + PrefServiceBase::ForContext(browser_context_)->GetBoolean( |
| prefs::kAutofillAuxiliaryProfilesEnabled) : |
| false; |
| if (!auxiliary_profiles_enabled) |
| @@ -567,7 +572,7 @@ void PersonalDataManager::Refresh() { |
| } |
| PersonalDataManager::PersonalDataManager() |
| - : profile_(NULL), |
| + : browser_context_(NULL), |
| is_data_loaded_(false), |
| pending_profiles_query_(0), |
| pending_creditcards_query_(0), |
| @@ -575,13 +580,13 @@ PersonalDataManager::PersonalDataManager() |
| has_logged_profile_count_(false) { |
| } |
| -void PersonalDataManager::Init(Profile* profile) { |
| - profile_ = profile; |
| +void PersonalDataManager::Init(BrowserContext* browser_context) { |
| + browser_context_ = browser_context; |
| metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); |
| // WebDataService may not be available in tests. |
| scoped_refptr<WebDataServiceBase> web_data_service = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!web_data_service.get()) |
| return; |
| @@ -595,7 +600,7 @@ void PersonalDataManager::Init(Profile* profile) { |
| } |
| bool PersonalDataManager::IsAutofillEnabled() const { |
| - return PrefServiceBase::ForProfile(profile_)->GetBoolean( |
| + return PrefServiceBase::ForContext(browser_context_)->GetBoolean( |
| prefs::kAutofillEnabled); |
| } |
| @@ -658,7 +663,7 @@ bool PersonalDataManager::MergeProfile( |
| } |
| void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { |
| - if (profile_->IsOffTheRecord()) |
| + if (browser_context_->IsOffTheRecord()) |
| return; |
| // Remove empty profiles from input. |
| @@ -677,7 +682,7 @@ void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { |
| AutofillProfile::AdjustInferredLabels(&profile_pointers); |
| scoped_refptr<WebDataServiceBase> wds = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!wds.get()) |
| return; |
| AutofillWebData* autofill_data = AutofillWebData::ForService(wds); |
| @@ -719,7 +724,7 @@ void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { |
| void PersonalDataManager::SetCreditCards( |
| std::vector<CreditCard>* credit_cards) { |
| - if (profile_->IsOffTheRecord()) |
| + if (browser_context_->IsOffTheRecord()) |
| return; |
| // Remove empty credit cards from input. |
| @@ -730,7 +735,7 @@ void PersonalDataManager::SetCreditCards( |
| credit_cards->end()); |
| scoped_refptr<WebDataServiceBase> wds = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!wds.get()) |
| return; |
| AutofillWebData* autofill_data = AutofillWebData::ForService(wds); |
| @@ -771,7 +776,7 @@ void PersonalDataManager::SetCreditCards( |
| void PersonalDataManager::LoadProfiles() { |
| scoped_refptr<WebDataServiceBase> web_data_service = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!web_data_service.get()) { |
| NOTREACHED(); |
| return; |
| @@ -792,7 +797,7 @@ void PersonalDataManager::LoadAuxiliaryProfiles() const { |
| void PersonalDataManager::LoadCreditCards() { |
| scoped_refptr<WebDataServiceBase> web_data_service = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!web_data_service.get()) { |
| NOTREACHED(); |
| return; |
| @@ -845,7 +850,7 @@ void PersonalDataManager::CancelPendingQuery( |
| WebDataServiceBase::Handle* handle) { |
| if (*handle) { |
| scoped_refptr<WebDataServiceBase> web_data_service = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!web_data_service.get()) { |
| NOTREACHED(); |
| return; |
| @@ -857,7 +862,7 @@ void PersonalDataManager::CancelPendingQuery( |
| void PersonalDataManager::SaveImportedProfile( |
| const AutofillProfile& imported_profile) { |
| - if (profile_->IsOffTheRecord()) { |
| + if (browser_context_->IsOffTheRecord()) { |
| // The |IsOffTheRecord| check should happen earlier in the import process, |
| // upon form submission. |
| NOTREACHED(); |
| @@ -882,7 +887,7 @@ void PersonalDataManager::SaveImportedProfile( |
| void PersonalDataManager::SaveImportedCreditCard( |
| const CreditCard& imported_credit_card) { |
| DCHECK(!imported_credit_card.number().empty()); |
| - if (profile_->IsOffTheRecord()) { |
| + if (browser_context_->IsOffTheRecord()) { |
| // The |IsOffTheRecord| check should happen earlier in the import process, |
| // upon form submission. |
| NOTREACHED(); |
| @@ -911,18 +916,19 @@ void PersonalDataManager::SaveImportedCreditCard( |
| } |
| void PersonalDataManager::EmptyMigrationTrash() { |
| - if (!profile_ || profile_->IsOffTheRecord()) |
| + if (!browser_context_ || browser_context_->IsOffTheRecord()) |
| return; |
| scoped_refptr<WebDataServiceBase> web_data_service = |
| - WebDataServiceBase::ForProfile(profile_); |
| + WebDataServiceBase::ForContext(browser_context_); |
| if (!web_data_service.get()) { |
| NOTREACHED(); |
| return; |
| } |
| ProfileSyncService* sync_service = |
| - ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
| + ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| + static_cast<Profile*>(browser_context_)); |
|
erikwright (departed)
2012/09/04 19:42:15
Will this be permanent?
Jói
2012/09/04 20:10:25
This goes away in the next change after, where ins
|
| if (!sync_service) |
| return; |