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 (sb_service_.get() && !sb_service_->CheckDownloadUrl(url_chain, this)) { |
mattm
2011/06/23 01:24:25
Should be checking safe_browsing_enabled_ here.
Miranda Callahan
2011/06/23 14:05:26
Done.
| |
77 // Wait for SafeBrowsingService to call back OnDownloadUrlCheckResult. | 79 // Wait for SafeBrowsingService to call back OnDownloadUrlCheckResult. |
78 return; | 80 return; |
79 } | 81 } |
80 OnDownloadUrlCheckResult(url_chain, SafeBrowsingService::SAFE); | 82 OnDownloadUrlCheckResult(url_chain, SafeBrowsingService::SAFE); |
81 } | 83 } |
82 | 84 |
83 // The callback interface for SafeBrowsingService::Client. | 85 // The callback interface for SafeBrowsingService::Client. |
84 // Called when the result of checking a download URL is known. | 86 // Called when the result of checking a download URL is known. |
85 void DownloadSBClient::OnDownloadUrlCheckResult( | 87 void DownloadSBClient::OnDownloadUrlCheckResult( |
86 const std::vector<GURL>& url_chain, | 88 const std::vector<GURL>& url_chain, |
87 SafeBrowsingService::UrlCheckResult result) { | 89 SafeBrowsingService::UrlCheckResult result) { |
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
89 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 91 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
90 NewRunnableMethod(this, | 92 NewRunnableMethod(this, |
91 &DownloadSBClient::SafeBrowsingCheckUrlDone, | 93 &DownloadSBClient::SafeBrowsingCheckUrlDone, |
92 result)); | 94 result)); |
93 Release(); | 95 Release(); |
94 } | 96 } |
95 | 97 |
96 void DownloadSBClient::CheckDownloadHashOnIOThread(const std::string& hash) { | 98 void DownloadSBClient::CheckDownloadHashOnIOThread(const std::string& hash) { |
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
98 // Will be released in OnDownloadUrlCheckResult. | 100 // Will be released in OnDownloadUrlCheckResult. |
99 AddRef(); | 101 AddRef(); |
100 if (sb_service_.get() && !sb_service_->CheckDownloadHash(hash, this)) { | 102 if (sb_service_.get() && !sb_service_->CheckDownloadHash(hash, this)) { |
mattm
2011/06/23 01:24:25
And here.
Miranda Callahan
2011/06/23 14:05:26
Done.
| |
101 // Wait for SafeBrowsingService to call back OnDownloadUrlCheckResult. | 103 // Wait for SafeBrowsingService to call back OnDownloadUrlCheckResult. |
102 return; | 104 return; |
103 } | 105 } |
104 OnDownloadHashCheckResult(hash, SafeBrowsingService::SAFE); | 106 OnDownloadHashCheckResult(hash, SafeBrowsingService::SAFE); |
105 } | 107 } |
106 | 108 |
107 // The callback interface for SafeBrowsingService::Client. | 109 // The callback interface for SafeBrowsingService::Client. |
108 // Called when the result of checking a download URL is known. | 110 // Called when the result of checking a download URL is known. |
109 void DownloadSBClient::OnDownloadHashCheckResult( | 111 void DownloadSBClient::OnDownloadHashCheckResult( |
110 const std::string& hash, SafeBrowsingService::UrlCheckResult result) { | 112 const std::string& hash, SafeBrowsingService::UrlCheckResult result) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 if (!hash.empty()) | 165 if (!hash.empty()) |
164 post_data += base::HexEncode(hash.data(), hash.size()) + "\n"; | 166 post_data += base::HexEncode(hash.data(), hash.size()) + "\n"; |
165 for (size_t i = 0; i < url_chain_.size(); ++i) | 167 for (size_t i = 0; i < url_chain_.size(); ++i) |
166 post_data += url_chain_[i].spec() + "\n"; | 168 post_data += url_chain_[i].spec() + "\n"; |
167 | 169 |
168 sb_service_->ReportSafeBrowsingHit(url_chain_.back(), // malicious_url | 170 sb_service_->ReportSafeBrowsingHit(url_chain_.back(), // malicious_url |
169 url_chain_.front(), // page_url | 171 url_chain_.front(), // page_url |
170 referrer_url_, | 172 referrer_url_, |
171 true, // is_subresource | 173 true, // is_subresource |
172 result, | 174 result, |
173 post_data); | 175 post_data, |
176 safe_browsing_enabled_); | |
174 } | 177 } |
175 | 178 |
176 void DownloadSBClient::UpdateDownloadCheckStats(SBStatsType stat_type) { | 179 void DownloadSBClient::UpdateDownloadCheckStats(SBStatsType stat_type) { |
177 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", | 180 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", |
178 stat_type, | 181 stat_type, |
179 DOWNLOAD_CHECKS_MAX); | 182 DOWNLOAD_CHECKS_MAX); |
180 } | 183 } |
OLD | NEW |