[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // 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 Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 7 | #include "base/metrics/histogram_functions.h" |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 8 | #include "base/strings/stringprintf.h" |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 9 | #include "chrome/browser/browser_process.h" |
Micah Morton | 5675f90 | 2017-08-16 22:35:19 | [diff] [blame] | 10 | #include "chrome/browser/safe_browsing/download_protection/download_protection_service.h" |
Xinghui Lu | 2db98ab | 2021-07-12 23:26:43 | [diff] [blame] | 11 | #include "chrome/browser/safe_browsing/download_protection/download_protection_util.h" |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 12 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 13 | #include "components/download/public/common/download_danger_type.h" |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 14 | #include "components/download/public/common/download_item.h" |
Colin Blundell | 641e4e4 | 2021-06-24 16:09:53 | [diff] [blame] | 15 | #include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h" |
Colin Blundell | 6c4f3fd | 2021-07-01 15:28:33 | [diff] [blame] | 16 | #include "components/safe_browsing/content/common/file_type_policies.h" |
Xinghui Lu | 2db98ab | 2021-07-12 23:26:43 | [diff] [blame] | 17 | #include "components/safe_browsing/core/common/proto/csd.pb.h" |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 18 | #include "content/public/browser/browser_task_traits.h" |
| 19 | #include "content/public/browser/browser_thread.h" |
Daniel Rubery | dd3f5a49 | 2020-08-18 19:20:35 | [diff] [blame] | 20 | #include "content/public/browser/download_item_utils.h" |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 21 | |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 22 | using safe_browsing::ClientDownloadResponse; |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 23 | using safe_browsing::ClientSafeBrowsingReportRequest; |
[email protected] | f85a34b | 2014-08-16 01:10:16 | [diff] [blame] | 24 | |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 25 | namespace { |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 26 | const char kDownloadDangerPromptPrefix[] = "Download.DownloadDangerPrompt"; |
[email protected] | cce1bad6 | 2013-01-04 02:26:38 | [diff] [blame] | 27 | } // namespace |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 28 | |
jialiul | 2c263858 | 2016-06-08 22:18:08 | [diff] [blame] | 29 | void DownloadDangerPrompt::SendSafeBrowsingDownloadReport( |
| 30 | ClientSafeBrowsingReportRequest::ReportType report_type, |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 31 | bool did_proceed, |
Xinghui Lu | 4274b60 | 2022-09-08 03:06:02 | [diff] [blame^] | 32 | download::DownloadItem* download) { |
Xinghui Lu | 2db98ab | 2021-07-12 23:26:43 | [diff] [blame] | 33 | ClientDownloadResponse::Verdict download_verdict = |
| 34 | safe_browsing::DownloadDangerTypeToDownloadResponseVerdict( |
Xinghui Lu | 4274b60 | 2022-09-08 03:06:02 | [diff] [blame^] | 35 | download->GetDangerType()); |
Xinghui Lu | 2db98ab | 2021-07-12 23:26:43 | [diff] [blame] | 36 | if (download_verdict == ClientDownloadResponse::SAFE) { |
| 37 | // Don't send report if the verdict is SAFE. |
| 38 | return; |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 39 | } |
Xinghui Lu | 4274b60 | 2022-09-08 03:06:02 | [diff] [blame^] | 40 | g_browser_process->safe_browsing_service()->SendDownloadReport( |
| 41 | download, report_type, did_proceed, |
| 42 | /*show_download_in_folder=*/absl::nullopt); |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 43 | } |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 44 | |
| 45 | void DownloadDangerPrompt::RecordDownloadDangerPrompt( |
| 46 | bool did_proceed, |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 47 | const download::DownloadItem& download) { |
nparker | ac9da06 | 2016-05-19 21:47:23 | [diff] [blame] | 48 | int64_t file_type_uma_value = |
| 49 | safe_browsing::FileTypePolicies::GetInstance()->UmaValueForFile( |
| 50 | download.GetTargetFilePath()); |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 51 | download::DownloadDangerType danger_type = download.GetDangerType(); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 52 | |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 53 | base::UmaHistogramSparse( |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 54 | base::StringPrintf("%s.%s.Shown", kDownloadDangerPromptPrefix, |
Rohit Bhatia | 6674a8f8a | 2022-04-26 01:58:59 | [diff] [blame] | 55 | download::GetDownloadDangerTypeString(danger_type)), |
nparker | ac9da06 | 2016-05-19 21:47:23 | [diff] [blame] | 56 | file_type_uma_value); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 57 | if (did_proceed) { |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 58 | base::UmaHistogramSparse( |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 59 | base::StringPrintf("%s.%s.Proceed", kDownloadDangerPromptPrefix, |
Rohit Bhatia | 6674a8f8a | 2022-04-26 01:58:59 | [diff] [blame] | 60 | download::GetDownloadDangerTypeString(danger_type)), |
nparker | ac9da06 | 2016-05-19 21:47:23 | [diff] [blame] | 61 | file_type_uma_value); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 62 | } |
| 63 | } |