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.
5 #ifndef COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_
6 #define COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_
11 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/metrics/field_trial.h"
15 #include "base/strings/string16.h"
16 #include "base/time/time.h"
17 #include "base/version.h"
18 #include "components/variations/proto/study.pb.h"
19 #include "components/variations/proto/variations_seed.pb.h"
21 namespace variations
{
25 // Helper class to instantiate field trials from a variations seed.
26 class VariationsSeedProcessor
{
28 typedef base::Callback
<void(uint32_t, const base::string16
&)>
29 UIStringOverrideCallback
;
31 VariationsSeedProcessor();
32 virtual ~VariationsSeedProcessor();
34 // Creates field trials from the specified variations |seed|, based on the
35 // specified configuration (locale, current date, version, channel, form
36 // factor, hardware_class, and permanent_consistency_country).
37 void CreateTrialsFromSeed(const VariationsSeed
& seed
,
38 const std::string
& locale
,
39 const base::Time
& reference_date
,
40 const base::Version
& version
,
41 Study_Channel channel
,
42 Study_FormFactor form_factor
,
43 const std::string
& hardware_class
,
44 const std::string
& permanent_consistency_country
,
45 const UIStringOverrideCallback
& override_callback
);
48 friend class VariationsSeedProcessorTest
;
49 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest
,
50 AllowForceGroupAndVariationId
);
51 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest
,
52 AllowVariationIdWithForcingFlag
);
53 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest
,
54 ForbidForceGroupWithVariationId
);
55 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest
, ForceGroupWithFlag1
);
56 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest
, ForceGroupWithFlag2
);
57 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest
,
58 ForceGroup_ChooseFirstGroupWithFlag
);
59 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest
,
60 ForceGroup_DontChooseGroupWithFlag
);
61 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest
, IsStudyExpired
);
62 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest
, VariationParams
);
63 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest
,
64 VariationParamsWithForcingFlag
);
66 // Check if the |study| is only associated with platform Android/iOS and
67 // channel dev/canary. If so, forcing flag and variation id can both be set.
68 // (Otherwise, forcing_flag and variation_id are mutually exclusive.)
69 bool AllowVariationIdWithForcingFlag(const Study
& study
);
71 // Creates and registers a field trial from the |processed_study| data.
72 // Disables the trial if |processed_study.is_expired| is true.
73 void CreateTrialFromStudy(const ProcessedStudy
& processed_study
,
74 const UIStringOverrideCallback
& override_callback
);
76 DISALLOW_COPY_AND_ASSIGN(VariationsSeedProcessor
);
79 } // namespace variations
81 #endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_