safe_browsing_navigation_observer_manager_factory.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_FACTORY_H_
  5. #define WEBLAYER_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_FACTORY_H_
  6. #include "base/no_destructor.h"
  7. #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
  8. class KeyedService;
  9. namespace content {
  10. class BrowserContext;
  11. }
  12. namespace safe_browsing {
  13. class SafeBrowsingNavigationObserverManager;
  14. }
  15. namespace weblayer {
  16. // Singleton that owns SafeBrowsingNavigationObserverManager objects, one for
  17. // each active BrowserContext. It returns a separate instance if the
  18. // BrowserContext is in incognito mode.
  19. class SafeBrowsingNavigationObserverManagerFactory
  20. : public BrowserContextKeyedServiceFactory {
  21. public:
  22. SafeBrowsingNavigationObserverManagerFactory(
  23. const SafeBrowsingNavigationObserverManagerFactory&) = delete;
  24. SafeBrowsingNavigationObserverManagerFactory& operator=(
  25. const SafeBrowsingNavigationObserverManagerFactory&) = delete;
  26. // Creates the service if it doesn't exist already for the given
  27. // |browser_context|. If the service already exists, returns its pointer.
  28. static safe_browsing::SafeBrowsingNavigationObserverManager*
  29. GetForBrowserContext(content::BrowserContext* browser_context);
  30. // Get the singleton instance.
  31. static SafeBrowsingNavigationObserverManagerFactory* GetInstance();
  32. private:
  33. friend class base::NoDestructor<SafeBrowsingNavigationObserverManagerFactory>;
  34. SafeBrowsingNavigationObserverManagerFactory();
  35. ~SafeBrowsingNavigationObserverManagerFactory() override = default;
  36. // BrowserContextKeyedServiceFactory:
  37. KeyedService* BuildServiceInstanceFor(
  38. content::BrowserContext* context) const override;
  39. content::BrowserContext* GetBrowserContextToUse(
  40. content::BrowserContext* context) const override;
  41. };
  42. } // namespace weblayer
  43. #endif // WEBLAYER_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_FACTORY_H_