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