File: content_analysis_info.h

package info (click to toggle)
chromium 139.0.7258.138-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,120,676 kB
  • sloc: cpp: 35,100,869; 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 (92 lines) | stat: -rw-r--r-- 3,877 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
// 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 CHROME_BROWSER_ENTERPRISE_CONNECTORS_ANALYSIS_CONTENT_ANALYSIS_INFO_H_
#define CHROME_BROWSER_ENTERPRISE_CONNECTORS_ANALYSIS_CONTENT_ANALYSIS_INFO_H_

#include "base/memory/raw_ptr.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/binary_upload_service.h"
#include "components/enterprise/common/proto/connectors.pb.h"
#include "components/enterprise/connectors/core/analysis_settings.h"
#include "components/safe_browsing/core/common/proto/csd.pb.h"
#include "content/public/browser/clipboard_types.h"

namespace signin {
class IdentityManager;
}  // namespace signin

namespace enterprise_connectors {

// Interface providing data about a given content analysis action. This should
// be used as an abstraction layer to access information about some content
// analysis context when the exact action that triggered is not important (ex.
// when populating protos).
class ContentAnalysisInfo {
 public:
  // The `AnalysisSettings` that should be applied to the content analysis scan.
  virtual const AnalysisSettings& settings() const = 0;

  // The `signin::IdentityManager` that corresponds to the browser context where
  // content analysis is taking place.
  virtual signin::IdentityManager* identity_manager() const = 0;

  // These methods correspond to fields in `BinaryUploadService::Request`.
  virtual int user_action_requests_count() const = 0;
  virtual std::string tab_title() const = 0;
  virtual std::string user_action_id() const = 0;
  virtual std::string email() const = 0;
  virtual std::string url() const = 0;
  virtual const GURL& tab_url() const = 0;
  virtual ContentAnalysisRequest::Reason reason() const = 0;
  virtual google::protobuf::RepeatedPtrField<
      ::safe_browsing::ReferrerChainEntry>
  referrer_chain() const = 0;
  virtual google::protobuf::RepeatedPtrField<std::string> frame_url_chain()
      const = 0;

  // Adds shared fields to `request` before sending it to the binary upload
  // service. Connector-specific fields need to be added to the request
  // separately.
  void InitializeRequest(safe_browsing::BinaryUploadService::Request* request,
                         bool include_enterprise_only_fields = true);

  // Returns email of the active Gaia user based on the values provided by
  // `tab_url()` and `identity_manager()`. Only returns a value for Workspace
  // sites.
  // TODO(crbug.com/415002299): Add tests for this.
  std::string GetContentAreaAccountEmail() const;
};

// Simple implementation of `ContentAnalysisInfo` meant to be used for
// `GetContentAreaAccountEmail` only
class ContentAreaUserProvider : public ContentAnalysisInfo {
 public:
  static std::string GetUser(Profile* profile, const GURL& tab_url);
  static std::string GetUser(const content::ClipboardEndpoint& source);

 private:
  const AnalysisSettings& settings() const override;
  signin::IdentityManager* identity_manager() const override;
  int user_action_requests_count() const override;
  std::string tab_title() const override;
  std::string user_action_id() const override;
  std::string email() const override;
  std::string url() const override;
  const GURL& tab_url() const override;
  ContentAnalysisRequest::Reason reason() const override;
  google::protobuf::RepeatedPtrField<::safe_browsing::ReferrerChainEntry>
  referrer_chain() const override;
  google::protobuf::RepeatedPtrField<std::string> frame_url_chain()
      const override;

  explicit ContentAreaUserProvider(signin::IdentityManager* im,
                                   const GURL& tab_url);

  raw_ptr<signin::IdentityManager> im_;
  raw_ref<const GURL> tab_url_;
};

}  // namespace enterprise_connectors

#endif  // CHROME_BROWSER_ENTERPRISE_CONNECTORS_ANALYSIS_CONTENT_ANALYSIS_INFO_H_