Add support for safebrowsing download protection. It is currently under flag --safebrowsing-download-protection.
TEST=safe_browsing_service_browsertest.cc
BUG=60822
Review URL: http://codereview.chromium.org/5141006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69979 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/renderer_host/download_resource_handler.h b/chrome/browser/renderer_host/download_resource_handler.h
index 3fb6961..5a66f662 100644
--- a/chrome/browser/renderer_host/download_resource_handler.h
+++ b/chrome/browser/renderer_host/download_resource_handler.h
@@ -12,6 +12,7 @@
#include "chrome/browser/download/download_file.h"
#include "chrome/browser/renderer_host/global_request_id.h"
#include "chrome/browser/renderer_host/resource_handler.h"
+#include "chrome/browser/safe_browsing/safe_browsing_service.h"
class DownloadFileManager;
class ResourceDispatcherHost;
@@ -22,7 +23,8 @@
} // namespace net
// Forwards data to the download thread.
-class DownloadResourceHandler : public ResourceHandler {
+class DownloadResourceHandler : public ResourceHandler,
+ public SafeBrowsingService::Client {
public:
DownloadResourceHandler(ResourceDispatcherHost* rdh,
int render_process_host_id,
@@ -70,10 +72,31 @@
std::string DebugString() const;
private:
+ // Enumerate for histogramming purposes. DO NOT CHANGE THE
+ // ORDERING OF THESE VALUES.
+ enum SBStatsType {
+ DOWNLOAD_URL_CHECKS_TOTAL,
+ DOWNLOAD_URL_CHECKS_CANCELED,
+ DOWNLOAD_URL_CHECKS_MALWARE,
+
+ // Memory space for histograms is determined by the max. ALWAYS
+ // ADD NEW VALUES BEFORE THIS ONE.
+ DOWNLOAD_URL_CHECKS_MAX
+ };
+
~DownloadResourceHandler();
void StartPauseTimer();
+ void StartDownloadUrlCheck();
+
+ // Called when the result of checking a download URL is known.
+ void OnDownloadUrlCheckResult(const GURL& url,
+ SafeBrowsingService::UrlCheckResult result);
+
+ // A helper function that updates UMA for download url checks.
+ static void UpdateDownloadUrlCheckStats(SBStatsType stat_type);
+
int download_id_;
GlobalRequestID global_id_;
int render_view_id_;
@@ -89,6 +112,8 @@
ResourceDispatcherHost* rdh_;
bool is_paused_;
base::OneShotTimer<DownloadResourceHandler> pause_timer_;
+ bool url_check_pending_;
+ base::TimeTicks download_start_time_; // used to collect stats.
static const int kReadBufSize = 32768; // bytes
static const size_t kLoadsToWrite = 100; // number of data buffers queued