summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-10 22:28:17 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-10 22:28:17 +0000
commita42f2e2d7447f9ae1a65f7171c29b75bd3d14826 (patch)
tree91ccbbce3bbe159175855c4352cba71b884ec16a /chrome
parent00475c046ebe17b9df0cf55d14afbebcb7f67437 (diff)
downloadchromium_src-a42f2e2d7447f9ae1a65f7171c29b75bd3d14826.zip
chromium_src-a42f2e2d7447f9ae1a65f7171c29b75bd3d14826.tar.gz
chromium_src-a42f2e2d7447f9ae1a65f7171c29b75bd3d14826.tar.bz2
profile: Add a way for each ProfileKeyedServiceFactory to specify its user prefernces.
To allow us to compile individual features in/out of a chrome build, we need to attack browser_prefs.cc, which is a giant static registration. This used to be done through another big code path starting in ProfileImpl which call browser::RegisterUserPrefs() which linked to other static methods. Now this is done through overridding ProfileKeyedServiceFactory::RegisterUserPrefs(), and there are no additional dependencies. BUG=none TEST=none Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=104412 Review URL: http://codereview.chromium.org/7901027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104806 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/background/background_contents_service.cc6
-rw-r--r--chrome/browser/background/background_contents_service.h2
-rw-r--r--chrome/browser/background/background_contents_service_factory.cc8
-rw-r--r--chrome/browser/background/background_contents_service_factory.h1
-rw-r--r--chrome/browser/background/background_contents_service_unittest.cc19
-rw-r--r--chrome/browser/chromeos/gview_request_interceptor_unittest.cc3
-rw-r--r--chrome/browser/plugin_prefs.cc108
-rw-r--r--chrome/browser/plugin_prefs.h4
-rw-r--r--chrome/browser/plugin_prefs_factory.cc95
-rw-r--r--chrome/browser/plugin_prefs_factory.h66
-rw-r--r--chrome/browser/prefs/browser_prefs.cc6
-rw-r--r--chrome/browser/profiles/profile.cc4
-rw-r--r--chrome/browser/profiles/profile.h4
-rw-r--r--chrome/browser/profiles/profile_dependency_manager.cc12
-rw-r--r--chrome/browser/profiles/profile_keyed_service_factory.cc48
-rw-r--r--chrome/browser/profiles/profile_keyed_service_factory.h16
-rw-r--r--chrome/browser/search_engines/template_url_service.cc34
-rw-r--r--chrome/browser/search_engines/template_url_service.h3
-rw-r--r--chrome/browser/search_engines/template_url_service_factory.cc37
-rw-r--r--chrome/browser/search_engines/template_url_service_factory.h2
-rw-r--r--chrome/chrome_browser.gypi2
21 files changed, 310 insertions, 170 deletions
diff --git a/chrome/browser/background/background_contents_service.cc b/chrome/browser/background/background_contents_service.cc
index b163f79..e9e310d 100644
--- a/chrome/browser/background/background_contents_service.cc
+++ b/chrome/browser/background/background_contents_service.cc
@@ -564,12 +564,6 @@ const string16& BackgroundContentsService::GetParentApplicationId(
return EmptyString16();
}
-// static
-void BackgroundContentsService::RegisterUserPrefs(PrefService* prefs) {
- prefs->RegisterDictionaryPref(prefs::kRegisteredBackgroundContents,
- PrefService::UNSYNCABLE_PREF);
-}
-
void BackgroundContentsService::AddTabContents(
TabContents* new_contents,
WindowOpenDisposition disposition,
diff --git a/chrome/browser/background/background_contents_service.h b/chrome/browser/background/background_contents_service.h
index 88787f6..66ce301 100644
--- a/chrome/browser/background/background_contents_service.h
+++ b/chrome/browser/background/background_contents_service.h
@@ -58,8 +58,6 @@ class BackgroundContentsService : private NotificationObserver,
// Returns all currently opened BackgroundContents (used by the task manager).
std::vector<BackgroundContents*> GetBackgroundContents() const;
- static void RegisterUserPrefs(PrefService* prefs);
-
// BackgroundContents::Delegate implementation.
virtual void AddTabContents(TabContents* new_contents,
WindowOpenDisposition disposition,
diff --git a/chrome/browser/background/background_contents_service_factory.cc b/chrome/browser/background/background_contents_service_factory.cc
index d9139dc..026f6c3 100644
--- a/chrome/browser/background/background_contents_service_factory.cc
+++ b/chrome/browser/background/background_contents_service_factory.cc
@@ -6,8 +6,10 @@
#include "base/command_line.h"
#include "chrome/browser/background/background_contents_service.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/common/pref_names.h"
// static
BackgroundContentsService* BackgroundContentsServiceFactory::GetForProfile(
@@ -35,6 +37,12 @@ ProfileKeyedService* BackgroundContentsServiceFactory::BuildServiceInstanceFor(
CommandLine::ForCurrentProcess());
}
+void BackgroundContentsServiceFactory::RegisterUserPrefs(
+ PrefService* user_prefs) {
+ user_prefs->RegisterDictionaryPref(prefs::kRegisteredBackgroundContents,
+ PrefService::UNSYNCABLE_PREF);
+}
+
bool BackgroundContentsServiceFactory::ServiceHasOwnInstanceInIncognito() {
return true;
}
diff --git a/chrome/browser/background/background_contents_service_factory.h b/chrome/browser/background/background_contents_service_factory.h
index 131f617..9e3e289 100644
--- a/chrome/browser/background/background_contents_service_factory.h
+++ b/chrome/browser/background/background_contents_service_factory.h
@@ -30,6 +30,7 @@ class BackgroundContentsServiceFactory : public ProfileKeyedServiceFactory {
// ProfileKeyedServiceFactory:
virtual ProfileKeyedService* BuildServiceInstanceFor(
Profile* profile) const OVERRIDE;
+ virtual void RegisterUserPrefs(PrefService* user_prefs);
// Use a separate background contents service for incognito.
virtual bool ServiceHasOwnInstanceInIncognito() OVERRIDE;
virtual bool ServiceIsCreatedWithProfile() OVERRIDE;
diff --git a/chrome/browser/background/background_contents_service_unittest.cc b/chrome/browser/background/background_contents_service_unittest.cc
index b6eac81..c62b64e 100644
--- a/chrome/browser/background/background_contents_service_unittest.cc
+++ b/chrome/browser/background/background_contents_service_unittest.cc
@@ -9,6 +9,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/background/background_contents_service.h"
+#include "chrome/browser/background/background_contents_service_factory.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/tab_contents/background_contents.h"
@@ -34,10 +35,6 @@ class BackgroundContentsServiceTest : public testing::Test {
prefs::kRegisteredBackgroundContents);
}
- void ClearPrefs(Profile* profile) {
- profile->GetPrefs()->ClearPref(prefs::kRegisteredBackgroundContents);
- }
-
// Returns the stored pref URL for the passed app id.
std::string GetPrefURLForApp(Profile* profile, const string16& appid) {
const DictionaryValue* pref = GetPrefs(profile);
@@ -125,8 +122,9 @@ TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) {
TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAdded) {
TestingProfile profile;
- ClearPrefs(&profile);
BackgroundContentsService service(&profile, command_line_.get());
+ BackgroundContentsServiceFactory::GetInstance()->RegisterUserPrefsOnProfile(
+ &profile);
GURL orig_url;
GURL url("http://a/");
GURL url2("http://a/");
@@ -151,8 +149,10 @@ TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAdded) {
TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAddedAndClosed) {
TestingProfile profile;
- ClearPrefs(&profile);
BackgroundContentsService service(&profile, command_line_.get());
+ BackgroundContentsServiceFactory::GetInstance()->RegisterUserPrefsOnProfile(
+ &profile);
+
GURL url("http://a/");
MockBackgroundContents* contents = new MockBackgroundContents(&profile);
EXPECT_EQ(0U, GetPrefs(&profile)->size());
@@ -170,8 +170,10 @@ TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAddedAndClosed) {
// crash) then is restarted. Should not persist URL twice.
TEST_F(BackgroundContentsServiceTest, RestartBackgroundContents) {
TestingProfile profile;
- ClearPrefs(&profile);
BackgroundContentsService service(&profile, command_line_.get());
+ BackgroundContentsServiceFactory::GetInstance()->RegisterUserPrefsOnProfile(
+ &profile);
+
GURL url("http://a/");
{
scoped_ptr<MockBackgroundContents> contents(new MockBackgroundContents(
@@ -201,7 +203,8 @@ TEST_F(BackgroundContentsServiceTest, RestartBackgroundContents) {
TEST_F(BackgroundContentsServiceTest, TestApplicationIDLinkage) {
TestingProfile profile;
BackgroundContentsService service(&profile, command_line_.get());
- ClearPrefs(&profile);
+ BackgroundContentsServiceFactory::GetInstance()->RegisterUserPrefsOnProfile(
+ &profile);
EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid")));
MockBackgroundContents* contents = new MockBackgroundContents(&profile,
diff --git a/chrome/browser/chromeos/gview_request_interceptor_unittest.cc b/chrome/browser/chromeos/gview_request_interceptor_unittest.cc
index 33662b7..c529f2e 100644
--- a/chrome/browser/chromeos/gview_request_interceptor_unittest.cc
+++ b/chrome/browser/chromeos/gview_request_interceptor_unittest.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/chrome_plugin_service_filter.h"
#include "chrome/browser/chromeos/gview_request_interceptor.h"
#include "chrome/browser/plugin_prefs.h"
+#include "chrome/browser/plugin_prefs_factory.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/testing_pref_service.h"
#include "content/browser/mock_resource_context.h"
@@ -83,7 +84,7 @@ class GViewRequestInterceptorTest : public testing::Test {
job_factory_.SetProtocolHandler("http", new GViewRequestProtocolFactory);
job_factory_.AddInterceptor(new GViewRequestInterceptor);
request_context->set_job_factory(&job_factory_);
- PluginPrefs::RegisterPrefs(&prefs_);
+ PluginPrefsFactory::GetInstance()->ForceRegisterPrefsForTest(&prefs_);
plugin_prefs_ = new PluginPrefs();
plugin_prefs_->SetPrefs(&prefs_);
ChromePluginServiceFilter* filter =
diff --git a/chrome/browser/plugin_prefs.cc b/chrome/browser/plugin_prefs.cc
index dd7df34..b7bc00f 100644
--- a/chrome/browser/plugin_prefs.cc
+++ b/chrome/browser/plugin_prefs.cc
@@ -18,12 +18,10 @@
#include "base/values.h"
#include "base/version.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/plugin_prefs_factory.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/browser/profiles/profile_keyed_service.h"
-#include "chrome/browser/profiles/profile_keyed_service_factory.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_notification_types.h"
@@ -38,67 +36,21 @@
namespace {
-class PluginPrefsWrapper : public ProfileKeyedService {
- public:
- explicit PluginPrefsWrapper(scoped_refptr<PluginPrefs> plugin_prefs)
- : plugin_prefs_(plugin_prefs) {}
- virtual ~PluginPrefsWrapper() {}
-
- PluginPrefs* plugin_prefs() { return plugin_prefs_.get(); }
-
- private:
- // ProfileKeyedService methods:
- virtual void Shutdown() OVERRIDE {
- plugin_prefs_->ShutdownOnUIThread();
- }
-
- scoped_refptr<PluginPrefs> plugin_prefs_;
-};
-
// Default state for a plug-in (not state of the default plug-in!).
// Accessed only on the UI thread.
base::LazyInstance<std::map<FilePath, bool> > g_default_plugin_state(
base::LINKER_INITIALIZED);
-}
+} // namespace
// How long to wait to save the plugin enabled information, which might need to
// go to disk.
#define kPluginUpdateDelayMs (60 * 1000)
-class PluginPrefs::Factory : public ProfileKeyedServiceFactory {
- public:
- static Factory* GetInstance();
-
- PluginPrefsWrapper* GetWrapperForProfile(Profile* profile);
-
- // Factory function for use with
- // ProfileKeyedServiceFactory::SetTestingFactory.
- static ProfileKeyedService* CreateWrapperForProfile(Profile* profile);
-
- private:
- friend struct DefaultSingletonTraits<Factory>;
-
- Factory();
- virtual ~Factory() {}
-
- // ProfileKeyedServiceFactory methods:
- virtual ProfileKeyedService* BuildServiceInstanceFor(
- Profile* profile) const OVERRIDE;
- virtual bool ServiceRedirectedInIncognito() OVERRIDE { return true; }
- virtual bool ServiceIsNULLWhileTesting() OVERRIDE { return true; }
- virtual bool ServiceIsCreatedWithProfile() OVERRIDE { return true; }
-};
-
-// static
-void PluginPrefs::Initialize() {
- Factory::GetInstance();
-}
-
// static
PluginPrefs* PluginPrefs::GetForProfile(Profile* profile) {
PluginPrefsWrapper* wrapper =
- Factory::GetInstance()->GetWrapperForProfile(profile);
+ PluginPrefsFactory::GetInstance()->GetWrapperForProfile(profile);
if (!wrapper)
return NULL;
return wrapper->plugin_prefs();
@@ -107,8 +59,8 @@ PluginPrefs* PluginPrefs::GetForProfile(Profile* profile) {
// static
PluginPrefs* PluginPrefs::GetForTestingProfile(Profile* profile) {
ProfileKeyedService* wrapper =
- Factory::GetInstance()->SetTestingFactoryAndUse(
- profile, &Factory::CreateWrapperForProfile);
+ PluginPrefsFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile, &PluginPrefsFactory::CreateWrapperForProfile);
return static_cast<PluginPrefsWrapper*>(wrapper)->plugin_prefs();
}
@@ -504,33 +456,6 @@ void PluginPrefs::ShutdownOnUIThread() {
registrar_.RemoveAll();
}
-// static
-PluginPrefs::Factory* PluginPrefs::Factory::GetInstance() {
- return Singleton<PluginPrefs::Factory>::get();
-}
-
-PluginPrefsWrapper* PluginPrefs::Factory::GetWrapperForProfile(
- Profile* profile) {
- return static_cast<PluginPrefsWrapper*>(GetServiceForProfile(profile, true));
-}
-
-// static
-ProfileKeyedService* PluginPrefs::Factory::CreateWrapperForProfile(
- Profile* profile) {
- return GetInstance()->BuildServiceInstanceFor(profile);
-}
-
-PluginPrefs::Factory::Factory()
- : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) {
-}
-
-ProfileKeyedService* PluginPrefs::Factory::BuildServiceInstanceFor(
- Profile* profile) const {
- scoped_refptr<PluginPrefs> plugin_prefs(new PluginPrefs());
- plugin_prefs->SetPrefs(profile->GetPrefs());
- return new PluginPrefsWrapper(plugin_prefs);
-}
-
PluginPrefs::PluginPrefs() : plugin_state_(g_default_plugin_state.Get()),
prefs_(NULL),
plugin_list_(NULL) {
@@ -618,26 +543,3 @@ void PluginPrefs::NotifyPluginStatusChanged() {
Source<PluginPrefs>(this),
NotificationService::NoDetails());
}
-
-/*static*/
-void PluginPrefs::RegisterPrefs(PrefService* prefs) {
- FilePath internal_dir;
- PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir);
- prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory,
- internal_dir,
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF,
- false,
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterBooleanPref(prefs::kPluginsEnabledNaCl,
- false,
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterListPref(prefs::kPluginsPluginsList,
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterListPref(prefs::kPluginsDisabledPlugins,
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions,
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterListPref(prefs::kPluginsEnabledPlugins,
- PrefService::UNSYNCABLE_PREF);
-}
diff --git a/chrome/browser/plugin_prefs.h b/chrome/browser/plugin_prefs.h
index c0dd445..7c6fdc0 100644
--- a/chrome/browser/plugin_prefs.h
+++ b/chrome/browser/plugin_prefs.h
@@ -50,10 +50,6 @@ class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>,
POLICY_DISABLED,
};
- // Initializes the factory for this class for dependency tracking.
- // This should be called before the first profile is created.
- static void Initialize();
-
// Returns the instance associated with |profile|, creating it if necessary.
static PluginPrefs* GetForProfile(Profile* profile);
diff --git a/chrome/browser/plugin_prefs_factory.cc b/chrome/browser/plugin_prefs_factory.cc
new file mode 100644
index 0000000..3cac28a
--- /dev/null
+++ b/chrome/browser/plugin_prefs_factory.cc
@@ -0,0 +1,95 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/plugin_prefs_factory.h"
+
+#include "base/path_service.h"
+#include "chrome/browser/plugin_prefs.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/pref_names.h"
+
+namespace {
+
+} // namespace
+
+PluginPrefsWrapper::PluginPrefsWrapper(scoped_refptr<PluginPrefs> plugin_prefs)
+ : plugin_prefs_(plugin_prefs) {
+}
+
+PluginPrefsWrapper::~PluginPrefsWrapper() {}
+
+void PluginPrefsWrapper::Shutdown() {
+ plugin_prefs_->ShutdownOnUIThread();
+}
+
+// static
+PluginPrefsFactory* PluginPrefsFactory::GetInstance() {
+ return Singleton<PluginPrefsFactory>::get();
+}
+
+PluginPrefsWrapper* PluginPrefsFactory::GetWrapperForProfile(
+ Profile* profile) {
+ return static_cast<PluginPrefsWrapper*>(GetServiceForProfile(profile, true));
+}
+
+// static
+ProfileKeyedService* PluginPrefsFactory::CreateWrapperForProfile(
+ Profile* profile) {
+ return GetInstance()->BuildServiceInstanceFor(profile);
+}
+
+void PluginPrefsFactory::ForceRegisterPrefsForTest(PrefService* prefs) {
+ RegisterUserPrefs(prefs);
+}
+
+PluginPrefsFactory::PluginPrefsFactory()
+ : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) {
+}
+
+PluginPrefsFactory::~PluginPrefsFactory() {}
+
+ProfileKeyedService* PluginPrefsFactory::BuildServiceInstanceFor(
+ Profile* profile) const {
+ scoped_refptr<PluginPrefs> plugin_prefs(new PluginPrefs());
+ plugin_prefs->SetPrefs(profile->GetPrefs());
+ return new PluginPrefsWrapper(plugin_prefs);
+}
+
+void PluginPrefsFactory::RegisterUserPrefs(PrefService* prefs) {
+ FilePath internal_dir;
+ PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir);
+ prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory,
+ internal_dir,
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF,
+ false,
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterBooleanPref(prefs::kPluginsEnabledNaCl,
+ false,
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterListPref(prefs::kPluginsPluginsList,
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterListPref(prefs::kPluginsDisabledPlugins,
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions,
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterListPref(prefs::kPluginsEnabledPlugins,
+ PrefService::UNSYNCABLE_PREF);
+}
+
+bool PluginPrefsFactory::ServiceRedirectedInIncognito() {
+ return true;
+}
+
+bool PluginPrefsFactory::ServiceIsNULLWhileTesting() {
+ return true;
+}
+
+bool PluginPrefsFactory::ServiceIsCreatedWithProfile() {
+ return true;
+}
diff --git a/chrome/browser/plugin_prefs_factory.h b/chrome/browser/plugin_prefs_factory.h
new file mode 100644
index 0000000..edb28a5
--- /dev/null
+++ b/chrome/browser/plugin_prefs_factory.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PLUGIN_PREFS_FACTORY_H_
+#define CHROME_BROWSER_PLUGIN_PREFS_FACTORY_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "base/memory/singleton.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
+#include "chrome/browser/profiles/profile_keyed_service_factory.h"
+
+class PluginPrefs;
+class PrefService;
+class Profile;
+class ProfileKeyedService;
+
+// A wrapper around PluginPrefs to own the reference to thre real object.
+//
+// This should totally go away; we need a generic bridge between PKSF and
+// scope_refptrs.
+class PluginPrefsWrapper : public ProfileKeyedService {
+ public:
+ explicit PluginPrefsWrapper(scoped_refptr<PluginPrefs> plugin_prefs);
+ virtual ~PluginPrefsWrapper();
+
+ PluginPrefs* plugin_prefs() { return plugin_prefs_.get(); }
+
+ private:
+ // ProfileKeyedService methods:
+ virtual void Shutdown() OVERRIDE;
+
+ scoped_refptr<PluginPrefs> plugin_prefs_;
+};
+
+class PluginPrefsFactory : public ProfileKeyedServiceFactory {
+ public:
+ static PluginPrefsFactory* GetInstance();
+
+ PluginPrefsWrapper* GetWrapperForProfile(Profile* profile);
+
+ // Factory function for use with
+ // ProfileKeyedServiceFactory::SetTestingFactory.
+ static ProfileKeyedService* CreateWrapperForProfile(Profile* profile);
+
+ // Some unit tests that deal with PluginPrefs don't run with a Profile. Let
+ // them still register their preferences.
+ void ForceRegisterPrefsForTest(PrefService* prefs);
+
+ private:
+ friend struct DefaultSingletonTraits<PluginPrefsFactory>;
+
+ PluginPrefsFactory();
+ virtual ~PluginPrefsFactory();
+
+ // ProfileKeyedServiceFactory methods:
+ virtual ProfileKeyedService* BuildServiceInstanceFor(
+ Profile* profile) const OVERRIDE;
+ virtual void RegisterUserPrefs(PrefService* prefs) OVERRIDE;
+ virtual bool ServiceRedirectedInIncognito() OVERRIDE;
+ virtual bool ServiceIsNULLWhileTesting() OVERRIDE;
+ virtual bool ServiceIsCreatedWithProfile() OVERRIDE;
+};
+
+#endif // CHROME_BROWSER_PLUGIN_PREFS_FACTORY_H_
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 1222f95..e922e50 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -6,7 +6,6 @@
#include "chrome/browser/about_flags.h"
#include "chrome/browser/autofill/autofill_manager.h"
-#include "chrome/browser/background/background_contents_service.h"
#include "chrome/browser/background/background_mode_manager.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
@@ -34,7 +33,6 @@
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/page_info_model.h"
#include "chrome/browser/password_manager/password_manager.h"
-#include "chrome/browser/plugin_prefs.h"
#include "chrome/browser/policy/cloud_policy_subsystem.h"
#include "chrome/browser/policy/url_blacklist_manager.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
@@ -46,7 +44,6 @@
#include "chrome/browser/remoting/firewall_traversal_observer.h"
#include "chrome/browser/renderer_host/web_cache_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
-#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
#include "chrome/browser/sync/signin_manager.h"
#include "chrome/browser/tabs/pinned_tab_codec.h"
@@ -156,7 +153,6 @@ void RegisterUserPrefs(PrefService* user_prefs) {
ExtensionSettingsHandler::RegisterUserPrefs(user_prefs);
IncognitoModePrefs::RegisterUserPrefs(user_prefs);
NewTabUI::RegisterUserPrefs(user_prefs);
- PluginPrefs::RegisterPrefs(user_prefs);
PluginsUI::RegisterUserPrefs(user_prefs);
ProfileImpl::RegisterUserPrefs(user_prefs);
PromoResourceService::RegisterUserPrefs(user_prefs);
@@ -174,9 +170,7 @@ void RegisterUserPrefs(PrefService* user_prefs) {
#if defined(OS_CHROMEOS)
chromeos::Preferences::RegisterUserPrefs(user_prefs);
#endif
- BackgroundContentsService::RegisterUserPrefs(user_prefs);
SigninManager::RegisterUserPrefs(user_prefs);
- TemplateURLService::RegisterUserPrefs(user_prefs);
InstantController::RegisterUserPrefs(user_prefs);
NetPrefObserver::RegisterPrefs(user_prefs);
ProtocolHandlerRegistry::RegisterPrefs(user_prefs);
diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc
index aba66c3..f3b5acb 100644
--- a/chrome/browser/profiles/profile.cc
+++ b/chrome/browser/profiles/profile.cc
@@ -100,6 +100,10 @@ Profile* Profile::FromWebUI(WebUI* web_ui) {
return FromBrowserContext(web_ui->tab_contents()->browser_context());
}
+TestingProfile* Profile::AsTestingProfile() {
+ return NULL;
+}
+
// static
const char* const Profile::kProfileKey = "__PROFILE__";
diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h
index 053c4ef..67029ff 100644
--- a/chrome/browser/profiles/profile.h
+++ b/chrome/browser/profiles/profile.h
@@ -79,6 +79,7 @@ class SSLConfigServiceManager;
class SpeechInputPreferences;
class SpellCheckHost;
class TemplateURLFetcher;
+class TestingProfile;
class TokenService;
class UserScriptMaster;
class UserStyleSheetWatcher;
@@ -205,6 +206,9 @@ class Profile : public content::BrowserContext {
// content::BrowserContext implementation ------------------------------------
+ // Typesafe upcast.
+ virtual TestingProfile* AsTestingProfile();
+
// Returns the name associated with this profile. This name is displayed in
// the browser frame.
virtual std::string GetProfileName() = 0;
diff --git a/chrome/browser/profiles/profile_dependency_manager.cc b/chrome/browser/profiles/profile_dependency_manager.cc
index d9c720e7..a372eef4 100644
--- a/chrome/browser/profiles/profile_dependency_manager.cc
+++ b/chrome/browser/profiles/profile_dependency_manager.cc
@@ -11,9 +11,10 @@
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/background/background_contents_service_factory.h"
#include "chrome/browser/extensions/extension_speech_input_manager.h"
-#include "chrome/browser/plugin_prefs.h"
+#include "chrome/browser/plugin_prefs_factory.h"
#include "chrome/browser/prerender/prerender_manager_factory.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_keyed_service.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
@@ -41,7 +42,7 @@ void AssertFactoriesBuilt() {
BackgroundContentsServiceFactory::GetInstance();
CloudPrintProxyServiceFactory::GetInstance();
PersonalDataManagerFactory::GetInstance();
- PluginPrefs::Initialize();
+ PluginPrefsFactory::GetInstance();
prerender::PrerenderManagerFactory::GetInstance();
SessionServiceFactory::GetInstance();
TabRestoreServiceFactory::GetInstance();
@@ -104,6 +105,13 @@ void ProfileDependencyManager::CreateProfileServices(Profile* profile,
for (std::vector<ProfileKeyedServiceFactory*>::reverse_iterator rit =
destruction_order_.rbegin(); rit != destruction_order_.rend();
++rit) {
+ if (!profile->IsOffTheRecord() && !profile->AsTestingProfile()) {
+ // We only register preferences on normal profiles because the incognito
+ // profile shares the pref service with the normal one and the testing
+ // profile will often just insert its own PrefService.
+ (*rit)->RegisterUserPrefsOnProfile(profile);
+ }
+
if (is_testing_profile && (*rit)->ServiceIsNULLWhileTesting()) {
(*rit)->SetTestingFactory(profile, NULL);
} else if ((*rit)->ServiceIsCreatedWithProfile()) {
diff --git a/chrome/browser/profiles/profile_keyed_service_factory.cc b/chrome/browser/profiles/profile_keyed_service_factory.cc
index 1f334038..e755ae3 100644
--- a/chrome/browser/profiles/profile_keyed_service_factory.cc
+++ b/chrome/browser/profiles/profile_keyed_service_factory.cc
@@ -13,9 +13,22 @@
void ProfileKeyedServiceFactory::SetTestingFactory(Profile* profile,
FactoryFunction factory) {
+ // Destroying the profile may cause us to lose data about whether |profile|
+ // has our preferences registered on it (since the profile object itself
+ // isn't dead). See if we need to readd it once we've gone through normal
+ // destruction.
+ bool add_profile = registered_preferences_.find(profile) !=
+ registered_preferences_.end();
+
+ // We have to go through the shutdown and destroy mechanisms because there
+ // are unit tests that create a service on a profile and then change the
+ // testing service mid-test.
ProfileShutdown(profile);
ProfileDestroyed(profile);
+ if (add_profile)
+ registered_preferences_.insert(profile);
+
factories_[profile] = factory;
}
@@ -27,6 +40,39 @@ ProfileKeyedService* ProfileKeyedServiceFactory::SetTestingFactoryAndUse(
return GetServiceForProfile(profile, true);
}
+void ProfileKeyedServiceFactory::RegisterUserPrefsOnProfile(Profile* profile) {
+ // Safe timing for pref registration is hard. Previously, we made Profile
+ // responsible for all pref registration on every service that used
+ // Profile. Now we don't and there are timing issues.
+ //
+ // With normal profiles, prefs can simply be registered at
+ // ProfileDependencyManager::CreateProfileServices time. With incognito
+ // profiles, we just never register since incognito profiles share the same
+ // pref services with their parent profiles.
+ //
+ // Testing profiles throw two wrenches into the mix. One: PrefService isn't
+ // created at profile creation time so we have to move pref registration to
+ // service creation time when using a testing factory. We can't change
+ // PrefService because Two: some tests switch out the PrefService after the
+ // TestingProfile has been created but before it's ever used. So we key our
+ // check on Profile since there's already error checking code to prevent
+ // a secondary PrefService from existing.
+ //
+ // Even worse is Three: Now that services are responsible for declaring their
+ // preferences, we have to enforce a uniquenes check here because some tests
+ // create one profile and multiple services of the same type attached to that
+ // profile (serially, not parallel). This wasn't a problem when it was the
+ // Profile that was responsible for registering the preferences, but now is
+ // because of the timing issues introduced by One.
+ DCHECK(!profile->IsOffTheRecord());
+
+ std::set<Profile*>::iterator it = registered_preferences_.find(profile);
+ if (it == registered_preferences_.end()) {
+ RegisterUserPrefs(profile->GetPrefs());
+ registered_preferences_.insert(profile);
+ }
+}
+
ProfileKeyedServiceFactory::ProfileKeyedServiceFactory(
ProfileDependencyManager* manager)
: dependency_manager_(manager) {
@@ -73,6 +119,7 @@ ProfileKeyedService* ProfileKeyedServiceFactory::GetServiceForProfile(
std::map<Profile*, FactoryFunction>::iterator jt = factories_.find(profile);
if (jt != factories_.end()) {
if (jt->second) {
+ RegisterUserPrefsOnProfile(profile);
service = jt->second(profile);
} else {
service = NULL;
@@ -135,4 +182,5 @@ void ProfileKeyedServiceFactory::ProfileDestroyed(Profile* profile) {
// object that lives at the same address (see other comments about unit tests
// in this file).
factories_.erase(profile);
+ registered_preferences_.erase(profile);
}
diff --git a/chrome/browser/profiles/profile_keyed_service_factory.h b/chrome/browser/profiles/profile_keyed_service_factory.h
index 90c4308..3cac950 100644
--- a/chrome/browser/profiles/profile_keyed_service_factory.h
+++ b/chrome/browser/profiles/profile_keyed_service_factory.h
@@ -6,7 +6,9 @@
#define CHROME_BROWSER_PROFILES_PROFILE_KEYED_SERVICE_FACTORY_H_
#include <map>
+#include <set>
+class PrefService;
class Profile;
class ProfileDependencyManager;
class ProfileKeyedService;
@@ -38,6 +40,12 @@ class ProfileKeyedServiceFactory {
ProfileKeyedService* SetTestingFactoryAndUse(Profile* profile,
FactoryFunction factory);
+ // Registers preferences used in this service on the pref service of
+ // |profile|. This is the public interface and is safe to be called multiple
+ // times because testing code can have multiple services of the same type
+ // attached to a single |profile|.
+ void RegisterUserPrefsOnProfile(Profile* profile);
+
protected:
// ProfileKeyedServiceFactories must communicate with a
// ProfileDependencyManager. For all non-test code, write your subclass
@@ -68,6 +76,11 @@ class ProfileKeyedServiceFactory {
virtual ProfileKeyedService* BuildServiceInstanceFor(
Profile* profile) const = 0;
+ // Register any user preferences on this service. This is called during
+ // CreateProfileService() since preferences are registered on a per Profile
+ // basis.
+ virtual void RegisterUserPrefs(PrefService* user_prefs) {}
+
// By default, if we are asked for a service with an Incognito profile, we
// pass back NULL. To redirect to the Incognito's original profile or to
// create another instance, even for Incognito windows, override one of the
@@ -111,6 +124,9 @@ class ProfileKeyedServiceFactory {
// The mapping between a Profile and its overridden FactoryFunction.
std::map<Profile*, FactoryFunction> factories_;
+ // Profiles that have this service's preferences registered on them.
+ std::set<Profile*> registered_preferences_;
+
// Which ProfileDependencyManager we should communicate with. In real code,
// this will always be ProfileDependencyManager::GetInstance(), but unit
// tests will want to use their own copy.
diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc
index b44f2d3..0aa8599 100644
--- a/chrome/browser/search_engines/template_url_service.cc
+++ b/chrome/browser/search_engines/template_url_service.cc
@@ -828,40 +828,6 @@ void TemplateURLService::ProcessTemplateURLChange(
}
// static
-void TemplateURLService::RegisterUserPrefs(PrefService* prefs) {
- prefs->RegisterBooleanPref(prefs::kDefaultSearchProviderEnabled,
- true,
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterStringPref(prefs::kDefaultSearchProviderName,
- std::string(),
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterStringPref(prefs::kDefaultSearchProviderID,
- std::string(),
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterStringPref(prefs::kDefaultSearchProviderPrepopulateID,
- std::string(),
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterStringPref(prefs::kDefaultSearchProviderSuggestURL,
- std::string(),
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterStringPref(prefs::kDefaultSearchProviderSearchURL,
- std::string(),
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterStringPref(prefs::kDefaultSearchProviderInstantURL,
- std::string(),
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterStringPref(prefs::kDefaultSearchProviderKeyword,
- std::string(),
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterStringPref(prefs::kDefaultSearchProviderIconURL,
- std::string(),
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterStringPref(prefs::kDefaultSearchProviderEncodings,
- std::string(),
- PrefService::UNSYNCABLE_PREF);
-}
-
-// static
SyncData TemplateURLService::CreateSyncDataFromTemplateURL(
const TemplateURL& turl) {
sync_pb::EntitySpecifics specifics;
diff --git a/chrome/browser/search_engines/template_url_service.h b/chrome/browser/search_engines/template_url_service.h
index 2846cb7e..9cc3918 100644
--- a/chrome/browser/search_engines/template_url_service.h
+++ b/chrome/browser/search_engines/template_url_service.h
@@ -281,9 +281,6 @@ class TemplateURLService : public WebDataServiceConsumer,
return search_engine_dialog_chosen_slot_;
}
- // Registers the preferences used to save a TemplateURL to prefs.
- static void RegisterUserPrefs(PrefService* prefs);
-
// Returns a SyncData with a sync representation of the search engine data
// from |turl|.
static SyncData CreateSyncDataFromTemplateURL(const TemplateURL& turl);
diff --git a/chrome/browser/search_engines/template_url_service_factory.cc b/chrome/browser/search_engines/template_url_service_factory.cc
index ddbe5a5..e3f0e0e 100644
--- a/chrome/browser/search_engines/template_url_service_factory.cc
+++ b/chrome/browser/search_engines/template_url_service_factory.cc
@@ -4,8 +4,10 @@
#include "chrome/browser/search_engines/template_url_service_factory.h"
-#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/common/pref_names.h"
TemplateURLService* TemplateURLServiceFactory::GetForProfile(Profile* profile) {
return static_cast<TemplateURLService*>(
@@ -32,6 +34,39 @@ ProfileKeyedService* TemplateURLServiceFactory::BuildServiceInstanceFor(
return new TemplateURLService(profile);
}
+void TemplateURLServiceFactory::RegisterUserPrefs(PrefService* prefs) {
+ prefs->RegisterBooleanPref(prefs::kDefaultSearchProviderEnabled,
+ true,
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterStringPref(prefs::kDefaultSearchProviderName,
+ std::string(),
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterStringPref(prefs::kDefaultSearchProviderID,
+ std::string(),
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterStringPref(prefs::kDefaultSearchProviderPrepopulateID,
+ std::string(),
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterStringPref(prefs::kDefaultSearchProviderSuggestURL,
+ std::string(),
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterStringPref(prefs::kDefaultSearchProviderSearchURL,
+ std::string(),
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterStringPref(prefs::kDefaultSearchProviderInstantURL,
+ std::string(),
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterStringPref(prefs::kDefaultSearchProviderKeyword,
+ std::string(),
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterStringPref(prefs::kDefaultSearchProviderIconURL,
+ std::string(),
+ PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterStringPref(prefs::kDefaultSearchProviderEncodings,
+ std::string(),
+ PrefService::UNSYNCABLE_PREF);
+}
+
bool TemplateURLServiceFactory::ServiceRedirectedInIncognito() {
return true;
}
diff --git a/chrome/browser/search_engines/template_url_service_factory.h b/chrome/browser/search_engines/template_url_service_factory.h
index 8d3dbe2..b70c5d0 100644
--- a/chrome/browser/search_engines/template_url_service_factory.h
+++ b/chrome/browser/search_engines/template_url_service_factory.h
@@ -9,6 +9,7 @@
#include "base/memory/singleton.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"
+class PrefService;
class Profile;
class TemplateURLService;
@@ -28,6 +29,7 @@ class TemplateURLServiceFactory : public ProfileKeyedServiceFactory {
// ProfileKeyedServiceFactory:
virtual ProfileKeyedService* BuildServiceInstanceFor(Profile* profile) const;
+ virtual void RegisterUserPrefs(PrefService* user_prefs);
virtual bool ServiceRedirectedInIncognito();
virtual bool ServiceIsNULLWhileTesting();
virtual void ProfileShutdown(Profile* profile);
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index ea82d69..98e3e4a 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1707,6 +1707,8 @@
'browser/plugin_observer.h',
'browser/plugin_prefs.cc',
'browser/plugin_prefs.h',
+ 'browser/plugin_prefs_factory.cc',
+ 'browser/plugin_prefs_factory.h',
'browser/policy/asynchronous_policy_loader.cc',
'browser/policy/asynchronous_policy_loader.h',
'browser/policy/asynchronous_policy_provider.cc',