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 // A ClientDownloadRequest was not generated for this download, so | |
790 // callbakcs were not run with one. Run them with null so they see that a | |
robertshield
2014/10/24 03:05:46
callbacks
grt (UTC plus 2)
2014/10/24 15:04:40
Done.
| |
791 // previously-seen ClientDownloadRequest is now stale. | |
792 // TODO(grt): persist metadata for these downloads as well. | |
793 service_->client_download_request_callbacks_.Notify(item_, nullptr); | |
794 } | |
785 if (service_) { | 795 if (service_) { |
786 VLOG(2) << "SafeBrowsing download verdict for: " | 796 VLOG(2) << "SafeBrowsing download verdict for: " |
787 << item_->DebugString(true) << " verdict:" << reason | 797 << item_->DebugString(true) << " verdict:" << reason |
788 << " result:" << result; | 798 << " result:" << result; |
789 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", | 799 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", |
790 reason, | 800 reason, |
791 REASON_MAX); | 801 REASON_MAX); |
792 #if defined(OS_MACOSX) | 802 #if defined(OS_MACOSX) |
793 // OSX is currently sending pings only for evaluation purposes, ignore | 803 // OSX is currently sending pings only for evaluation purposes, ignore |
794 // the result for now. | 804 // the result for now. |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
954 ClientDownloadRequest::DownloadType type = | 964 ClientDownloadRequest::DownloadType type = |
955 ClientDownloadRequest::WIN_EXECUTABLE; | 965 ClientDownloadRequest::WIN_EXECUTABLE; |
956 return (CheckClientDownloadRequest::IsSupportedDownload( | 966 return (CheckClientDownloadRequest::IsSupportedDownload( |
957 item, target_path, &reason, &type) && | 967 item, target_path, &reason, &type) && |
958 (ClientDownloadRequest::CHROME_EXTENSION != type)); | 968 (ClientDownloadRequest::CHROME_EXTENSION != type)); |
959 #else | 969 #else |
960 return false; | 970 return false; |
961 #endif | 971 #endif |
962 } | 972 } |
963 | 973 |
974 DownloadProtectionService::ClientDownloadRequestSubscription | |
975 DownloadProtectionService::RegisterClientDownloadRequestCallback( | |
976 const ClientDownloadRequestCallback& callback) { | |
977 return client_download_request_callbacks_.Add(callback); | |
978 } | |
979 | |
964 void DownloadProtectionService::CancelPendingRequests() { | 980 void DownloadProtectionService::CancelPendingRequests() { |
965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 981 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
966 for (std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = | 982 for (std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = |
967 download_requests_.begin(); | 983 download_requests_.begin(); |
968 it != download_requests_.end();) { | 984 it != download_requests_.end();) { |
969 // We need to advance the iterator before we cancel because canceling | 985 // We need to advance the iterator before we cancel because canceling |
970 // the request will invalidate it when RequestFinished is called below. | 986 // the request will invalidate it when RequestFinished is called below. |
971 scoped_refptr<CheckClientDownloadRequest> tmp = *it++; | 987 scoped_refptr<CheckClientDownloadRequest> tmp = *it++; |
972 tmp->Cancel(); | 988 tmp->Cancel(); |
973 } | 989 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1076 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1092 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
1077 GURL url(kDownloadRequestUrl); | 1093 GURL url(kDownloadRequestUrl); |
1078 std::string api_key = google_apis::GetAPIKey(); | 1094 std::string api_key = google_apis::GetAPIKey(); |
1079 if (!api_key.empty()) | 1095 if (!api_key.empty()) |
1080 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1096 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
1081 | 1097 |
1082 return url; | 1098 return url; |
1083 } | 1099 } |
1084 | 1100 |
1085 } // namespace safe_browsing | 1101 } // namespace safe_browsing |
OLD | NEW |