tuneable.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 MEDIA_BASE_TUNEABLE_H_
  5. #define MEDIA_BASE_TUNEABLE_H_
  6. #include "base/unguessable_token.h"
  7. #include "media/base/media_export.h"
  8. namespace media {
  9. // One tuneable value. Each Tuneable has:
  10. // name - Used to set the finch parameter name.
  11. // value - Current runtime value. All Tuneable instances with the same name
  12. // will return the same value. This value will be a constant over the
  13. // lifetime of the process as well.
  14. // min / default / max values - hardcoded range and default for this tuneable.
  15. //
  16. // Via finch, one may enable randomization of the Tuneables, such that a value
  17. // will be chosen at random between a finch-provided miniumum and maximum. This
  18. // minumum and maximum will be constrained by the hardcoded one provided during
  19. // construction. Different Tuneable instances for the same name are still
  20. // guaranteed to be equal, as described above.
  21. template <typename T>
  22. class MEDIA_EXPORT Tuneable {
  23. public:
  24. Tuneable(const char* name, T minimum_value, T default_value, T maximum_value);
  25. Tuneable(const Tuneable&) = delete;
  26. Tuneable(Tuneable&&) = delete;
  27. ~Tuneable();
  28. Tuneable& operator=(const Tuneable&) = delete;
  29. Tuneable& operator=(Tuneable&&) = delete;
  30. T value() const { return t_; }
  31. void set_for_testing(T value) { t_ = value; }
  32. private:
  33. T t_;
  34. };
  35. // Set the random number seed that the tuneable will use to choose its value.
  36. // Must be called before the first tuneable is constructed.
  37. void MEDIA_EXPORT SetRandomSeedForTuneables(const base::UnguessableToken& seed);
  38. } // namespace media
  39. #endif // MEDIA_BASE_TUNEABLE_H_