File: client_filterable_state.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 (120 lines) | stat: -rw-r--r-- 4,403 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2017 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_CLIENT_FILTERABLE_STATE_H_
#define COMPONENTS_VARIATIONS_CLIENT_FILTERABLE_STATE_H_

#include <optional>
#include <string>

#include "base/component_export.h"
#include "base/containers/flat_set.h"
#include "base/functional/callback.h"
#include "base/time/time.h"
#include "base/version.h"
#include "components/variations/proto/study.pb.h"

namespace variations {

// The values of the ChromeVariations policy. Those should be kept in sync
// with the values defined in policy_templates.json!
enum class RestrictionPolicy {
  // No restrictions applied by policy. Default value when policy not set.
  NO_RESTRICTIONS = 0,
  // Only critical security variations should be applied.
  CRITICAL_ONLY = 1,
  // All variations disabled. Disables the variations framework altogether.
  ALL = 2,
  kMaxValue = ALL,
};

using IsEnterpriseFunction = base::OnceCallback<bool()>;
using GoogleGroupsFunction = base::OnceCallback<base::flat_set<uint64_t>()>;

// A container for all of the client state which is used for filtering studies.
struct COMPONENT_EXPORT(VARIATIONS) ClientFilterableState {
  // The system locale.
  std::string locale;

  // The date on which the variations seed was fetched.
  base::Time reference_date;

  // The Chrome version to filter on.
  base::Version version;

  // The OS version to filter on. See |min_os_version| in study.proto for
  // details.
  base::Version os_version;

  // The Channel for this Chrome installation.
  Study::Channel channel = Study::UNKNOWN;

  // The hardware form factor that Chrome is running on.
  Study::FormFactor form_factor = Study::DESKTOP;

  // The CPU architecture on which Chrome is running.
  Study::CpuArchitecture cpu_architecture = Study::X86_64;

  // The OS on which Chrome is running.
  Study::Platform platform = Study::PLATFORM_WINDOWS;

  // The named hardware configuration that Chrome is running on -- used to
  // identify models of devices.
  std::string hardware_class;

  // Whether this is a low-end device. Currently only supported on Android.
  // Based on base::SysInfo::IsLowEndDevice().
  bool is_low_end_device = false;

  // The country code to use for studies configured with session consistency.
  std::string session_consistency_country;

  // The country code to use for studies configured with permanent consistency.
  std::string permanent_consistency_country;

  // The restriction applied to Chrome through the "ChromeVariations" policy.
  RestrictionPolicy policy_restriction = RestrictionPolicy::NO_RESTRICTIONS;

  explicit ClientFilterableState(IsEnterpriseFunction is_enterprise_function,
                                 GoogleGroupsFunction google_groups_function);

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

  ~ClientFilterableState();

  // Whether this is an enterprise client. Always false on Android, iOS, and
  // Linux. Determined by VariationsServiceClient::IsEnterprise() for Windows,
  // ChromeOS, and Mac.
  bool IsEnterprise() const;

  // The list of Google groups that one or more signed-in syncing users are a
  // a member of. Each value is the Gaia ID of the Google group.
  base::flat_set<uint64_t> GoogleGroups() const;

  static Study::Platform GetCurrentPlatform();

  // base::Version used in {min,max}_os_version filtering.
  static base::Version GetOSVersion();

  // Returns the hardware class string used for hardware_class filtering.
  static std::string GetHardwareClass();

 private:
  // Evaluating enterprise status negatively affects performance, so we only
  // evaluate it if needed (i.e. if a study is filtering by enterprise) and at
  // most once.
  mutable IsEnterpriseFunction is_enterprise_function_;
  mutable std::optional<bool> is_enterprise_;

  // Evaluating group memberships involves parsing data received from Chrome
  // Sync server.  For safe rollout we do this only for studies that require
  // inspecting group memberships (and for efficiency we do it only once.)
  mutable GoogleGroupsFunction google_groups_function_;
  mutable std::optional<base::flat_set<uint64_t>> google_groups_;
};

}  // namespace variations

#endif  // COMPONENTS_VARIATIONS_CLIENT_FILTERABLE_STATE_H_