Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service.cc

Issue 303123006: Add SBClientDownload.DownloadRequestNetworkDuration and DownloadRequestTimeoutDuration histograms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review changes Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 << item_->GetUrlChain().back(); 727 << item_->GetUrlChain().back();
727 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */, 728 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */,
728 GetDownloadRequestUrl(), 729 GetDownloadRequestUrl(),
729 net::URLFetcher::POST, 730 net::URLFetcher::POST,
730 this)); 731 this));
731 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); 732 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE);
732 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error. 733 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error.
733 fetcher_->SetRequestContext(service_->request_context_getter_.get()); 734 fetcher_->SetRequestContext(service_->request_context_getter_.get());
734 fetcher_->SetUploadData("application/octet-stream", 735 fetcher_->SetUploadData("application/octet-stream",
735 client_download_request_data_); 736 client_download_request_data_);
737 request_start_time_ = base::TimeTicks::Now();
736 UMA_HISTOGRAM_COUNTS("SBClientDownload.DownloadRequestPayloadSize", 738 UMA_HISTOGRAM_COUNTS("SBClientDownload.DownloadRequestPayloadSize",
737 client_download_request_data_.size()); 739 client_download_request_data_.size());
738 fetcher_->Start(); 740 fetcher_->Start();
739 } 741 }
740 742
741 void PostFinishTask(DownloadCheckResult result, 743 void PostFinishTask(DownloadCheckResult result,
742 DownloadCheckResultReason reason) { 744 DownloadCheckResultReason reason) {
743 BrowserThread::PostTask( 745 BrowserThread::PostTask(
744 BrowserThread::UI, 746 BrowserThread::UI,
745 FROM_HERE, 747 FROM_HERE,
746 base::Bind(&CheckClientDownloadRequest::FinishRequest, this, result, 748 base::Bind(&CheckClientDownloadRequest::FinishRequest, this, result,
747 reason)); 749 reason));
748 } 750 }
749 751
750 void FinishRequest(DownloadCheckResult result, 752 void FinishRequest(DownloadCheckResult result,
751 DownloadCheckResultReason reason) { 753 DownloadCheckResultReason reason) {
752 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
753 if (finished_) { 755 if (finished_) {
754 return; 756 return;
755 } 757 }
756 finished_ = true; 758 finished_ = true;
757 // Ensure the timeout task is cancelled while we still have a non-zero 759 // Ensure the timeout task is cancelled while we still have a non-zero
758 // refcount. (crbug.com/240449) 760 // refcount. (crbug.com/240449)
759 weakptr_factory_.InvalidateWeakPtrs(); 761 weakptr_factory_.InvalidateWeakPtrs();
762 if (!timeout_start_time_.is_null()) {
763 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestTimeoutDuration",
764 base::TimeTicks::Now() - timeout_start_time_);
765 }
766 if (!request_start_time_.is_null()) {
767 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestNetworkDuration",
768 base::TimeTicks::Now() - request_start_time_);
769 }
760 if (service_) { 770 if (service_) {
761 VLOG(2) << "SafeBrowsing download verdict for: " 771 VLOG(2) << "SafeBrowsing download verdict for: "
762 << item_->DebugString(true) << " verdict:" << reason; 772 << item_->DebugString(true) << " verdict:" << reason;
763 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", 773 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats",
764 reason, 774 reason,
765 REASON_MAX); 775 REASON_MAX);
766 callback_.Run(result); 776 callback_.Run(result);
767 item_->RemoveObserver(this); 777 item_->RemoveObserver(this);
768 item_ = NULL; 778 item_ = NULL;
769 DownloadProtectionService* service = service_; 779 DownloadProtectionService* service = service_;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 const bool pingback_enabled_; 850 const bool pingback_enabled_;
841 scoped_ptr<net::URLFetcher> fetcher_; 851 scoped_ptr<net::URLFetcher> fetcher_;
842 scoped_refptr<SandboxedZipAnalyzer> analyzer_; 852 scoped_refptr<SandboxedZipAnalyzer> analyzer_;
843 base::TimeTicks zip_analysis_start_time_; 853 base::TimeTicks zip_analysis_start_time_;
844 bool finished_; 854 bool finished_;
845 ClientDownloadRequest::DownloadType type_; 855 ClientDownloadRequest::DownloadType type_;
846 std::string client_download_request_data_; 856 std::string client_download_request_data_;
847 CancelableRequestConsumer request_consumer_; // For HistoryService lookup. 857 CancelableRequestConsumer request_consumer_; // For HistoryService lookup.
848 base::WeakPtrFactory<CheckClientDownloadRequest> weakptr_factory_; 858 base::WeakPtrFactory<CheckClientDownloadRequest> weakptr_factory_;
849 base::TimeTicks start_time_; // Used for stats. 859 base::TimeTicks start_time_; // Used for stats.
860 base::TimeTicks timeout_start_time_;
861 base::TimeTicks request_start_time_;
850 862
851 DISALLOW_COPY_AND_ASSIGN(CheckClientDownloadRequest); 863 DISALLOW_COPY_AND_ASSIGN(CheckClientDownloadRequest);
852 }; 864 };
853 865
854 DownloadProtectionService::DownloadProtectionService( 866 DownloadProtectionService::DownloadProtectionService(
855 SafeBrowsingService* sb_service, 867 SafeBrowsingService* sb_service,
856 net::URLRequestContextGetter* request_context_getter) 868 net::URLRequestContextGetter* request_context_getter)
857 : request_context_getter_(request_context_getter), 869 : request_context_getter_(request_context_getter),
858 enabled_(false), 870 enabled_(false),
859 binary_feature_extractor_(new BinaryFeatureExtractor()), 871 binary_feature_extractor_(new BinaryFeatureExtractor()),
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 GURL DownloadProtectionService::GetDownloadRequestUrl() { 1052 GURL DownloadProtectionService::GetDownloadRequestUrl() {
1041 GURL url(kDownloadRequestUrl); 1053 GURL url(kDownloadRequestUrl);
1042 std::string api_key = google_apis::GetAPIKey(); 1054 std::string api_key = google_apis::GetAPIKey();
1043 if (!api_key.empty()) 1055 if (!api_key.empty())
1044 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); 1056 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true));
1045 1057
1046 return url; 1058 return url;
1047 } 1059 }
1048 1060
1049 } // namespace safe_browsing 1061 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698