1 // Copyright 2017 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 
5 #ifndef COMPONENTS_VARIATIONS_CLIENT_FILTERABLE_STATE_H_
6 #define COMPONENTS_VARIATIONS_CLIENT_FILTERABLE_STATE_H_
7 
8 #include <string>
9 
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/optional.h"
13 #include "base/time/time.h"
14 #include "base/version.h"
15 #include "components/variations/proto/study.pb.h"
16 
17 namespace variations {
18 
19 // The values of the ChromeVariations policy. Those should be kept in sync
20 // with the values defined in policy_templates.json!
21 enum class RestrictionPolicy {
22   // No restrictions applied by policy. Default value when policy not set.
23   NO_RESTRICTIONS = 0,
24   // Only critical security variations should be applied.
25   CRITICAL_ONLY = 1,
26   // All variations disabled. Disables the variations framework altogether.
27   ALL = 2,
28   kMaxValue = ALL,
29 };
30 
31 using IsEnterpriseFunction = base::OnceCallback<bool()>;
32 
33 // A container for all of the client state which is used for filtering studies.
34 struct ClientFilterableState {
35   static Study::Platform GetCurrentPlatform();
36 
37   explicit ClientFilterableState(IsEnterpriseFunction is_enterprise_function);
38   ~ClientFilterableState();
39 
40   // Whether this is an enterprise client. Always false on android, iOS, and
41   // linux. Determined by VariationsServiceClient::IsEnterprise for windows,
42   // chromeOs, and mac.
43   bool IsEnterprise() const;
44 
45   // The system locale.
46   std::string locale;
47 
48   // The date on which the variations seed was fetched.
49   base::Time reference_date;
50 
51   // The Chrome version to filter on.
52   base::Version version;
53 
54   // The OS version to filter on. See |min_os_version| in study.proto for
55   // details.
56   base::Version os_version;
57 
58   // The Channel for this Chrome installation.
59   Study::Channel channel;
60 
61   // The hardware form factor that Chrome is running on.
62   Study::FormFactor form_factor;
63 
64   // The OS on which Chrome is running.
65   Study::Platform platform;
66 
67   // The named hardware configuration that Chrome is running on -- used to
68   // identify models of devices.
69   std::string hardware_class;
70 
71   // Whether this is a low-end device. Currently only supported on Android.
72   // Based on base::SysInfo::IsLowEndDevice().
73   bool is_low_end_device = false;
74 
75   // The country code to use for studies configured with session consistency.
76   std::string session_consistency_country;
77 
78   // The country code to use for studies configured with permanent consistency.
79   std::string permanent_consistency_country;
80 
81   // The restriction applied to Chrome through the "ChromeVariations" policy.
82   RestrictionPolicy policy_restriction = RestrictionPolicy::NO_RESTRICTIONS;
83 
84  private:
85   // Evaluating enterprise status negatively affects performance, so we only
86   // evaluate it if needed (i.e. if a study is filtering by enterprise) and at
87   // most once.
88   mutable IsEnterpriseFunction is_enterprise_function_;
89   mutable base::Optional<bool> is_enterprise_;
90 
91   DISALLOW_COPY_AND_ASSIGN(ClientFilterableState);
92 };
93 
94 }  // namespace variations
95 
96 #endif  // COMPONENTS_VARIATIONS_CLIENT_FILTERABLE_STATE_H_
97