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
|
// 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/safe_browsing/download_protection/deep_scanning_metadata.h"
namespace safe_browsing {
DeepScanningMetadata::DownloadScopedObservation::DownloadScopedObservation(
DeepScanningMetadata* metadata,
download::DownloadItem::Observer* observer)
: metadata_(metadata) {
observation_ = std::make_unique<base::ScopedObservation<
download::DownloadItem, download::DownloadItem::Observer>>(observer);
}
DeepScanningMetadata::DownloadScopedObservation::~DownloadScopedObservation() {
// Remove observation from the list of observers.
if (observation_ && metadata_) {
metadata_->RemoveObservation(observation_->GetObserver());
}
}
void DeepScanningMetadata::DownloadScopedObservation::Stop() {
// Stop observing the `DownloadItem`.
if (observation_ && observation_->IsObserving()) {
observation_->Reset();
}
}
void DeepScanningMetadata::DownloadScopedObservation::Observe(
download::DownloadItem* source) {
if (observation_) {
observation_->Observe(source);
}
}
DownloadCheckResult DeepScanningMetadata::MaybeOverrideScanResult(
DownloadCheckResultReason reason,
DownloadCheckResult deep_scan_result) {
DownloadCheckResult result = deep_scan_result;
switch (deep_scan_result) {
// These results are more dangerous or equivalent to any |reason|, so they
// take precedence.
case DownloadCheckResult::DANGEROUS_HOST:
case DownloadCheckResult::DANGEROUS:
case DownloadCheckResult::DANGEROUS_ACCOUNT_COMPROMISE:
break;
// These deep scanning results don't override any dangerous reasons.
case DownloadCheckResult::UNKNOWN:
case DownloadCheckResult::SENSITIVE_CONTENT_WARNING:
case DownloadCheckResult::DEEP_SCANNED_SAFE:
case DownloadCheckResult::DEEP_SCANNED_FAILED:
case DownloadCheckResult::SAFE:
case DownloadCheckResult::PROMPT_FOR_SCANNING:
case DownloadCheckResult::PROMPT_FOR_LOCAL_PASSWORD_SCANNING:
case DownloadCheckResult::POTENTIALLY_UNWANTED:
case DownloadCheckResult::UNCOMMON:
case DownloadCheckResult::IMMEDIATE_DEEP_SCAN:
if (reason == REASON_DOWNLOAD_DANGEROUS) {
result = DownloadCheckResult::DANGEROUS;
} else if (reason == REASON_DOWNLOAD_DANGEROUS_HOST) {
result = DownloadCheckResult::DANGEROUS_HOST;
} else if (reason == REASON_DOWNLOAD_POTENTIALLY_UNWANTED) {
result = DownloadCheckResult::POTENTIALLY_UNWANTED;
} else if (reason == REASON_DOWNLOAD_UNCOMMON) {
result = DownloadCheckResult::UNCOMMON;
} else if (reason == REASON_DOWNLOAD_DANGEROUS_ACCOUNT_COMPROMISE) {
result = DownloadCheckResult::DANGEROUS_ACCOUNT_COMPROMISE;
}
break;
// These other results have precedence over dangerous ones because they
// indicate the scan is not done, that the file is blocked for another
// reason, or that the file is allowed by policy.
case DownloadCheckResult::ASYNC_SCANNING:
case DownloadCheckResult::ASYNC_LOCAL_PASSWORD_SCANNING:
case DownloadCheckResult::BLOCKED_PASSWORD_PROTECTED:
case DownloadCheckResult::BLOCKED_TOO_LARGE:
case DownloadCheckResult::SENSITIVE_CONTENT_BLOCK:
case DownloadCheckResult::ALLOWLISTED_BY_POLICY:
case DownloadCheckResult::BLOCKED_SCAN_FAILED:
break;
}
return result;
}
} // namespace safe_browsing
|