Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: components/variations/variations_params_manager.h

Issue 2321273003: Extend VariationParamsManager to support feature associations. (Closed)
Patch Set: Last comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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_PARAMS_MANAGER_H_
6 #define COMPONENTS_VARIATIONS_VARIATIONS_PARAMS_MANAGER_H_
7
8 #include <map>
9 #include <memory>
10 #include <set>
11 #include <string>
12
13 #include "base/macros.h"
14 #include "base/metrics/field_trial.h"
15
16 namespace base {
17 class FieldTrialList;
18
19 namespace test {
20 class ScopedFeatureList;
21 } // namespace test
22
23 } // namespace base
24
25 namespace variations {
26 namespace testing {
27
28 // Use this class as a member in your test class to set variation params for
29 // your tests. You can directly set the parameters in the constructor (if they
30 // are used by other members upon construction). You can change them later
31 // arbitrarily many times using the SetVariationParams function. Internally, it
32 // creates a FieldTrialList as a member. It works well for multiple tests of a
33 // given test class, as it clears the parameters when this class is destructed.
34 // Note that it clears all parameters (not just those registered here).
35 class VariationParamsManager {
36 public:
37 // Does not associate any parameters.
38 VariationParamsManager();
39 // Calls directly SetVariationParams with the provided arguments.
40 VariationParamsManager(
41 const std::string& trial_name,
42 const std::map<std::string, std::string>& param_values);
43 // Calls directly SetVariationParamsWithFeatures with the provided arguments.
44 VariationParamsManager(
45 const std::string& trial_name,
46 const std::map<std::string, std::string>& param_values,
47 const std::set<std::string>& associated_features);
48 ~VariationParamsManager();
49
50 // Associates |param_values| with the given |trial_name|. |param_values| maps
51 // parameter names to their values. The function creates a new trial group,
52 // used only for testing. Between two calls of this function,
53 // ClearAllVariationParams() has to be called.
54 void SetVariationParams(
55 const std::string& trial_name,
56 const std::map<std::string, std::string>& param_values);
57
58 // Like SetVariationParams(). |associated_features| lists names of features
59 // to be associated to the newly created trial group. As a result, all
60 // parameters from |param_values| can be accessed via any of the feature from
61 // |associated_features|.
62 void SetVariationParamsWithFeatureAssociations(
63 const std::string& trial_name,
64 const std::map<std::string, std::string>& param_values,
65 const std::set<std::string>& associated_features);
66
67 // Clears all of the mapped associations.
68 void ClearAllVariationIDs();
69
70 // Clears all of the associated params.
71 void ClearAllVariationParams();
72
73 private:
74 std::unique_ptr<base::FieldTrialList> field_trial_list_;
75 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_;
76
77 DISALLOW_COPY_AND_ASSIGN(VariationParamsManager);
78 };
79
80 } // namespace testing
81 } // namespace variations
82
83 #endif // COMPONENTS_VARIATIONS_VARIATIONS_PARAMS_MANAGER_H_
OLDNEW
« no previous file with comments | « components/variations/variations_associated_data.cc ('k') | components/variations/variations_params_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698