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 "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/download/download_create_info.h" |
13 #include "chrome/browser/download/download_manager.h" | 14 #include "chrome/browser/download/download_manager.h" |
14 #include "chrome/browser/history/download_create_info.h" | |
15 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 15 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
18 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 18 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
19 | 19 |
20 // TODO(lzheng): Get rid of the AddRef and Release after | 20 // TODO(lzheng): Get rid of the AddRef and Release after |
21 // SafeBrowsingService::Client is changed to RefCountedThreadSafe<>. | 21 // SafeBrowsingService::Client is changed to RefCountedThreadSafe<>. |
22 | 22 |
23 DownloadSBClient::DownloadSBClient(int32 download_id, | 23 DownloadSBClient::DownloadSBClient(int32 download_id, |
24 const std::vector<GURL>& url_chain, | 24 const std::vector<GURL>& url_chain, |
25 const GURL& referrer_url) | 25 const GURL& referrer_url) |
26 : info_(NULL), | 26 : download_id_(download_id), |
27 download_id_(download_id), | |
28 url_chain_(url_chain), | 27 url_chain_(url_chain), |
29 referrer_url_(referrer_url) { | 28 referrer_url_(referrer_url) { |
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
31 DCHECK(!url_chain.empty()); | 30 DCHECK(!url_chain.empty()); |
32 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); | 31 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); |
33 if (rdh) | 32 if (rdh) |
34 sb_service_ = rdh->safe_browsing_service(); | 33 sb_service_ = rdh->safe_browsing_service(); |
35 } | 34 } |
36 | 35 |
37 DownloadSBClient::~DownloadSBClient() {} | 36 DownloadSBClient::~DownloadSBClient() {} |
38 | 37 |
39 void DownloadSBClient::CheckDownloadUrl(DownloadCreateInfo* info, | 38 void DownloadSBClient::CheckDownloadUrl(UrlDoneCallback* callback) { |
40 UrlDoneCallback* callback) { | |
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
42 // It is not allowed to call this method twice. | 40 // It is not allowed to call this method twice. |
43 CHECK(!url_done_callback_.get() && !hash_done_callback_.get()); | 41 CHECK(!url_done_callback_.get() && !hash_done_callback_.get()); |
44 CHECK(callback); | 42 CHECK(callback); |
45 CHECK(info); | |
46 | 43 |
47 info_ = info; | |
48 start_time_ = base::TimeTicks::Now(); | 44 start_time_ = base::TimeTicks::Now(); |
49 url_done_callback_.reset(callback); | 45 url_done_callback_.reset(callback); |
50 BrowserThread::PostTask( | 46 BrowserThread::PostTask( |
51 BrowserThread::IO, FROM_HERE, | 47 BrowserThread::IO, FROM_HERE, |
52 NewRunnableMethod(this, | 48 NewRunnableMethod(this, |
53 &DownloadSBClient::CheckDownloadUrlOnIOThread, | 49 &DownloadSBClient::CheckDownloadUrlOnIOThread, |
54 info->url_chain)); | 50 url_chain_)); |
55 } | 51 } |
56 | 52 |
57 void DownloadSBClient::CheckDownloadHash(const std::string& hash, | 53 void DownloadSBClient::CheckDownloadHash(const std::string& hash, |
58 HashDoneCallback* callback) { | 54 HashDoneCallback* callback) { |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
60 // It is not allowed to call this method twice. | 56 // It is not allowed to call this method twice. |
61 CHECK(!url_done_callback_.get() && !hash_done_callback_.get()); | 57 CHECK(!url_done_callback_.get() && !hash_done_callback_.get()); |
62 CHECK(callback); | 58 CHECK(callback); |
63 | 59 |
64 start_time_ = base::TimeTicks::Now(); | 60 start_time_ = base::TimeTicks::Now(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 result)); | 114 result)); |
119 Release(); | 115 Release(); |
120 } | 116 } |
121 | 117 |
122 void DownloadSBClient::SafeBrowsingCheckUrlDone( | 118 void DownloadSBClient::SafeBrowsingCheckUrlDone( |
123 SafeBrowsingService::UrlCheckResult result) { | 119 SafeBrowsingService::UrlCheckResult result) { |
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
125 DVLOG(1) << "SafeBrowsingCheckUrlDone with result: " << result; | 121 DVLOG(1) << "SafeBrowsingCheckUrlDone with result: " << result; |
126 | 122 |
127 bool is_dangerous = result != SafeBrowsingService::SAFE; | 123 bool is_dangerous = result != SafeBrowsingService::SAFE; |
128 url_done_callback_->Run(info_, is_dangerous); | 124 url_done_callback_->Run(download_id_, is_dangerous); |
129 | 125 |
130 if (sb_service_.get() && sb_service_->download_protection_enabled()) { | 126 if (sb_service_.get() && sb_service_->download_protection_enabled()) { |
131 UMA_HISTOGRAM_TIMES("SB2.DownloadUrlCheckDuration", | 127 UMA_HISTOGRAM_TIMES("SB2.DownloadUrlCheckDuration", |
132 base::TimeTicks::Now() - start_time_); | 128 base::TimeTicks::Now() - start_time_); |
133 UpdateDownloadCheckStats(DOWNLOAD_URL_CHECKS_TOTAL); | 129 UpdateDownloadCheckStats(DOWNLOAD_URL_CHECKS_TOTAL); |
134 if (is_dangerous) { | 130 if (is_dangerous) { |
135 UpdateDownloadCheckStats(DOWNLOAD_URL_CHECKS_MALWARE); | 131 UpdateDownloadCheckStats(DOWNLOAD_URL_CHECKS_MALWARE); |
136 ReportMalware(result); | 132 ReportMalware(result); |
137 } | 133 } |
138 } | 134 } |
(...skipping 30 matching lines...) Expand all Loading... |
169 true, | 165 true, |
170 result, | 166 result, |
171 post_data); | 167 post_data); |
172 } | 168 } |
173 | 169 |
174 void DownloadSBClient::UpdateDownloadCheckStats(SBStatsType stat_type) { | 170 void DownloadSBClient::UpdateDownloadCheckStats(SBStatsType stat_type) { |
175 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", | 171 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", |
176 stat_type, | 172 stat_type, |
177 DOWNLOAD_CHECKS_MAX); | 173 DOWNLOAD_CHECKS_MAX); |
178 } | 174 } |
OLD | NEW |