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/ios/refcounted_browser_state_keyed_service_factory.h"
7 #include "base/logging.h"
8 #include "components/keyed_service/core/refcounted_keyed_service.h"
9 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
10 #include "components/keyed_service/ios/browser_state_helper.h"
11 #include "ios/web/public/browser_state.h"
13 void RefcountedBrowserStateKeyedServiceFactory::SetTestingFactory(
14 web::BrowserState
* context
,
15 TestingFactoryFunction testing_factory
) {
16 RefcountedKeyedServiceFactory::SetTestingFactory(
18 reinterpret_cast<RefcountedKeyedServiceFactory::TestingFactoryFunction
>(
22 scoped_refptr
<RefcountedKeyedService
>
23 RefcountedBrowserStateKeyedServiceFactory::SetTestingFactoryAndUse(
24 web::BrowserState
* context
,
25 TestingFactoryFunction testing_factory
) {
26 return RefcountedKeyedServiceFactory::SetTestingFactoryAndUse(
28 reinterpret_cast<RefcountedKeyedServiceFactory::TestingFactoryFunction
>(
32 RefcountedBrowserStateKeyedServiceFactory::
33 RefcountedBrowserStateKeyedServiceFactory(
35 /*BrowserState*/DependencyManager
* manager
)
36 : RefcountedKeyedServiceFactory(name
, manager
) {
39 RefcountedBrowserStateKeyedServiceFactory::
40 ~RefcountedBrowserStateKeyedServiceFactory() {
43 scoped_refptr
<RefcountedKeyedService
>
44 RefcountedBrowserStateKeyedServiceFactory::GetServiceForBrowserState(
45 web::BrowserState
* context
,
47 return RefcountedKeyedServiceFactory::GetServiceForContext(context
, create
);
51 RefcountedBrowserStateKeyedServiceFactory::GetBrowserStateToUse(
52 web::BrowserState
* context
) const {
53 DCHECK(CalledOnValidThread());
56 AssertContextWasntDestroyed(context
);
59 // Safe default for Incognito mode: no service.
60 if (context
->IsOffTheRecord())
66 bool RefcountedBrowserStateKeyedServiceFactory::
67 ServiceIsCreatedWithBrowserState() const {
68 return KeyedServiceBaseFactory::ServiceIsCreatedWithContext();
71 bool RefcountedBrowserStateKeyedServiceFactory::ServiceIsNULLWhileTesting()
73 return KeyedServiceBaseFactory::ServiceIsNULLWhileTesting();
76 void RefcountedBrowserStateKeyedServiceFactory::BrowserStateShutdown(
77 web::BrowserState
* context
) {
78 RefcountedKeyedServiceFactory::ContextShutdown(context
);
81 void RefcountedBrowserStateKeyedServiceFactory::BrowserStateDestroyed(
82 web::BrowserState
* context
) {
83 RefcountedKeyedServiceFactory::ContextDestroyed(context
);
86 scoped_refptr
<RefcountedKeyedService
>
87 RefcountedBrowserStateKeyedServiceFactory::BuildServiceInstanceFor(
88 base::SupportsUserData
* context
) const {
89 return BuildServiceInstanceFor(BrowserStateFromContext(context
));
92 bool RefcountedBrowserStateKeyedServiceFactory::IsOffTheRecord(
93 base::SupportsUserData
* context
) const {
94 return BrowserStateFromContext(context
)->IsOffTheRecord();
97 user_prefs::PrefRegistrySyncable
*
98 RefcountedBrowserStateKeyedServiceFactory::GetAssociatedPrefRegistry(
99 base::SupportsUserData
* context
) const {
104 base::SupportsUserData
*
105 RefcountedBrowserStateKeyedServiceFactory::GetContextToUse(
106 base::SupportsUserData
* context
) const {
107 return GetBrowserStateToUse(BrowserStateFromContext(context
));
110 bool RefcountedBrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext()
112 return ServiceIsCreatedWithBrowserState();
115 void RefcountedBrowserStateKeyedServiceFactory::ContextShutdown(
116 base::SupportsUserData
* context
) {
117 BrowserStateShutdown(BrowserStateFromContext(context
));
120 void RefcountedBrowserStateKeyedServiceFactory::ContextDestroyed(
121 base::SupportsUserData
* context
) {
122 BrowserStateDestroyed(BrowserStateFromContext(context
));
125 void RefcountedBrowserStateKeyedServiceFactory::RegisterPrefs(
126 user_prefs::PrefRegistrySyncable
* registry
) {
127 RegisterProfilePrefs(registry
);