This source file includes following definitions.
- service_name_
- DependsOn
- RegisterProfilePrefsIfNecessaryForContext
- GetBrowserContextToUse
- RegisterUserPrefsOnBrowserContextForTest
- ServiceIsCreatedWithBrowserContext
- ServiceIsNULLWhileTesting
- BrowserContextDestroyed
- ArePreferencesSetOn
- MarkPreferencesSetOn
#include "components/keyed_service/content/browser_context_keyed_base_factory.h"
#include "base/prefs/pref_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
BrowserContextKeyedBaseFactory::BrowserContextKeyedBaseFactory(
const char* name,
BrowserContextDependencyManager* manager)
: dependency_manager_(manager)
#ifndef NDEBUG
,
service_name_(name)
#endif
{
dependency_manager_->AddComponent(this);
}
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(
content::BrowserContext* context) const {
DCHECK(CalledOnValidThread());
#ifndef NDEBUG
dependency_manager_->AssertBrowserContextWasntDestroyed(context);
#endif
if (context->IsOffTheRecord())
return NULL;
return context;
}
void BrowserContextKeyedBaseFactory::RegisterUserPrefsOnBrowserContextForTest(
content::BrowserContext* context) {
PrefService* prefs = user_prefs::UserPrefs::Get(context);
user_prefs::PrefRegistrySyncable* registry =
static_cast<user_prefs::PrefRegistrySyncable*>(
prefs->DeprecatedGetPrefRegistry());
RegisterProfilePrefsIfNecessaryForContext(context, registry);
}
bool BrowserContextKeyedBaseFactory::ServiceIsCreatedWithBrowserContext()
const {
return false;
}
bool BrowserContextKeyedBaseFactory::ServiceIsNULLWhileTesting() const {
return false;
}
void BrowserContextKeyedBaseFactory::BrowserContextDestroyed(
content::BrowserContext* context) {
DCHECK(CalledOnValidThread());
registered_preferences_.erase(context);
}
bool BrowserContextKeyedBaseFactory::ArePreferencesSetOn(
content::BrowserContext* context) const {
return registered_preferences_.find(context) != registered_preferences_.end();
}
void BrowserContextKeyedBaseFactory::MarkPreferencesSetOn(
content::BrowserContext* context) {
DCHECK(!ArePreferencesSetOn(context));
registered_preferences_.insert(context);
}