diff options
author | blundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-04 21:15:12 +0000 |
---|---|---|
committer | blundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-04 21:15:12 +0000 |
commit | 1caf7cd7536176b784138c2d5d60489b097480b2 (patch) | |
tree | f9cbb67ca13aa995eef335317e19691fc0c02d38 | |
parent | ba278fc8bcdf07e2641d5556f7cf85bc8560ceeb (diff) | |
download | chromium_src-1caf7cd7536176b784138c2d5d60489b097480b2.zip chromium_src-1caf7cd7536176b784138c2d5d60489b097480b2.tar.gz chromium_src-1caf7cd7536176b784138c2d5d60489b097480b2.tar.bz2 |
Parameterize the PrefService that PersonalDataManager uses.
Rather than having PersonalDataManager obtain the PrefService that it uses from
its BrowserContext, have the client pass in the PrefService to use.
Incremental step toward abstracting BrowserContext knowledge out of
PersonalDataManager.
BUG=303050
Review URL: https://codereview.chromium.org/52713006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232798 0039d316-1c4b-4281-b951-d872f2087c98
8 files changed, 35 insertions, 14 deletions
diff --git a/chrome/browser/autofill/personal_data_manager_factory.cc b/chrome/browser/autofill/personal_data_manager_factory.cc index 17b234e..5bdfc98 100644 --- a/chrome/browser/autofill/personal_data_manager_factory.cc +++ b/chrome/browser/autofill/personal_data_manager_factory.cc @@ -33,7 +33,7 @@ PersonalDataManagerServiceImpl::PersonalDataManagerServiceImpl( Profile* profile) { personal_data_manager_.reset(new PersonalDataManager( g_browser_process->GetApplicationLocale())); - personal_data_manager_->Init(profile); + personal_data_manager_->Init(profile, profile->GetPrefs()); } PersonalDataManagerServiceImpl::~PersonalDataManagerServiceImpl() {} diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index 56e25fd..dbec8bc 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -531,7 +531,7 @@ class ProfileSyncServiceAutofillTest EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1); EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1); - personal_data_manager_->Init(profile_.get()); + personal_data_manager_->Init(profile_.get(), profile_->GetPrefs()); web_data_service_->StartSyncableService(); } diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc index 285a23b..b1ccd60 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc @@ -38,6 +38,7 @@ #include "components/autofill/core/browser/test_personal_data_manager.h" #include "components/autofill/core/common/autofill_switches.h" #include "components/autofill/core/common/form_data.h" +#include "components/user_prefs/user_prefs.h" #include "content/public/browser/web_contents.h" #include "content/public/test/mock_render_process_host.h" #include "google_apis/gaia/google_service_auth_error.h" @@ -255,7 +256,8 @@ class TestAutofillDialogController } void Init(content::BrowserContext* browser_context) { - test_manager_.Init(browser_context); + test_manager_.Init(browser_context, + user_prefs::UserPrefs::Get(browser_context)); } TestAutofillDialogView* GetView() { diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc index 863eb3e..ddb6f52 100644 --- a/components/autofill/core/browser/autofill_manager_unittest.cc +++ b/components/autofill/core/browser/autofill_manager_unittest.cc @@ -79,6 +79,10 @@ class TestPersonalDataManager : public PersonalDataManager { set_browser_context(context); } + void SetPrefService(PrefService* pref_service) { + set_pref_service(pref_service); + } + // Factory method for keyed service. PersonalDataManager is NULL for testing. static BrowserContextKeyedService* Build(content::BrowserContext* profile) { return NULL; @@ -697,6 +701,7 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness { autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); personal_data_.SetBrowserContext(profile()); + personal_data_.SetPrefService(profile()->GetPrefs()); autofill_driver_.reset(new MockAutofillDriver(web_contents())); autofill_manager_.reset(new TestAutofillManager( autofill_driver_.get(), diff --git a/components/autofill/core/browser/autofill_metrics_unittest.cc b/components/autofill/core/browser/autofill_metrics_unittest.cc index c12b2ff..c9dec86e 100644 --- a/components/autofill/core/browser/autofill_metrics_unittest.cc +++ b/components/autofill/core/browser/autofill_metrics_unittest.cc @@ -98,6 +98,10 @@ class TestPersonalDataManager : public PersonalDataManager { set_browser_context(context); } + void SetPrefService(PrefService* pref_service) { + set_pref_service(pref_service); + } + // Overridden to avoid a trip to the database. This should be a no-op except // for the side-effect of logging the profile count. virtual void LoadProfiles() OVERRIDE { @@ -287,6 +291,7 @@ void AutofillMetricsTest::SetUp() { personal_data_.reset(new TestPersonalDataManager()); personal_data_->SetBrowserContext(profile()); + personal_data_->SetPrefService(profile()->GetPrefs()); autofill_driver_.reset(new TestAutofillDriver(web_contents())); autofill_manager_.reset(new TestAutofillManager( autofill_driver_.get(), @@ -1004,7 +1009,7 @@ TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { personal_data_->set_autofill_enabled(true); EXPECT_CALL(*personal_data_->metric_logger(), LogIsAutofillEnabledAtStartup(true)).Times(1); - personal_data_->Init(profile()); + personal_data_->Init(profile(), profile()->GetPrefs()); } // Test that we correctly log when Autofill is disabled. @@ -1012,7 +1017,7 @@ TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { personal_data_->set_autofill_enabled(false); EXPECT_CALL(*personal_data_->metric_logger(), LogIsAutofillEnabledAtStartup(false)).Times(1); - personal_data_->Init(profile()); + personal_data_->Init(profile(), profile()->GetPrefs()); } // Test that we log the number of Autofill suggestions when filling a form. diff --git a/components/autofill/core/browser/personal_data_manager.cc b/components/autofill/core/browser/personal_data_manager.cc index 44ec88f..9785a01 100644 --- a/components/autofill/core/browser/personal_data_manager.cc +++ b/components/autofill/core/browser/personal_data_manager.cc @@ -25,7 +25,6 @@ #include "components/autofill/core/browser/validation.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" #include "components/autofill/core/common/autofill_pref_names.h" -#include "components/user_prefs/user_prefs.h" #include "content/public/browser/browser_context.h" namespace autofill { @@ -156,8 +155,10 @@ PersonalDataManager::PersonalDataManager(const std::string& app_locale) metric_logger_(new AutofillMetrics), has_logged_profile_count_(false) {} -void PersonalDataManager::Init(content::BrowserContext* browser_context) { +void PersonalDataManager::Init(content::BrowserContext* browser_context, + PrefService* pref_service) { browser_context_ = browser_context; + pref_service_ = pref_service; if (!browser_context_->IsOffTheRecord()) metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); @@ -549,8 +550,7 @@ bool PersonalDataManager::IsDataLoaded() const { } const std::vector<AutofillProfile*>& PersonalDataManager::GetProfiles() const { - if (!user_prefs::UserPrefs::Get(browser_context_)->GetBoolean( - prefs::kAutofillAuxiliaryProfilesEnabled)) { + if (!pref_service_->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)) { return web_profiles(); } @@ -704,8 +704,7 @@ void PersonalDataManager::GetCreditCardSuggestions( } bool PersonalDataManager::IsAutofillEnabled() const { - return user_prefs::UserPrefs::Get(browser_context_)->GetBoolean( - prefs::kAutofillEnabled); + return pref_service_->GetBoolean(prefs::kAutofillEnabled); } // static @@ -1050,6 +1049,10 @@ void PersonalDataManager::set_browser_context( browser_context_ = context; } +void PersonalDataManager::set_pref_service(PrefService* pref_service) { + pref_service_ = pref_service; +} + std::string PersonalDataManager::MostCommonCountryCodeFromProfiles() const { // Count up country codes from existing profiles. std::map<std::string, int> votes; diff --git a/components/autofill/core/browser/personal_data_manager.h b/components/autofill/core/browser/personal_data_manager.h index 40d5159..62e3bfc 100644 --- a/components/autofill/core/browser/personal_data_manager.h +++ b/components/autofill/core/browser/personal_data_manager.h @@ -19,6 +19,7 @@ #include "components/autofill/core/browser/webdata/autofill_webdata_service_observer.h" #include "components/webdata/common/web_data_service_consumer.h" +class PrefService; class RemoveAutofillTester; namespace content { @@ -54,8 +55,9 @@ class PersonalDataManager : public WebDataServiceConsumer, explicit PersonalDataManager(const std::string& app_locale); virtual ~PersonalDataManager(); - // Kicks off asynchronous loading of profiles and credit cards. - void Init(content::BrowserContext* context); + // Kicks off asynchronous loading of profiles and credit cards. |context| and + // |pref_service| must outlive this instance. + void Init(content::BrowserContext* context, PrefService* pref_service); // WebDataServiceConsumer: virtual void OnWebDataServiceRequestDone( @@ -256,6 +258,7 @@ class PersonalDataManager : public WebDataServiceConsumer, const AutofillMetrics* metric_logger() const; void set_metric_logger(const AutofillMetrics* metric_logger); void set_browser_context(content::BrowserContext* context); + void set_pref_service(PrefService* pref_service); // The browser context this PersonalDataManager is in. content::BrowserContext* browser_context_; @@ -299,6 +302,9 @@ class PersonalDataManager : public WebDataServiceConsumer, // For logging UMA metrics. Overridden by metrics tests. scoped_ptr<const AutofillMetrics> metric_logger_; + // The PrefService that this instance uses. Must outlive this instance. + PrefService* pref_service_; + // Whether we have already logged the number of profiles this session. mutable bool has_logged_profile_count_; diff --git a/components/autofill/core/browser/personal_data_manager_unittest.cc b/components/autofill/core/browser/personal_data_manager_unittest.cc index eede583..05f4c7e 100644 --- a/components/autofill/core/browser/personal_data_manager_unittest.cc +++ b/components/autofill/core/browser/personal_data_manager_unittest.cc @@ -89,7 +89,7 @@ class PersonalDataManagerTest : public testing::Test { void ResetPersonalDataManager() { personal_data_.reset(new PersonalDataManager("en-US")); - personal_data_->Init(profile_.get()); + personal_data_->Init(profile_.get(), profile_->GetPrefs()); personal_data_->AddObserver(&personal_data_observer_); // Verify that the web database has been updated and the notification sent. |