Index: components/keyed_service/core/keyed_service_base_factory.cc |
diff --git a/components/keyed_service/core/keyed_service_base_factory.cc b/components/keyed_service/core/keyed_service_base_factory.cc |
index 7157c0eb234e99fcdf7e91d5ec8f3885c7d7feab..20ef2104af55b64c9715ea174cf0b721e20371c2 100644 |
--- a/components/keyed_service/core/keyed_service_base_factory.cc |
+++ b/components/keyed_service/core/keyed_service_base_factory.cc |
@@ -8,6 +8,8 @@ |
#include "base/supports_user_data.h" |
#include "base/trace_event/trace_event.h" |
#include "components/keyed_service/core/dependency_manager.h" |
+#include "components/pref_registry/pref_registry_syncable.h" |
+#include "components/user_prefs/user_prefs.h" |
void KeyedServiceBaseFactory::RegisterUserPrefsOnContextForTest( |
base::SupportsUserData* context) { |
@@ -35,9 +37,8 @@ void KeyedServiceBaseFactory::RegisterUserPrefsOnContextForTest( |
// 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. |
+ // This is the purpose of RegisterPrefsIfNecessaryForContext() which could be |
+ // replaced directly by RegisterPrefs() if this method is ever phased out. |
RegisterPrefsIfNecessaryForContext(context, |
GetAssociatedPrefRegistry(context)); |
} |
@@ -60,7 +61,7 @@ void KeyedServiceBaseFactory::DependsOn(KeyedServiceBaseFactory* rhs) { |
} |
void KeyedServiceBaseFactory::RegisterPrefsIfNecessaryForContext( |
- const base::SupportsUserData* context, |
+ base::SupportsUserData* context, |
user_prefs::PrefRegistrySyncable* registry) { |
if (!ArePreferencesSetOn(context)) { |
RegisterPrefs(registry); |
@@ -68,16 +69,29 @@ void KeyedServiceBaseFactory::RegisterPrefsIfNecessaryForContext( |
} |
} |
+user_prefs::PrefRegistrySyncable* |
+KeyedServiceBaseFactory::GetAssociatedPrefRegistry( |
+ base::SupportsUserData* context) const { |
+ PrefService* prefs = |
+ user_prefs::UserPrefs::Get(GetContextForDependencyManager(context)); |
+ user_prefs::PrefRegistrySyncable* registry = |
+ static_cast<user_prefs::PrefRegistrySyncable*>( |
+ prefs->DeprecatedGetPrefRegistry()); |
+ return registry; |
+} |
+ |
#ifndef NDEBUG |
void KeyedServiceBaseFactory::AssertContextWasntDestroyed( |
- const base::SupportsUserData* context) const { |
+ base::SupportsUserData* context) const { |
DCHECK(CalledOnValidThread()); |
+ context = GetContextForDependencyManager(context); |
dependency_manager_->AssertContextWasntDestroyed(context); |
} |
void KeyedServiceBaseFactory::MarkContextLiveForTesting( |
- const base::SupportsUserData* context) { |
+ base::SupportsUserData* context) { |
DCHECK(CalledOnValidThread()); |
+ context = GetContextForDependencyManager(context); |
dependency_manager_->MarkContextLiveForTesting(context); |
} |
#endif |
@@ -95,17 +109,28 @@ void KeyedServiceBaseFactory::ContextDestroyed( |
// While object destruction can be customized in ways where the object is |
// only dereferenced, this still must run on the UI thread. |
DCHECK(CalledOnValidThread()); |
- |
registered_preferences_.erase(context); |
} |
bool KeyedServiceBaseFactory::ArePreferencesSetOn( |
- const base::SupportsUserData* context) const { |
+ base::SupportsUserData* context) const { |
return registered_preferences_.find(context) != registered_preferences_.end(); |
} |
void KeyedServiceBaseFactory::MarkPreferencesSetOn( |
- const base::SupportsUserData* context) { |
+ base::SupportsUserData* context) { |
DCHECK(!ArePreferencesSetOn(context)); |
registered_preferences_.insert(context); |
} |
+ |
+#if defined(OS_IOS) |
+base::SupportsUserData* KeyedServiceBaseFactory::GetTypedContext( |
+ base::SupportsUserData* context) const { |
+ return context; |
+} |
+ |
+base::SupportsUserData* KeyedServiceBaseFactory::GetContextForDependencyManager( |
+ base::SupportsUserData* context) const { |
+ return context; |
+} |
+#endif // defined(OS_IOS) |