blob: e8c6829be75850f335776da56c7754495cb6362a [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
8#include <string>
[email protected]d4f84852013-11-08 01:05:359#include <vector>
[email protected]1871a1702013-07-26 09:37:4310
[email protected]e24fff362014-07-22 01:19:0211#include "base/callback_forward.h"
[email protected]1871a1702013-07-26 09:37:4312#include "base/compiler_specific.h"
13#include "base/gtest_prod_util.h"
14#include "base/metrics/field_trial.h"
[email protected]e24fff362014-07-22 01:19:0215#include "base/strings/string16.h"
[email protected]1871a1702013-07-26 09:37:4316#include "base/time/time.h"
[email protected]12a9b5552013-08-09 11:05:5017#include "base/version.h"
[email protected]50ae9f12013-08-29 18:03:2218#include "components/variations/proto/study.pb.h"
[email protected]541f66e2013-09-03 15:00:1519#include "components/variations/proto/variations_seed.pb.h"
[email protected]1871a1702013-07-26 09:37:4320
[email protected]59b6f672014-07-26 18:35:4721namespace variations {
[email protected]1871a1702013-07-26 09:37:4322
[email protected]70fbd0052013-11-20 02:22:0623class ProcessedStudy;
[email protected]d4f84852013-11-08 01:05:3524
[email protected]1871a1702013-07-26 09:37:4325// Helper class to instantiate field trials from a variations seed.
26class VariationsSeedProcessor {
27 public:
[email protected]e24fff362014-07-22 01:19:0228 typedef base::Callback<void(uint32_t, const base::string16&)>
29 UIStringOverrideCallback;
30
[email protected]1871a1702013-07-26 09:37:4331 VariationsSeedProcessor();
32 virtual ~VariationsSeedProcessor();
33
34 // Creates field trials from the specified variations |seed|, based on the
[email protected]bca25942014-05-02 04:36:5535 // specified configuration (locale, current date, version, channel, form
36 // factor and hardware_class).
[email protected]541f66e2013-09-03 15:00:1537 void CreateTrialsFromSeed(const VariationsSeed& seed,
[email protected]1871a1702013-07-26 09:37:4338 const std::string& locale,
39 const base::Time& reference_date,
[email protected]12a9b5552013-08-09 11:05:5040 const base::Version& version,
[email protected]1c5fd2d2013-11-12 20:33:4441 Study_Channel channel,
[email protected]bca25942014-05-02 04:36:5542 Study_FormFactor form_factor,
[email protected]e24fff362014-07-22 01:19:0243 const std::string& hardware_class,
44 const UIStringOverrideCallback& override_callback);
[email protected]1871a1702013-07-26 09:37:4345
46 private:
[email protected]70fbd0052013-11-20 02:22:0647 friend class VariationsSeedProcessorTest;
[email protected]0aafa3e2013-11-18 09:32:4548 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest,
49 AllowForceGroupAndVariationId);
50 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest,
51 AllowVariationIdWithForcingFlag);
[email protected]0aafa3e2013-11-18 09:32:4552 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest,
53 ForbidForceGroupWithVariationId);
[email protected]1871a1702013-07-26 09:37:4354 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]1871a1702013-07-26 09:37:4361 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest, VariationParams);
[email protected]f2fc7cf42013-11-07 21:53:0362 FRIEND_TEST_ALL_PREFIXES(VariationsSeedProcessorTest,
63 VariationParamsWithForcingFlag);
[email protected]1871a1702013-07-26 09:37:4364
[email protected]0aafa3e2013-11-18 09:32:4565 // 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]d4f84852013-11-08 01:05:3570 // Creates and registers a field trial from the |processed_study| data.
71 // Disables the trial if |processed_study.is_expired| is true.
[email protected]e24fff362014-07-22 01:19:0272 void CreateTrialFromStudy(const ProcessedStudy& processed_study,
73 const UIStringOverrideCallback& override_callback);
[email protected]1871a1702013-07-26 09:37:4374
[email protected]1871a1702013-07-26 09:37:4375 DISALLOW_COPY_AND_ASSIGN(VariationsSeedProcessor);
76};
77
[email protected]59b6f672014-07-26 18:35:4778} // namespace variations
[email protected]1871a1702013-07-26 09:37:4379
[email protected]50ae9f12013-08-29 18:03:2280#endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_