File: request_handler_base.h

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 (93 lines) | stat: -rw-r--r-- 3,781 bytes parent folder | download | duplicates (6)
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
// Copyright 2022 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_REQUEST_HANDLER_BASE_H_
#define CHROME_BROWSER_ENTERPRISE_CONNECTORS_ANALYSIS_REQUEST_HANDLER_BASE_H_

#include <string>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_info.h"
#include "chrome/browser/enterprise/connectors/common.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/binary_upload_service.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
#include "components/enterprise/common/proto/connectors.pb.h"

namespace enterprise_connectors {

// Abstract base class for handling the scanning and reporting of deep scanning
// requests.
// Scanning should be started using `UploadData()`. `ReportWarningBypass()` is
// only allowed to be called once scanning is complete.
// The typical flow is:
// 1. Create instance of a child class of RequestHandlerBase.
// 2. Call UploadData().
// 3. Wait for the upload to be completed.
// 4. Potentially call ReportWarningBypass() if a bypass of a warning should be
// reported.
class RequestHandlerBase {
 public:
  RequestHandlerBase(ContentAnalysisInfo* content_analysis_info,
                     safe_browsing::BinaryUploadService* upload_service,
                     Profile* profile,
                     GURL url,
                     safe_browsing::DeepScanAccessPoint access_point);

  virtual ~RequestHandlerBase();

  // Uploads data for deep scanning. Returns true if uploading is occurring in
  // the background and false if there is nothing to do.
  bool UploadData();

  // Moves the tokens-actions mapping of all file requests being handled to the
  // given map.
  void AppendFinalActionsTo(
      std::map<std::string, ContentAnalysisAcknowledgement::FinalAction>*
          final_actions);

  // This method is called after a user has bypassed a scanning warning and is
  // expected to send one or more reports corresponding to the data that was
  // allowed to be transferred by the user.
  virtual void ReportWarningBypass(
      std::optional<std::u16string> user_justification) = 0;

  // After all file requests have been processed, this call can be used to
  // retrieve any final actions stored internally.  There should one for
  // each successful request.
  const std::map<std::string, ContentAnalysisAcknowledgement::FinalAction>&
  request_tokens_to_ack_final_actions() const {
    return request_tokens_to_ack_final_actions_;
  }

 private:
  // Uploads the actual requests. To be implemented by child classes.
  // Returns true if uploading is occurring in the background and false if there
  // is nothing to do. This function is called by UploadData().
  virtual bool UploadDataImpl() = 0;

 protected:
  // Returns the BinaryUploadService used to upload content for deep scanning.
  safe_browsing::BinaryUploadService* GetBinaryUploadService();

  raw_ptr<ContentAnalysisInfo> content_analysis_info_ = nullptr;
  base::WeakPtr<safe_browsing::BinaryUploadService> upload_service_ = nullptr;
  raw_ptr<Profile> profile_ = nullptr;
  GURL url_;
  safe_browsing::DeepScanAccessPoint access_point_;

  // A mapping of request tokens (corresponding to one user action) to their Ack
  // final action.
  std::map<std::string, ContentAnalysisAcknowledgement::FinalAction>
      request_tokens_to_ack_final_actions_;

  base::TimeTicks upload_start_time_;
};

}  // namespace enterprise_connectors

#endif  // CHROME_BROWSER_ENTERPRISE_CONNECTORS_ANALYSIS_REQUEST_HANDLER_BASE_H_