| 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 "base/prefs/pref_service.h" | |
| 9 #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_context_converter.h" |
| 10 #include "components/keyed_service/ios/browser_state_dependency_manager.h" | 10 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
| 11 #include "components/keyed_service/ios/browser_state_helper.h" | |
| 12 #include "components/pref_registry/pref_registry_syncable.h" | |
| 13 #include "components/user_prefs/user_prefs.h" | |
| 14 #include "ios/web/public/browser_state.h" | 11 #include "ios/web/public/browser_state.h" |
| 15 | 12 |
| 16 void BrowserStateKeyedServiceFactory::SetTestingFactory( | 13 void BrowserStateKeyedServiceFactory::SetTestingFactory( |
| 17 web::BrowserState* context, | 14 web::BrowserState* context, |
| 18 TestingFactoryFunction testing_factory) { | 15 TestingFactoryFunction testing_factory) { |
| 19 KeyedServiceFactory::SetTestingFactory( | 16 KeyedServiceFactory::SetTestingFactory( |
| 20 context, reinterpret_cast<KeyedServiceFactory::TestingFactoryFunction>( | 17 context, reinterpret_cast<KeyedServiceFactory::TestingFactoryFunction>( |
| 21 testing_factory)); | 18 testing_factory)); |
| 22 } | 19 } |
| 23 | 20 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 KeyedServiceFactory::ContextShutdown(context); | 69 KeyedServiceFactory::ContextShutdown(context); |
| 73 } | 70 } |
| 74 | 71 |
| 75 void BrowserStateKeyedServiceFactory::BrowserStateDestroyed( | 72 void BrowserStateKeyedServiceFactory::BrowserStateDestroyed( |
| 76 web::BrowserState* context) { | 73 web::BrowserState* context) { |
| 77 KeyedServiceFactory::ContextDestroyed(context); | 74 KeyedServiceFactory::ContextDestroyed(context); |
| 78 } | 75 } |
| 79 | 76 |
| 80 KeyedService* BrowserStateKeyedServiceFactory::BuildServiceInstanceFor( | 77 KeyedService* BrowserStateKeyedServiceFactory::BuildServiceInstanceFor( |
| 81 base::SupportsUserData* context) const { | 78 base::SupportsUserData* context) const { |
| 82 return BuildServiceInstanceFor(BrowserStateFromContext(context)); | 79 return BuildServiceInstanceFor(static_cast<web::BrowserState*>(context)); |
| 83 } | 80 } |
| 84 | 81 |
| 85 bool BrowserStateKeyedServiceFactory::IsOffTheRecord( | 82 bool BrowserStateKeyedServiceFactory::IsOffTheRecord( |
| 86 base::SupportsUserData* context) const { | 83 base::SupportsUserData* context) const { |
| 87 return BrowserStateFromContext(context)->IsOffTheRecord(); | 84 return static_cast<web::BrowserState*>(context)->IsOffTheRecord(); |
| 88 } | 85 } |
| 89 | 86 |
| 90 user_prefs::PrefRegistrySyncable* | 87 #if defined(OS_IOS) |
| 91 BrowserStateKeyedServiceFactory::GetAssociatedPrefRegistry( | 88 base::SupportsUserData* BrowserStateKeyedServiceFactory::GetTypedContext( |
| 92 base::SupportsUserData* context) const { | 89 base::SupportsUserData* context) const { |
| 93 // TODO(droger): Move this code to KeyedServiceFactory and share it with the | 90 if (context) { |
| 94 // other platforms once iOS no longer needs BrowserStateFromContext(). | 91 BrowserStateContextConverter* context_converter = |
| 95 PrefService* prefs = | 92 BrowserStateContextConverter::GetInstance(); |
| 96 user_prefs::UserPrefs::Get(BrowserStateFromContext(context)); | 93 if (context_converter) { |
| 97 user_prefs::PrefRegistrySyncable* registry = | 94 context = context_converter->GetBrowserStateForContext(context); |
| 98 static_cast<user_prefs::PrefRegistrySyncable*>( | 95 DCHECK(context); |
| 99 prefs->DeprecatedGetPrefRegistry()); | 96 } |
| 100 return registry; | 97 } |
| 98 return context; |
| 101 } | 99 } |
| 102 | 100 |
| 101 base::SupportsUserData* |
| 102 BrowserStateKeyedServiceFactory::GetContextForDependencyManager( |
| 103 base::SupportsUserData* context) const { |
| 104 if (context) { |
| 105 BrowserStateContextConverter* context_converter = |
| 106 BrowserStateContextConverter::GetInstance(); |
| 107 if (context_converter) { |
| 108 context = context_converter->GetBrowserContextForContext(context); |
| 109 DCHECK(context); |
| 110 } |
| 111 } |
| 112 return context; |
| 113 } |
| 114 #endif // defined(OS_IOS) |
| 115 |
| 103 base::SupportsUserData* BrowserStateKeyedServiceFactory::GetContextToUse( | 116 base::SupportsUserData* BrowserStateKeyedServiceFactory::GetContextToUse( |
| 104 base::SupportsUserData* context) const { | 117 base::SupportsUserData* context) const { |
| 105 return GetBrowserStateToUse(BrowserStateFromContext(context)); | 118 return GetBrowserStateToUse(static_cast<web::BrowserState*>(context)); |
| 106 } | 119 } |
| 107 | 120 |
| 108 bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const { | 121 bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const { |
| 109 return ServiceIsCreatedWithBrowserState(); | 122 return ServiceIsCreatedWithBrowserState(); |
| 110 } | 123 } |
| 111 | 124 |
| 112 void BrowserStateKeyedServiceFactory::ContextShutdown( | 125 void BrowserStateKeyedServiceFactory::ContextShutdown( |
| 113 base::SupportsUserData* context) { | 126 base::SupportsUserData* context) { |
| 114 BrowserStateShutdown(BrowserStateFromContext(context)); | 127 BrowserStateShutdown(static_cast<web::BrowserState*>(context)); |
| 115 } | 128 } |
| 116 | 129 |
| 117 void BrowserStateKeyedServiceFactory::ContextDestroyed( | 130 void BrowserStateKeyedServiceFactory::ContextDestroyed( |
| 118 base::SupportsUserData* context) { | 131 base::SupportsUserData* context) { |
| 119 BrowserStateDestroyed(BrowserStateFromContext(context)); | 132 BrowserStateDestroyed(static_cast<web::BrowserState*>(context)); |
| 120 } | 133 } |
| 121 | 134 |
| 122 void BrowserStateKeyedServiceFactory::RegisterPrefs( | 135 void BrowserStateKeyedServiceFactory::RegisterPrefs( |
| 123 user_prefs::PrefRegistrySyncable* registry) { | 136 user_prefs::PrefRegistrySyncable* registry) { |
| 124 RegisterProfilePrefs(registry); | 137 RegisterBrowserStatePrefs(registry); |
| 125 } | 138 } |
| OLD | NEW |