blob: 8c3cd73ec07aceeb707d5c8d91a45e7a26050fee [file] [log] [blame]
[email protected]1871a1702013-07-26 09:37:431// 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]50ae9f12013-08-29 18:03:225#ifndef COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_
6#define COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_
[email protected]1871a1702013-07-26 09:37:437
avi5dd91f82015-12-25 22:30:468#include <stdint.h>
9
[email protected]1871a1702013-07-26 09:37:4310#include <string>
[email protected]d4f84852013-11-08 01:05:3511#include <vector>
[email protected]1871a1702013-07-26 09:37:4312
[email protected]e24fff362014-07-22 01:19:0213#include "base/callback_forward.h"
[email protected]1871a1702013-07-26 09:37:4314#include "base/compiler_specific.h"
15#include "base/gtest_prod_util.h"
avi5dd91f82015-12-25 22:30:4616#include "base/macros.h"
[email protected]1871a1702013-07-26 09:37:4317#include "base/metrics/field_trial.h"
[email protected]e24fff362014-07-22 01:19:0218#include "base/strings/string16.h"
[email protected]1871a1702013-07-26 09:37:4319#include "base/time/time.h"
[email protected]12a9b5552013-08-09 11:05:5020#include "base/version.h"
[email protected]50ae9f12013-08-29 18:03:2221#include "components/variations/proto/study.pb.h"
[email protected]541f66e2013-09-03 15:00:1522#include "components/variations/proto/variations_seed.pb.h"
[email protected]1871a1702013-07-26 09:37:4323
asvitkine8423d172015-09-28 23:23:4424namespace base {
25class FeatureList;
26}
27
[email protected]59b6f672014-07-26 18:35:4728namespace variations {
[email protected]1871a1702013-07-26 09:37:4329
[email protected]70fbd0052013-11-20 02:22:0630class ProcessedStudy;
isherman52a81bd2017-06-07 23:30:0631struct ClientFilterableState;
[email protected]d4f84852013-11-08 01:05:3532
[email protected]1871a1702013-07-26 09:37:4333// Helper class to instantiate field trials from a variations seed.
34class VariationsSeedProcessor {
35 public:
Ken Rockot5d21db32019-12-17 03:24:2836 using UIStringOverrideCallback =
37 base::RepeatingCallback<void(uint32_t, const base::string16&)>;
[email protected]e24fff362014-07-22 01:19:0238
[email protected]1871a1702013-07-26 09:37:4339 VariationsSeedProcessor();
40 virtual ~VariationsSeedProcessor();
41
isherman52a81bd2017-06-07 23:30:0642 // 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;
jwd67c08f752016-05-18 21:04:5946 void CreateTrialsFromSeed(
47 const VariationsSeed& seed,
isherman52a81bd2017-06-07 23:30:0648 const ClientFilterableState& client_state,
jwd67c08f752016-05-18 21:04:5949 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]1871a1702013-07-26 09:37:4356
57 private:
[email protected]70fbd0052013-11-20 02:22:0658 friend class VariationsSeedProcessorTest;
[email protected]0aafa3e2013-11-18 09:32:4559 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest,
60 AllowForceGroupAndVariationId);
61 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest,
62 AllowVariationIdWithForcingFlag);
[email protected]0aafa3e2013-11-18 09:32:4563 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest,
64 ForbidForceGroupWithVariationId);
[email protected]1871a1702013-07-26 09:37:4365 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]1871a1702013-07-26 09:37:4372 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, VariationParams);
[email protected]f2fc7cf42013-11-07 21:53:0373 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest,
74 VariationParamsWithForcingFlag);
[email protected]1871a1702013-07-26 09:37:4375
[email protected]0aafa3e2013-11-18 09:32:4576 // 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]d4f84852013-11-08 01:05:3581 // Creates and registers a field trial from the |processed_study| data.
jwd67c08f752016-05-18 21:04:5982 // 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]1871a1702013-07-26 09:37:4390
[email protected]1871a1702013-07-26 09:37:4391 DISALLOW_COPY_AND_ASSIGN(VariationsSeedProcessor);
92};
93
[email protected]59b6f672014-07-26 18:35:4794} // namespace variations
[email protected]1871a1702013-07-26 09:37:4395
[email protected]50ae9f12013-08-29 18:03:2296#endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_