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..765209e85269a81de6d61d2c095161dac113a53c 100644 |
--- a/components/keyed_service/core/keyed_service_base_factory.cc |
+++ b/components/keyed_service/core/keyed_service_base_factory.cc |
@@ -8,9 +8,12 @@ |
#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) { |
+ context = GetUnderlyingContext(context); |
TRACE_EVENT0("browser,startup", |
"KeyedServiceBaseFactory::RegisterUserPrefsOnContextForTest"); |
// Safe timing for pref registration is hard. Previously, we made |
@@ -35,9 +38,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,24 +62,37 @@ void KeyedServiceBaseFactory::DependsOn(KeyedServiceBaseFactory* rhs) { |
} |
void KeyedServiceBaseFactory::RegisterPrefsIfNecessaryForContext( |
- const base::SupportsUserData* context, |
+ base::SupportsUserData* context, |
user_prefs::PrefRegistrySyncable* registry) { |
+ context = GetUnderlyingContext(context); |
if (!ArePreferencesSetOn(context)) { |
RegisterPrefs(registry); |
MarkPreferencesSetOn(context); |
} |
} |
+user_prefs::PrefRegistrySyncable* |
+KeyedServiceBaseFactory::GetAssociatedPrefRegistry( |
+ base::SupportsUserData* context) const { |
+ PrefService* prefs = user_prefs::UserPrefs::Get(GetOriginalContext(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 = GetOriginalContext(context); |
dependency_manager_->AssertContextWasntDestroyed(context); |
} |
void KeyedServiceBaseFactory::MarkContextLiveForTesting( |
- const base::SupportsUserData* context) { |
+ base::SupportsUserData* context) { |
DCHECK(CalledOnValidThread()); |
+ context = GetOriginalContext(context); |
dependency_manager_->MarkContextLiveForTesting(context); |
} |
#endif |
@@ -96,16 +111,37 @@ void KeyedServiceBaseFactory::ContextDestroyed( |
// only dereferenced, this still must run on the UI thread. |
DCHECK(CalledOnValidThread()); |
+ context = GetUnderlyingContext(context); |
registered_preferences_.erase(context); |
} |
bool KeyedServiceBaseFactory::ArePreferencesSetOn( |
- const base::SupportsUserData* context) const { |
+ base::SupportsUserData* context) const { |
+ context = GetUnderlyingContext(context); |
return registered_preferences_.find(context) != registered_preferences_.end(); |
} |
void KeyedServiceBaseFactory::MarkPreferencesSetOn( |
- const base::SupportsUserData* context) { |
+ base::SupportsUserData* context) { |
+ context = GetUnderlyingContext(context); |
DCHECK(!ArePreferencesSetOn(context)); |
registered_preferences_.insert(context); |
} |
+ |
+base::SupportsUserData* KeyedServiceBaseFactory::GetUnderlyingContext( |
+ base::SupportsUserData* context) const { |
+ if (context) { |
+ context = GetUnderlyingContextInternal(context); |
+ DCHECK(context); |
+ } |
+ return context; |
+} |
+ |
+base::SupportsUserData* KeyedServiceBaseFactory::GetOriginalContext( |
+ base::SupportsUserData* context) const { |
+ if (context) { |
+ context = GetOriginalContextInternal(context); |
+ DCHECK(context); |
+ } |
+ return context; |
+} |