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_service_factory.h"
7 #include "base/logging.h"
8 #include "components/keyed_service/content/browser_context_dependency_manager.h"
9 #include "components/keyed_service/core/keyed_service.h"
10 #include "components/pref_registry/pref_registry_syncable.h"
11 #include "components/user_prefs/user_prefs.h"
12 #include "content/public/browser/browser_context.h"
14 void BrowserContextKeyedServiceFactory::SetTestingFactory(
15 content::BrowserContext
* context
,
16 TestingFactoryFunction testing_factory
) {
17 KeyedServiceFactory::SetTestingFactory(
19 reinterpret_cast<KeyedServiceFactory::TestingFactoryFunction
>(
23 KeyedService
* BrowserContextKeyedServiceFactory::SetTestingFactoryAndUse(
24 content::BrowserContext
* context
,
25 TestingFactoryFunction testing_factory
) {
26 return KeyedServiceFactory::SetTestingFactoryAndUse(
28 reinterpret_cast<KeyedServiceFactory::TestingFactoryFunction
>(
32 BrowserContextKeyedServiceFactory::BrowserContextKeyedServiceFactory(
34 BrowserContextDependencyManager
* manager
)
35 : KeyedServiceFactory(name
, manager
) {
38 BrowserContextKeyedServiceFactory::~BrowserContextKeyedServiceFactory() {
41 KeyedService
* BrowserContextKeyedServiceFactory::GetServiceForBrowserContext(
42 content::BrowserContext
* context
,
44 return KeyedServiceFactory::GetServiceForContext(context
, create
);
47 content::BrowserContext
*
48 BrowserContextKeyedServiceFactory::GetBrowserContextToUse(
49 content::BrowserContext
* context
) const {
50 DCHECK(CalledOnValidThread());
53 AssertContextWasntDestroyed(context
);
56 // Safe default for Incognito mode: no service.
57 if (context
->IsOffTheRecord())
64 BrowserContextKeyedServiceFactory::RegisterUserPrefsOnBrowserContextForTest(
65 content::BrowserContext
* context
) {
66 KeyedServiceBaseFactory::RegisterUserPrefsOnContextForTest(context
);
69 bool BrowserContextKeyedServiceFactory::ServiceIsCreatedWithBrowserContext()
71 return KeyedServiceBaseFactory::ServiceIsCreatedWithContext();
74 bool BrowserContextKeyedServiceFactory::ServiceIsNULLWhileTesting() const {
75 return KeyedServiceBaseFactory::ServiceIsNULLWhileTesting();
78 void BrowserContextKeyedServiceFactory::BrowserContextShutdown(
79 content::BrowserContext
* context
) {
80 KeyedServiceFactory::ContextShutdown(context
);
83 void BrowserContextKeyedServiceFactory::BrowserContextDestroyed(
84 content::BrowserContext
* context
) {
85 KeyedServiceFactory::ContextDestroyed(context
);
88 scoped_ptr
<KeyedService
>
89 BrowserContextKeyedServiceFactory::BuildServiceInstanceFor(
90 base::SupportsUserData
* context
) const {
91 // TODO(isherman): The wrapped BuildServiceInstanceFor() should return a
92 // scoped_ptr as well.
93 return make_scoped_ptr(
94 BuildServiceInstanceFor(static_cast<content::BrowserContext
*>(context
)));
97 bool BrowserContextKeyedServiceFactory::IsOffTheRecord(
98 base::SupportsUserData
* context
) const {
99 return static_cast<content::BrowserContext
*>(context
)->IsOffTheRecord();
102 base::SupportsUserData
* BrowserContextKeyedServiceFactory::GetContextToUse(
103 base::SupportsUserData
* context
) const {
104 return GetBrowserContextToUse(static_cast<content::BrowserContext
*>(context
));
107 bool BrowserContextKeyedServiceFactory::ServiceIsCreatedWithContext() const {
108 return ServiceIsCreatedWithBrowserContext();
111 void BrowserContextKeyedServiceFactory::ContextShutdown(
112 base::SupportsUserData
* context
) {
113 BrowserContextShutdown(static_cast<content::BrowserContext
*>(context
));
116 void BrowserContextKeyedServiceFactory::ContextDestroyed(
117 base::SupportsUserData
* context
) {
118 BrowserContextDestroyed(static_cast<content::BrowserContext
*>(context
));
121 void BrowserContextKeyedServiceFactory::RegisterPrefs(
122 user_prefs::PrefRegistrySyncable
* registry
) {
123 RegisterProfilePrefs(registry
);