client_filterable_state.h 3.4 KB

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