Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Unified Diff: components/keyed_service/core/keyed_service_base_factory.cc

Issue 1090373003: Allow cross dependencies between BCKSF and BSKSF (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix dependencies and DCHECK in Get{Original,Underlying}ContextInternal Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+}

Powered by Google App Engine
This is Rietveld 408576698