site_engagement_service_factory.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include "weblayer/browser/site_engagement/site_engagement_service_factory.h"
  5. #include "base/no_destructor.h"
  6. #include "components/keyed_service/content/browser_context_dependency_manager.h"
  7. using site_engagement::SiteEngagementService;
  8. namespace weblayer {
  9. // static
  10. SiteEngagementService* SiteEngagementServiceFactory::GetForBrowserContext(
  11. content::BrowserContext* browser_context) {
  12. return static_cast<SiteEngagementService*>(
  13. GetInstance()->GetServiceForBrowserContext(browser_context,
  14. /*create=*/true));
  15. }
  16. // static
  17. SiteEngagementServiceFactory* SiteEngagementServiceFactory::GetInstance() {
  18. static base::NoDestructor<SiteEngagementServiceFactory> factory;
  19. return factory.get();
  20. }
  21. SiteEngagementServiceFactory::SiteEngagementServiceFactory()
  22. : BrowserContextKeyedServiceFactory(
  23. "SiteEngagementService",
  24. BrowserContextDependencyManager::GetInstance()) {
  25. SiteEngagementService::SetServiceProvider(this);
  26. }
  27. SiteEngagementServiceFactory::~SiteEngagementServiceFactory() {
  28. SiteEngagementService::ClearServiceProvider(this);
  29. }
  30. KeyedService* SiteEngagementServiceFactory::BuildServiceInstanceFor(
  31. content::BrowserContext* browser_context) const {
  32. return new SiteEngagementService(browser_context);
  33. }
  34. content::BrowserContext* SiteEngagementServiceFactory::GetBrowserContextToUse(
  35. content::BrowserContext* context) const {
  36. return context;
  37. }
  38. SiteEngagementService* SiteEngagementServiceFactory::GetSiteEngagementService(
  39. content::BrowserContext* browser_context) {
  40. return GetForBrowserContext(browser_context);
  41. }
  42. } // namespace weblayer