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