1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/keyed_service/content/browser_context_keyed_base_factory.h"
7 #include "base/prefs/pref_service.h"
8 #include "components/keyed_service/content/browser_context_dependency_manager.h"
9 #include "components/pref_registry/pref_registry_syncable.h"
10 #include "components/user_prefs/user_prefs.h"
11 #include "content/public/browser/browser_context.h"
13 BrowserContextKeyedBaseFactory::BrowserContextKeyedBaseFactory(
15 BrowserContextDependencyManager
* manager
)
16 : KeyedServiceBaseFactory(name
, manager
) {
19 BrowserContextKeyedBaseFactory::~BrowserContextKeyedBaseFactory() {
22 content::BrowserContext
* BrowserContextKeyedBaseFactory::GetBrowserContextToUse(
23 content::BrowserContext
* context
) const {
24 DCHECK(CalledOnValidThread());
27 AssertContextWasntDestroyed(context
);
30 // Safe default for the Incognito mode: no service.
31 if (context
->IsOffTheRecord())
37 void BrowserContextKeyedBaseFactory::RegisterUserPrefsOnBrowserContextForTest(
38 content::BrowserContext
* context
) {
39 KeyedServiceBaseFactory::RegisterUserPrefsOnContextForTest(context
);
42 bool BrowserContextKeyedBaseFactory::ServiceIsCreatedWithBrowserContext()
44 return KeyedServiceBaseFactory::ServiceIsCreatedWithContext();
47 bool BrowserContextKeyedBaseFactory::ServiceIsNULLWhileTesting() const {
48 return KeyedServiceBaseFactory::ServiceIsNULLWhileTesting();
51 void BrowserContextKeyedBaseFactory::BrowserContextDestroyed(
52 content::BrowserContext
* context
) {
53 KeyedServiceBaseFactory::ContextDestroyed(context
);
56 user_prefs::PrefRegistrySyncable
*
57 BrowserContextKeyedBaseFactory::GetAssociatedPrefRegistry(
58 base::SupportsUserData
* context
) const {
59 PrefService
* prefs
= user_prefs::UserPrefs::Get(
60 static_cast<content::BrowserContext
*>(context
));
61 user_prefs::PrefRegistrySyncable
* registry
=
62 static_cast<user_prefs::PrefRegistrySyncable
*>(
63 prefs
->DeprecatedGetPrefRegistry());
67 base::SupportsUserData
* BrowserContextKeyedBaseFactory::GetContextToUse(
68 base::SupportsUserData
* context
) const {
69 return GetBrowserContextToUse(static_cast<content::BrowserContext
*>(context
));
72 bool BrowserContextKeyedBaseFactory::ServiceIsCreatedWithContext() const {
73 return ServiceIsCreatedWithBrowserContext();
76 void BrowserContextKeyedBaseFactory::ContextShutdown(
77 base::SupportsUserData
* context
) {
78 BrowserContextShutdown(static_cast<content::BrowserContext
*>(context
));
81 void BrowserContextKeyedBaseFactory::ContextDestroyed(
82 base::SupportsUserData
* context
) {
83 BrowserContextDestroyed(static_cast<content::BrowserContext
*>(context
));
86 void BrowserContextKeyedBaseFactory::RegisterPrefs(
87 user_prefs::PrefRegistrySyncable
* registry
) {
88 RegisterProfilePrefs(registry
);
91 void BrowserContextKeyedBaseFactory::SetEmptyTestingFactory(
92 base::SupportsUserData
* context
) {
93 SetEmptyTestingFactory(static_cast<content::BrowserContext
*>(context
));
96 bool BrowserContextKeyedBaseFactory::HasTestingFactory(
97 base::SupportsUserData
* context
) {
98 return HasTestingFactory(static_cast<content::BrowserContext
*>(context
));
101 void BrowserContextKeyedBaseFactory::CreateServiceNow(
102 base::SupportsUserData
* context
) {
103 CreateServiceNow(static_cast<content::BrowserContext
*>(context
));