blob: ec95939553650616a3e90bdec83749d3a6805870 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2014 The Chromium Authors
[email protected]92e09a182014-01-08 18:21:002// 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"
[email protected]92e09a182014-01-08 18:21:0013#include "base/metrics/field_trial.h"
[email protected]a81120b62014-04-18 01:56:0314#include "base/version.h"
15#include "components/variations/proto/study.pb.h"
16#include "components/variations/proto/variations_seed.pb.h"
[email protected]92e09a182014-01-08 18:21:0017
[email protected]59b6f672014-07-26 18:35:4718namespace variations {
[email protected]92e09a182014-01-08 18:21:0019
20class ProcessedStudy;
isherman52a81bd2017-06-07 23:30:0621struct ClientFilterableState;
[email protected]a81120b62014-04-18 01:56:0322class VariationsSeed;
[email protected]92e09a182014-01-08 18:21:0023
24// VariationsSeedSimulator simulates the result of creating a set of studies
25// and detecting which studies would result in group changes.
Scott Violet69a5d8dd2021-06-01 23:46:4826class COMPONENT_EXPORT(VARIATIONS) VariationsSeedSimulator {
[email protected]92e09a182014-01-08 18:21:0027 public:
[email protected]a81120b62014-04-18 01:56:0328 // 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.
Scott Violet69a5d8dd2021-06-01 23:46:4831 struct COMPONENT_EXPORT(VARIATIONS) Result {
32 Result();
33 ~Result();
34
[email protected]a81120b62014-04-18 01:56:0335 // The number of expected group changes that do not fall into any special
36 // category. This is a lower bound due to session randomized studies.
37 int normal_group_change_count;
38
39 // The number of expected group changes that fall in the category of killed
40 // experiments that should trigger the "best effort" restart mechanism.
41 int kill_best_effort_group_change_count;
42
43 // The number of expected group changes that fall in the category of killed
44 // experiments that should trigger the "critical" restart mechanism.
45 int kill_critical_group_change_count;
[email protected]a81120b62014-04-18 01:56:0346 };
47
jwd67c08f752016-05-18 21:04:5948 // 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);
Peter Boström09c01822021-09-20 22:43:2756
57 VariationsSeedSimulator(const VariationsSeedSimulator&) = delete;
58 VariationsSeedSimulator& operator=(const VariationsSeedSimulator&) = delete;
59
[email protected]92e09a182014-01-08 18:21:0060 virtual ~VariationsSeedSimulator();
61
62 // Computes differences between the current process' field trial state and
[email protected]a81120b62014-04-18 01:56:0363 // the result of evaluating |seed| with the given parameters. Returns the
64 // results of the simulation as a set of expected group change counts of each
65 // type.
66 Result SimulateSeedStudies(const VariationsSeed& seed,
isherman52a81bd2017-06-07 23:30:0667 const ClientFilterableState& client_state);
[email protected]92e09a182014-01-08 18:21:0068
69 private:
[email protected]a81120b62014-04-18 01:56:0370 friend class VariationsSeedSimulatorTest;
71
72 enum ChangeType {
73 NO_CHANGE,
74 CHANGED,
75 CHANGED_KILL_BEST_EFFORT,
76 CHANGED_KILL_CRITICAL,
77 };
78
79 // Computes differences between the current process' field trial state and
80 // the result of evaluating the |processed_studies| list. It is expected that
81 // |processed_studies| have already been filtered and only contain studies
82 // that apply to the configuration being simulated. Returns the results of the
83 // simulation as a set of expected group change counts of each type.
84 Result ComputeDifferences(
85 const std::vector<ProcessedStudy>& processed_studies);
86
87 // Maps proto enum |type| to a ChangeType.
88 ChangeType ConvertExperimentTypeToChangeType(Study_Experiment_Type type);
89
[email protected]92e09a182014-01-08 18:21:0090 // For the given |processed_study| with PERMANENT consistency, simulates group
[email protected]a81120b62014-04-18 01:56:0391 // assignment and returns a corresponding ChangeType if the result differs
92 // from that study's group in the current process.
93 ChangeType PermanentStudyGroupChanged(const ProcessedStudy& processed_study,
94 const std::string& selected_group);
[email protected]92e09a182014-01-08 18:21:0095
96 // For the given |processed_study| with SESSION consistency, determines if
97 // there are enough changes in the study config that restarting will result
[email protected]a81120b62014-04-18 01:56:0398 // in a guaranteed different group assignment (or different params) and
99 // returns the corresponding ChangeType.
100 ChangeType SessionStudyGroupChanged(const ProcessedStudy& filtered_study,
101 const std::string& selected_group);
[email protected]92e09a182014-01-08 18:21:00102
jwd67c08f752016-05-18 21:04:59103 const base::FieldTrial::EntropyProvider& default_entropy_provider_;
104 const base::FieldTrial::EntropyProvider& low_entropy_provider_;
[email protected]92e09a182014-01-08 18:21:00105};
106
[email protected]59b6f672014-07-26 18:35:47107} // namespace variations
[email protected]92e09a182014-01-08 18:21:00108
109#endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_SIMULATOR_H_