blob: c18e6c3210a10a31db24d10143e2fc60e685b60c [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;
[email protected]a81120b62014-04-18 01:56:0321class VariationsSeed;
[email protected]92e09a182014-01-08 18:21:0022
23// VariationsSeedSimulator simulates the result of creating a set of studies
24// and detecting which studies would result in group changes.
25class VariationsSeedSimulator {
26 public:
[email protected]a81120b62014-04-18 01:56:0327 // 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
jwd67c08f752016-05-18 21:04:5947 // 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]92e09a182014-01-08 18:21:0055 virtual ~VariationsSeedSimulator();
56
57 // Computes differences between the current process' field trial state and
[email protected]a81120b62014-04-18 01:56:0358 // 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]bca25942014-05-02 04:36:5566 Study_FormFactor form_factor,
sclittle761459b2015-05-07 23:40:1767 const std::string& hardware_class,
asvitkine75b14df42015-08-03 18:40:5668 const std::string& session_consistency_country,
sclittle761459b2015-05-07 23:40:1769 const std::string& permanent_consistency_country);
[email protected]92e09a182014-01-08 18:21:0070
71 private:
[email protected]a81120b62014-04-18 01:56:0372 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]92e09a182014-01-08 18:21:0092 // For the given |processed_study| with PERMANENT consistency, simulates group
[email protected]a81120b62014-04-18 01:56:0393 // 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]92e09a182014-01-08 18:21:0097
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]a81120b62014-04-18 01:56:03100 // 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]92e09a182014-01-08 18:21:00104
jwd67c08f752016-05-18 21:04:59105 const base::FieldTrial::EntropyProvider& default_entropy_provider_;
106 const base::FieldTrial::EntropyProvider& low_entropy_provider_;
[email protected]92e09a182014-01-08 18:21:00107
108 DISALLOW_COPY_AND_ASSIGN(VariationsSeedSimulator);
109};
110
[email protected]59b6f672014-07-26 18:35:47111} // namespace variations
[email protected]92e09a182014-01-08 18:21:00112
113#endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_SIMULATOR_H_