| 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" |
| 10 #include "components/keyed_service/ios/browser_state_dependency_manager.h" | 9 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
| 11 #include "components/keyed_service/ios/browser_state_helper.h" | 10 #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(UnderlyingContextFromContext(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 UnderlyingContextFromContext(context)->IsOffTheRecord(); |
| 88 } | 85 } |
| 89 | 86 |
| 90 user_prefs::PrefRegistrySyncable* | 87 base::SupportsUserData* |
| 91 BrowserStateKeyedServiceFactory::GetAssociatedPrefRegistry( | 88 BrowserStateKeyedServiceFactory::GetUnderlyingContextInternal( |
| 92 base::SupportsUserData* context) const { | 89 base::SupportsUserData* context) const { |
| 93 // TODO(droger): Move this code to KeyedServiceFactory and share it with the | 90 return UnderlyingContextFromContext(context); |
| 94 // other platforms once iOS no longer needs BrowserStateFromContext(). | 91 } |
| 95 PrefService* prefs = | 92 |
| 96 user_prefs::UserPrefs::Get(BrowserStateFromContext(context)); | 93 base::SupportsUserData* |
| 97 user_prefs::PrefRegistrySyncable* registry = | 94 BrowserStateKeyedServiceFactory::GetOriginalContextInternal( |
| 98 static_cast<user_prefs::PrefRegistrySyncable*>( | 95 base::SupportsUserData* context) const { |
| 99 prefs->DeprecatedGetPrefRegistry()); | 96 return OriginalContextFromContext(context); |
| 100 return registry; | |
| 101 } | 97 } |
| 102 | 98 |
| 103 base::SupportsUserData* BrowserStateKeyedServiceFactory::GetContextToUse( | 99 base::SupportsUserData* BrowserStateKeyedServiceFactory::GetContextToUse( |
| 104 base::SupportsUserData* context) const { | 100 base::SupportsUserData* context) const { |
| 105 return GetBrowserStateToUse(BrowserStateFromContext(context)); | 101 return GetBrowserStateToUse(UnderlyingContextFromContext(context)); |
| 106 } | 102 } |
| 107 | 103 |
| 108 bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const { | 104 bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const { |
| 109 return ServiceIsCreatedWithBrowserState(); | 105 return ServiceIsCreatedWithBrowserState(); |
| 110 } | 106 } |
| 111 | 107 |
| 112 void BrowserStateKeyedServiceFactory::ContextShutdown( | 108 void BrowserStateKeyedServiceFactory::ContextShutdown( |
| 113 base::SupportsUserData* context) { | 109 base::SupportsUserData* context) { |
| 114 BrowserStateShutdown(BrowserStateFromContext(context)); | 110 BrowserStateShutdown(UnderlyingContextFromContext(context)); |
| 115 } | 111 } |
| 116 | 112 |
| 117 void BrowserStateKeyedServiceFactory::ContextDestroyed( | 113 void BrowserStateKeyedServiceFactory::ContextDestroyed( |
| 118 base::SupportsUserData* context) { | 114 base::SupportsUserData* context) { |
| 119 BrowserStateDestroyed(BrowserStateFromContext(context)); | 115 BrowserStateDestroyed(UnderlyingContextFromContext(context)); |
| 120 } | 116 } |
| 121 | 117 |
| 122 void BrowserStateKeyedServiceFactory::RegisterPrefs( | 118 void BrowserStateKeyedServiceFactory::RegisterPrefs( |
| 123 user_prefs::PrefRegistrySyncable* registry) { | 119 user_prefs::PrefRegistrySyncable* registry) { |
| 124 RegisterProfilePrefs(registry); | 120 RegisterBrowserStatePrefs(registry); |
| 125 } | 121 } |
| OLD | NEW |