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