File: check_client_download_request.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 (124 lines) | stat: -rw-r--r-- 5,302 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// 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.

#ifndef CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_CHECK_CLIENT_DOWNLOAD_REQUEST_H_
#define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_CHECK_CLIENT_DOWNLOAD_REQUEST_H_

#include <stdint.h>

#include <string>
#include <vector>

#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/time/time.h"
#include "build/build_config.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/download_protection/check_client_download_request_base.h"
#include "chrome/browser/safe_browsing/download_protection/download_protection_util.h"
#include "components/download/public/common/download_item.h"
#include "components/safe_browsing/core/browser/download_check_result.h"
#include "content/public/browser/browser_thread.h"

class Profile;

namespace safe_browsing {

class CheckClientDownloadRequest : public CheckClientDownloadRequestBase,
                                   public download::DownloadItem::Observer {
 public:
  CheckClientDownloadRequest(
      download::DownloadItem* item,
      CheckDownloadRepeatingCallback callback,
      DownloadProtectionService* service,
      scoped_refptr<SafeBrowsingDatabaseManager> database_manager,
      scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor,
      base::optional_ref<const std::string> password = std::nullopt);

  CheckClientDownloadRequest(const CheckClientDownloadRequest&) = delete;
  CheckClientDownloadRequest& operator=(const CheckClientDownloadRequest&) =
      delete;

  ~CheckClientDownloadRequest() override;

  // download::DownloadItem::Observer:
  void OnDownloadDestroyed(download::DownloadItem* download) override;
  void OnDownloadUpdated(download::DownloadItem* download) override;

  // Returns enum value indicating whether `item` is eligible for
  // CheckClientDownloadRequest. If return value is not kMayCheckDownload, then
  // `reason` will be populated with the reason why.
  // Note: Behavior is platform-specific.
  // TODO(chlily): Rename this method since it does not return a bool.
  static MayCheckDownloadResult IsSupportedDownload(
      const download::DownloadItem& item,
      const base::FilePath& file_name,
      DownloadCheckResultReason* reason);

  download::DownloadItem* item() const override;

 private:
  // CheckClientDownloadRequestBase overrides:
  MayCheckDownloadResult IsSupportedDownload(
      DownloadCheckResultReason* reason) override;
  content::BrowserContext* GetBrowserContext() const override;
  bool IsCancelled() override;
  base::WeakPtr<CheckClientDownloadRequestBase> GetWeakPtr() override;

  void NotifySendRequest(const ClientDownloadRequest* request) override;
  void SetDownloadProtectionData(
      const std::string& token,
      const ClientDownloadResponse::Verdict& verdict,
      const ClientDownloadResponse::TailoredVerdict& tailored_verdict) override;
#if !BUILDFLAG(IS_ANDROID)
  void MaybeBeginFeedbackForDownload(DownloadCheckResult result,
                                     bool upload_requested,
                                     const std::string& request_data,
                                     const std::string& response_body) override;
#endif
  bool ShouldImmediatelyDeepScan(bool server_requests_prompt) const override;
  bool ShouldPromptForDeepScanning(bool server_requests_prompt) const override;
  bool ShouldPromptForLocalDecryption(
      bool server_requests_prompt) const override;
  bool ShouldPromptForIncorrectPassword() const override;
  bool ShouldShowScanFailure() const override;
  void LogDeepScanningPrompt(bool did_prompt) const override;

  // Uploads the binary for deep scanning if the reason and policies indicate
  // it should be. ShouldUploadBinary will returns the settings to apply for
  // deep scanning if it should occur, or std::nullopt if no scan should be
  // done.
  std::optional<enterprise_connectors::AnalysisSettings> ShouldUploadBinary(
      DownloadCheckResultReason reason) override;
  void UploadBinary(DownloadCheckResult result,
                    DownloadCheckResultReason reason,
                    enterprise_connectors::AnalysisSettings settings) override;

  // Called when this request is completed.
  void NotifyRequestFinished(DownloadCheckResult result,
                             DownloadCheckResultReason reason) override;


  bool IsAllowlistedByPolicy() const override;

  bool IsUnderAdvancedProtection(Profile* profile) const;

  // The DownloadItem we are checking. Will be NULL if the request has been
  // canceled. Must be accessed only on UI thread.
  raw_ptr<download::DownloadItem> item_;
  std::optional<std::string> password_;
  CheckDownloadRepeatingCallback callback_;

  // Upload start time used for UMA duration histograms.
  base::TimeTicks upload_start_time_;

  base::WeakPtrFactory<CheckClientDownloadRequest> weakptr_factory_{this};
};

}  // namespace safe_browsing

#endif  // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_CHECK_CLIENT_DOWNLOAD_REQUEST_H_