BrowserContextKeyedBaseFactory::BrowserContextKeyedBaseFactory(
const char* name,
BrowserContextDependencyManager* manager)
- : dependency_manager_(manager)
-#ifndef NDEBUG
- ,
- service_name_(name)
-#endif
-{
- dependency_manager_->AddComponent(this);
+ : KeyedServiceBaseFactory(name, manager) {
}
BrowserContextKeyedBaseFactory::~BrowserContextKeyedBaseFactory() {
- dependency_manager_->RemoveComponent(this);
-}
-
-void BrowserContextKeyedBaseFactory::DependsOn(
- BrowserContextKeyedBaseFactory* rhs) {
- dependency_manager_->AddEdge(rhs, this);
-}
-
-void BrowserContextKeyedBaseFactory::RegisterProfilePrefsIfNecessaryForContext(
- const content::BrowserContext* context,
- user_prefs::PrefRegistrySyncable* registry) {
- std::set<const content::BrowserContext*>::iterator it =
- registered_preferences_.find(context);
- if (it == registered_preferences_.end()) {
- RegisterProfilePrefs(registry);
- registered_preferences_.insert(context);
- }
}
content::BrowserContext* BrowserContextKeyedBaseFactory::GetBrowserContextToUse(
DCHECK(CalledOnValidThread());
#ifndef NDEBUG
- dependency_manager_->AssertBrowserContextWasntDestroyed(context);
+ AssertContextWasntDestroyed(context);
#endif
// Safe default for the Incognito mode: no service.
void BrowserContextKeyedBaseFactory::RegisterUserPrefsOnBrowserContextForTest(
content::BrowserContext* context) {
- // Safe timing for pref registration is hard. Previously, we made
- // BrowserContext responsible for all pref registration on every service
- // that used BrowserContext. Now we don't and there are timing issues.
- //
- // With normal contexts, prefs can simply be registered at
- // BrowserContextDependencyManager::RegisterProfilePrefsForServices time.
- // With incognito contexts, we just never register since incognito contexts
- // share the same pref services with their parent contexts.
- //
- // TestingBrowserContexts throw a wrench into the mix, in that some tests will
- // swap out the PrefService after we've registered user prefs on the original
- // PrefService. Test code that does this is responsible for either manually
- // invoking RegisterProfilePrefs() on the appropriate
- // BrowserContextKeyedServiceFactory associated with the prefs they need,
- // or they can use SetTestingFactory() and create a service (since service
- // creation with a factory method causes registration to happen at
- // TestingProfile creation time).
- //
- // Now that services are responsible for declaring their preferences, we have
- // to enforce a uniquenes check here because some tests create one context and
- // multiple services of the same type attached to that context (serially, not
- // parallel) and we don't want to register multiple times on the same context.
- // This is the purpose of RegisterProfilePrefsIfNecessary() which could be
- // replaced directly by RegisterProfilePrefs() if this method is ever phased
- // out.
- PrefService* prefs = user_prefs::UserPrefs::Get(context);
- user_prefs::PrefRegistrySyncable* registry =
- static_cast<user_prefs::PrefRegistrySyncable*>(
- prefs->DeprecatedGetPrefRegistry());
- RegisterProfilePrefsIfNecessaryForContext(context, registry);
+ KeyedServiceBaseFactory::RegisterUserPrefsOnContextForTest(context);
}
bool BrowserContextKeyedBaseFactory::ServiceIsCreatedWithBrowserContext()
const {
- return false;
+ return KeyedServiceBaseFactory::ServiceIsCreatedWithContext();
}
bool BrowserContextKeyedBaseFactory::ServiceIsNULLWhileTesting() const {
- return false;
+ return KeyedServiceBaseFactory::ServiceIsNULLWhileTesting();
}
void BrowserContextKeyedBaseFactory::BrowserContextDestroyed(
content::BrowserContext* context) {
- // While object destruction can be customized in ways where the object is
- // only dereferenced, this still must run on the UI thread.
- DCHECK(CalledOnValidThread());
+ KeyedServiceBaseFactory::ContextDestroyed(context);
+}
+
+user_prefs::PrefRegistrySyncable*
+BrowserContextKeyedBaseFactory::GetAssociatedPrefRegistry(
+ base::SupportsUserData* context) const {
+ PrefService* prefs = user_prefs::UserPrefs::Get(
+ static_cast<content::BrowserContext*>(context));
+ user_prefs::PrefRegistrySyncable* registry =
+ static_cast<user_prefs::PrefRegistrySyncable*>(
+ prefs->DeprecatedGetPrefRegistry());
+ return registry;
+}
- registered_preferences_.erase(context);
+base::SupportsUserData* BrowserContextKeyedBaseFactory::GetContextToUse(
+ base::SupportsUserData* context) const {
+ return GetBrowserContextToUse(static_cast<content::BrowserContext*>(context));
}
-bool BrowserContextKeyedBaseFactory::ArePreferencesSetOn(
- content::BrowserContext* context) const {
- return registered_preferences_.find(context) != registered_preferences_.end();
+bool BrowserContextKeyedBaseFactory::ServiceIsCreatedWithContext() const {
+ return ServiceIsCreatedWithBrowserContext();
}
-void BrowserContextKeyedBaseFactory::MarkPreferencesSetOn(
- content::BrowserContext* context) {
- DCHECK(!ArePreferencesSetOn(context));
- registered_preferences_.insert(context);
+void BrowserContextKeyedBaseFactory::ContextShutdown(
+ base::SupportsUserData* context) {
+ BrowserContextShutdown(static_cast<content::BrowserContext*>(context));
+}
+
+void BrowserContextKeyedBaseFactory::ContextDestroyed(
+ base::SupportsUserData* context) {
+ BrowserContextDestroyed(static_cast<content::BrowserContext*>(context));
+}
+
+void BrowserContextKeyedBaseFactory::RegisterPrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ RegisterProfilePrefs(registry);
+}
+
+void BrowserContextKeyedBaseFactory::SetEmptyTestingFactory(
+ base::SupportsUserData* context) {
+ SetEmptyTestingFactory(static_cast<content::BrowserContext*>(context));
+}
+
+bool BrowserContextKeyedBaseFactory::HasTestingFactory(
+ base::SupportsUserData* context) {
+ return HasTestingFactory(static_cast<content::BrowserContext*>(context));
+}
+
+void BrowserContextKeyedBaseFactory::CreateServiceNow(
+ base::SupportsUserData* context) {
+ CreateServiceNow(static_cast<content::BrowserContext*>(context));
}