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" |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 request.set_file_basename( | 725 request.set_file_basename( |
726 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); | 726 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); |
727 request.set_download_type(type_); | 727 request.set_download_type(type_); |
728 request.mutable_signature()->CopyFrom(signature_info_); | 728 request.mutable_signature()->CopyFrom(signature_info_); |
729 request.mutable_image_headers()->CopyFrom(image_headers_); | 729 request.mutable_image_headers()->CopyFrom(image_headers_); |
730 if (!request.SerializeToString(&client_download_request_data_)) { | 730 if (!request.SerializeToString(&client_download_request_data_)) { |
731 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); | 731 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); |
732 return; | 732 return; |
733 } | 733 } |
734 | 734 |
735 service_->client_download_request_callbacks_.Notify(item_, &request); | |
736 | |
735 VLOG(2) << "Sending a request for URL: " | 737 VLOG(2) << "Sending a request for URL: " |
736 << item_->GetUrlChain().back(); | 738 << item_->GetUrlChain().back(); |
737 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */, | 739 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */, |
738 GetDownloadRequestUrl(), | 740 GetDownloadRequestUrl(), |
739 net::URLFetcher::POST, | 741 net::URLFetcher::POST, |
740 this)); | 742 this)); |
741 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 743 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
742 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error. | 744 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error. |
743 fetcher_->SetRequestContext(service_->request_context_getter_.get()); | 745 fetcher_->SetRequestContext(service_->request_context_getter_.get()); |
744 fetcher_->SetUploadData("application/octet-stream", | 746 fetcher_->SetUploadData("application/octet-stream", |
(...skipping 30 matching lines...) Expand all Loading... | |
775 } | 777 } |
776 if (!timeout_start_time_.is_null()) { | 778 if (!timeout_start_time_.is_null()) { |
777 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.DownloadRequestTimeoutStats", | 779 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.DownloadRequestTimeoutStats", |
778 reason, | 780 reason, |
779 REASON_MAX); | 781 REASON_MAX); |
780 if (reason != REASON_REQUEST_CANCELED) { | 782 if (reason != REASON_REQUEST_CANCELED) { |
781 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestTimeoutDuration", | 783 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestTimeoutDuration", |
782 base::TimeTicks::Now() - timeout_start_time_); | 784 base::TimeTicks::Now() - timeout_start_time_); |
783 } | 785 } |
784 } | 786 } |
787 if (result == SAFE && (reason == REASON_WHITELISTED_URL || | |
788 reason == REASON_TRUSTED_EXECUTABLE)) { | |
789 // This is a supported download for which a ClientDownloadRequest is not | |
robertshield
2014/10/21 13:15:38
What does a supported download mean in this contex
grt (UTC plus 2)
2014/10/23 19:53:12
One for which CheckClientDownload was called.
| |
790 // generated. Clear out metadata for what has now become a stale download. | |
791 // TODO(grt): persist metadata for these downloads as well. | |
792 service_->client_download_request_callbacks_.Notify(item_, nullptr); | |
793 } | |
785 if (service_) { | 794 if (service_) { |
786 VLOG(2) << "SafeBrowsing download verdict for: " | 795 VLOG(2) << "SafeBrowsing download verdict for: " |
787 << item_->DebugString(true) << " verdict:" << reason | 796 << item_->DebugString(true) << " verdict:" << reason |
788 << " result:" << result; | 797 << " result:" << result; |
789 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", | 798 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", |
790 reason, | 799 reason, |
791 REASON_MAX); | 800 REASON_MAX); |
792 #if defined(OS_MACOSX) | 801 #if defined(OS_MACOSX) |
793 // OSX is currently sending pings only for evaluation purposes, ignore | 802 // OSX is currently sending pings only for evaluation purposes, ignore |
794 // the result for now. | 803 // the result for now. |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
954 ClientDownloadRequest::DownloadType type = | 963 ClientDownloadRequest::DownloadType type = |
955 ClientDownloadRequest::WIN_EXECUTABLE; | 964 ClientDownloadRequest::WIN_EXECUTABLE; |
956 return (CheckClientDownloadRequest::IsSupportedDownload( | 965 return (CheckClientDownloadRequest::IsSupportedDownload( |
957 item, target_path, &reason, &type) && | 966 item, target_path, &reason, &type) && |
958 (ClientDownloadRequest::CHROME_EXTENSION != type)); | 967 (ClientDownloadRequest::CHROME_EXTENSION != type)); |
959 #else | 968 #else |
960 return false; | 969 return false; |
961 #endif | 970 #endif |
962 } | 971 } |
963 | 972 |
973 DownloadProtectionService::ClientDownloadRequestSubscription | |
974 DownloadProtectionService::RegisterClientDownloadRequestCallback( | |
975 const ClientDownloadRequestCallback& callback) { | |
976 return client_download_request_callbacks_.Add(callback); | |
977 } | |
978 | |
964 void DownloadProtectionService::CancelPendingRequests() { | 979 void DownloadProtectionService::CancelPendingRequests() { |
965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 980 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
966 for (std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = | 981 for (std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = |
967 download_requests_.begin(); | 982 download_requests_.begin(); |
968 it != download_requests_.end();) { | 983 it != download_requests_.end();) { |
969 // We need to advance the iterator before we cancel because canceling | 984 // We need to advance the iterator before we cancel because canceling |
970 // the request will invalidate it when RequestFinished is called below. | 985 // the request will invalidate it when RequestFinished is called below. |
971 scoped_refptr<CheckClientDownloadRequest> tmp = *it++; | 986 scoped_refptr<CheckClientDownloadRequest> tmp = *it++; |
972 tmp->Cancel(); | 987 tmp->Cancel(); |
973 } | 988 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1076 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1091 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
1077 GURL url(kDownloadRequestUrl); | 1092 GURL url(kDownloadRequestUrl); |
1078 std::string api_key = google_apis::GetAPIKey(); | 1093 std::string api_key = google_apis::GetAPIKey(); |
1079 if (!api_key.empty()) | 1094 if (!api_key.empty()) |
1080 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1095 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
1081 | 1096 |
1082 return url; | 1097 return url; |
1083 } | 1098 } |
1084 | 1099 |
1085 } // namespace safe_browsing | 1100 } // namespace safe_browsing |
OLD | NEW |