OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 5 |
6 #include "chrome/browser/download/download_safe_browsing_client.h" | 6 #include "chrome/browser/download/download_safe_browsing_client.h" |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/metrics/stats_counters.h" | 11 #include "base/metrics/stats_counters.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/download/download_create_info.h" | 14 #include "chrome/browser/download/download_create_info.h" |
15 #include "chrome/browser/download/download_manager.h" | 15 #include "chrome/browser/download/download_manager.h" |
16 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 16 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "content/browser/browser_thread.h" | 18 #include "content/browser/browser_thread.h" |
19 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 19 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
20 | 20 |
21 // TODO(lzheng): Get rid of the AddRef and Release after | 21 // TODO(lzheng): Get rid of the AddRef and Release after |
22 // SafeBrowsingService::Client is changed to RefCountedThreadSafe<>. | 22 // SafeBrowsingService::Client is changed to RefCountedThreadSafe<>. |
23 | 23 |
24 DownloadSBClient::DownloadSBClient(int32 download_id, | 24 DownloadSBClient::DownloadSBClient(int32 download_id, |
25 const std::vector<GURL>& url_chain, | 25 const std::vector<GURL>& url_chain, |
26 const GURL& referrer_url) | 26 const GURL& referrer_url, |
| 27 bool safe_browsing_enabled) |
27 : download_id_(download_id), | 28 : download_id_(download_id), |
28 url_chain_(url_chain), | 29 url_chain_(url_chain), |
29 referrer_url_(referrer_url) { | 30 referrer_url_(referrer_url), |
| 31 safe_browsing_enabled_(safe_browsing_enabled) { |
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
31 DCHECK(!url_chain.empty()); | 33 DCHECK(!url_chain.empty()); |
32 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); | 34 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); |
33 if (rdh) | 35 if (rdh) |
34 sb_service_ = g_browser_process->safe_browsing_service(); | 36 sb_service_ = g_browser_process->safe_browsing_service(); |
35 } | 37 } |
36 | 38 |
37 DownloadSBClient::~DownloadSBClient() {} | 39 DownloadSBClient::~DownloadSBClient() {} |
38 | 40 |
39 void DownloadSBClient::CheckDownloadUrl(UrlDoneCallback* callback) { | 41 void DownloadSBClient::CheckDownloadUrl(UrlDoneCallback* callback) { |
(...skipping 26 matching lines...) Expand all Loading... |
66 &DownloadSBClient::CheckDownloadHashOnIOThread, | 68 &DownloadSBClient::CheckDownloadHashOnIOThread, |
67 hash)); | 69 hash)); |
68 } | 70 } |
69 | 71 |
70 void DownloadSBClient::CheckDownloadUrlOnIOThread( | 72 void DownloadSBClient::CheckDownloadUrlOnIOThread( |
71 const std::vector<GURL>& url_chain) { | 73 const std::vector<GURL>& url_chain) { |
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
73 | 75 |
74 // Will be released in OnDownloadUrlCheckResult. | 76 // Will be released in OnDownloadUrlCheckResult. |
75 AddRef(); | 77 AddRef(); |
76 if (sb_service_.get() && !sb_service_->CheckDownloadUrl(url_chain, this)) { | 78 if (safe_browsing_enabled_ && sb_service_.get() && |
| 79 !sb_service_->CheckDownloadUrl(url_chain, this)) { |
77 // Wait for SafeBrowsingService to call back OnDownloadUrlCheckResult. | 80 // Wait for SafeBrowsingService to call back OnDownloadUrlCheckResult. |
78 return; | 81 return; |
79 } | 82 } |
80 OnDownloadUrlCheckResult(url_chain, SafeBrowsingService::SAFE); | 83 OnDownloadUrlCheckResult(url_chain, SafeBrowsingService::SAFE); |
81 } | 84 } |
82 | 85 |
83 // The callback interface for SafeBrowsingService::Client. | 86 // The callback interface for SafeBrowsingService::Client. |
84 // Called when the result of checking a download URL is known. | 87 // Called when the result of checking a download URL is known. |
85 void DownloadSBClient::OnDownloadUrlCheckResult( | 88 void DownloadSBClient::OnDownloadUrlCheckResult( |
86 const std::vector<GURL>& url_chain, | 89 const std::vector<GURL>& url_chain, |
87 SafeBrowsingService::UrlCheckResult result) { | 90 SafeBrowsingService::UrlCheckResult result) { |
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
89 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 92 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
90 NewRunnableMethod(this, | 93 NewRunnableMethod(this, |
91 &DownloadSBClient::SafeBrowsingCheckUrlDone, | 94 &DownloadSBClient::SafeBrowsingCheckUrlDone, |
92 result)); | 95 result)); |
93 Release(); | 96 Release(); |
94 } | 97 } |
95 | 98 |
96 void DownloadSBClient::CheckDownloadHashOnIOThread(const std::string& hash) { | 99 void DownloadSBClient::CheckDownloadHashOnIOThread(const std::string& hash) { |
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
98 // Will be released in OnDownloadUrlCheckResult. | 101 // Will be released in OnDownloadUrlCheckResult. |
99 AddRef(); | 102 AddRef(); |
100 if (sb_service_.get() && !sb_service_->CheckDownloadHash(hash, this)) { | 103 if (safe_browsing_enabled_ && sb_service_.get() && |
| 104 !sb_service_->CheckDownloadHash(hash, this)) { |
101 // Wait for SafeBrowsingService to call back OnDownloadUrlCheckResult. | 105 // Wait for SafeBrowsingService to call back OnDownloadUrlCheckResult. |
102 return; | 106 return; |
103 } | 107 } |
104 OnDownloadHashCheckResult(hash, SafeBrowsingService::SAFE); | 108 OnDownloadHashCheckResult(hash, SafeBrowsingService::SAFE); |
105 } | 109 } |
106 | 110 |
107 // The callback interface for SafeBrowsingService::Client. | 111 // The callback interface for SafeBrowsingService::Client. |
108 // Called when the result of checking a download URL is known. | 112 // Called when the result of checking a download URL is known. |
109 void DownloadSBClient::OnDownloadHashCheckResult( | 113 void DownloadSBClient::OnDownloadHashCheckResult( |
110 const std::string& hash, SafeBrowsingService::UrlCheckResult result) { | 114 const std::string& hash, SafeBrowsingService::UrlCheckResult result) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 true, // is_subresource | 175 true, // is_subresource |
172 result, | 176 result, |
173 post_data); | 177 post_data); |
174 } | 178 } |
175 | 179 |
176 void DownloadSBClient::UpdateDownloadCheckStats(SBStatsType stat_type) { | 180 void DownloadSBClient::UpdateDownloadCheckStats(SBStatsType stat_type) { |
177 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", | 181 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", |
178 stat_type, | 182 stat_type, |
179 DOWNLOAD_CHECKS_MAX); | 183 DOWNLOAD_CHECKS_MAX); |
180 } | 184 } |
OLD | NEW |