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

Side by Side Diff: chrome/browser/download/download_safe_browsing_client.cc

Issue 7134017: Make safe browsing work in a multi-profile environment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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) 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const std::string& hash, SafeBrowsingService::UrlCheckResult result) { 112 const std::string& hash, SafeBrowsingService::UrlCheckResult result) {
111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
112 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 114 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
113 NewRunnableMethod(this, 115 NewRunnableMethod(this,
114 &DownloadSBClient::SafeBrowsingCheckHashDone, 116 &DownloadSBClient::SafeBrowsingCheckHashDone,
115 result, 117 result,
116 hash)); 118 hash));
117 Release(); 119 Release();
118 } 120 }
119 121
122 // pass in knowledge of can we report stats
120 void DownloadSBClient::SafeBrowsingCheckUrlDone( 123 void DownloadSBClient::SafeBrowsingCheckUrlDone(
121 SafeBrowsingService::UrlCheckResult result) { 124 SafeBrowsingService::UrlCheckResult result) {
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
123 DVLOG(1) << "SafeBrowsingCheckUrlDone with result: " << result; 126 DVLOG(1) << "SafeBrowsingCheckUrlDone with result: " << result;
124 127
125 bool is_dangerous = result != SafeBrowsingService::SAFE; 128 bool is_dangerous = result != SafeBrowsingService::SAFE;
126 url_done_callback_->Run(download_id_, is_dangerous); 129 url_done_callback_->Run(download_id_, is_dangerous);
127 130
128 if (sb_service_.get() && sb_service_->download_protection_enabled()) { 131 if (sb_service_.get() && sb_service_->download_protection_enabled()) {
129 UMA_HISTOGRAM_TIMES("SB2.DownloadUrlCheckDuration", 132 UMA_HISTOGRAM_TIMES("SB2.DownloadUrlCheckDuration",
(...skipping 19 matching lines...) Expand all
149 UMA_HISTOGRAM_TIMES("SB2.DownloadHashCheckDuration", 152 UMA_HISTOGRAM_TIMES("SB2.DownloadHashCheckDuration",
150 base::TimeTicks::Now() - start_time_); 153 base::TimeTicks::Now() - start_time_);
151 UpdateDownloadCheckStats(DOWNLOAD_HASH_CHECKS_TOTAL); 154 UpdateDownloadCheckStats(DOWNLOAD_HASH_CHECKS_TOTAL);
152 if (is_dangerous) { 155 if (is_dangerous) {
153 UpdateDownloadCheckStats(DOWNLOAD_HASH_CHECKS_MALWARE); 156 UpdateDownloadCheckStats(DOWNLOAD_HASH_CHECKS_MALWARE);
154 ReportMalware(result, hash); 157 ReportMalware(result, hash);
155 } 158 }
156 } 159 }
157 } 160 }
158 161
162
159 void DownloadSBClient::ReportMalware( 163 void DownloadSBClient::ReportMalware(
160 SafeBrowsingService::UrlCheckResult result, 164 SafeBrowsingService::UrlCheckResult result,
161 const std::string& hash) { 165 const std::string& hash) {
162 std::string post_data; 166 std::string post_data;
163 if (!hash.empty()) 167 if (!hash.empty())
164 post_data += base::HexEncode(hash.data(), hash.size()) + "\n"; 168 post_data += base::HexEncode(hash.data(), hash.size()) + "\n";
165 for (size_t i = 0; i < url_chain_.size(); ++i) 169 for (size_t i = 0; i < url_chain_.size(); ++i)
166 post_data += url_chain_[i].spec() + "\n"; 170 post_data += url_chain_[i].spec() + "\n";
167 171
168 sb_service_->ReportSafeBrowsingHit(url_chain_.back(), // malicious_url 172 sb_service_->ReportSafeBrowsingHit(url_chain_.back(), // malicious_url
169 url_chain_.front(), // page_url 173 url_chain_.front(), // page_url
170 referrer_url_, 174 referrer_url_,
171 true, // is_subresource 175 true, // is_subresource
172 result, 176 result,
173 post_data); 177 post_data,
178 safe_browsing_enabled_);
174 } 179 }
175 180
176 void DownloadSBClient::UpdateDownloadCheckStats(SBStatsType stat_type) { 181 void DownloadSBClient::UpdateDownloadCheckStats(SBStatsType stat_type) {
177 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", 182 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks",
178 stat_type, 183 stat_type,
179 DOWNLOAD_CHECKS_MAX); 184 DOWNLOAD_CHECKS_MAX);
180 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698