heavy_ad_blocklist.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2019 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_HEAVY_AD_INTERVENTION_HEAVY_AD_BLOCKLIST_H_
  5. #define COMPONENTS_HEAVY_AD_INTERVENTION_HEAVY_AD_BLOCKLIST_H_
  6. #include <stdint.h>
  7. #include "base/time/time.h"
  8. #include "components/blocklist/opt_out_blocklist/opt_out_blocklist.h"
  9. namespace base {
  10. class Clock;
  11. }
  12. namespace blocklist {
  13. class OptOutBlocklistDelegate;
  14. class OptOutStore;
  15. } // namespace blocklist
  16. namespace heavy_ad_intervention {
  17. // The heavy ad intervention only supports one type for the blocklist.
  18. enum class HeavyAdBlocklistType {
  19. kHeavyAdOnlyType = 0,
  20. };
  21. // A class that manages opt out blocklist parameters for the heavy ad
  22. // intervention. The blocklist is used to allow at most 5 interventions per top
  23. // frame origin per day. This prevents the intervention from being used as a
  24. // cross-origin side channel.
  25. class HeavyAdBlocklist : public blocklist::OptOutBlocklist {
  26. public:
  27. HeavyAdBlocklist(std::unique_ptr<blocklist::OptOutStore> opt_out_store,
  28. base::Clock* clock,
  29. blocklist::OptOutBlocklistDelegate* blocklist_delegate);
  30. HeavyAdBlocklist(const HeavyAdBlocklist&) = delete;
  31. HeavyAdBlocklist& operator=(const HeavyAdBlocklist&) = delete;
  32. ~HeavyAdBlocklist() override;
  33. protected:
  34. // OptOutBlocklist:
  35. bool ShouldUseSessionPolicy(base::TimeDelta* duration,
  36. size_t* history,
  37. int* threshold) const override;
  38. bool ShouldUsePersistentPolicy(base::TimeDelta* duration,
  39. size_t* history,
  40. int* threshold) const override;
  41. bool ShouldUseHostPolicy(base::TimeDelta* duration,
  42. size_t* history,
  43. int* threshold,
  44. size_t* max_hosts) const override;
  45. bool ShouldUseTypePolicy(base::TimeDelta* duration,
  46. size_t* history,
  47. int* threshold) const override;
  48. blocklist::BlocklistData::AllowedTypesAndVersions GetAllowedTypes()
  49. const override;
  50. };
  51. } // namespace heavy_ad_intervention
  52. #endif // COMPONENTS_HEAVY_AD_INTERVENTION_HEAVY_AD_BLOCKLIST_H_