/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.cc

https://gitlab.com/0072016/Facebook-SDK- · C++ · 121 lines · 95 code · 22 blank · 4 comment · 1 complexity · e544b47f26dc1abd7c98c24b28af8918 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/content/refcounted_browser_context_keyed_service_factory.h"
  5. #include "base/logging.h"
  6. #include "components/keyed_service/content/browser_context_dependency_manager.h"
  7. #include "components/keyed_service/core/refcounted_keyed_service.h"
  8. #include "content/public/browser/browser_context.h"
  9. void RefcountedBrowserContextKeyedServiceFactory::SetTestingFactory(
  10. content::BrowserContext* context,
  11. TestingFactoryFunction testing_factory) {
  12. RefcountedKeyedServiceFactory::SetTestingFactory(
  13. context,
  14. reinterpret_cast<RefcountedKeyedServiceFactory::TestingFactoryFunction>(
  15. testing_factory));
  16. }
  17. scoped_refptr<RefcountedKeyedService>
  18. RefcountedBrowserContextKeyedServiceFactory::SetTestingFactoryAndUse(
  19. content::BrowserContext* context,
  20. TestingFactoryFunction testing_factory) {
  21. return RefcountedKeyedServiceFactory::SetTestingFactoryAndUse(
  22. context,
  23. reinterpret_cast<RefcountedKeyedServiceFactory::TestingFactoryFunction>(
  24. testing_factory));
  25. }
  26. RefcountedBrowserContextKeyedServiceFactory::
  27. RefcountedBrowserContextKeyedServiceFactory(
  28. const char* name,
  29. BrowserContextDependencyManager* manager)
  30. : RefcountedKeyedServiceFactory(name, manager) {
  31. }
  32. RefcountedBrowserContextKeyedServiceFactory::
  33. ~RefcountedBrowserContextKeyedServiceFactory() {
  34. }
  35. scoped_refptr<RefcountedKeyedService>
  36. RefcountedBrowserContextKeyedServiceFactory::GetServiceForBrowserContext(
  37. content::BrowserContext* context,
  38. bool create) {
  39. return RefcountedKeyedServiceFactory::GetServiceForContext(context, create);
  40. }
  41. content::BrowserContext*
  42. RefcountedBrowserContextKeyedServiceFactory::GetBrowserContextToUse(
  43. content::BrowserContext* 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 RefcountedBrowserContextKeyedServiceFactory::
  54. ServiceIsCreatedWithBrowserContext() const {
  55. return KeyedServiceBaseFactory::ServiceIsCreatedWithContext();
  56. }
  57. bool RefcountedBrowserContextKeyedServiceFactory::ServiceIsNULLWhileTesting()
  58. const {
  59. return KeyedServiceBaseFactory::ServiceIsNULLWhileTesting();
  60. }
  61. void RefcountedBrowserContextKeyedServiceFactory::BrowserContextShutdown(
  62. content::BrowserContext* context) {
  63. RefcountedKeyedServiceFactory::ContextShutdown(context);
  64. }
  65. void RefcountedBrowserContextKeyedServiceFactory::BrowserContextDestroyed(
  66. content::BrowserContext* context) {
  67. RefcountedKeyedServiceFactory::ContextDestroyed(context);
  68. }
  69. scoped_refptr<RefcountedKeyedService>
  70. RefcountedBrowserContextKeyedServiceFactory::BuildServiceInstanceFor(
  71. base::SupportsUserData* context) const {
  72. return BuildServiceInstanceFor(
  73. static_cast<content::BrowserContext*>(context));
  74. }
  75. bool RefcountedBrowserContextKeyedServiceFactory::IsOffTheRecord(
  76. base::SupportsUserData* context) const {
  77. return static_cast<content::BrowserContext*>(context)->IsOffTheRecord();
  78. }
  79. base::SupportsUserData*
  80. RefcountedBrowserContextKeyedServiceFactory::GetContextToUse(
  81. base::SupportsUserData* context) const {
  82. return GetBrowserContextToUse(static_cast<content::BrowserContext*>(context));
  83. }
  84. bool RefcountedBrowserContextKeyedServiceFactory::ServiceIsCreatedWithContext()
  85. const {
  86. return ServiceIsCreatedWithBrowserContext();
  87. }
  88. void RefcountedBrowserContextKeyedServiceFactory::ContextShutdown(
  89. base::SupportsUserData* context) {
  90. BrowserContextShutdown(static_cast<content::BrowserContext*>(context));
  91. }
  92. void RefcountedBrowserContextKeyedServiceFactory::ContextDestroyed(
  93. base::SupportsUserData* context) {
  94. BrowserContextDestroyed(static_cast<content::BrowserContext*>(context));
  95. }
  96. void RefcountedBrowserContextKeyedServiceFactory::RegisterPrefs(
  97. user_prefs::PrefRegistrySyncable* registry) {
  98. RegisterProfilePrefs(registry);
  99. }