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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 348 } |
349 | 349 |
350 // Start a timeout to cancel the request if it takes too long. | 350 // Start a timeout to cancel the request if it takes too long. |
351 // This should only be called after we have finished accessing the file. | 351 // This should only be called after we have finished accessing the file. |
352 void StartTimeout() { | 352 void StartTimeout() { |
353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
354 if (!service_) { | 354 if (!service_) { |
355 // Request has already been cancelled. | 355 // Request has already been cancelled. |
356 return; | 356 return; |
357 } | 357 } |
| 358 timeout_start_time_ = base::TimeTicks::Now(); |
358 BrowserThread::PostDelayedTask( | 359 BrowserThread::PostDelayedTask( |
359 BrowserThread::UI, | 360 BrowserThread::UI, |
360 FROM_HERE, | 361 FROM_HERE, |
361 base::Bind(&CheckClientDownloadRequest::Cancel, | 362 base::Bind(&CheckClientDownloadRequest::Cancel, |
362 weakptr_factory_.GetWeakPtr()), | 363 weakptr_factory_.GetWeakPtr()), |
363 base::TimeDelta::FromMilliseconds( | 364 base::TimeDelta::FromMilliseconds( |
364 service_->download_request_timeout_ms())); | 365 service_->download_request_timeout_ms())); |
365 } | 366 } |
366 | 367 |
367 // Canceling a request will cause us to always report the result as SAFE | 368 // Canceling a request will cause us to always report the result as SAFE |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 << response.verdict(); | 444 << response.verdict(); |
444 reason = REASON_INVALID_RESPONSE_VERDICT; | 445 reason = REASON_INVALID_RESPONSE_VERDICT; |
445 } | 446 } |
446 DownloadFeedbackService::MaybeStorePingsForDownload( | 447 DownloadFeedbackService::MaybeStorePingsForDownload( |
447 result, item_, client_download_request_data_, data); | 448 result, item_, client_download_request_data_, data); |
448 } | 449 } |
449 // We don't need the fetcher anymore. | 450 // We don't need the fetcher anymore. |
450 fetcher_.reset(); | 451 fetcher_.reset(); |
451 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestDuration", | 452 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestDuration", |
452 base::TimeTicks::Now() - start_time_); | 453 base::TimeTicks::Now() - start_time_); |
| 454 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestNetworkDuration", |
| 455 base::TimeTicks::Now() - request_start_time_); |
453 FinishRequest(result, reason); | 456 FinishRequest(result, reason); |
454 } | 457 } |
455 | 458 |
456 static bool IsSupportedDownload(const content::DownloadItem& item, | 459 static bool IsSupportedDownload(const content::DownloadItem& item, |
457 const base::FilePath& target_path, | 460 const base::FilePath& target_path, |
458 DownloadCheckResultReason* reason, | 461 DownloadCheckResultReason* reason, |
459 ClientDownloadRequest::DownloadType* type) { | 462 ClientDownloadRequest::DownloadType* type) { |
460 if (item.GetUrlChain().empty()) { | 463 if (item.GetUrlChain().empty()) { |
461 *reason = REASON_EMPTY_URL_CHAIN; | 464 *reason = REASON_EMPTY_URL_CHAIN; |
462 return false; | 465 return false; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 << item_->GetUrlChain().back(); | 729 << item_->GetUrlChain().back(); |
727 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */, | 730 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */, |
728 GetDownloadRequestUrl(), | 731 GetDownloadRequestUrl(), |
729 net::URLFetcher::POST, | 732 net::URLFetcher::POST, |
730 this)); | 733 this)); |
731 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 734 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
732 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error. | 735 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error. |
733 fetcher_->SetRequestContext(service_->request_context_getter_.get()); | 736 fetcher_->SetRequestContext(service_->request_context_getter_.get()); |
734 fetcher_->SetUploadData("application/octet-stream", | 737 fetcher_->SetUploadData("application/octet-stream", |
735 client_download_request_data_); | 738 client_download_request_data_); |
| 739 request_start_time_ = base::TimeTicks::Now(); |
736 UMA_HISTOGRAM_COUNTS("SBClientDownload.DownloadRequestPayloadSize", | 740 UMA_HISTOGRAM_COUNTS("SBClientDownload.DownloadRequestPayloadSize", |
737 client_download_request_data_.size()); | 741 client_download_request_data_.size()); |
738 fetcher_->Start(); | 742 fetcher_->Start(); |
739 } | 743 } |
740 | 744 |
741 void PostFinishTask(DownloadCheckResult result, | 745 void PostFinishTask(DownloadCheckResult result, |
742 DownloadCheckResultReason reason) { | 746 DownloadCheckResultReason reason) { |
743 BrowserThread::PostTask( | 747 BrowserThread::PostTask( |
744 BrowserThread::UI, | 748 BrowserThread::UI, |
745 FROM_HERE, | 749 FROM_HERE, |
746 base::Bind(&CheckClientDownloadRequest::FinishRequest, this, result, | 750 base::Bind(&CheckClientDownloadRequest::FinishRequest, this, result, |
747 reason)); | 751 reason)); |
748 } | 752 } |
749 | 753 |
750 void FinishRequest(DownloadCheckResult result, | 754 void FinishRequest(DownloadCheckResult result, |
751 DownloadCheckResultReason reason) { | 755 DownloadCheckResultReason reason) { |
752 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 756 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
753 if (finished_) { | 757 if (finished_) { |
754 return; | 758 return; |
755 } | 759 } |
756 finished_ = true; | 760 finished_ = true; |
757 // Ensure the timeout task is cancelled while we still have a non-zero | 761 // Ensure the timeout task is cancelled while we still have a non-zero |
758 // refcount. (crbug.com/240449) | 762 // refcount. (crbug.com/240449) |
759 weakptr_factory_.InvalidateWeakPtrs(); | 763 weakptr_factory_.InvalidateWeakPtrs(); |
| 764 if (!request_start_time_.is_null()) { |
| 765 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.DownloadRequestNetworkStats", |
| 766 reason, |
| 767 REASON_MAX); |
| 768 } |
| 769 if (!timeout_start_time_.is_null()) { |
| 770 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.DownloadRequestTimeoutStats", |
| 771 reason, |
| 772 REASON_MAX); |
| 773 if (reason != REASON_REQUEST_CANCELED) { |
| 774 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestTimeoutDuration", |
| 775 base::TimeTicks::Now() - timeout_start_time_); |
| 776 } |
| 777 } |
760 if (service_) { | 778 if (service_) { |
761 VLOG(2) << "SafeBrowsing download verdict for: " | 779 VLOG(2) << "SafeBrowsing download verdict for: " |
762 << item_->DebugString(true) << " verdict:" << reason; | 780 << item_->DebugString(true) << " verdict:" << reason; |
763 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", | 781 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", |
764 reason, | 782 reason, |
765 REASON_MAX); | 783 REASON_MAX); |
766 callback_.Run(result); | 784 callback_.Run(result); |
767 item_->RemoveObserver(this); | 785 item_->RemoveObserver(this); |
768 item_ = NULL; | 786 item_ = NULL; |
769 DownloadProtectionService* service = service_; | 787 DownloadProtectionService* service = service_; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 const bool pingback_enabled_; | 858 const bool pingback_enabled_; |
841 scoped_ptr<net::URLFetcher> fetcher_; | 859 scoped_ptr<net::URLFetcher> fetcher_; |
842 scoped_refptr<SandboxedZipAnalyzer> analyzer_; | 860 scoped_refptr<SandboxedZipAnalyzer> analyzer_; |
843 base::TimeTicks zip_analysis_start_time_; | 861 base::TimeTicks zip_analysis_start_time_; |
844 bool finished_; | 862 bool finished_; |
845 ClientDownloadRequest::DownloadType type_; | 863 ClientDownloadRequest::DownloadType type_; |
846 std::string client_download_request_data_; | 864 std::string client_download_request_data_; |
847 CancelableRequestConsumer request_consumer_; // For HistoryService lookup. | 865 CancelableRequestConsumer request_consumer_; // For HistoryService lookup. |
848 base::WeakPtrFactory<CheckClientDownloadRequest> weakptr_factory_; | 866 base::WeakPtrFactory<CheckClientDownloadRequest> weakptr_factory_; |
849 base::TimeTicks start_time_; // Used for stats. | 867 base::TimeTicks start_time_; // Used for stats. |
| 868 base::TimeTicks timeout_start_time_; |
| 869 base::TimeTicks request_start_time_; |
850 | 870 |
851 DISALLOW_COPY_AND_ASSIGN(CheckClientDownloadRequest); | 871 DISALLOW_COPY_AND_ASSIGN(CheckClientDownloadRequest); |
852 }; | 872 }; |
853 | 873 |
854 DownloadProtectionService::DownloadProtectionService( | 874 DownloadProtectionService::DownloadProtectionService( |
855 SafeBrowsingService* sb_service, | 875 SafeBrowsingService* sb_service, |
856 net::URLRequestContextGetter* request_context_getter) | 876 net::URLRequestContextGetter* request_context_getter) |
857 : request_context_getter_(request_context_getter), | 877 : request_context_getter_(request_context_getter), |
858 enabled_(false), | 878 enabled_(false), |
859 binary_feature_extractor_(new BinaryFeatureExtractor()), | 879 binary_feature_extractor_(new BinaryFeatureExtractor()), |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1060 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
1041 GURL url(kDownloadRequestUrl); | 1061 GURL url(kDownloadRequestUrl); |
1042 std::string api_key = google_apis::GetAPIKey(); | 1062 std::string api_key = google_apis::GetAPIKey(); |
1043 if (!api_key.empty()) | 1063 if (!api_key.empty()) |
1044 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1064 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
1045 | 1065 |
1046 return url; | 1066 return url; |
1047 } | 1067 } |
1048 | 1068 |
1049 } // namespace safe_browsing | 1069 } // namespace safe_browsing |
OLD | NEW |