| 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/safe_browsing/download_protection_service.h" | 5 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/metrics/field_trial.h" | |
| 13 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/sequenced_task_runner_helpers.h" | 14 #include "base/sequenced_task_runner_helpers.h" |
| 16 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 17 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 19 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 20 #include "base/task/cancelable_task_tracker.h" | 19 #include "base/task/cancelable_task_tracker.h" |
| 21 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
| 22 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 } | 608 } |
| 610 | 609 |
| 611 if (!pingback_enabled_) { | 610 if (!pingback_enabled_) { |
| 612 PostFinishTask(UNKNOWN, REASON_PING_DISABLED); | 611 PostFinishTask(UNKNOWN, REASON_PING_DISABLED); |
| 613 return; | 612 return; |
| 614 } | 613 } |
| 615 | 614 |
| 616 // Currently, the UI only works on Windows so we don't even bother with | 615 // Currently, the UI only works on Windows so we don't even bother with |
| 617 // pinging the server if we're not on Windows. | 616 // pinging the server if we're not on Windows. |
| 618 // TODO(noelutz): change this code once the UI is done for Linux and Mac. | 617 // TODO(noelutz): change this code once the UI is done for Linux and Mac. |
| 619 #if defined(OS_MACOSX) | 618 #if defined(OS_WIN) |
| 620 // TODO(mattm): remove this (see crbug.com/414834). | |
| 621 if (base::FieldTrialList::FindFullName("SafeBrowsingOSXClientDownloadPings") | |
| 622 != "Enabled") { | |
| 623 PostFinishTask(UNKNOWN, REASON_OS_NOT_SUPPORTED); | |
| 624 return; | |
| 625 } | |
| 626 #endif | |
| 627 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 628 // The URLFetcher is owned by the UI thread, so post a message to | 619 // The URLFetcher is owned by the UI thread, so post a message to |
| 629 // start the pingback. | 620 // start the pingback. |
| 630 BrowserThread::PostTask( | 621 BrowserThread::PostTask( |
| 631 BrowserThread::UI, | 622 BrowserThread::UI, |
| 632 FROM_HERE, | 623 FROM_HERE, |
| 633 base::Bind(&CheckClientDownloadRequest::GetTabRedirects, this)); | 624 base::Bind(&CheckClientDownloadRequest::GetTabRedirects, this)); |
| 634 #else | 625 #else |
| 635 PostFinishTask(UNKNOWN, REASON_OS_NOT_SUPPORTED); | 626 PostFinishTask(UNKNOWN, REASON_OS_NOT_SUPPORTED); |
| 636 #endif | 627 #endif |
| 637 } | 628 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 base::TimeTicks::Now() - timeout_start_time_); | 773 base::TimeTicks::Now() - timeout_start_time_); |
| 783 } | 774 } |
| 784 } | 775 } |
| 785 if (service_) { | 776 if (service_) { |
| 786 VLOG(2) << "SafeBrowsing download verdict for: " | 777 VLOG(2) << "SafeBrowsing download verdict for: " |
| 787 << item_->DebugString(true) << " verdict:" << reason | 778 << item_->DebugString(true) << " verdict:" << reason |
| 788 << " result:" << result; | 779 << " result:" << result; |
| 789 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", | 780 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", |
| 790 reason, | 781 reason, |
| 791 REASON_MAX); | 782 REASON_MAX); |
| 792 #if defined(OS_MACOSX) | |
| 793 // OSX is currently sending pings only for evaluation purposes, ignore | |
| 794 // the result for now. | |
| 795 // TODO(mattm): remove this and update the ifdef in | |
| 796 // DownloadItemImpl::IsDangerous (see crbug.com/413968). | |
| 797 result = UNKNOWN; | |
| 798 #endif | |
| 799 callback_.Run(result); | 783 callback_.Run(result); |
| 800 item_->RemoveObserver(this); | 784 item_->RemoveObserver(this); |
| 801 item_ = NULL; | 785 item_ = NULL; |
| 802 DownloadProtectionService* service = service_; | 786 DownloadProtectionService* service = service_; |
| 803 service_ = NULL; | 787 service_ = NULL; |
| 804 service->RequestFinished(this); | 788 service->RequestFinished(this); |
| 805 // DownloadProtectionService::RequestFinished will decrement our refcount, | 789 // DownloadProtectionService::RequestFinished will decrement our refcount, |
| 806 // so we may be deleted now. | 790 // so we may be deleted now. |
| 807 } else { | 791 } else { |
| 808 callback_.Run(UNKNOWN); | 792 callback_.Run(UNKNOWN); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 // The client will release itself once it is done. | 922 // The client will release itself once it is done. |
| 939 BrowserThread::PostTask( | 923 BrowserThread::PostTask( |
| 940 BrowserThread::IO, | 924 BrowserThread::IO, |
| 941 FROM_HERE, | 925 FROM_HERE, |
| 942 base::Bind(&DownloadUrlSBClient::StartCheck, client)); | 926 base::Bind(&DownloadUrlSBClient::StartCheck, client)); |
| 943 } | 927 } |
| 944 | 928 |
| 945 bool DownloadProtectionService::IsSupportedDownload( | 929 bool DownloadProtectionService::IsSupportedDownload( |
| 946 const content::DownloadItem& item, | 930 const content::DownloadItem& item, |
| 947 const base::FilePath& target_path) const { | 931 const base::FilePath& target_path) const { |
| 948 // Currently, the UI is only enabled on Windows. On Mac we send the ping but | 932 // Currently, the UI only works on Windows. On Linux and Mac we still |
| 949 // ignore the result (see ifdef in FinishRequest). On Linux we still | |
| 950 // want to show the dangerous file type warning if the file is possibly | 933 // want to show the dangerous file type warning if the file is possibly |
| 951 // dangerous which means we have to always return false here. | 934 // dangerous which means we have to always return false here. |
| 952 #if defined(OS_WIN) | 935 #if defined(OS_WIN) |
| 953 DownloadCheckResultReason reason = REASON_MAX; | 936 DownloadCheckResultReason reason = REASON_MAX; |
| 954 ClientDownloadRequest::DownloadType type = | 937 ClientDownloadRequest::DownloadType type = |
| 955 ClientDownloadRequest::WIN_EXECUTABLE; | 938 ClientDownloadRequest::WIN_EXECUTABLE; |
| 956 return (CheckClientDownloadRequest::IsSupportedDownload( | 939 return (CheckClientDownloadRequest::IsSupportedDownload(item, target_path, |
| 957 item, target_path, &reason, &type) && | 940 &reason, &type) && |
| 958 (ClientDownloadRequest::CHROME_EXTENSION != type)); | 941 (ClientDownloadRequest::ANDROID_APK == type || |
| 942 ClientDownloadRequest::WIN_EXECUTABLE == type || |
| 943 ClientDownloadRequest::ZIPPED_EXECUTABLE == type)); |
| 959 #else | 944 #else |
| 960 return false; | 945 return false; |
| 961 #endif | 946 #endif |
| 962 } | 947 } |
| 963 | 948 |
| 964 void DownloadProtectionService::CancelPendingRequests() { | 949 void DownloadProtectionService::CancelPendingRequests() { |
| 965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 950 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 966 for (std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = | 951 for (std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = |
| 967 download_requests_.begin(); | 952 download_requests_.begin(); |
| 968 it != download_requests_.end();) { | 953 it != download_requests_.end();) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1061 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
| 1077 GURL url(kDownloadRequestUrl); | 1062 GURL url(kDownloadRequestUrl); |
| 1078 std::string api_key = google_apis::GetAPIKey(); | 1063 std::string api_key = google_apis::GetAPIKey(); |
| 1079 if (!api_key.empty()) | 1064 if (!api_key.empty()) |
| 1080 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1065 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 1081 | 1066 |
| 1082 return url; | 1067 return url; |
| 1083 } | 1068 } |
| 1084 | 1069 |
| 1085 } // namespace safe_browsing | 1070 } // namespace safe_browsing |
| OLD | NEW |