File: reporting_utils.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 (117 lines) | stat: -rw-r--r-- 4,838 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
114
115
116
117
// 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.

#ifndef COMPONENTS_ENTERPRISE_CONNECTORS_CORE_REPORTING_UTILS_H_
#define COMPONENTS_ENTERPRISE_CONNECTORS_CORE_REPORTING_UTILS_H_

#include "components/enterprise/common/proto/synced/browser_events.pb.h"
#include "components/enterprise/connectors/core/common.h"
#include "components/safe_browsing/core/common/proto/realtimeapi.pb.h"
#include "components/url_matcher/url_matcher.h"
#include "url/gurl.h"
#include "url/scheme_host_port.h"

namespace enterprise_connectors {

// The maximum number of referrers to include in the referrer chain.
inline constexpr int kReferrerUserGestureLimit = 5;

using ReferrerChain =
    google::protobuf::RepeatedPtrField<safe_browsing::ReferrerChainEntry>;

// Helper functions that compiles information into event protos. The
// logic is shared across platforms to ensure event consistency.
//
// Do a best-effort masking of `username`. If it's an email address (such as
// foo@example.com), everything before @ should be masked. Otherwise, the entire
// username should be masked.
std::string MaskUsername(const std::u16string& username);

// Convert base::Time to Timestamp proto.
::google3_protos::Timestamp ToProtoTimestamp(base::Time);

// Verify if the given `matcher` matches the `url`.
bool IsUrlMatched(url_matcher::URLMatcher* matcher, const GURL& url);

// Map `threat_type` to `EventResult`.
EventResult GetEventResultFromThreatType(std::string threat_type);

// Extract triggered rules from `response` and add them to the url filtering
// events.
void AddTriggeredRuleInfoToUrlFilteringInterstitialEvent(
    const safe_browsing::RTLookupResponse& response,
    base::Value::Dict& event);

// Create a URLMatcher representing the filters in
// `settings.enabled_opt_in_events` for `event_type`. This field of the
// reporting settings connector contains a map where keys are event types and
// values are lists of URL patterns specifying on which URLs the events are
// allowed to be reported. An event is generated iff its event type is present
// in the opt-in events field and the URL it relates to matches at least one of
// the event type's filters.
std::unique_ptr<url_matcher::URLMatcher> CreateURLMatcherForOptInEvent(
    const enterprise_connectors::ReportingSettings& settings,
    const char* event_type);

// PasswordBreachEvent could be empty if none of the `identities` matched a
// pattern in the URL filters.
std::optional<chrome::cros::reporting::proto::PasswordBreachEvent>
GetPasswordBreachEvent(
    const std::string& trigger,
    const std::vector<std::pair<GURL, std::u16string>>& identities,
    const enterprise_connectors::ReportingSettings& settings,
    const std::string& profile_identifier,
    const std::string& profile_username);

chrome::cros::reporting::proto::SafeBrowsingPasswordReuseEvent
GetPasswordReuseEvent(const GURL& url,
                      const std::string& user_name,
                      bool is_phishing_url,
                      bool warning_shown);

chrome::cros::reporting::proto::SafeBrowsingPasswordChangedEvent
GetPasswordChangedEvent(const std::string& user_name);

chrome::cros::reporting::proto::LoginEvent GetLoginEvent(
    const GURL& url,
    bool is_federated,
    const url::SchemeHostPort& federated_origin,
    const std::u16string& username,
    const std::string& profile_identifier,
    const std::string& profile_username);

chrome::cros::reporting::proto::SafeBrowsingInterstitialEvent
GetInterstitialEvent(const GURL& url,
                     const std::string& reason,
                     int net_error_code,
                     bool clicked_through,
                     EventResult event_result,
                     const std::string& profile_identifier,
                     const std::string& profile_username,
                     const ReferrerChain& referrer_chain);

chrome::cros::reporting::proto::UrlFilteringInterstitialEvent
GetUrlFilteringInterstitialEvent(
    const GURL& url,
    const std::string& threat_type,
    const safe_browsing::RTLookupResponse& response,
    const std::string& profile_identifier,
    const std::string& profile_username,
    const ReferrerChain& referrer_chain);

chrome::cros::reporting::proto::BrowserCrashEvent GetBrowserCrashEvent(
    const std::string& channel,
    const std::string& version,
    const std::string& report_id,
    const std::string& platform);

// Returns a list of the local IPv4 and IPv6 addresses of the device.
std::vector<std::string> GetLocalIpAddresses();

void AddReferrerChainToEvent(const ReferrerChain& referrer_chain,
                             base::Value::Dict& event);

}  // namespace enterprise_connectors

#endif  // COMPONENTS_ENTERPRISE_CONNECTORS_CORE_REPORTING_UTILS_H_