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/browser_state_keyed_service_factory.h" | 5 #include "components/keyed_service/ios/browser_state_keyed_service_factory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "components/keyed_service/core/keyed_service.h" | 8 #include "components/keyed_service/core/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 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 | 36 |
37 KeyedService* BrowserStateKeyedServiceFactory::GetServiceForBrowserState( | 37 KeyedService* BrowserStateKeyedServiceFactory::GetServiceForBrowserState( |
38 web::BrowserState* context, | 38 web::BrowserState* context, |
39 bool create) { | 39 bool create) { |
40 return KeyedServiceFactory::GetServiceForContext(context, create); | 40 return KeyedServiceFactory::GetServiceForContext(context, create); |
41 } | 41 } |
42 | 42 |
43 web::BrowserState* BrowserStateKeyedServiceFactory::GetBrowserStateToUse( | 43 web::BrowserState* BrowserStateKeyedServiceFactory::GetBrowserStateToUse( |
44 web::BrowserState* context) const { | 44 web::BrowserState* context) const { |
| 45 // TODO(crbug.com/701326): This DCHECK should be moved to GetContextToUse(). |
45 DCHECK(CalledOnValidThread()); | 46 DCHECK(CalledOnValidThread()); |
46 | 47 |
47 #ifndef NDEBUG | |
48 AssertContextWasntDestroyed(context); | |
49 #endif | |
50 | |
51 // Safe default for Incognito mode: no service. | 48 // Safe default for Incognito mode: no service. |
52 if (context->IsOffTheRecord()) | 49 if (context->IsOffTheRecord()) |
53 return nullptr; | 50 return nullptr; |
54 | 51 |
55 return context; | 52 return context; |
56 } | 53 } |
57 | 54 |
58 bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithBrowserState() const { | 55 bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithBrowserState() const { |
59 return KeyedServiceBaseFactory::ServiceIsCreatedWithContext(); | 56 return KeyedServiceBaseFactory::ServiceIsCreatedWithContext(); |
60 } | 57 } |
(...skipping 18 matching lines...) Expand all Loading... |
79 return BuildServiceInstanceFor(static_cast<web::BrowserState*>(context)); | 76 return BuildServiceInstanceFor(static_cast<web::BrowserState*>(context)); |
80 } | 77 } |
81 | 78 |
82 bool BrowserStateKeyedServiceFactory::IsOffTheRecord( | 79 bool BrowserStateKeyedServiceFactory::IsOffTheRecord( |
83 base::SupportsUserData* context) const { | 80 base::SupportsUserData* context) const { |
84 return static_cast<web::BrowserState*>(context)->IsOffTheRecord(); | 81 return static_cast<web::BrowserState*>(context)->IsOffTheRecord(); |
85 } | 82 } |
86 | 83 |
87 base::SupportsUserData* BrowserStateKeyedServiceFactory::GetContextToUse( | 84 base::SupportsUserData* BrowserStateKeyedServiceFactory::GetContextToUse( |
88 base::SupportsUserData* context) const { | 85 base::SupportsUserData* context) const { |
| 86 AssertContextWasntDestroyed(context); |
89 return GetBrowserStateToUse(static_cast<web::BrowserState*>(context)); | 87 return GetBrowserStateToUse(static_cast<web::BrowserState*>(context)); |
90 } | 88 } |
91 | 89 |
92 bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const { | 90 bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const { |
93 return ServiceIsCreatedWithBrowserState(); | 91 return ServiceIsCreatedWithBrowserState(); |
94 } | 92 } |
95 | 93 |
96 void BrowserStateKeyedServiceFactory::ContextShutdown( | 94 void BrowserStateKeyedServiceFactory::ContextShutdown( |
97 base::SupportsUserData* context) { | 95 base::SupportsUserData* context) { |
98 BrowserStateShutdown(static_cast<web::BrowserState*>(context)); | 96 BrowserStateShutdown(static_cast<web::BrowserState*>(context)); |
99 } | 97 } |
100 | 98 |
101 void BrowserStateKeyedServiceFactory::ContextDestroyed( | 99 void BrowserStateKeyedServiceFactory::ContextDestroyed( |
102 base::SupportsUserData* context) { | 100 base::SupportsUserData* context) { |
103 BrowserStateDestroyed(static_cast<web::BrowserState*>(context)); | 101 BrowserStateDestroyed(static_cast<web::BrowserState*>(context)); |
104 } | 102 } |
105 | 103 |
106 void BrowserStateKeyedServiceFactory::RegisterPrefs( | 104 void BrowserStateKeyedServiceFactory::RegisterPrefs( |
107 user_prefs::PrefRegistrySyncable* registry) { | 105 user_prefs::PrefRegistrySyncable* registry) { |
108 RegisterBrowserStatePrefs(registry); | 106 RegisterBrowserStatePrefs(registry); |
109 } | 107 } |
OLD | NEW |