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