| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/download/download_danger_prompt.h" | 5 #include "chrome/browser/download/download_danger_prompt.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/metrics/sparse_histogram.h" | 8 #include "base/metrics/sparse_histogram.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 11 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 12 #include "chrome/common/safe_browsing/csd.pb.h" | |
| 13 #include "chrome/common/safe_browsing/file_type_policies.h" | 12 #include "chrome/common/safe_browsing/file_type_policies.h" |
| 14 #include "content/public/browser/download_danger_type.h" | 13 #include "content/public/browser/download_danger_type.h" |
| 15 #include "content/public/browser/download_item.h" | 14 #include "content/public/browser/download_item.h" |
| 16 | 15 |
| 17 using safe_browsing::ClientDownloadResponse; | 16 using safe_browsing::ClientDownloadResponse; |
| 18 using safe_browsing::ClientSafeBrowsingReportRequest; | 17 using safe_browsing::ClientSafeBrowsingReportRequest; |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 const char kDownloadDangerPromptPrefix[] = "Download.DownloadDangerPrompt"; | 21 const char kDownloadDangerPromptPrefix[] = "Download.DownloadDangerPrompt"; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 42 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: | 41 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: |
| 43 case content::DOWNLOAD_DANGER_TYPE_MAX: | 42 case content::DOWNLOAD_DANGER_TYPE_MAX: |
| 44 break; | 43 break; |
| 45 } | 44 } |
| 46 NOTREACHED(); | 45 NOTREACHED(); |
| 47 return nullptr; | 46 return nullptr; |
| 48 } | 47 } |
| 49 | 48 |
| 50 } // namespace | 49 } // namespace |
| 51 | 50 |
| 52 void DownloadDangerPrompt::SendSafeBrowsingDownloadRecoveryReport( | 51 void DownloadDangerPrompt::SendSafeBrowsingDownloadReport( |
| 52 ClientSafeBrowsingReportRequest::ReportType report_type, |
| 53 bool did_proceed, | 53 bool did_proceed, |
| 54 const content::DownloadItem& download) { | 54 const content::DownloadItem& download) { |
| 55 safe_browsing::SafeBrowsingService* sb_service = | 55 safe_browsing::SafeBrowsingService* sb_service = |
| 56 g_browser_process->safe_browsing_service(); | 56 g_browser_process->safe_browsing_service(); |
| 57 ClientSafeBrowsingReportRequest report; | 57 ClientSafeBrowsingReportRequest report; |
| 58 report.set_type(ClientSafeBrowsingReportRequest::DANGEROUS_DOWNLOAD_RECOVERY); | 58 report.set_type(report_type); |
| 59 switch (download.GetDangerType()) { | 59 switch (download.GetDangerType()) { |
| 60 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | 60 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
| 61 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 61 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
| 62 report.set_download_verdict(ClientDownloadResponse::DANGEROUS); | 62 report.set_download_verdict(ClientDownloadResponse::DANGEROUS); |
| 63 break; | 63 break; |
| 64 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: | 64 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
| 65 report.set_download_verdict(ClientDownloadResponse::UNCOMMON); | 65 report.set_download_verdict(ClientDownloadResponse::UNCOMMON); |
| 66 break; | 66 break; |
| 67 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: | 67 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: |
| 68 report.set_download_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); | 68 report.set_download_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); |
| 69 break; | 69 break; |
| 70 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: | 70 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
| 71 report.set_download_verdict(ClientDownloadResponse::DANGEROUS_HOST); | 71 report.set_download_verdict(ClientDownloadResponse::DANGEROUS_HOST); |
| 72 break; | 72 break; |
| 73 default: // Don't send report for any other danger types. | 73 default: // Don't send report for any other danger types. |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 report.set_url(download.GetURL().spec()); | 76 report.set_url(download.GetURL().spec()); |
| 77 report.set_did_proceed(did_proceed); | 77 report.set_did_proceed(did_proceed); |
| 78 std::string token = download.GetDownloadPingToken(); |
| 79 if (!token.empty()) |
| 80 report.set_token(token); |
| 78 | 81 |
| 79 std::string serialized_report; | 82 std::string serialized_report; |
| 80 if (report.SerializeToString(&serialized_report)) | 83 if (report.SerializeToString(&serialized_report)) |
| 81 sb_service->SendSerializedDownloadReport(serialized_report); | 84 sb_service->SendSerializedDownloadReport(serialized_report); |
| 82 else | 85 else |
| 83 DLOG(ERROR) << "Unable to serialize the threat report."; | 86 DLOG(ERROR) << "Unable to serialize the threat report."; |
| 84 } | 87 } |
| 85 | 88 |
| 86 void DownloadDangerPrompt::RecordDownloadDangerPrompt( | 89 void DownloadDangerPrompt::RecordDownloadDangerPrompt( |
| 87 bool did_proceed, | 90 bool did_proceed, |
| 88 const content::DownloadItem& download) { | 91 const content::DownloadItem& download) { |
| 89 int64_t file_type_uma_value = | 92 int64_t file_type_uma_value = |
| 90 safe_browsing::FileTypePolicies::GetInstance()->UmaValueForFile( | 93 safe_browsing::FileTypePolicies::GetInstance()->UmaValueForFile( |
| 91 download.GetTargetFilePath()); | 94 download.GetTargetFilePath()); |
| 92 content::DownloadDangerType danger_type = download.GetDangerType(); | 95 content::DownloadDangerType danger_type = download.GetDangerType(); |
| 93 | 96 |
| 94 UMA_HISTOGRAM_SPARSE_SLOWLY( | 97 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 95 base::StringPrintf("%s.%s.Shown", kDownloadDangerPromptPrefix, | 98 base::StringPrintf("%s.%s.Shown", kDownloadDangerPromptPrefix, |
| 96 GetDangerTypeString(danger_type)), | 99 GetDangerTypeString(danger_type)), |
| 97 file_type_uma_value); | 100 file_type_uma_value); |
| 98 if (did_proceed) { | 101 if (did_proceed) { |
| 99 UMA_HISTOGRAM_SPARSE_SLOWLY( | 102 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 100 base::StringPrintf("%s.%s.Proceed", kDownloadDangerPromptPrefix, | 103 base::StringPrintf("%s.%s.Proceed", kDownloadDangerPromptPrefix, |
| 101 GetDangerTypeString(danger_type)), | 104 GetDangerTypeString(danger_type)), |
| 102 file_type_uma_value); | 105 file_type_uma_value); |
| 103 } | 106 } |
| 104 } | 107 } |
| OLD | NEW |