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