variations_seed_simulator.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2014 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_SEED_SIMULATOR_H_
  5. #define COMPONENTS_VARIATIONS_VARIATIONS_SEED_SIMULATOR_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/compiler_specific.h"
  9. #include "base/component_export.h"
  10. #include "base/metrics/field_trial.h"
  11. #include "base/version.h"
  12. #include "components/variations/proto/study.pb.h"
  13. #include "components/variations/proto/variations_seed.pb.h"
  14. namespace variations {
  15. class ProcessedStudy;
  16. struct ClientFilterableState;
  17. class VariationsSeed;
  18. // VariationsSeedSimulator simulates the result of creating a set of studies
  19. // and detecting which studies would result in group changes.
  20. class COMPONENT_EXPORT(VARIATIONS) VariationsSeedSimulator {
  21. public:
  22. // The result of variations seed simulation, counting the number of experiment
  23. // group changes of each type that are expected to occur on a restart with the
  24. // seed.
  25. struct COMPONENT_EXPORT(VARIATIONS) Result {
  26. Result();
  27. ~Result();
  28. // The number of expected group changes that do not fall into any special
  29. // category. This is a lower bound due to session randomized studies.
  30. int normal_group_change_count;
  31. // The number of expected group changes that fall in the category of killed
  32. // experiments that should trigger the "best effort" restart mechanism.
  33. int kill_best_effort_group_change_count;
  34. // The number of expected group changes that fall in the category of killed
  35. // experiments that should trigger the "critical" restart mechanism.
  36. int kill_critical_group_change_count;
  37. };
  38. // Creates the simulator with the given default and low entropy providers. The
  39. // |low_entropy_provider| will be used for studies that should only use a low
  40. // entropy source. This is defined by
  41. // VariationsSeedProcessor::ShouldStudyUseLowEntropy, in
  42. // variations_seed_processor.h.
  43. VariationsSeedSimulator(
  44. const base::FieldTrial::EntropyProvider& default_entropy_provider,
  45. const base::FieldTrial::EntropyProvider& low_entropy_provider);
  46. VariationsSeedSimulator(const VariationsSeedSimulator&) = delete;
  47. VariationsSeedSimulator& operator=(const VariationsSeedSimulator&) = delete;
  48. virtual ~VariationsSeedSimulator();
  49. // Computes differences between the current process' field trial state and
  50. // the result of evaluating |seed| with the given parameters. Returns the
  51. // results of the simulation as a set of expected group change counts of each
  52. // type.
  53. Result SimulateSeedStudies(const VariationsSeed& seed,
  54. const ClientFilterableState& client_state);
  55. private:
  56. friend class VariationsSeedSimulatorTest;
  57. enum ChangeType {
  58. NO_CHANGE,
  59. CHANGED,
  60. CHANGED_KILL_BEST_EFFORT,
  61. CHANGED_KILL_CRITICAL,
  62. };
  63. // Computes differences between the current process' field trial state and
  64. // the result of evaluating the |processed_studies| list. It is expected that
  65. // |processed_studies| have already been filtered and only contain studies
  66. // that apply to the configuration being simulated. Returns the results of the
  67. // simulation as a set of expected group change counts of each type.
  68. Result ComputeDifferences(
  69. const std::vector<ProcessedStudy>& processed_studies);
  70. // Maps proto enum |type| to a ChangeType.
  71. ChangeType ConvertExperimentTypeToChangeType(Study_Experiment_Type type);
  72. // For the given |processed_study| with PERMANENT consistency, simulates group
  73. // assignment and returns a corresponding ChangeType if the result differs
  74. // from that study's group in the current process.
  75. ChangeType PermanentStudyGroupChanged(const ProcessedStudy& processed_study,
  76. const std::string& selected_group);
  77. // For the given |processed_study| with SESSION consistency, determines if
  78. // there are enough changes in the study config that restarting will result
  79. // in a guaranteed different group assignment (or different params) and
  80. // returns the corresponding ChangeType.
  81. ChangeType SessionStudyGroupChanged(const ProcessedStudy& filtered_study,
  82. const std::string& selected_group);
  83. const base::FieldTrial::EntropyProvider& default_entropy_provider_;
  84. const base::FieldTrial::EntropyProvider& low_entropy_provider_;
  85. };
  86. } // namespace variations
  87. #endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_SIMULATOR_H_