File: variations_seed_processor.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (89 lines) | stat: -rw-r--r-- 3,380 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_
#define COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_

#include <stdint.h>

#include <string>

#include "base/component_export.h"
#include "base/functional/callback_forward.h"
#include "components/variations/entropy_provider.h"
#include "components/variations/proto/study.pb.h"
#include "components/variations/proto/variations_seed.pb.h"

namespace base {
class FeatureList;
}

namespace variations {

namespace internal {
// The trial group selected when a study specifies a feature that is already
// associated with another trial. Exposed in the header file for testing.
COMPONENT_EXPORT(VARIATIONS)
extern const char kFeatureConflictGroupName[];

// The name of an auto-generated feature parameter for studies that have a
// non-empty google_groups filter.
COMPONENT_EXPORT(VARIATIONS)
extern const char kGoogleGroupFeatureParamName[];

// The separator between multiple Google groups in when serialized into a string
// for the feature parameter.
COMPONENT_EXPORT(VARIATIONS)
extern const char kGoogleGroupFeatureParamSeparator[];
}  // namespace internal

class ProcessedStudy;
struct ClientFilterableState;
class VariationsLayers;

// Helper class to instantiate field trials from a variations seed.
class COMPONENT_EXPORT(VARIATIONS) VariationsSeedProcessor {
 public:
  using UIStringOverrideCallback =
      base::RepeatingCallback<void(uint32_t, const std::u16string&)>;

  VariationsSeedProcessor();

  VariationsSeedProcessor(const VariationsSeedProcessor&) = delete;
  VariationsSeedProcessor& operator=(const VariationsSeedProcessor&) = delete;

  virtual ~VariationsSeedProcessor();

  // Whether the experiment has a `google_web_experiment_id` or a
  // `google_web_trigger_experiment_id`.
  static bool HasGoogleWebExperimentId(const Study::Experiment& experiment);

  // Creates field trials from the specified variations |seed|, filtered
  // according to the client's |client_state|.
  void CreateTrialsFromSeed(const VariationsSeed& seed,
                            const ClientFilterableState& client_state,
                            const UIStringOverrideCallback& override_callback,
                            const EntropyProviders& entropy_providers,
                            const VariationsLayers& layers,
                            base::FeatureList* feature_list);

 private:
  friend void CreateTrialFromStudyFuzzer(const Study& study);

  // Check if the |study| is only associated with platform Android/iOS and
  // channel dev/canary. If so, forcing flag and variation id can both be set.
  // (Otherwise, forcing_flag and variation_id are mutually exclusive.)
  bool AllowVariationIdWithForcingFlag(const Study& study);

  // Creates and registers a field trial from the |processed_study| data.
  void CreateTrialFromStudy(const ProcessedStudy& processed_study,
                            const UIStringOverrideCallback& override_callback,
                            const EntropyProviders& entropy_providers,
                            const VariationsLayers& layers,
                            base::FeatureList* feature_list);
};

}  // namespace variations

#endif  // COMPONENTS_VARIATIONS_VARIATIONS_SEED_PROCESSOR_H_