variations_layers.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 COMPONENTS_VARIATIONS_VARIATIONS_LAYERS_H_
  5. #define COMPONENTS_VARIATIONS_VARIATIONS_LAYERS_H_
  6. #include <map>
  7. #include "base/component_export.h"
  8. #include "base/metrics/field_trial.h"
  9. #include "components/variations/proto/variations_seed.pb.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. namespace variations {
  12. // Parses out the Variations Layers data from the provided seed and
  13. // chooses which member within each layer should be the active one.
  14. class COMPONENT_EXPORT(VARIATIONS) VariationsLayers {
  15. public:
  16. VariationsLayers(
  17. const VariationsSeed& seed,
  18. const base::FieldTrial::EntropyProvider* low_entropy_provider);
  19. VariationsLayers();
  20. ~VariationsLayers();
  21. VariationsLayers(const VariationsLayers&) = delete;
  22. VariationsLayers& operator=(const VariationsLayers&) = delete;
  23. // Return whether the given layer has the given member active.
  24. bool IsLayerMemberActive(uint32_t layer_id, uint32_t member_id) const;
  25. // Return whether the layer should use the default entropy source
  26. // (usually the high entropy source).
  27. bool IsLayerUsingDefaultEntropy(uint32_t layer_id) const;
  28. private:
  29. void ConstructLayer(
  30. const base::FieldTrial::EntropyProvider& low_entropy_provider,
  31. const Layer& layer_proto);
  32. struct LayerInfo {
  33. LayerInfo(absl::optional<uint32_t> active_member_id,
  34. Layer::EntropyMode entropy_mode);
  35. ~LayerInfo();
  36. LayerInfo(const LayerInfo& other); // = delete;
  37. LayerInfo& operator=(const LayerInfo&) = delete;
  38. absl::optional<uint32_t> active_member_id;
  39. Layer::EntropyMode entropy_mode;
  40. };
  41. std::map<uint32_t, LayerInfo> active_member_for_layer_;
  42. };
  43. } // namespace variations
  44. #endif // COMPONENTS_VARIATIONS_VARIATIONS_LAYERS_H_