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_WIN) || defined(OS_MACOSX) |
619 // The URLFetcher is owned by the UI thread, so post a message to | 620 // The URLFetcher is owned by the UI thread, so post a message to |
620 // start the pingback. | 621 // start the pingback. |
621 BrowserThread::PostTask( | 622 BrowserThread::PostTask( |
622 BrowserThread::UI, | 623 BrowserThread::UI, |
623 FROM_HERE, | 624 FROM_HERE, |
624 base::Bind(&CheckClientDownloadRequest::GetTabRedirects, this)); | 625 base::Bind(&CheckClientDownloadRequest::GetTabRedirects, this)); |
625 #else | 626 #else |
626 PostFinishTask(UNKNOWN, REASON_OS_NOT_SUPPORTED); | 627 PostFinishTask(UNKNOWN, REASON_OS_NOT_SUPPORTED); |
627 #endif | 628 #endif |
628 } | 629 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestTimeoutDuration", | 773 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestTimeoutDuration", |
773 base::TimeTicks::Now() - timeout_start_time_); | 774 base::TimeTicks::Now() - timeout_start_time_); |
774 } | 775 } |
775 } | 776 } |
776 if (service_) { | 777 if (service_) { |
777 VLOG(2) << "SafeBrowsing download verdict for: " | 778 VLOG(2) << "SafeBrowsing download verdict for: " |
778 << item_->DebugString(true) << " verdict:" << reason; | 779 << item_->DebugString(true) << " verdict:" << reason; |
779 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", | 780 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", |
780 reason, | 781 reason, |
781 REASON_MAX); | 782 REASON_MAX); |
783 #if defined(OS_MACOSX) | |
784 // OSX is currently sending pings only for evaluation purposes, ignore | |
785 // the result for now. | |
786 // TODO(mattm): remove this and update the ifdef in | |
787 // DownloadItemImpl::IsDangerous (see crbug.com/413968). | |
788 result = UNKNOWN; | |
789 #endif | |
782 callback_.Run(result); | 790 callback_.Run(result); |
783 item_->RemoveObserver(this); | 791 item_->RemoveObserver(this); |
784 item_ = NULL; | 792 item_ = NULL; |
785 DownloadProtectionService* service = service_; | 793 DownloadProtectionService* service = service_; |
786 service_ = NULL; | 794 service_ = NULL; |
787 service->RequestFinished(this); | 795 service->RequestFinished(this); |
788 // DownloadProtectionService::RequestFinished will decrement our refcount, | 796 // DownloadProtectionService::RequestFinished will decrement our refcount, |
789 // so we may be deleted now. | 797 // so we may be deleted now. |
790 } else { | 798 } else { |
791 callback_.Run(UNKNOWN); | 799 callback_.Run(UNKNOWN); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
921 // The client will release itself once it is done. | 929 // The client will release itself once it is done. |
922 BrowserThread::PostTask( | 930 BrowserThread::PostTask( |
923 BrowserThread::IO, | 931 BrowserThread::IO, |
924 FROM_HERE, | 932 FROM_HERE, |
925 base::Bind(&DownloadUrlSBClient::StartCheck, client)); | 933 base::Bind(&DownloadUrlSBClient::StartCheck, client)); |
926 } | 934 } |
927 | 935 |
928 bool DownloadProtectionService::IsSupportedDownload( | 936 bool DownloadProtectionService::IsSupportedDownload( |
929 const content::DownloadItem& item, | 937 const content::DownloadItem& item, |
930 const base::FilePath& target_path) const { | 938 const base::FilePath& target_path) const { |
931 // Currently, the UI only works on Windows. On Linux and Mac we still | 939 // Currently, the UI is only enabled on Windows. On Mac we send the ping but |
940 // ignore the result (see ifdef in FinishRequest). On Linux we still | |
932 // want to show the dangerous file type warning if the file is possibly | 941 // want to show the dangerous file type warning if the file is possibly |
933 // dangerous which means we have to always return false here. | 942 // dangerous which means we have to always return false here. |
934 #if defined(OS_WIN) | 943 #if defined(OS_MACOSX) |
944 // TODO(mattm): remove this (see crbug.com/X). | |
noé
2014/09/15 16:10:03
s/X/413968 ?
mattm
2014/09/16 20:04:20
Done (used the finch experiment bug number)
| |
945 if (base::FieldTrialList::FindFullName("OSXSBClientDownloadPings") != | |
946 "Enabled") | |
947 return false; | |
948 #endif | |
949 #if defined(OS_WIN) || defined(OS_MACOSX) | |
935 DownloadCheckResultReason reason = REASON_MAX; | 950 DownloadCheckResultReason reason = REASON_MAX; |
936 ClientDownloadRequest::DownloadType type = | 951 ClientDownloadRequest::DownloadType type = |
937 ClientDownloadRequest::WIN_EXECUTABLE; | 952 ClientDownloadRequest::WIN_EXECUTABLE; |
938 return (CheckClientDownloadRequest::IsSupportedDownload(item, target_path, | 953 return (CheckClientDownloadRequest::IsSupportedDownload( |
939 &reason, &type) && | 954 item, target_path, &reason, &type) && |
940 (ClientDownloadRequest::ANDROID_APK == type || | 955 (ClientDownloadRequest::CHROME_EXTENSION != type)); |
941 ClientDownloadRequest::WIN_EXECUTABLE == type || | |
942 ClientDownloadRequest::ZIPPED_EXECUTABLE == type)); | |
943 #else | 956 #else |
944 return false; | 957 return false; |
945 #endif | 958 #endif |
946 } | 959 } |
947 | 960 |
948 void DownloadProtectionService::CancelPendingRequests() { | 961 void DownloadProtectionService::CancelPendingRequests() { |
949 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
950 for (std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = | 963 for (std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = |
951 download_requests_.begin(); | 964 download_requests_.begin(); |
952 it != download_requests_.end();) { | 965 it != download_requests_.end();) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1060 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1073 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
1061 GURL url(kDownloadRequestUrl); | 1074 GURL url(kDownloadRequestUrl); |
1062 std::string api_key = google_apis::GetAPIKey(); | 1075 std::string api_key = google_apis::GetAPIKey(); |
1063 if (!api_key.empty()) | 1076 if (!api_key.empty()) |
1064 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1077 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
1065 | 1078 |
1066 return url; | 1079 return url; |
1067 } | 1080 } |
1068 | 1081 |
1069 } // namespace safe_browsing | 1082 } // namespace safe_browsing |
OLD | NEW |