File: profile_signals_collector.cc

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 (113 lines) | stat: -rw-r--r-- 4,733 bytes parent folder | download | duplicates (3)
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
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/enterprise/signals/profile_signals_collector.h"

#include <utility>

#include "base/check.h"
#include "base/functional/bind.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/enterprise/identifiers/profile_id_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/device_signals/core/browser/browser_utils.h"
#include "components/device_signals/core/browser/signals_types.h"
#include "components/device_signals/core/browser/user_permission_service.h"
#include "components/device_signals/core/common/platform_utils.h"
#include "components/enterprise/browser/identifiers/profile_id_service.h"
#include "components/enterprise/buildflags/buildflags.h"
#include "components/policy/content/policy_blocklist_service.h"
#include "components/policy/core/common/cloud/cloud_policy_manager.h"
#include "components/prefs/pref_service.h"
#include "components/version_info/version_info.h"

#if BUILDFLAG(ENTERPRISE_CLOUD_CONTENT_ANALYSIS)
#include "chrome/browser/enterprise/connectors/connectors_service.h"
#endif

namespace device_signals {

namespace {

bool GetBuiltInDnsClientEnabled(PrefService* local_state) {
  DCHECK(local_state);
  return local_state->GetBoolean(prefs::kBuiltInDnsClientEnabled);
}

}  // namespace

ProfileSignalsCollector::ProfileSignalsCollector(Profile* profile)
    : BaseSignalsCollector({
          {SignalName::kBrowserContextSignals,
           base::BindRepeating(&ProfileSignalsCollector::GetProfileSignals,
                               base::Unretained(this))},
      }),
      policy_blocklist_service_(
          PolicyBlocklistFactory::GetForBrowserContext(profile)),
      profile_prefs_(profile->GetPrefs()),
      policy_manager_(profile->GetCloudPolicyManager()),
      connectors_service_(
          enterprise_connectors::ConnectorsServiceFactory::GetForBrowserContext(
              profile)),
      profile_id_service_(
          enterprise::ProfileIdServiceFactory::GetForProfile(profile)) {
#if BUILDFLAG(ENTERPRISE_CLOUD_CONTENT_ANALYSIS)
  CHECK(connectors_service_);
#endif  // BUILDFLAG(ENTERPRISE_CLOUD_CONTENT_ANALYSIS)
  CHECK(policy_blocklist_service_);
  CHECK(profile_id_service_);
}

ProfileSignalsCollector::~ProfileSignalsCollector() = default;

void ProfileSignalsCollector::GetProfileSignals(
    UserPermission permission,
    const SignalsAggregationRequest& request,
    SignalsAggregationResponse& response,
    base::OnceClosure done_closure) {
  ProfileSignalsResponse signal_response;
  signal_response.built_in_dns_client_enabled =
      GetBuiltInDnsClientEnabled(g_browser_process->local_state());
  signal_response.chrome_remote_desktop_app_blocked =
      device_signals::GetChromeRemoteDesktopAppBlocked(
          policy_blocklist_service_);
  signal_response.password_protection_warning_trigger =
      device_signals::GetPasswordProtectionWarningTrigger(profile_prefs_);
  signal_response.profile_enrollment_domain =
      device_signals::TryGetEnrollmentDomain(policy_manager_);
  signal_response.safe_browsing_protection_level =
      device_signals::GetSafeBrowsingProtectionLevel(profile_prefs_);
  signal_response.site_isolation_enabled =
      device_signals::GetSiteIsolationEnabled();
  signal_response.profile_id = profile_id_service_->GetProfileId();

#if BUILDFLAG(ENTERPRISE_CLOUD_CONTENT_ANALYSIS)
  signal_response.realtime_url_check_mode =
      connectors_service_->GetAppliedRealTimeUrlCheck();
  signal_response.file_downloaded_providers =
      connectors_service_->GetAnalysisServiceProviderNames(
          enterprise_connectors::FILE_DOWNLOADED);
  signal_response.file_attached_providers =
      connectors_service_->GetAnalysisServiceProviderNames(
          enterprise_connectors::FILE_ATTACHED);
  signal_response.bulk_data_entry_providers =
      connectors_service_->GetAnalysisServiceProviderNames(
          enterprise_connectors::BULK_DATA_ENTRY);
  signal_response.print_providers =
      connectors_service_->GetAnalysisServiceProviderNames(
          enterprise_connectors::PRINT);
  signal_response.security_event_providers =
      connectors_service_->GetReportingServiceProviderNames();
#endif  // BUILDFLAG(ENTERPRISE_CLOUD_CONTENT_ANALYSIS)

  response.profile_signals_response = std::move(signal_response);

  // All signals are fetched synchronously for now, so we can run the closure
  // immediately. Once async signals are added, `done_closure` should be moved
  // to be run in the callback.
  std::move(done_closure).Run();
}

}  // namespace device_signals