Add a string for translation.
[chromium-blink-merge.git] / components / variations / variations_seed_simulator.h
blobef9207bb1b6105f3915eccdf9b2f4dde6532aa9d
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_
8 #include <string>
9 #include <vector>
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 chrome_variations {
20 class ProcessedStudy;
21 class VariationsSeed;
23 // VariationsSeedSimulator simulates the result of creating a set of studies
24 // and detecting which studies would result in group changes.
25 class VariationsSeedSimulator {
26 public:
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
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;
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;
43 Result();
44 ~Result();
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
55 // type.
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);
63 private:
64 friend class VariationsSeedSimulatorTest;
66 enum ChangeType {
67 NO_CHANGE,
68 CHANGED,
69 CHANGED_KILL_BEST_EFFORT,
70 CHANGED_KILL_CRITICAL,
73 // Computes differences between the current process' field trial state and
74 // the result of evaluating the |processed_studies| list. It is expected that
75 // |processed_studies| have already been filtered and only contain studies
76 // that apply to the configuration being simulated. Returns the results of the
77 // simulation as a set of expected group change counts of each type.
78 Result ComputeDifferences(
79 const std::vector<ProcessedStudy>& processed_studies);
81 // Maps proto enum |type| to a ChangeType.
82 ChangeType ConvertExperimentTypeToChangeType(Study_Experiment_Type type);
84 // For the given |processed_study| with PERMANENT consistency, simulates group
85 // assignment and returns a corresponding ChangeType if the result differs
86 // from that study's group in the current process.
87 ChangeType PermanentStudyGroupChanged(const ProcessedStudy& processed_study,
88 const std::string& selected_group);
90 // For the given |processed_study| with SESSION consistency, determines if
91 // there are enough changes in the study config that restarting will result
92 // in a guaranteed different group assignment (or different params) and
93 // returns the corresponding ChangeType.
94 ChangeType SessionStudyGroupChanged(const ProcessedStudy& filtered_study,
95 const std::string& selected_group);
97 const base::FieldTrial::EntropyProvider& entropy_provider_;
99 DISALLOW_COPY_AND_ASSIGN(VariationsSeedSimulator);
102 } // namespace chrome_variations
104 #endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_SIMULATOR_H_