site_engagement_service_factory.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2021 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 WEBLAYER_BROWSER_SITE_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_FACTORY_H_
  5. #define WEBLAYER_BROWSER_SITE_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_FACTORY_H_
  6. #include "base/no_destructor.h"
  7. #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
  8. #include "components/site_engagement/content/site_engagement_service.h"
  9. namespace weblayer {
  10. // Singleton that owns all SiteEngagementServices and associates them with
  11. // BrowserContexts.
  12. class SiteEngagementServiceFactory
  13. : public BrowserContextKeyedServiceFactory,
  14. public site_engagement::SiteEngagementService::ServiceProvider {
  15. public:
  16. SiteEngagementServiceFactory(const SiteEngagementServiceFactory&) = delete;
  17. SiteEngagementServiceFactory& operator=(const SiteEngagementServiceFactory&) =
  18. delete;
  19. // Creates the service if it doesn't already exist for the given
  20. // |browser_context|. If the service already exists, return it.
  21. static site_engagement::SiteEngagementService* GetForBrowserContext(
  22. content::BrowserContext* browser_context);
  23. static SiteEngagementServiceFactory* GetInstance();
  24. // SiteEngagementService::ServiceProvider:
  25. site_engagement::SiteEngagementService* GetSiteEngagementService(
  26. content::BrowserContext* browser_context) override;
  27. private:
  28. friend class base::NoDestructor<SiteEngagementServiceFactory>;
  29. SiteEngagementServiceFactory();
  30. ~SiteEngagementServiceFactory() override;
  31. // BrowserContextKeyedServiceFactory:
  32. KeyedService* BuildServiceInstanceFor(
  33. content::BrowserContext* browser_context) const override;
  34. content::BrowserContext* GetBrowserContextToUse(
  35. content::BrowserContext* context) const override;
  36. };
  37. } // namespace weblayer
  38. #endif // WEBLAYER_BROWSER_SITE_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_FACTORY_H_