/components/keyed_service/content/browser_context_keyed_base_factory.h

https://gitlab.com/0072016/Facebook-SDK- · C Header · 121 lines · 44 code · 19 blank · 58 comment · 0 complexity · 897bb68c0c59012ef4db8921c0cdf775 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. #ifndef COMPONENTS_KEYED_SERVICE_CONTENT_BROWSER_CONTEXT_KEYED_BASE_FACTORY_H_
  5. #define COMPONENTS_KEYED_SERVICE_CONTENT_BROWSER_CONTEXT_KEYED_BASE_FACTORY_H_
  6. #include "components/keyed_service/core/keyed_service_base_factory.h"
  7. #include "components/keyed_service/core/keyed_service_export.h"
  8. class BrowserContextDependencyManager;
  9. class PrefService;
  10. namespace content {
  11. class BrowserContext;
  12. }
  13. namespace user_prefs {
  14. class PrefRegistrySyncable;
  15. }
  16. // Base class for Factories that take a BrowserContext object and return some
  17. // service.
  18. //
  19. // Unless you're trying to make a new type of Factory, you probably don't want
  20. // this class, but its subclasses: BrowserContextKeyedServiceFactory and
  21. // RefcountedBrowserContextKeyedServiceFactory. This object describes general
  22. // dependency management between Factories; subclasses react to lifecycle
  23. // events and implement memory management.
  24. //
  25. // Note: this class is deprecated and should not be used and will be removed
  26. // once http://crbug.com/131843 and http://crbug.com/131844 are closed. If you
  27. // need to implement a new way to manage KeyedService lifetime, base your code
  28. // on KeyedServiceBaseFactory instead.
  29. class KEYED_SERVICE_EXPORT BrowserContextKeyedBaseFactory
  30. : public KeyedServiceBaseFactory {
  31. public:
  32. // Registers preferences used in this service on the pref service of
  33. // |context|. This is the public interface and is safe to be called multiple
  34. // times because testing code can have multiple services of the same type
  35. // attached to a single |context|. Only test code is allowed to call this
  36. // method.
  37. // TODO(gab): This method can be removed entirely when
  38. // PrefService::DeprecatedGetPrefRegistry() is phased out.
  39. void RegisterUserPrefsOnBrowserContextForTest(
  40. content::BrowserContext* context);
  41. protected:
  42. BrowserContextKeyedBaseFactory(const char* name,
  43. BrowserContextDependencyManager* manager);
  44. ~BrowserContextKeyedBaseFactory() override;
  45. // Interface for people building a concrete FooServiceFactory: --------------
  46. // Finds which browser context (if any) to use.
  47. virtual content::BrowserContext* GetBrowserContextToUse(
  48. content::BrowserContext* context) const;
  49. // By default, we create instances of a service lazily and wait until
  50. // GetForBrowserContext() is called on our subclass. Some services need to be
  51. // created as soon as the BrowserContext has been brought up.
  52. virtual bool ServiceIsCreatedWithBrowserContext() const;
  53. // By default, TestingBrowserContexts will be treated like normal contexts.
  54. // You can override this so that by default, the service associated with the
  55. // TestingBrowserContext is NULL. (This is just a shortcut around
  56. // SetTestingFactory() to make sure our contexts don't directly refer to the
  57. // services they use.)
  58. bool ServiceIsNULLWhileTesting() const override;
  59. // Interface for people building a type of BrowserContextKeyedFactory: -------
  60. // A helper object actually listens for notifications about BrowserContext
  61. // destruction, calculates the order in which things are destroyed and then
  62. // does a two pass shutdown.
  63. //
  64. // It is up to the individual factory types to determine what this two pass
  65. // shutdown means. The general framework guarantees the following:
  66. //
  67. // - Each BrowserContextShutdown() is called in dependency order (and you may
  68. // reach out to other services during this phase).
  69. //
  70. // - Each BrowserContextDestroyed() is called in dependency order. We will
  71. // NOTREACHED() if you attempt to GetForBrowserContext() any other service.
  72. // You should delete/deref/do other final memory management things during
  73. // this phase. You must also call the base class method as the last thing
  74. // you do.
  75. virtual void BrowserContextShutdown(content::BrowserContext* context) = 0;
  76. virtual void BrowserContextDestroyed(content::BrowserContext* context);
  77. private:
  78. // Registers any user preferences on this service. This is called by
  79. // RegisterPrefsIfNecessaryForContext() and should be overriden by any service
  80. // that wants to register profile-specific preferences.
  81. virtual void RegisterProfilePrefs(
  82. user_prefs::PrefRegistrySyncable* registry) {}
  83. // Because of ServiceIsNULLWhileTesting(), we need a way to tell different
  84. // subclasses that they should disable testing.
  85. virtual void SetEmptyTestingFactory(content::BrowserContext* context) = 0;
  86. // Returns true if a testing factory function has been set for |context|.
  87. virtual bool HasTestingFactory(content::BrowserContext* context) = 0;
  88. // We also need a generalized, non-returning method that generates the object
  89. // now for when we're creating the context.
  90. virtual void CreateServiceNow(content::BrowserContext* context) = 0;
  91. // KeyedServiceBaseFactory:
  92. base::SupportsUserData* GetContextToUse(
  93. base::SupportsUserData* context) const final;
  94. bool ServiceIsCreatedWithContext() const final;
  95. void ContextShutdown(base::SupportsUserData* context) final;
  96. void ContextDestroyed(base::SupportsUserData* context) final;
  97. void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry) final;
  98. void SetEmptyTestingFactory(base::SupportsUserData* context) final;
  99. bool HasTestingFactory(base::SupportsUserData* context) final;
  100. void CreateServiceNow(base::SupportsUserData* context) final;
  101. };
  102. #endif // COMPONENTS_KEYED_SERVICE_CONTENT_BROWSER_CONTEXT_KEYED_BASE_FACTORY_H_