blob: b435573c813579a0f36c6b14209e4a175d68f3fd [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2012 The Chromium Authors
[email protected]33ca232f2012-04-10 00:08:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/download/download_danger_prompt.h"
6
Ilya Sherman982457e62017-12-13 02:19:367#include "base/metrics/histogram_functions.h"
jialiul70cd6f2c2016-02-02 23:24:578#include "base/strings/stringprintf.h"
jialiul7f11b742015-11-26 04:54:499#include "chrome/browser/browser_process.h"
Micah Morton5675f902017-08-16 22:35:1910#include "chrome/browser/safe_browsing/download_protection/download_protection_service.h"
Xinghui Lu2db98ab2021-07-12 23:26:4311#include "chrome/browser/safe_browsing/download_protection/download_protection_util.h"
jialiul7f11b742015-11-26 04:54:4912#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Min Qin0ca8e1ee2018-01-31 00:49:3513#include "components/download/public/common/download_danger_type.h"
Min Qina9f487872018-02-09 20:43:2314#include "components/download/public/common/download_item.h"
Colin Blundell641e4e42021-06-24 16:09:5315#include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h"
Colin Blundell6c4f3fd2021-07-01 15:28:3316#include "components/safe_browsing/content/common/file_type_policies.h"
Xinghui Lu2db98ab2021-07-12 23:26:4317#include "components/safe_browsing/core/common/proto/csd.pb.h"
Xinghui Lu09e84f582021-05-11 19:18:2918#include "content/public/browser/browser_task_traits.h"
19#include "content/public/browser/browser_thread.h"
Daniel Ruberydd3f5a492020-08-18 19:20:3520#include "content/public/browser/download_item_utils.h"
[email protected]33ca232f2012-04-10 00:08:4521
jialiulee910ec12016-01-11 19:42:4622using safe_browsing::ClientDownloadResponse;
jialiul7f11b742015-11-26 04:54:4923using safe_browsing::ClientSafeBrowsingReportRequest;
[email protected]f85a34b2014-08-16 01:10:1624
[email protected]33ca232f2012-04-10 00:08:4525namespace {
jialiul70cd6f2c2016-02-02 23:24:5726const char kDownloadDangerPromptPrefix[] = "Download.DownloadDangerPrompt";
[email protected]cce1bad62013-01-04 02:26:3827} // namespace
[email protected]33ca232f2012-04-10 00:08:4528
jialiul2c2638582016-06-08 22:18:0829void DownloadDangerPrompt::SendSafeBrowsingDownloadReport(
30 ClientSafeBrowsingReportRequest::ReportType report_type,
jialiul7f11b742015-11-26 04:54:4931 bool did_proceed,
Xinghui Lu4274b602022-09-08 03:06:0232 download::DownloadItem* download) {
Xinghui Lu2db98ab2021-07-12 23:26:4333 ClientDownloadResponse::Verdict download_verdict =
Xinghui Lue3e8da02022-09-10 07:46:0334 safe_browsing::DownloadProtectionService::GetDownloadProtectionVerdict(
35 download);
Xinghui Lu2db98ab2021-07-12 23:26:4336 if (download_verdict == ClientDownloadResponse::SAFE) {
37 // Don't send report if the verdict is SAFE.
38 return;
jialiulee910ec12016-01-11 19:42:4639 }
Xinghui Lu4274b602022-09-08 03:06:0240 g_browser_process->safe_browsing_service()->SendDownloadReport(
41 download, report_type, did_proceed,
42 /*show_download_in_folder=*/absl::nullopt);
jialiul7f11b742015-11-26 04:54:4943}
jialiul70cd6f2c2016-02-02 23:24:5744
45void DownloadDangerPrompt::RecordDownloadDangerPrompt(
46 bool did_proceed,
Min Qina9f487872018-02-09 20:43:2347 const download::DownloadItem& download) {
nparkerac9da062016-05-19 21:47:2348 int64_t file_type_uma_value =
49 safe_browsing::FileTypePolicies::GetInstance()->UmaValueForFile(
50 download.GetTargetFilePath());
Min Qin0ca8e1ee2018-01-31 00:49:3551 download::DownloadDangerType danger_type = download.GetDangerType();
jialiul70cd6f2c2016-02-02 23:24:5752
Ilya Sherman982457e62017-12-13 02:19:3653 base::UmaHistogramSparse(
jialiul70cd6f2c2016-02-02 23:24:5754 base::StringPrintf("%s.%s.Shown", kDownloadDangerPromptPrefix,
Rohit Bhatia6674a8f8a2022-04-26 01:58:5955 download::GetDownloadDangerTypeString(danger_type)),
nparkerac9da062016-05-19 21:47:2356 file_type_uma_value);
jialiul70cd6f2c2016-02-02 23:24:5757 if (did_proceed) {
Ilya Sherman982457e62017-12-13 02:19:3658 base::UmaHistogramSparse(
jialiul70cd6f2c2016-02-02 23:24:5759 base::StringPrintf("%s.%s.Proceed", kDownloadDangerPromptPrefix,
Rohit Bhatia6674a8f8a2022-04-26 01:58:5960 download::GetDownloadDangerTypeString(danger_type)),
nparkerac9da062016-05-19 21:47:2361 file_type_uma_value);
jialiul70cd6f2c2016-02-02 23:24:5762 }
63}