real_time_url_lookup_service_factory.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2020 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_REAL_TIME_URL_LOOKUP_SERVICE_FACTORY_H_
  5. #define WEBLAYER_BROWSER_SAFE_BROWSING_REAL_TIME_URL_LOOKUP_SERVICE_FACTORY_H_
  6. #include "base/memory/singleton.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 RealTimeUrlLookupService;
  14. } // namespace safe_browsing
  15. namespace weblayer {
  16. // Singleton that owns RealTimeUrlLookupService objects and associates them
  17. // them with BrowserContextImpl instances.
  18. class RealTimeUrlLookupServiceFactory
  19. : public BrowserContextKeyedServiceFactory {
  20. public:
  21. // Creates the service if it doesn't exist already for the given
  22. // |browser_context|. If the service already exists, return its pointer.
  23. static safe_browsing::RealTimeUrlLookupService* GetForBrowserContext(
  24. content::BrowserContext* browser_context);
  25. // Get the singleton instance.
  26. static RealTimeUrlLookupServiceFactory* GetInstance();
  27. // TODO(crbug.com/1171215): Remove this once browsertests can enable this
  28. // functionality via the production mechanism for doing so.
  29. void set_access_token_fetches_enabled_for_testing() {
  30. access_token_fetches_enabled_for_testing_ = true;
  31. }
  32. private:
  33. friend struct base::DefaultSingletonTraits<RealTimeUrlLookupServiceFactory>;
  34. RealTimeUrlLookupServiceFactory();
  35. ~RealTimeUrlLookupServiceFactory() override = default;
  36. RealTimeUrlLookupServiceFactory(const RealTimeUrlLookupServiceFactory&) =
  37. delete;
  38. RealTimeUrlLookupServiceFactory& operator=(
  39. const RealTimeUrlLookupServiceFactory&) = delete;
  40. // BrowserContextKeyedServiceFactory:
  41. KeyedService* BuildServiceInstanceFor(
  42. content::BrowserContext* context) const override;
  43. // TODO(crbug.com/1171215): Remove this once browsertests can enable this
  44. // functionality via the production mechanism for doing so.
  45. bool access_token_fetches_enabled_for_testing(
  46. bool user_has_enabled_enhanced_protection) const {
  47. return access_token_fetches_enabled_for_testing_;
  48. }
  49. // TODO(crbug.com/1171215): Remove this once browsertests can enable this
  50. // functionality via the production mechanism for doing so.
  51. bool access_token_fetches_enabled_for_testing_ = false;
  52. };
  53. } // namespace weblayer
  54. #endif // WEBLAYER_BROWSER_SAFE_BROWSING_REAL_TIME_URL_LOOKUP_SERVICE_FACTORY_H_