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 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 | 586 |
587 if (!database_manager_.get()) { | 587 if (!database_manager_.get()) { |
588 PostFinishTask(UNKNOWN, REASON_SB_DISABLED); | 588 PostFinishTask(UNKNOWN, REASON_SB_DISABLED); |
589 return; | 589 return; |
590 } | 590 } |
591 | 591 |
592 const GURL& url = url_chain_.back(); | 592 const GURL& url = url_chain_.back(); |
593 if (url.is_valid() && database_manager_->MatchDownloadWhitelistUrl(url)) { | 593 if (url.is_valid() && database_manager_->MatchDownloadWhitelistUrl(url)) { |
594 VLOG(2) << url << " is on the download whitelist."; | 594 VLOG(2) << url << " is on the download whitelist."; |
595 RecordCountOfSignedOrWhitelistedDownload(); | 595 RecordCountOfSignedOrWhitelistedDownload(); |
596 // TODO(grt): Continue processing without uploading so that | |
597 // ClientDownloadRequest callbacks can be run even for this type of safe | |
598 // download. | |
596 PostFinishTask(SAFE, REASON_WHITELISTED_URL); | 599 PostFinishTask(SAFE, REASON_WHITELISTED_URL); |
597 return; | 600 return; |
598 } | 601 } |
599 | 602 |
600 if (signature_info_.trusted()) { | 603 if (signature_info_.trusted()) { |
601 RecordCountOfSignedOrWhitelistedDownload(); | 604 RecordCountOfSignedOrWhitelistedDownload(); |
602 for (int i = 0; i < signature_info_.certificate_chain_size(); ++i) { | 605 for (int i = 0; i < signature_info_.certificate_chain_size(); ++i) { |
603 if (CertificateChainIsWhitelisted( | 606 if (CertificateChainIsWhitelisted( |
604 signature_info_.certificate_chain(i))) { | 607 signature_info_.certificate_chain(i))) { |
608 // TODO(grt): Continue processing without uploading so that | |
609 // ClientDownloadRequest callbacks can be run even for this type of | |
610 // safe download. | |
605 PostFinishTask(SAFE, REASON_TRUSTED_EXECUTABLE); | 611 PostFinishTask(SAFE, REASON_TRUSTED_EXECUTABLE); |
606 return; | 612 return; |
607 } | 613 } |
608 } | 614 } |
609 } | 615 } |
610 | 616 |
611 if (!pingback_enabled_) { | 617 if (!pingback_enabled_) { |
612 PostFinishTask(UNKNOWN, REASON_PING_DISABLED); | 618 PostFinishTask(UNKNOWN, REASON_PING_DISABLED); |
613 return; | 619 return; |
614 } | 620 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 request.set_file_basename( | 731 request.set_file_basename( |
726 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); | 732 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); |
727 request.set_download_type(type_); | 733 request.set_download_type(type_); |
728 request.mutable_signature()->CopyFrom(signature_info_); | 734 request.mutable_signature()->CopyFrom(signature_info_); |
729 request.mutable_image_headers()->CopyFrom(image_headers_); | 735 request.mutable_image_headers()->CopyFrom(image_headers_); |
730 if (!request.SerializeToString(&client_download_request_data_)) { | 736 if (!request.SerializeToString(&client_download_request_data_)) { |
731 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); | 737 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); |
732 return; | 738 return; |
733 } | 739 } |
734 | 740 |
741 service_->client_download_request_callbacks_.Notify(item_, &request); | |
742 | |
735 VLOG(2) << "Sending a request for URL: " | 743 VLOG(2) << "Sending a request for URL: " |
736 << item_->GetUrlChain().back(); | 744 << item_->GetUrlChain().back(); |
737 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */, | 745 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */, |
738 GetDownloadRequestUrl(), | 746 GetDownloadRequestUrl(), |
739 net::URLFetcher::POST, | 747 net::URLFetcher::POST, |
740 this)); | 748 this)); |
741 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 749 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
742 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error. | 750 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error. |
743 fetcher_->SetRequestContext(service_->request_context_getter_.get()); | 751 fetcher_->SetRequestContext(service_->request_context_getter_.get()); |
744 fetcher_->SetUploadData("application/octet-stream", | 752 fetcher_->SetUploadData("application/octet-stream", |
(...skipping 30 matching lines...) Expand all Loading... | |
775 } | 783 } |
776 if (!timeout_start_time_.is_null()) { | 784 if (!timeout_start_time_.is_null()) { |
777 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.DownloadRequestTimeoutStats", | 785 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.DownloadRequestTimeoutStats", |
778 reason, | 786 reason, |
779 REASON_MAX); | 787 REASON_MAX); |
780 if (reason != REASON_REQUEST_CANCELED) { | 788 if (reason != REASON_REQUEST_CANCELED) { |
781 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestTimeoutDuration", | 789 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestTimeoutDuration", |
782 base::TimeTicks::Now() - timeout_start_time_); | 790 base::TimeTicks::Now() - timeout_start_time_); |
783 } | 791 } |
784 } | 792 } |
793 if (result == SAFE && (reason == REASON_WHITELISTED_URL || | |
794 reason == REASON_TRUSTED_EXECUTABLE)) { | |
795 // Due to the short-circuit logic in CheckWhitelists (see TODOs there), a | |
796 // ClientDownloadRequest was not generated for this download and callbacks | |
797 // were not run. Run them now with null to indicate that a download has | |
798 // taken place. | |
799 // TODO(grt): persist metadata for these downloads as well. | |
800 service_->client_download_request_callbacks_.Notify(item_, nullptr); | |
801 } | |
785 if (service_) { | 802 if (service_) { |
786 VLOG(2) << "SafeBrowsing download verdict for: " | 803 VLOG(2) << "SafeBrowsing download verdict for: " |
787 << item_->DebugString(true) << " verdict:" << reason | 804 << item_->DebugString(true) << " verdict:" << reason |
788 << " result:" << result; | 805 << " result:" << result; |
789 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", | 806 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", |
790 reason, | 807 reason, |
791 REASON_MAX); | 808 REASON_MAX); |
792 #if defined(OS_MACOSX) | 809 #if defined(OS_MACOSX) |
793 // OSX is currently sending pings only for evaluation purposes, ignore | 810 // OSX is currently sending pings only for evaluation purposes, ignore |
794 // the result for now. | 811 // the result for now. |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
954 ClientDownloadRequest::DownloadType type = | 971 ClientDownloadRequest::DownloadType type = |
955 ClientDownloadRequest::WIN_EXECUTABLE; | 972 ClientDownloadRequest::WIN_EXECUTABLE; |
956 return (CheckClientDownloadRequest::IsSupportedDownload( | 973 return (CheckClientDownloadRequest::IsSupportedDownload( |
957 item, target_path, &reason, &type) && | 974 item, target_path, &reason, &type) && |
958 (ClientDownloadRequest::CHROME_EXTENSION != type)); | 975 (ClientDownloadRequest::CHROME_EXTENSION != type)); |
959 #else | 976 #else |
960 return false; | 977 return false; |
961 #endif | 978 #endif |
962 } | 979 } |
963 | 980 |
981 DownloadProtectionService::ClientDownloadRequestSubscription | |
982 DownloadProtectionService::RegisterClientDownloadRequestCallback( | |
983 const ClientDownloadRequestCallback& callback) { | |
mattm
2014/11/04 11:39:04
Add DCHECK(BrowserThread::CurrentlyOn(BrowserThrea
| |
984 return client_download_request_callbacks_.Add(callback); | |
985 } | |
986 | |
964 void DownloadProtectionService::CancelPendingRequests() { | 987 void DownloadProtectionService::CancelPendingRequests() { |
965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 988 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
966 for (std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = | 989 for (std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = |
967 download_requests_.begin(); | 990 download_requests_.begin(); |
968 it != download_requests_.end();) { | 991 it != download_requests_.end();) { |
969 // We need to advance the iterator before we cancel because canceling | 992 // We need to advance the iterator before we cancel because canceling |
970 // the request will invalidate it when RequestFinished is called below. | 993 // the request will invalidate it when RequestFinished is called below. |
971 scoped_refptr<CheckClientDownloadRequest> tmp = *it++; | 994 scoped_refptr<CheckClientDownloadRequest> tmp = *it++; |
972 tmp->Cancel(); | 995 tmp->Cancel(); |
973 } | 996 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1076 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1099 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
1077 GURL url(kDownloadRequestUrl); | 1100 GURL url(kDownloadRequestUrl); |
1078 std::string api_key = google_apis::GetAPIKey(); | 1101 std::string api_key = google_apis::GetAPIKey(); |
1079 if (!api_key.empty()) | 1102 if (!api_key.empty()) |
1080 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1103 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
1081 | 1104 |
1082 return url; | 1105 return url; |
1083 } | 1106 } |
1084 | 1107 |
1085 } // namespace safe_browsing | 1108 } // namespace safe_browsing |
OLD | NEW |