| 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/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/metrics/histogram.h" |
| 14 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/task_runner.h" | 18 #include "base/task_runner.h" |
| 18 #include "base/task_runner_util.h" | 19 #include "base/task_runner_util.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/download/download_completion_blocker.h" | 24 #include "chrome/browser/download/download_completion_blocker.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 175 |
| 175 #endif // FULL_SAFE_BROWSING | 176 #endif // FULL_SAFE_BROWSING |
| 176 | 177 |
| 177 // Called on the blocking pool to determine the MIME type for |path|. | 178 // Called on the blocking pool to determine the MIME type for |path|. |
| 178 std::string GetMimeType(const base::FilePath& path) { | 179 std::string GetMimeType(const base::FilePath& path) { |
| 179 std::string mime_type; | 180 std::string mime_type; |
| 180 net::GetMimeTypeFromFile(path, &mime_type); | 181 net::GetMimeTypeFromFile(path, &mime_type); |
| 181 return mime_type; | 182 return mime_type; |
| 182 } | 183 } |
| 183 | 184 |
| 185 // Reason for why danger type is DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE. |
| 186 // Used by "Download.DangerousFile.Reason" UMA metric. |
| 187 // Do not change the ordering or remove items. |
| 188 enum DangerousFileReason { |
| 189 SB_NOT_AVAILABLE = 0, |
| 190 SB_RETURNS_UNKOWN = 1, |
| 191 SB_RETURNS_SAFE = 2, |
| 192 DANGEROUS_FILE_REASON_MAX |
| 193 }; |
| 194 |
| 184 } // namespace | 195 } // namespace |
| 185 | 196 |
| 186 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) | 197 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) |
| 187 : profile_(profile), | 198 : profile_(profile), |
| 188 next_download_id_(content::DownloadItem::kInvalidId), | 199 next_download_id_(content::DownloadItem::kInvalidId), |
| 189 download_prefs_(new DownloadPrefs(profile)), | 200 download_prefs_(new DownloadPrefs(profile)), |
| 190 weak_ptr_factory_(this) { | 201 weak_ptr_factory_(this) { |
| 191 } | 202 } |
| 192 | 203 |
| 193 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { | 204 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 content::DownloadDangerType danger_type = item->GetDangerType(); | 341 content::DownloadDangerType danger_type = item->GetDangerType(); |
| 331 if (DownloadItemModel(item).GetDangerLevel() != | 342 if (DownloadItemModel(item).GetDangerLevel() != |
| 332 DownloadFileType::NOT_DANGEROUS && | 343 DownloadFileType::NOT_DANGEROUS && |
| 333 (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || | 344 (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || |
| 334 danger_type == | 345 danger_type == |
| 335 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)) { | 346 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)) { |
| 336 DVLOG(2) << __FUNCTION__ | 347 DVLOG(2) << __FUNCTION__ |
| 337 << "() SB service disabled. Marking download as DANGEROUS FILE"; | 348 << "() SB service disabled. Marking download as DANGEROUS FILE"; |
| 338 item->OnContentCheckCompleted( | 349 item->OnContentCheckCompleted( |
| 339 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); | 350 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); |
| 351 UMA_HISTOGRAM_ENUMERATION("Download.DangerousFile.Reason", |
| 352 SB_NOT_AVAILABLE, DANGEROUS_FILE_REASON_MAX); |
| 340 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 353 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 341 internal_complete_callback); | 354 internal_complete_callback); |
| 342 return false; | 355 return false; |
| 343 } | 356 } |
| 344 } else if (!state->is_complete()) { | 357 } else if (!state->is_complete()) { |
| 345 // Don't complete the download until we have an answer. | 358 // Don't complete the download until we have an answer. |
| 346 state->set_callback(internal_complete_callback); | 359 state->set_callback(internal_complete_callback); |
| 347 return false; | 360 return false; |
| 348 } | 361 } |
| 349 | 362 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 // has not been set to DANGEROUS yet. We don't want to show two warnings. | 692 // has not been set to DANGEROUS yet. We don't want to show two warnings. |
| 680 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || | 693 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || |
| 681 item->GetDangerType() == | 694 item->GetDangerType() == |
| 682 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { | 695 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { |
| 683 content::DownloadDangerType danger_type = | 696 content::DownloadDangerType danger_type = |
| 684 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; | 697 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; |
| 685 switch (result) { | 698 switch (result) { |
| 686 case DownloadProtectionService::UNKNOWN: | 699 case DownloadProtectionService::UNKNOWN: |
| 687 // The check failed or was inconclusive. | 700 // The check failed or was inconclusive. |
| 688 if (DownloadItemModel(item).GetDangerLevel() != | 701 if (DownloadItemModel(item).GetDangerLevel() != |
| 689 DownloadFileType::NOT_DANGEROUS) | 702 DownloadFileType::NOT_DANGEROUS) { |
| 690 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; | 703 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; |
| 704 UMA_HISTOGRAM_ENUMERATION("Download.DangerousFile.Reason", |
| 705 SB_RETURNS_UNKOWN, |
| 706 DANGEROUS_FILE_REASON_MAX); |
| 707 } |
| 691 break; | 708 break; |
| 692 case DownloadProtectionService::SAFE: | 709 case DownloadProtectionService::SAFE: |
| 693 // If this file type require explicit consent, then set the danger type | 710 // If this file type require explicit consent, then set the danger type |
| 694 // to DANGEROUS_FILE so that the user be required to manually vet | 711 // to DANGEROUS_FILE so that the user be required to manually vet |
| 695 // whether the download is intended or not. | 712 // whether the download is intended or not. |
| 696 if (DownloadItemModel(item).GetDangerLevel() == | 713 if (DownloadItemModel(item).GetDangerLevel() == |
| 697 DownloadFileType::DANGEROUS) | 714 DownloadFileType::DANGEROUS) { |
| 698 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; | 715 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; |
| 716 UMA_HISTOGRAM_ENUMERATION("Download.DangerousFile.Reason", |
| 717 SB_RETURNS_SAFE, DANGEROUS_FILE_REASON_MAX); |
| 718 } |
| 699 break; | 719 break; |
| 700 case DownloadProtectionService::DANGEROUS: | 720 case DownloadProtectionService::DANGEROUS: |
| 701 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT; | 721 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT; |
| 702 break; | 722 break; |
| 703 case DownloadProtectionService::UNCOMMON: | 723 case DownloadProtectionService::UNCOMMON: |
| 704 danger_type = content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT; | 724 danger_type = content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT; |
| 705 break; | 725 break; |
| 706 case DownloadProtectionService::DANGEROUS_HOST: | 726 case DownloadProtectionService::DANGEROUS_HOST: |
| 707 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST; | 727 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST; |
| 708 break; | 728 break; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || | 809 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || |
| 790 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || | 810 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || |
| 791 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || | 811 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || |
| 792 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || | 812 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || |
| 793 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { | 813 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { |
| 794 return true; | 814 return true; |
| 795 } | 815 } |
| 796 #endif | 816 #endif |
| 797 return false; | 817 return false; |
| 798 } | 818 } |
| OLD | NEW |