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(). | |
46 DCHECK(CalledOnValidThread()); | |
47 | |
48 // Safe default for Incognito mode: no service. | 45 // Safe default for Incognito mode: no service. |
49 if (context->IsOffTheRecord()) | 46 if (context->IsOffTheRecord()) |
50 return nullptr; | 47 return nullptr; |
51 | 48 |
52 return context; | 49 return context; |
53 } | 50 } |
54 | 51 |
55 bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithBrowserState() const { | 52 bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithBrowserState() const { |
56 return KeyedServiceBaseFactory::ServiceIsCreatedWithContext(); | 53 return KeyedServiceBaseFactory::ServiceIsCreatedWithContext(); |
57 } | 54 } |
(...skipping 18 matching lines...) Expand all Loading... |
76 return BuildServiceInstanceFor(static_cast<web::BrowserState*>(context)); | 73 return BuildServiceInstanceFor(static_cast<web::BrowserState*>(context)); |
77 } | 74 } |
78 | 75 |
79 bool BrowserStateKeyedServiceFactory::IsOffTheRecord( | 76 bool BrowserStateKeyedServiceFactory::IsOffTheRecord( |
80 base::SupportsUserData* context) const { | 77 base::SupportsUserData* context) const { |
81 return static_cast<web::BrowserState*>(context)->IsOffTheRecord(); | 78 return static_cast<web::BrowserState*>(context)->IsOffTheRecord(); |
82 } | 79 } |
83 | 80 |
84 base::SupportsUserData* BrowserStateKeyedServiceFactory::GetContextToUse( | 81 base::SupportsUserData* BrowserStateKeyedServiceFactory::GetContextToUse( |
85 base::SupportsUserData* context) const { | 82 base::SupportsUserData* context) const { |
| 83 DCHECK(CalledOnValidThread()); |
86 AssertContextWasntDestroyed(context); | 84 AssertContextWasntDestroyed(context); |
87 return GetBrowserStateToUse(static_cast<web::BrowserState*>(context)); | 85 return GetBrowserStateToUse(static_cast<web::BrowserState*>(context)); |
88 } | 86 } |
89 | 87 |
90 bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const { | 88 bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const { |
91 return ServiceIsCreatedWithBrowserState(); | 89 return ServiceIsCreatedWithBrowserState(); |
92 } | 90 } |
93 | 91 |
94 void BrowserStateKeyedServiceFactory::ContextShutdown( | 92 void BrowserStateKeyedServiceFactory::ContextShutdown( |
95 base::SupportsUserData* context) { | 93 base::SupportsUserData* context) { |
96 BrowserStateShutdown(static_cast<web::BrowserState*>(context)); | 94 BrowserStateShutdown(static_cast<web::BrowserState*>(context)); |
97 } | 95 } |
98 | 96 |
99 void BrowserStateKeyedServiceFactory::ContextDestroyed( | 97 void BrowserStateKeyedServiceFactory::ContextDestroyed( |
100 base::SupportsUserData* context) { | 98 base::SupportsUserData* context) { |
101 BrowserStateDestroyed(static_cast<web::BrowserState*>(context)); | 99 BrowserStateDestroyed(static_cast<web::BrowserState*>(context)); |
102 } | 100 } |
103 | 101 |
104 void BrowserStateKeyedServiceFactory::RegisterPrefs( | 102 void BrowserStateKeyedServiceFactory::RegisterPrefs( |
105 user_prefs::PrefRegistrySyncable* registry) { | 103 user_prefs::PrefRegistrySyncable* registry) { |
106 RegisterBrowserStatePrefs(registry); | 104 RegisterBrowserStatePrefs(registry); |
107 } | 105 } |
OLD | NEW |