File: client_filterable_state.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (94 lines) | stat: -rw-r--r-- 3,040 bytes parent folder | download | duplicates (5)
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
// 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.

#include "components/variations/client_filterable_state.h"

#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/system/sys_info.h"
#include "build/build_config.h"
#include "components/prefs/pref_service.h"
#include "components/variations/pref_names.h"

namespace variations {

ClientFilterableState::ClientFilterableState(
    IsEnterpriseFunction is_enterprise_function,
    GoogleGroupsFunction google_groups_function)
    : is_enterprise_function_(std::move(is_enterprise_function)),
      google_groups_function_(std::move(google_groups_function)) {
  // The callback is only used when processing a study that uses the
  // is_enterprise filter. If you're building a client that isn't expecting that
  // filter, you should use a callback that always returns false.
  DCHECK(is_enterprise_function_);
}
ClientFilterableState::~ClientFilterableState() = default;

bool ClientFilterableState::IsEnterprise() const {
  if (!is_enterprise_.has_value()) {
    is_enterprise_ = std::move(is_enterprise_function_).Run();
  }
  return is_enterprise_.value();
}

base::flat_set<uint64_t> ClientFilterableState::GoogleGroups() const {
  if (!google_groups_.has_value()) {
    google_groups_ = std::move(google_groups_function_).Run();
  }
  return google_groups_.value();
}

// static
Study::Platform ClientFilterableState::GetCurrentPlatform() {
#if BUILDFLAG(IS_WIN)
  return Study::PLATFORM_WINDOWS;
#elif BUILDFLAG(IS_IOS)
  return Study::PLATFORM_IOS;
#elif BUILDFLAG(IS_MAC)
  return Study::PLATFORM_MAC;
#elif BUILDFLAG(IS_CHROMEOS)
  return Study::PLATFORM_CHROMEOS;
#elif BUILDFLAG(IS_ANDROID)
  return Study::PLATFORM_ANDROID;
#elif BUILDFLAG(IS_FUCHSIA)
  return Study::PLATFORM_FUCHSIA;
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) || BUILDFLAG(IS_SOLARIS)
  // Default BSD and SOLARIS to Linux to not break those builds, although these
  // platforms are not officially supported by Chrome.
  return Study::PLATFORM_LINUX;
#else
#error Unknown platform
#endif
}

// static
base::Version ClientFilterableState::GetOSVersion() {
  base::Version ret;

#if BUILDFLAG(IS_WIN)
  std::string win_version = base::SysInfo::OperatingSystemVersion();
  base::ReplaceSubstringsAfterOffset(&win_version, 0, " SP", ".");
  ret = base::Version(win_version);
  DCHECK(ret.IsValid()) << win_version;
#else
  // Every other OS is supported by OperatingSystemVersionNumbers
  int major, minor, build;
  base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &build);
  ret = base::Version(base::StringPrintf("%d.%d.%d", major, minor, build));
  DCHECK(ret.IsValid());
#endif

  return ret;
}

std::string ClientFilterableState::GetHardwareClass() {
  // TODO(crbug.com/40708998): Expand to other platforms.
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
  return base::SysInfo::HardwareModelName();
#else
  return "";
#endif
}

}  // namespace variations