| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 172 |
| 172 #endif // FULL_SAFE_BROWSING | 173 #endif // FULL_SAFE_BROWSING |
| 173 | 174 |
| 174 // Called on the blocking pool to determine the MIME type for |path|. | 175 // Called on the blocking pool to determine the MIME type for |path|. |
| 175 std::string GetMimeType(const base::FilePath& path) { | 176 std::string GetMimeType(const base::FilePath& path) { |
| 176 std::string mime_type; | 177 std::string mime_type; |
| 177 net::GetMimeTypeFromFile(path, &mime_type); | 178 net::GetMimeTypeFromFile(path, &mime_type); |
| 178 return mime_type; | 179 return mime_type; |
| 179 } | 180 } |
| 180 | 181 |
| 182 // Reason for why danger type is DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE. |
| 183 // Used by "Download.DangerousFile.Reason" UMA metric. |
| 184 // Do not change the ordering or remove items. |
| 185 enum DangerousFileReason { |
| 186 SB_NOT_AVAILABLE = 0, |
| 187 SB_RETURNS_UNKOWN = 1, |
| 188 SB_RETURNS_SAFE = 2, |
| 189 DANGEROUS_FILE_REASON_MAX |
| 190 }; |
| 191 |
| 181 } // namespace | 192 } // namespace |
| 182 | 193 |
| 183 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) | 194 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) |
| 184 : profile_(profile), | 195 : profile_(profile), |
| 185 next_download_id_(content::DownloadItem::kInvalidId), | 196 next_download_id_(content::DownloadItem::kInvalidId), |
| 186 download_prefs_(new DownloadPrefs(profile)), | 197 download_prefs_(new DownloadPrefs(profile)), |
| 187 weak_ptr_factory_(this) { | 198 weak_ptr_factory_(this) { |
| 188 } | 199 } |
| 189 | 200 |
| 190 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { | 201 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 content::DownloadDangerType danger_type = item->GetDangerType(); | 338 content::DownloadDangerType danger_type = item->GetDangerType(); |
| 328 if (DownloadItemModel(item).GetDangerLevel() != | 339 if (DownloadItemModel(item).GetDangerLevel() != |
| 329 DownloadFileType::NOT_DANGEROUS && | 340 DownloadFileType::NOT_DANGEROUS && |
| 330 (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || | 341 (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || |
| 331 danger_type == | 342 danger_type == |
| 332 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)) { | 343 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)) { |
| 333 DVLOG(2) << __FUNCTION__ | 344 DVLOG(2) << __FUNCTION__ |
| 334 << "() SB service disabled. Marking download as DANGEROUS FILE"; | 345 << "() SB service disabled. Marking download as DANGEROUS FILE"; |
| 335 item->OnContentCheckCompleted( | 346 item->OnContentCheckCompleted( |
| 336 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); | 347 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); |
| 348 UMA_HISTOGRAM_ENUMERATION("Download.DangerousFile.Reason", |
| 349 SB_NOT_AVAILABLE, DANGEROUS_FILE_REASON_MAX); |
| 337 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 350 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 338 internal_complete_callback); | 351 internal_complete_callback); |
| 339 return false; | 352 return false; |
| 340 } | 353 } |
| 341 } else if (!state->is_complete()) { | 354 } else if (!state->is_complete()) { |
| 342 // Don't complete the download until we have an answer. | 355 // Don't complete the download until we have an answer. |
| 343 state->set_callback(internal_complete_callback); | 356 state->set_callback(internal_complete_callback); |
| 344 return false; | 357 return false; |
| 345 } | 358 } |
| 346 | 359 |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 // has not been set to DANGEROUS yet. We don't want to show two warnings. | 675 // has not been set to DANGEROUS yet. We don't want to show two warnings. |
| 663 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || | 676 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || |
| 664 item->GetDangerType() == | 677 item->GetDangerType() == |
| 665 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { | 678 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { |
| 666 content::DownloadDangerType danger_type = | 679 content::DownloadDangerType danger_type = |
| 667 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; | 680 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; |
| 668 switch (result) { | 681 switch (result) { |
| 669 case DownloadProtectionService::UNKNOWN: | 682 case DownloadProtectionService::UNKNOWN: |
| 670 // The check failed or was inconclusive. | 683 // The check failed or was inconclusive. |
| 671 if (DownloadItemModel(item).GetDangerLevel() != | 684 if (DownloadItemModel(item).GetDangerLevel() != |
| 672 DownloadFileType::NOT_DANGEROUS) | 685 DownloadFileType::NOT_DANGEROUS) { |
| 673 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; | 686 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; |
| 687 UMA_HISTOGRAM_ENUMERATION("Download.DangerousFile.Reason", |
| 688 SB_RETURNS_UNKOWN, |
| 689 DANGEROUS_FILE_REASON_MAX); |
| 690 } |
| 674 break; | 691 break; |
| 675 case DownloadProtectionService::SAFE: | 692 case DownloadProtectionService::SAFE: |
| 676 // If this file type require explicit consent, then set the danger type | 693 // If this file type require explicit consent, then set the danger type |
| 677 // to DANGEROUS_FILE so that the user be required to manually vet | 694 // to DANGEROUS_FILE so that the user be required to manually vet |
| 678 // whether the download is intended or not. | 695 // whether the download is intended or not. |
| 679 if (DownloadItemModel(item).GetDangerLevel() == | 696 if (DownloadItemModel(item).GetDangerLevel() == |
| 680 DownloadFileType::DANGEROUS) | 697 DownloadFileType::DANGEROUS) { |
| 681 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; | 698 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; |
| 699 UMA_HISTOGRAM_ENUMERATION("Download.DangerousFile.Reason", |
| 700 SB_RETURNS_SAFE, DANGEROUS_FILE_REASON_MAX); |
| 701 } |
| 682 break; | 702 break; |
| 683 case DownloadProtectionService::DANGEROUS: | 703 case DownloadProtectionService::DANGEROUS: |
| 684 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT; | 704 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT; |
| 685 break; | 705 break; |
| 686 case DownloadProtectionService::UNCOMMON: | 706 case DownloadProtectionService::UNCOMMON: |
| 687 danger_type = content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT; | 707 danger_type = content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT; |
| 688 break; | 708 break; |
| 689 case DownloadProtectionService::DANGEROUS_HOST: | 709 case DownloadProtectionService::DANGEROUS_HOST: |
| 690 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST; | 710 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST; |
| 691 break; | 711 break; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || | 792 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || |
| 773 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || | 793 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || |
| 774 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || | 794 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || |
| 775 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || | 795 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || |
| 776 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { | 796 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { |
| 777 return true; | 797 return true; |
| 778 } | 798 } |
| 779 #endif | 799 #endif |
| 780 return false; | 800 return false; |
| 781 } | 801 } |
| OLD | NEW |