/components/keyed_service/ios/browser_state_keyed_service_factory.cc

https://gitlab.com/jonnialva90/iridium-browser · C++ · 139 lines · 111 code · 24 blank · 4 comment · 5 complexity · 82d61a5c98bb4ce8f0594183d766718a MD5 · raw file

  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
  3. // found in the LICENSE file.
  4. #include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
  5. #include "base/logging.h"
  6. #include "components/keyed_service/core/keyed_service.h"
  7. #include "components/keyed_service/ios/browser_state_context_converter.h"
  8. #include "components/keyed_service/ios/browser_state_dependency_manager.h"
  9. #include "ios/web/public/browser_state.h"
  10. void BrowserStateKeyedServiceFactory::SetTestingFactory(
  11. web::BrowserState* context,
  12. TestingFactoryFunction testing_factory) {
  13. KeyedServiceFactory::SetTestingFactory(
  14. context, reinterpret_cast<KeyedServiceFactory::TestingFactoryFunction>(
  15. testing_factory));
  16. }
  17. KeyedService* BrowserStateKeyedServiceFactory::SetTestingFactoryAndUse(
  18. web::BrowserState* context,
  19. TestingFactoryFunction testing_factory) {
  20. return KeyedServiceFactory::SetTestingFactoryAndUse(
  21. context, reinterpret_cast<KeyedServiceFactory::TestingFactoryFunction>(
  22. testing_factory));
  23. }
  24. BrowserStateKeyedServiceFactory::BrowserStateKeyedServiceFactory(
  25. const char* name,
  26. /*BrowserState*/DependencyManager* manager)
  27. : KeyedServiceFactory(name, manager) {
  28. }
  29. BrowserStateKeyedServiceFactory::~BrowserStateKeyedServiceFactory() {
  30. }
  31. KeyedService* BrowserStateKeyedServiceFactory::GetServiceForBrowserState(
  32. web::BrowserState* context,
  33. bool create) {
  34. return KeyedServiceFactory::GetServiceForContext(context, create);
  35. }
  36. web::BrowserState* BrowserStateKeyedServiceFactory::GetBrowserStateToUse(
  37. web::BrowserState* context) const {
  38. DCHECK(CalledOnValidThread());
  39. #ifndef NDEBUG
  40. AssertContextWasntDestroyed(context);
  41. #endif
  42. // Safe default for Incognito mode: no service.
  43. if (context->IsOffTheRecord())
  44. return nullptr;
  45. return context;
  46. }
  47. bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithBrowserState() const {
  48. return KeyedServiceBaseFactory::ServiceIsCreatedWithContext();
  49. }
  50. bool BrowserStateKeyedServiceFactory::ServiceIsNULLWhileTesting() const {
  51. return KeyedServiceBaseFactory::ServiceIsNULLWhileTesting();
  52. }
  53. void BrowserStateKeyedServiceFactory::BrowserStateShutdown(
  54. web::BrowserState* context) {
  55. KeyedServiceFactory::ContextShutdown(context);
  56. }
  57. void BrowserStateKeyedServiceFactory::BrowserStateDestroyed(
  58. web::BrowserState* context) {
  59. KeyedServiceFactory::ContextDestroyed(context);
  60. }
  61. scoped_ptr<KeyedService>
  62. BrowserStateKeyedServiceFactory::BuildServiceInstanceFor(
  63. base::SupportsUserData* context) const {
  64. return BuildServiceInstanceFor(static_cast<web::BrowserState*>(context));
  65. }
  66. bool BrowserStateKeyedServiceFactory::IsOffTheRecord(
  67. base::SupportsUserData* context) const {
  68. return static_cast<web::BrowserState*>(context)->IsOffTheRecord();
  69. }
  70. #if defined(OS_IOS)
  71. base::SupportsUserData* BrowserStateKeyedServiceFactory::GetTypedContext(
  72. base::SupportsUserData* context) const {
  73. if (context) {
  74. BrowserStateContextConverter* context_converter =
  75. BrowserStateContextConverter::GetInstance();
  76. if (context_converter) {
  77. context = context_converter->GetBrowserStateForContext(context);
  78. DCHECK(context);
  79. }
  80. }
  81. return context;
  82. }
  83. base::SupportsUserData*
  84. BrowserStateKeyedServiceFactory::GetContextForDependencyManager(
  85. base::SupportsUserData* context) const {
  86. if (context) {
  87. BrowserStateContextConverter* context_converter =
  88. BrowserStateContextConverter::GetInstance();
  89. if (context_converter) {
  90. context = context_converter->GetBrowserContextForContext(context);
  91. DCHECK(context);
  92. }
  93. }
  94. return context;
  95. }
  96. #endif // defined(OS_IOS)
  97. base::SupportsUserData* BrowserStateKeyedServiceFactory::GetContextToUse(
  98. base::SupportsUserData* context) const {
  99. return GetBrowserStateToUse(static_cast<web::BrowserState*>(context));
  100. }
  101. bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const {
  102. return ServiceIsCreatedWithBrowserState();
  103. }
  104. void BrowserStateKeyedServiceFactory::ContextShutdown(
  105. base::SupportsUserData* context) {
  106. BrowserStateShutdown(static_cast<web::BrowserState*>(context));
  107. }
  108. void BrowserStateKeyedServiceFactory::ContextDestroyed(
  109. base::SupportsUserData* context) {
  110. BrowserStateDestroyed(static_cast<web::BrowserState*>(context));
  111. }
  112. void BrowserStateKeyedServiceFactory::RegisterPrefs(
  113. user_prefs::PrefRegistrySyncable* registry) {
  114. RegisterBrowserStatePrefs(registry);
  115. }