blob: 3cb9e1feb63d1ef3f6e90a38f0f8d283410db6bf [file] [log] [blame]
[email protected]92e09a182014-01-08 18:21:001// 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"
Scott Violet69a5d8dd2021-06-01 23:46:4812#include "base/component_export.h"
avi5dd91f82015-12-25 22:30:4613#include "base/macros.h"
[email protected]92e09a182014-01-08 18:21:0014#include "base/metrics/field_trial.h"
[email protected]a81120b62014-04-18 01:56:0315#include "base/version.h"
16#include "components/variations/proto/study.pb.h"
17#include "components/variations/proto/variations_seed.pb.h"
[email protected]92e09a182014-01-08 18:21:0018
[email protected]59b6f672014-07-26 18:35:4719namespace variations {
[email protected]92e09a182014-01-08 18:21:0020
21class ProcessedStudy;
isherman52a81bd2017-06-07 23:30:0622struct ClientFilterableState;
[email protected]a81120b62014-04-18 01:56:0323class VariationsSeed;
[email protected]92e09a182014-01-08 18:21:0024
25// VariationsSeedSimulator simulates the result of creating a set of studies
26// and detecting which studies would result in group changes.
Scott Violet69a5d8dd2021-06-01 23:46:4827class COMPONENT_EXPORT(VARIATIONS) VariationsSeedSimulator {
[email protected]92e09a182014-01-08 18:21:0028 public:
[email protected]a81120b62014-04-18 01:56:0329 // The result of variations seed simulation, counting the number of experiment
30 // group changes of each type that are expected to occur on a restart with the
31 // seed.
Scott Violet69a5d8dd2021-06-01 23:46:4832 struct COMPONENT_EXPORT(VARIATIONS) Result {
33 Result();
34 ~Result();
35
[email protected]a81120b62014-04-18 01:56:0336 // The number of expected group changes that do not fall into any special
37 // category. This is a lower bound due to session randomized studies.
38 int normal_group_change_count;
39
40 // The number of expected group changes that fall in the category of killed
41 // experiments that should trigger the "best effort" restart mechanism.
42 int kill_best_effort_group_change_count;
43
44 // The number of expected group changes that fall in the category of killed
45 // experiments that should trigger the "critical" restart mechanism.
46 int kill_critical_group_change_count;
[email protected]a81120b62014-04-18 01:56:0347 };
48
jwd67c08f752016-05-18 21:04:5949 // Creates the simulator with the given default and low entropy providers. The
50 // |low_entropy_provider| will be used for studies that should only use a low
51 // entropy source. This is defined by
52 // VariationsSeedProcessor::ShouldStudyUseLowEntropy, in
53 // variations_seed_processor.h.
54 VariationsSeedSimulator(
55 const base::FieldTrial::EntropyProvider& default_entropy_provider,
56 const base::FieldTrial::EntropyProvider& low_entropy_provider);
[email protected]92e09a182014-01-08 18:21:0057 virtual ~VariationsSeedSimulator();
58
59 // Computes differences between the current process' field trial state and
[email protected]a81120b62014-04-18 01:56:0360 // the result of evaluating |seed| with the given parameters. Returns the
61 // results of the simulation as a set of expected group change counts of each
62 // type.
63 Result SimulateSeedStudies(const VariationsSeed& seed,
isherman52a81bd2017-06-07 23:30:0664 const ClientFilterableState& client_state);
[email protected]92e09a182014-01-08 18:21:0065
66 private:
[email protected]a81120b62014-04-18 01:56:0367 friend class VariationsSeedSimulatorTest;
68
69 enum ChangeType {
70 NO_CHANGE,
71 CHANGED,
72 CHANGED_KILL_BEST_EFFORT,
73 CHANGED_KILL_CRITICAL,
74 };
75
76 // Computes differences between the current process' field trial state and
77 // the result of evaluating the |processed_studies| list. It is expected that
78 // |processed_studies| have already been filtered and only contain studies
79 // that apply to the configuration being simulated. Returns the results of the
80 // simulation as a set of expected group change counts of each type.
81 Result ComputeDifferences(
82 const std::vector<ProcessedStudy>& processed_studies);
83
84 // Maps proto enum |type| to a ChangeType.
85 ChangeType ConvertExperimentTypeToChangeType(Study_Experiment_Type type);
86
[email protected]92e09a182014-01-08 18:21:0087 // For the given |processed_study| with PERMANENT consistency, simulates group
[email protected]a81120b62014-04-18 01:56:0388 // assignment and returns a corresponding ChangeType if the result differs
89 // from that study's group in the current process.
90 ChangeType PermanentStudyGroupChanged(const ProcessedStudy& processed_study,
91 const std::string& selected_group);
[email protected]92e09a182014-01-08 18:21:0092
93 // For the given |processed_study| with SESSION consistency, determines if
94 // there are enough changes in the study config that restarting will result
[email protected]a81120b62014-04-18 01:56:0395 // in a guaranteed different group assignment (or different params) and
96 // returns the corresponding ChangeType.
97 ChangeType SessionStudyGroupChanged(const ProcessedStudy& filtered_study,
98 const std::string& selected_group);
[email protected]92e09a182014-01-08 18:21:0099
jwd67c08f752016-05-18 21:04:59100 const base::FieldTrial::EntropyProvider& default_entropy_provider_;
101 const base::FieldTrial::EntropyProvider& low_entropy_provider_;
[email protected]92e09a182014-01-08 18:21:00102
103 DISALLOW_COPY_AND_ASSIGN(VariationsSeedSimulator);
104};
105
[email protected]59b6f672014-07-26 18:35:47106} // namespace variations
[email protected]92e09a182014-01-08 18:21:00107
108#endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_SIMULATOR_H_