[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 1 | // Copyright 2013 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 | |
[email protected] | 50ae9f1 | 2013-08-29 18:03:22 | [diff] [blame] | 5 | #ifndef COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_ |
| 6 | #define COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_ |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 7 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 10 | #include <string> |
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 11 | #include <vector> |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 12 | |
[email protected] | e24fff36 | 2014-07-22 01:19:02 | [diff] [blame] | 13 | #include "base/callback_forward.h" |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 14 | #include "base/compiler_specific.h" |
| 15 | #include "base/gtest_prod_util.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 16 | #include "base/macros.h" |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 17 | #include "base/metrics/field_trial.h" |
[email protected] | e24fff36 | 2014-07-22 01:19:02 | [diff] [blame] | 18 | #include "base/strings/string16.h" |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 19 | #include "base/time/time.h" |
[email protected] | 12a9b555 | 2013-08-09 11:05:50 | [diff] [blame] | 20 | #include "base/version.h" |
[email protected] | 50ae9f1 | 2013-08-29 18:03:22 | [diff] [blame] | 21 | #include "components/variations/proto/study.pb.h" |
[email protected] | 541f66e | 2013-09-03 15:00:15 | [diff] [blame] | 22 | #include "components/variations/proto/variations_seed.pb.h" |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 23 | |
asvitkine | 8423d17 | 2015-09-28 23:23:44 | [diff] [blame] | 24 | namespace base { |
| 25 | class FeatureList; |
| 26 | } |
| 27 | |
[email protected] | 59b6f67 | 2014-07-26 18:35:47 | [diff] [blame] | 28 | namespace variations { |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 29 | |
[email protected] | 70fbd005 | 2013-11-20 02:22:06 | [diff] [blame] | 30 | class ProcessedStudy; |
isherman | 52a81bd | 2017-06-07 23:30:06 | [diff] [blame] | 31 | struct ClientFilterableState; |
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 32 | |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 33 | // Helper class to instantiate field trials from a variations seed. |
| 34 | class VariationsSeedProcessor { |
| 35 | public: |
Ken Rockot | 5d21db3 | 2019-12-17 03:24:28 | [diff] [blame] | 36 | using UIStringOverrideCallback = |
| 37 | base::RepeatingCallback<void(uint32_t, const base::string16&)>; |
[email protected] | e24fff36 | 2014-07-22 01:19:02 | [diff] [blame] | 38 | |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 39 | VariationsSeedProcessor(); |
| 40 | virtual ~VariationsSeedProcessor(); |
| 41 | |
isherman | 52a81bd | 2017-06-07 23:30:06 | [diff] [blame] | 42 | // Creates field trials from the specified variations |seed|, filtered |
| 43 | // according to the client's |client_state|. Any study that should use low |
| 44 | // entropy will use |low_entropy_provider| for group selection. These studies |
| 45 | // are defined by ShouldStudyUseLowEntropy; |
jwd | 67c08f75 | 2016-05-18 21:04:59 | [diff] [blame] | 46 | void CreateTrialsFromSeed( |
| 47 | const VariationsSeed& seed, |
isherman | 52a81bd | 2017-06-07 23:30:06 | [diff] [blame] | 48 | const ClientFilterableState& client_state, |
jwd | 67c08f75 | 2016-05-18 21:04:59 | [diff] [blame] | 49 | const UIStringOverrideCallback& override_callback, |
| 50 | const base::FieldTrial::EntropyProvider* low_entropy_provider, |
| 51 | base::FeatureList* feature_list); |
| 52 | |
| 53 | // If the given |study| should alwoys use low entropy. This is true for any |
| 54 | // study that can send data to other Google properties. |
| 55 | static bool ShouldStudyUseLowEntropy(const Study& study); |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 56 | |
| 57 | private: |
[email protected] | 70fbd005 | 2013-11-20 02:22:06 | [diff] [blame] | 58 | friend class VariationsSeedProcessorTest; |
[email protected] | 0aafa3e | 2013-11-18 09:32:45 | [diff] [blame] | 59 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, |
| 60 | AllowForceGroupAndVariationId); |
| 61 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, |
| 62 | AllowVariationIdWithForcingFlag); |
[email protected] | 0aafa3e | 2013-11-18 09:32:45 | [diff] [blame] | 63 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, |
| 64 | ForbidForceGroupWithVariationId); |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 65 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, ForceGroupWithFlag1); |
| 66 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, ForceGroupWithFlag2); |
| 67 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, |
| 68 | ForceGroup_ChooseFirstGroupWithFlag); |
| 69 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, |
| 70 | ForceGroup_DontChooseGroupWithFlag); |
| 71 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, IsStudyExpired); |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 72 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, VariationParams); |
[email protected] | f2fc7cf4 | 2013-11-07 21:53:03 | [diff] [blame] | 73 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, |
| 74 | VariationParamsWithForcingFlag); |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 75 | |
[email protected] | 0aafa3e | 2013-11-18 09:32:45 | [diff] [blame] | 76 | // Check if the |study| is only associated with platform Android/iOS and |
| 77 | // channel dev/canary. If so, forcing flag and variation id can both be set. |
| 78 | // (Otherwise, forcing_flag and variation_id are mutually exclusive.) |
| 79 | bool AllowVariationIdWithForcingFlag(const Study& study); |
| 80 | |
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 81 | // Creates and registers a field trial from the |processed_study| data. |
jwd | 67c08f75 | 2016-05-18 21:04:59 | [diff] [blame] | 82 | // Disables the trial if |processed_study.is_expired| is true. Uses |
| 83 | // |low_entropy_provider| if ShouldStudyUseLowEntropy returns true for the |
| 84 | // study. |
| 85 | void CreateTrialFromStudy( |
| 86 | const ProcessedStudy& processed_study, |
| 87 | const UIStringOverrideCallback& override_callback, |
| 88 | const base::FieldTrial::EntropyProvider* low_entropy_provider, |
| 89 | base::FeatureList* feature_list); |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 90 | |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 91 | DISALLOW_COPY_AND_ASSIGN(VariationsSeedProcessor); |
| 92 | }; |
| 93 | |
[email protected] | 59b6f67 | 2014-07-26 18:35:47 | [diff] [blame] | 94 | } // namespace variations |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 95 | |
[email protected] | 50ae9f1 | 2013-08-29 18:03:22 | [diff] [blame] | 96 | #endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_ |