| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/metrics/sparse_histogram.h" | 9 #include "base/metrics/sparse_histogram.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 251 } |
| 252 | 252 |
| 253 void DownloadDangerPromptImpl::RunDone(Action action) { | 253 void DownloadDangerPromptImpl::RunDone(Action action) { |
| 254 // Invoking the callback can cause the download item state to change or cause | 254 // Invoking the callback can cause the download item state to change or cause |
| 255 // the constrained window to close, and |callback| refers to a member | 255 // the constrained window to close, and |callback| refers to a member |
| 256 // variable. | 256 // variable. |
| 257 OnDone done = done_; | 257 OnDone done = done_; |
| 258 done_.Reset(); | 258 done_.Reset(); |
| 259 if (download_ != NULL) { | 259 if (download_ != NULL) { |
| 260 const bool accept = action == DownloadDangerPrompt::ACCEPT; | 260 const bool accept = action == DownloadDangerPrompt::ACCEPT; |
| 261 RecordDownloadDangerPrompt(accept, *download_); | 261 if (download_->IsDangerous() && !download_->IsDone()) { |
| 262 if (!download_->GetURL().is_empty() && | 262 RecordDownloadDangerPrompt(accept, *download_); |
| 263 !download_->GetBrowserContext()->IsOffTheRecord()) { | 263 if (!download_->GetURL().is_empty() && |
| 264 SendSafeBrowsingDownloadRecoveryReport(accept, *download_); | 264 !download_->GetBrowserContext()->IsOffTheRecord()) { |
| 265 SendSafeBrowsingDownloadRecoveryReport(accept, *download_); |
| 266 } |
| 265 } | 267 } |
| 266 download_->RemoveObserver(this); | 268 download_->RemoveObserver(this); |
| 267 download_ = NULL; | 269 download_ = NULL; |
| 268 } | 270 } |
| 269 if (!done.is_null()) | 271 if (!done.is_null()) |
| 270 done.Run(action); | 272 done.Run(action); |
| 271 } | 273 } |
| 272 | 274 |
| 273 // Converts DownloadDangerType into their corresponding string. | 275 // Converts DownloadDangerType into their corresponding string. |
| 274 const char* GetDangerTypeString( | 276 const char* GetDangerTypeString( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 break; | 329 break; |
| 328 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: | 330 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
| 329 report.set_download_verdict(ClientDownloadResponse::UNCOMMON); | 331 report.set_download_verdict(ClientDownloadResponse::UNCOMMON); |
| 330 break; | 332 break; |
| 331 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: | 333 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: |
| 332 report.set_download_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); | 334 report.set_download_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); |
| 333 break; | 335 break; |
| 334 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: | 336 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
| 335 report.set_download_verdict(ClientDownloadResponse::DANGEROUS_HOST); | 337 report.set_download_verdict(ClientDownloadResponse::DANGEROUS_HOST); |
| 336 break; | 338 break; |
| 337 default: | 339 default: // Don't send report for any other danger types. |
| 338 break; | 340 return; |
| 339 } | 341 } |
| 340 report.set_url(download.GetURL().spec()); | 342 report.set_url(download.GetURL().spec()); |
| 341 report.set_did_proceed(did_proceed); | 343 report.set_did_proceed(did_proceed); |
| 342 | 344 |
| 343 std::string serialized_report; | 345 std::string serialized_report; |
| 344 if (report.SerializeToString(&serialized_report)) | 346 if (report.SerializeToString(&serialized_report)) |
| 345 sb_service->SendSerializedDownloadReport(serialized_report); | 347 sb_service->SendSerializedDownloadReport(serialized_report); |
| 346 else | 348 else |
| 347 DLOG(ERROR) << "Unable to serialize the threat report."; | 349 DLOG(ERROR) << "Unable to serialize the threat report."; |
| 348 } | 350 } |
| 349 | 351 |
| 350 void DownloadDangerPrompt::RecordDownloadDangerPrompt( | 352 void DownloadDangerPrompt::RecordDownloadDangerPrompt( |
| 351 bool did_proceed, | 353 bool did_proceed, |
| 352 const content::DownloadItem& download) { | 354 const content::DownloadItem& download) { |
| 353 int dangerous_file_type = | 355 int dangerous_file_type = |
| 354 GetSBClientDownloadExtensionValueForUMA(download.GetTargetFilePath()); | 356 GetSBClientDownloadExtensionValueForUMA(download.GetTargetFilePath()); |
| 355 content::DownloadDangerType danger_type = download.GetDangerType(); | 357 content::DownloadDangerType danger_type = download.GetDangerType(); |
| 356 | 358 |
| 357 UMA_HISTOGRAM_SPARSE_SLOWLY( | 359 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 358 base::StringPrintf("%s.%s.Shown", kDownloadDangerPromptPrefix, | 360 base::StringPrintf("%s.%s.Shown", kDownloadDangerPromptPrefix, |
| 359 GetDangerTypeString(danger_type)), | 361 GetDangerTypeString(danger_type)), |
| 360 dangerous_file_type); | 362 dangerous_file_type); |
| 361 if (did_proceed) { | 363 if (did_proceed) { |
| 362 UMA_HISTOGRAM_SPARSE_SLOWLY( | 364 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 363 base::StringPrintf("%s.%s.Proceed", kDownloadDangerPromptPrefix, | 365 base::StringPrintf("%s.%s.Proceed", kDownloadDangerPromptPrefix, |
| 364 GetDangerTypeString(danger_type)), | 366 GetDangerTypeString(danger_type)), |
| 365 dangerous_file_type); | 367 dangerous_file_type); |
| 366 } | 368 } |
| 367 } | 369 } |
| OLD | NEW |