blob: 72986afc6ff4de2ce3714b2ecba9e5d70e03d74a [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"
avi5dd91f82015-12-25 22:30:4612#include "base/macros.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.
26class VariationsSeedSimulator {
27 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.
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
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);
[email protected]92e09a182014-01-08 18:21:0056 virtual ~VariationsSeedSimulator();
57
58 // Computes differences between the current process' field trial state and
[email protected]a81120b62014-04-18 01:56:0359 // 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,
isherman52a81bd2017-06-07 23:30:0663 const ClientFilterableState& client_state);
[email protected]92e09a182014-01-08 18:21:0064
65 private:
[email protected]a81120b62014-04-18 01:56:0366 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]92e09a182014-01-08 18:21:0086 // For the given |processed_study| with PERMANENT consistency, simulates group
[email protected]a81120b62014-04-18 01:56:0387 // 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]92e09a182014-01-08 18:21:0091
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]a81120b62014-04-18 01:56:0394 // 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]92e09a182014-01-08 18:21:0098
jwd67c08f752016-05-18 21:04:5999 const base::FieldTrial::EntropyProvider& default_entropy_provider_;
100 const base::FieldTrial::EntropyProvider& low_entropy_provider_;
[email protected]92e09a182014-01-08 18:21:00101
102 DISALLOW_COPY_AND_ASSIGN(VariationsSeedSimulator);
103};
104
[email protected]59b6f672014-07-26 18:35:47105} // namespace variations
[email protected]92e09a182014-01-08 18:21:00106
107#endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_SIMULATOR_H_