Chromium Code Reviews| Index: chrome/browser/download/download_danger_prompt.cc |
| diff --git a/chrome/browser/download/download_danger_prompt.cc b/chrome/browser/download/download_danger_prompt.cc |
| index f581e42b6408ba8d18ccab4cf71b672b937b6a56..5091454dcd50fd4271e0b6465c5eea0204ef01d3 100644 |
| --- a/chrome/browser/download/download_danger_prompt.cc |
| +++ b/chrome/browser/download/download_danger_prompt.cc |
| @@ -6,19 +6,25 @@ |
| #include "base/bind.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| #include "chrome/browser/download/download_stats.h" |
| #include "chrome/browser/extensions/api/experience_sampling_private/experience_sampling.h" |
| +#include "chrome/browser/safe_browsing/ping_manager.h" |
| +#include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
| #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
| +#include "chrome/common/safe_browsing/csd.pb.h" |
| #include "chrome/grit/chromium_strings.h" |
| #include "chrome/grit/generated_resources.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/download_danger_type.h" |
| #include "content/public/browser/download_item.h" |
| #include "ui/base/l10n/l10n_util.h" |
| using extensions::ExperienceSamplingEvent; |
| +using safe_browsing::ClientSafeBrowsingReportRequest; |
| namespace { |
| @@ -38,7 +44,7 @@ class DownloadDangerPromptImpl : public DownloadDangerPrompt, |
| ~DownloadDangerPromptImpl() override; |
| // DownloadDangerPrompt: |
| - void InvokeActionForTesting(Action action) override; |
| + std::string InvokeActionForTesting(Action action, const GURL& url) override; |
| private: |
| // content::DownloadItem::Observer: |
| @@ -92,7 +98,8 @@ DownloadDangerPromptImpl::~DownloadDangerPromptImpl() { |
| RunDone(DISMISS); |
| } |
| -void DownloadDangerPromptImpl::InvokeActionForTesting(Action action) { |
| +std::string DownloadDangerPromptImpl::InvokeActionForTesting(Action action, |
| + const GURL& url) { |
| switch (action) { |
| case ACCEPT: Accept(); break; |
| case CANCEL: Cancel(); break; |
| @@ -101,6 +108,7 @@ void DownloadDangerPromptImpl::InvokeActionForTesting(Action action) { |
| Cancel(); |
| break; |
| } |
| + return CreateSafeBrowsingDownloadRecoveryReport(action == ACCEPT, url); |
| } |
| void DownloadDangerPromptImpl::OnDownloadUpdated( |
| @@ -240,6 +248,12 @@ void DownloadDangerPromptImpl::RunDone(Action action) { |
| OnDone done = done_; |
| done_.Reset(); |
| if (download_ != NULL) { |
| + if (!download_->GetURL().is_empty()) { |
| + std::string report = CreateSafeBrowsingDownloadRecoveryReport( |
| + action == DownloadDangerPrompt::ACCEPT, download_->GetURL()); |
| + if (!report.empty()) |
| + SendSerializedReport(report); |
| + } |
| download_->RemoveObserver(this); |
| download_ = NULL; |
| } |
| @@ -263,3 +277,29 @@ DownloadDangerPrompt* DownloadDangerPrompt::Create( |
| return prompt; |
| } |
| #endif |
| + |
| +std::string DownloadDangerPrompt::CreateSafeBrowsingDownloadRecoveryReport( |
| + bool did_proceed, |
| + const GURL& url) { |
| + ClientSafeBrowsingReportRequest report; |
| + report.set_type(ClientSafeBrowsingReportRequest::MALICIOUS_DOWNLOAD_RECOVERY); |
| + report.set_url(url.spec()); |
| + report.set_did_proceed(did_proceed); |
| + |
| + std::string serialized_report; |
| + if (!report.SerializeToString(&serialized_report)) { |
| + DLOG(ERROR) << "Unable to serialize the threat report."; |
| + return ""; |
|
msw
2015/11/17 01:17:37
nit: return std::string()
Jialiu Lin
2015/11/17 02:05:50
Done.
|
| + } |
| + |
| + return serialized_report; |
| +} |
| + |
| +void DownloadDangerPrompt::SendSerializedReport( |
| + const std::string& serialized_report) { |
| + safe_browsing::SafeBrowsingService* sb_service = |
| + g_browser_process->safe_browsing_service(); |
| + if (sb_service) { |
|
msw
2015/11/17 01:17:37
nit: curlies not needed
Jialiu Lin
2015/11/17 02:05:50
Done.
|
| + sb_service->SendDownloadRecoveryReport(serialized_report); |
| + } |
| +} |