[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 | |
| 8 | #include <string> |
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 9 | #include <vector> |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 10 | |
[email protected] | e24fff36 | 2014-07-22 01:19:02 | [diff] [blame] | 11 | #include "base/callback_forward.h" |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
| 13 | #include "base/gtest_prod_util.h" |
| 14 | #include "base/metrics/field_trial.h" |
[email protected] | e24fff36 | 2014-07-22 01:19:02 | [diff] [blame] | 15 | #include "base/strings/string16.h" |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 16 | #include "base/time/time.h" |
[email protected] | 12a9b555 | 2013-08-09 11:05:50 | [diff] [blame] | 17 | #include "base/version.h" |
[email protected] | 50ae9f1 | 2013-08-29 18:03:22 | [diff] [blame] | 18 | #include "components/variations/proto/study.pb.h" |
[email protected] | 541f66e | 2013-09-03 15:00:15 | [diff] [blame] | 19 | #include "components/variations/proto/variations_seed.pb.h" |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 20 | |
[email protected] | 59b6f67 | 2014-07-26 18:35:47 | [diff] [blame] | 21 | namespace variations { |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 22 | |
[email protected] | 70fbd005 | 2013-11-20 02:22:06 | [diff] [blame] | 23 | class ProcessedStudy; |
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 24 | |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 25 | // Helper class to instantiate field trials from a variations seed. |
| 26 | class VariationsSeedProcessor { |
| 27 | public: |
[email protected] | e24fff36 | 2014-07-22 01:19:02 | [diff] [blame] | 28 | typedef base::Callback<void(uint32_t, const base::string16&)> |
| 29 | UIStringOverrideCallback; |
| 30 | |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 31 | VariationsSeedProcessor(); |
| 32 | virtual ~VariationsSeedProcessor(); |
| 33 | |
| 34 | // Creates field trials from the specified variations |seed|, based on the |
[email protected] | bca2594 | 2014-05-02 04:36:55 | [diff] [blame] | 35 | // specified configuration (locale, current date, version, channel, form |
| 36 | // factor and hardware_class). |
[email protected] | 541f66e | 2013-09-03 15:00:15 | [diff] [blame] | 37 | void CreateTrialsFromSeed(const VariationsSeed& seed, |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 38 | const std::string& locale, |
| 39 | const base::Time& reference_date, |
[email protected] | 12a9b555 | 2013-08-09 11:05:50 | [diff] [blame] | 40 | const base::Version& version, |
[email protected] | 1c5fd2d | 2013-11-12 20:33:44 | [diff] [blame] | 41 | Study_Channel channel, |
[email protected] | bca2594 | 2014-05-02 04:36:55 | [diff] [blame] | 42 | Study_FormFactor form_factor, |
[email protected] | e24fff36 | 2014-07-22 01:19:02 | [diff] [blame] | 43 | const std::string& hardware_class, |
| 44 | const UIStringOverrideCallback& override_callback); |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 45 | |
| 46 | private: |
[email protected] | 70fbd005 | 2013-11-20 02:22:06 | [diff] [blame] | 47 | friend class VariationsSeedProcessorTest; |
[email protected] | 0aafa3e | 2013-11-18 09:32:45 | [diff] [blame] | 48 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, |
| 49 | AllowForceGroupAndVariationId); |
| 50 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, |
| 51 | AllowVariationIdWithForcingFlag); |
[email protected] | 0aafa3e | 2013-11-18 09:32:45 | [diff] [blame] | 52 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, |
| 53 | ForbidForceGroupWithVariationId); |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 54 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, ForceGroupWithFlag1); |
| 55 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, ForceGroupWithFlag2); |
| 56 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, |
| 57 | ForceGroup_ChooseFirstGroupWithFlag); |
| 58 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, |
| 59 | ForceGroup_DontChooseGroupWithFlag); |
| 60 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, IsStudyExpired); |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 61 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, VariationParams); |
[email protected] | f2fc7cf4 | 2013-11-07 21:53:03 | [diff] [blame] | 62 | FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, |
| 63 | VariationParamsWithForcingFlag); |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 64 | |
[email protected] | 0aafa3e | 2013-11-18 09:32:45 | [diff] [blame] | 65 | // Check if the |study| is only associated with platform Android/iOS and |
| 66 | // channel dev/canary. If so, forcing flag and variation id can both be set. |
| 67 | // (Otherwise, forcing_flag and variation_id are mutually exclusive.) |
| 68 | bool AllowVariationIdWithForcingFlag(const Study& study); |
| 69 | |
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 70 | // Creates and registers a field trial from the |processed_study| data. |
| 71 | // Disables the trial if |processed_study.is_expired| is true. |
[email protected] | e24fff36 | 2014-07-22 01:19:02 | [diff] [blame] | 72 | void CreateTrialFromStudy(const ProcessedStudy& processed_study, |
| 73 | const UIStringOverrideCallback& override_callback); |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 74 | |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 75 | DISALLOW_COPY_AND_ASSIGN(VariationsSeedProcessor); |
| 76 | }; |
| 77 | |
[email protected] | 59b6f67 | 2014-07-26 18:35:47 | [diff] [blame] | 78 | } // namespace variations |
[email protected] | 1871a170 | 2013-07-26 09:37:43 | [diff] [blame] | 79 | |
[email protected] | 50ae9f1 | 2013-08-29 18:03:22 | [diff] [blame] | 80 | #endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_ |