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.
5 #ifndef COMPONENTS_VARIATIONS_VARIATIONS_SEED_SIMULATOR_H_
6 #define COMPONENTS_VARIATIONS_VARIATIONS_SEED_SIMULATOR_H_
11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/metrics/field_trial.h"
14 #include "base/version.h"
15 #include "components/variations/proto/study.pb.h"
16 #include "components/variations/proto/variations_seed.pb.h"
18 namespace variations
{
23 // VariationsSeedSimulator simulates the result of creating a set of studies
24 // and detecting which studies would result in group changes.
25 class VariationsSeedSimulator
{
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
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
;
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
;
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
;
47 // Creates the simulator with the given entropy |provider|.
48 explicit VariationsSeedSimulator(
49 const base::FieldTrial::EntropyProvider
& provider
);
50 virtual ~VariationsSeedSimulator();
52 // Computes differences between the current process' field trial state and
53 // the result of evaluating |seed| with the given parameters. Returns the
54 // results of the simulation as a set of expected group change counts of each
56 Result
SimulateSeedStudies(const VariationsSeed
& seed
,
57 const std::string
& locale
,
58 const base::Time
& reference_date
,
59 const base::Version
& version
,
60 Study_Channel channel
,
61 Study_FormFactor form_factor
,
62 const std::string
& hardware_class
,
63 const std::string
& permanent_consistency_country
);
66 friend class VariationsSeedSimulatorTest
;
71 CHANGED_KILL_BEST_EFFORT
,
72 CHANGED_KILL_CRITICAL
,
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
);
83 // Maps proto enum |type| to a ChangeType.
84 ChangeType
ConvertExperimentTypeToChangeType(Study_Experiment_Type type
);
86 // For the given |processed_study| with PERMANENT consistency, simulates group
87 // 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
);
92 // For the given |processed_study| with SESSION consistency, determines if
93 // there are enough changes in the study config that restarting will result
94 // 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
);
99 const base::FieldTrial::EntropyProvider
& entropy_provider_
;
101 DISALLOW_COPY_AND_ASSIGN(VariationsSeedSimulator
);
104 } // namespace variations
106 #endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_SIMULATOR_H_