OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/keyed_service/ios/refcounted_browser_state_keyed_service_fa
ctory.h" | 5 #include "components/keyed_service/ios/refcounted_browser_state_keyed_service_fa
ctory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "components/keyed_service/core/refcounted_keyed_service.h" | 8 #include "components/keyed_service/core/refcounted_keyed_service.h" |
9 #include "components/keyed_service/ios/browser_state_dependency_manager.h" | 9 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
10 #include "ios/web/public/browser_state.h" | 10 #include "ios/web/public/browser_state.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 scoped_refptr<RefcountedKeyedService> | 42 scoped_refptr<RefcountedKeyedService> |
43 RefcountedBrowserStateKeyedServiceFactory::GetServiceForBrowserState( | 43 RefcountedBrowserStateKeyedServiceFactory::GetServiceForBrowserState( |
44 web::BrowserState* context, | 44 web::BrowserState* context, |
45 bool create) { | 45 bool create) { |
46 return RefcountedKeyedServiceFactory::GetServiceForContext(context, create); | 46 return RefcountedKeyedServiceFactory::GetServiceForContext(context, create); |
47 } | 47 } |
48 | 48 |
49 web::BrowserState* | 49 web::BrowserState* |
50 RefcountedBrowserStateKeyedServiceFactory::GetBrowserStateToUse( | 50 RefcountedBrowserStateKeyedServiceFactory::GetBrowserStateToUse( |
51 web::BrowserState* context) const { | 51 web::BrowserState* context) const { |
| 52 // TODO(crbug.com/701326): This DCHECK should be moved to GetContextToUse(). |
52 DCHECK(CalledOnValidThread()); | 53 DCHECK(CalledOnValidThread()); |
53 | 54 |
54 #ifndef NDEBUG | |
55 AssertContextWasntDestroyed(context); | |
56 #endif | |
57 | |
58 // Safe default for Incognito mode: no service. | 55 // Safe default for Incognito mode: no service. |
59 if (context->IsOffTheRecord()) | 56 if (context->IsOffTheRecord()) |
60 return nullptr; | 57 return nullptr; |
61 | 58 |
62 return context; | 59 return context; |
63 } | 60 } |
64 | 61 |
65 bool RefcountedBrowserStateKeyedServiceFactory:: | 62 bool RefcountedBrowserStateKeyedServiceFactory:: |
66 ServiceIsCreatedWithBrowserState() const { | 63 ServiceIsCreatedWithBrowserState() const { |
67 return KeyedServiceBaseFactory::ServiceIsCreatedWithContext(); | 64 return KeyedServiceBaseFactory::ServiceIsCreatedWithContext(); |
(...skipping 21 matching lines...) Expand all Loading... |
89 } | 86 } |
90 | 87 |
91 bool RefcountedBrowserStateKeyedServiceFactory::IsOffTheRecord( | 88 bool RefcountedBrowserStateKeyedServiceFactory::IsOffTheRecord( |
92 base::SupportsUserData* context) const { | 89 base::SupportsUserData* context) const { |
93 return static_cast<web::BrowserState*>(context)->IsOffTheRecord(); | 90 return static_cast<web::BrowserState*>(context)->IsOffTheRecord(); |
94 } | 91 } |
95 | 92 |
96 base::SupportsUserData* | 93 base::SupportsUserData* |
97 RefcountedBrowserStateKeyedServiceFactory::GetContextToUse( | 94 RefcountedBrowserStateKeyedServiceFactory::GetContextToUse( |
98 base::SupportsUserData* context) const { | 95 base::SupportsUserData* context) const { |
| 96 AssertContextWasntDestroyed(context); |
99 return GetBrowserStateToUse(static_cast<web::BrowserState*>(context)); | 97 return GetBrowserStateToUse(static_cast<web::BrowserState*>(context)); |
100 } | 98 } |
101 | 99 |
102 bool RefcountedBrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() | 100 bool RefcountedBrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() |
103 const { | 101 const { |
104 return ServiceIsCreatedWithBrowserState(); | 102 return ServiceIsCreatedWithBrowserState(); |
105 } | 103 } |
106 | 104 |
107 void RefcountedBrowserStateKeyedServiceFactory::ContextShutdown( | 105 void RefcountedBrowserStateKeyedServiceFactory::ContextShutdown( |
108 base::SupportsUserData* context) { | 106 base::SupportsUserData* context) { |
109 BrowserStateShutdown(static_cast<web::BrowserState*>(context)); | 107 BrowserStateShutdown(static_cast<web::BrowserState*>(context)); |
110 } | 108 } |
111 | 109 |
112 void RefcountedBrowserStateKeyedServiceFactory::ContextDestroyed( | 110 void RefcountedBrowserStateKeyedServiceFactory::ContextDestroyed( |
113 base::SupportsUserData* context) { | 111 base::SupportsUserData* context) { |
114 BrowserStateDestroyed(static_cast<web::BrowserState*>(context)); | 112 BrowserStateDestroyed(static_cast<web::BrowserState*>(context)); |
115 } | 113 } |
116 | 114 |
117 void RefcountedBrowserStateKeyedServiceFactory::RegisterPrefs( | 115 void RefcountedBrowserStateKeyedServiceFactory::RegisterPrefs( |
118 user_prefs::PrefRegistrySyncable* registry) { | 116 user_prefs::PrefRegistrySyncable* registry) { |
119 RegisterBrowserStatePrefs(registry); | 117 RegisterBrowserStatePrefs(registry); |
120 } | 118 } |
OLD | NEW |