/components/keyed_service/ios/refcounted_browser_state_keyed_service_factory.cc

https://gitlab.com/0072016/Facebook-SDK- · C++ · 120 lines · 94 code · 22 blank · 4 comment · 1 complexity · 64ff2fcc095b200b133d37360f1c2787 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/refcounted_browser_state_keyed_service_factory.h"
  5. #include "base/logging.h"
  6. #include "components/keyed_service/core/refcounted_keyed_service.h"
  7. #include "components/keyed_service/ios/browser_state_dependency_manager.h"
  8. #include "ios/web/public/browser_state.h"
  9. void RefcountedBrowserStateKeyedServiceFactory::SetTestingFactory(
  10. web::BrowserState* context,
  11. TestingFactoryFunction testing_factory) {
  12. RefcountedKeyedServiceFactory::SetTestingFactory(
  13. context,
  14. reinterpret_cast<RefcountedKeyedServiceFactory::TestingFactoryFunction>(
  15. testing_factory));
  16. }
  17. scoped_refptr<RefcountedKeyedService>
  18. RefcountedBrowserStateKeyedServiceFactory::SetTestingFactoryAndUse(
  19. web::BrowserState* context,
  20. TestingFactoryFunction testing_factory) {
  21. return RefcountedKeyedServiceFactory::SetTestingFactoryAndUse(
  22. context,
  23. reinterpret_cast<RefcountedKeyedServiceFactory::TestingFactoryFunction>(
  24. testing_factory));
  25. }
  26. RefcountedBrowserStateKeyedServiceFactory::
  27. RefcountedBrowserStateKeyedServiceFactory(
  28. const char* name,
  29. BrowserStateDependencyManager* manager)
  30. : RefcountedKeyedServiceFactory(name, manager) {
  31. }
  32. RefcountedBrowserStateKeyedServiceFactory::
  33. ~RefcountedBrowserStateKeyedServiceFactory() {
  34. }
  35. scoped_refptr<RefcountedKeyedService>
  36. RefcountedBrowserStateKeyedServiceFactory::GetServiceForBrowserState(
  37. web::BrowserState* context,
  38. bool create) {
  39. return RefcountedKeyedServiceFactory::GetServiceForContext(context, create);
  40. }
  41. web::BrowserState*
  42. RefcountedBrowserStateKeyedServiceFactory::GetBrowserStateToUse(
  43. web::BrowserState* context) const {
  44. DCHECK(CalledOnValidThread());
  45. #ifndef NDEBUG
  46. AssertContextWasntDestroyed(context);
  47. #endif
  48. // Safe default for Incognito mode: no service.
  49. if (context->IsOffTheRecord())
  50. return nullptr;
  51. return context;
  52. }
  53. bool RefcountedBrowserStateKeyedServiceFactory::
  54. ServiceIsCreatedWithBrowserState() const {
  55. return KeyedServiceBaseFactory::ServiceIsCreatedWithContext();
  56. }
  57. bool RefcountedBrowserStateKeyedServiceFactory::ServiceIsNULLWhileTesting()
  58. const {
  59. return KeyedServiceBaseFactory::ServiceIsNULLWhileTesting();
  60. }
  61. void RefcountedBrowserStateKeyedServiceFactory::BrowserStateShutdown(
  62. web::BrowserState* context) {
  63. RefcountedKeyedServiceFactory::ContextShutdown(context);
  64. }
  65. void RefcountedBrowserStateKeyedServiceFactory::BrowserStateDestroyed(
  66. web::BrowserState* context) {
  67. RefcountedKeyedServiceFactory::ContextDestroyed(context);
  68. }
  69. scoped_refptr<RefcountedKeyedService>
  70. RefcountedBrowserStateKeyedServiceFactory::BuildServiceInstanceFor(
  71. base::SupportsUserData* context) const {
  72. return BuildServiceInstanceFor(static_cast<web::BrowserState*>(context));
  73. }
  74. bool RefcountedBrowserStateKeyedServiceFactory::IsOffTheRecord(
  75. base::SupportsUserData* context) const {
  76. return static_cast<web::BrowserState*>(context)->IsOffTheRecord();
  77. }
  78. base::SupportsUserData*
  79. RefcountedBrowserStateKeyedServiceFactory::GetContextToUse(
  80. base::SupportsUserData* context) const {
  81. return GetBrowserStateToUse(static_cast<web::BrowserState*>(context));
  82. }
  83. bool RefcountedBrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext()
  84. const {
  85. return ServiceIsCreatedWithBrowserState();
  86. }
  87. void RefcountedBrowserStateKeyedServiceFactory::ContextShutdown(
  88. base::SupportsUserData* context) {
  89. BrowserStateShutdown(static_cast<web::BrowserState*>(context));
  90. }
  91. void RefcountedBrowserStateKeyedServiceFactory::ContextDestroyed(
  92. base::SupportsUserData* context) {
  93. BrowserStateDestroyed(static_cast<web::BrowserState*>(context));
  94. }
  95. void RefcountedBrowserStateKeyedServiceFactory::RegisterPrefs(
  96. user_prefs::PrefRegistrySyncable* registry) {
  97. RegisterBrowserStatePrefs(registry);
  98. }