Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / keyed_service / content / browser_context_keyed_service_factory.cc
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.
4
5 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
6
7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h"
9 #include "components/keyed_service/content/browser_context_dependency_manager.h"
10 #include "components/keyed_service/core/keyed_service.h"
11 #include "components/pref_registry/pref_registry_syncable.h"
12 #include "components/user_prefs/user_prefs.h"
13 #include "content/public/browser/browser_context.h"
14
15 void BrowserContextKeyedServiceFactory::SetTestingFactory(
16     content::BrowserContext* context,
17     TestingFactoryFunction testing_factory) {
18   KeyedServiceFactory::SetTestingFactory(
19       context,
20       reinterpret_cast<KeyedServiceFactory::TestingFactoryFunction>(
21           testing_factory));
22 }
23
24 KeyedService* BrowserContextKeyedServiceFactory::SetTestingFactoryAndUse(
25     content::BrowserContext* context,
26     TestingFactoryFunction testing_factory) {
27   return KeyedServiceFactory::SetTestingFactoryAndUse(
28       context,
29       reinterpret_cast<KeyedServiceFactory::TestingFactoryFunction>(
30           testing_factory));
31 }
32
33 BrowserContextKeyedServiceFactory::BrowserContextKeyedServiceFactory(
34     const char* name,
35     BrowserContextDependencyManager* manager)
36     : KeyedServiceFactory(name, manager) {
37 }
38
39 BrowserContextKeyedServiceFactory::~BrowserContextKeyedServiceFactory() {
40 }
41
42 KeyedService* BrowserContextKeyedServiceFactory::GetServiceForBrowserContext(
43     content::BrowserContext* context,
44     bool create) {
45   return KeyedServiceFactory::GetServiceForContext(context, create);
46 }
47
48 content::BrowserContext*
49 BrowserContextKeyedServiceFactory::GetBrowserContextToUse(
50     content::BrowserContext* context) const {
51   DCHECK(CalledOnValidThread());
52
53 #ifndef NDEBUG
54   AssertContextWasntDestroyed(context);
55 #endif
56
57   // Safe default for Incognito mode: no service.
58   if (context->IsOffTheRecord())
59     return nullptr;
60
61   return context;
62 }
63
64 void
65 BrowserContextKeyedServiceFactory::RegisterUserPrefsOnBrowserContextForTest(
66     content::BrowserContext* context) {
67   KeyedServiceBaseFactory::RegisterUserPrefsOnContextForTest(context);
68 }
69
70 bool BrowserContextKeyedServiceFactory::ServiceIsCreatedWithBrowserContext()
71     const {
72   return KeyedServiceBaseFactory::ServiceIsCreatedWithContext();
73 }
74
75 bool BrowserContextKeyedServiceFactory::ServiceIsNULLWhileTesting() const {
76   return KeyedServiceBaseFactory::ServiceIsNULLWhileTesting();
77 }
78
79 void BrowserContextKeyedServiceFactory::BrowserContextShutdown(
80     content::BrowserContext* context) {
81   KeyedServiceFactory::ContextShutdown(context);
82 }
83
84 void BrowserContextKeyedServiceFactory::BrowserContextDestroyed(
85     content::BrowserContext* context) {
86   KeyedServiceFactory::ContextDestroyed(context);
87 }
88
89 KeyedService* BrowserContextKeyedServiceFactory::BuildServiceInstanceFor(
90     base::SupportsUserData* context) const {
91   return BuildServiceInstanceFor(
92       static_cast<content::BrowserContext*>(context));
93 }
94
95 bool BrowserContextKeyedServiceFactory::IsOffTheRecord(
96     base::SupportsUserData* context) const {
97   return static_cast<content::BrowserContext*>(context)->IsOffTheRecord();
98 }
99
100 user_prefs::PrefRegistrySyncable*
101 BrowserContextKeyedServiceFactory::GetAssociatedPrefRegistry(
102     base::SupportsUserData* context) const {
103   PrefService* prefs = user_prefs::UserPrefs::Get(
104       static_cast<content::BrowserContext*>(context));
105   user_prefs::PrefRegistrySyncable* registry =
106       static_cast<user_prefs::PrefRegistrySyncable*>(
107           prefs->DeprecatedGetPrefRegistry());
108   return registry;
109 }
110
111 base::SupportsUserData* BrowserContextKeyedServiceFactory::GetContextToUse(
112     base::SupportsUserData* context) const {
113   return GetBrowserContextToUse(static_cast<content::BrowserContext*>(context));
114 }
115
116 bool BrowserContextKeyedServiceFactory::ServiceIsCreatedWithContext() const {
117   return ServiceIsCreatedWithBrowserContext();
118 }
119
120 void BrowserContextKeyedServiceFactory::ContextShutdown(
121     base::SupportsUserData* context) {
122   BrowserContextShutdown(static_cast<content::BrowserContext*>(context));
123 }
124
125 void BrowserContextKeyedServiceFactory::ContextDestroyed(
126     base::SupportsUserData* context) {
127   BrowserContextDestroyed(static_cast<content::BrowserContext*>(context));
128 }
129
130 void BrowserContextKeyedServiceFactory::RegisterPrefs(
131     user_prefs::PrefRegistrySyncable* registry) {
132   RegisterProfilePrefs(registry);
133 }