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

Side by Side Diff: chrome/browser/safe_browsing/ui_manager.cc

Issue 1060033003: [chrome/browser/safe_browsing] favor DCHECK_CURRENTLY_ON for better logs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit test break now Created 5 years, 8 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
« no previous file with comments | « chrome/browser/safe_browsing/sandboxed_zip_analyzer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/safe_browsing/ui_manager.h" 5 #include "chrome/browser/safe_browsing/ui_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/debug/leak_tracker.h" 10 #include "base/debug/leak_tracker.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 SafeBrowsingUIManager::UnsafeResource::~UnsafeResource() { } 51 SafeBrowsingUIManager::UnsafeResource::~UnsafeResource() { }
52 52
53 SafeBrowsingUIManager::SafeBrowsingUIManager( 53 SafeBrowsingUIManager::SafeBrowsingUIManager(
54 const scoped_refptr<SafeBrowsingService>& service) 54 const scoped_refptr<SafeBrowsingService>& service)
55 : sb_service_(service) { 55 : sb_service_(service) {
56 } 56 }
57 57
58 SafeBrowsingUIManager::~SafeBrowsingUIManager() { } 58 SafeBrowsingUIManager::~SafeBrowsingUIManager() { }
59 59
60 void SafeBrowsingUIManager::StopOnIOThread(bool shutdown) { 60 void SafeBrowsingUIManager::StopOnIOThread(bool shutdown) {
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 61 DCHECK_CURRENTLY_ON(BrowserThread::IO);
62 62
63 if (shutdown) 63 if (shutdown)
64 sb_service_ = NULL; 64 sb_service_ = NULL;
65 } 65 }
66 66
67 void SafeBrowsingUIManager::LogPauseDelay(base::TimeDelta time) { 67 void SafeBrowsingUIManager::LogPauseDelay(base::TimeDelta time) {
68 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time); 68 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time);
69 } 69 }
70 70
71 // Only report SafeBrowsing related stats when UMA is enabled. User must also 71 // Only report SafeBrowsing related stats when UMA is enabled. User must also
72 // ensure that safe browsing is enabled from the calling profile. 72 // ensure that safe browsing is enabled from the calling profile.
73 bool SafeBrowsingUIManager::CanReportStats() const { 73 bool SafeBrowsingUIManager::CanReportStats() const {
74 const metrics::MetricsService* metrics = g_browser_process->metrics_service(); 74 const metrics::MetricsService* metrics = g_browser_process->metrics_service();
75 return metrics && metrics->reporting_active(); 75 return metrics && metrics->reporting_active();
76 } 76 }
77 77
78 void SafeBrowsingUIManager::OnBlockingPageDone( 78 void SafeBrowsingUIManager::OnBlockingPageDone(
79 const std::vector<UnsafeResource>& resources, 79 const std::vector<UnsafeResource>& resources,
80 bool proceed) { 80 bool proceed) {
81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 81 DCHECK_CURRENTLY_ON(BrowserThread::IO);
82 for (std::vector<UnsafeResource>::const_iterator iter = resources.begin(); 82 for (std::vector<UnsafeResource>::const_iterator iter = resources.begin();
83 iter != resources.end(); ++iter) { 83 iter != resources.end(); ++iter) {
84 const UnsafeResource& resource = *iter; 84 const UnsafeResource& resource = *iter;
85 if (!resource.callback.is_null()) 85 if (!resource.callback.is_null())
86 resource.callback.Run(proceed); 86 resource.callback.Run(proceed);
87 87
88 if (proceed) { 88 if (proceed) {
89 BrowserThread::PostTask( 89 BrowserThread::PostTask(
90 BrowserThread::UI, 90 BrowserThread::UI,
91 FROM_HERE, 91 FROM_HERE,
92 base::Bind(&SafeBrowsingUIManager::UpdateWhitelist, this, resource)); 92 base::Bind(&SafeBrowsingUIManager::UpdateWhitelist, this, resource));
93 } 93 }
94 } 94 }
95 } 95 }
96 96
97 void SafeBrowsingUIManager::DisplayBlockingPage( 97 void SafeBrowsingUIManager::DisplayBlockingPage(
98 const UnsafeResource& resource) { 98 const UnsafeResource& resource) {
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 99 DCHECK_CURRENTLY_ON(BrowserThread::UI);
100 if (resource.is_subresource && !resource.is_subframe) { 100 if (resource.is_subresource && !resource.is_subframe) {
101 // Sites tagged as serving Unwanted Software should only show a warning for 101 // Sites tagged as serving Unwanted Software should only show a warning for
102 // main-frame or sub-frame resource. Similar warning restrictions should be 102 // main-frame or sub-frame resource. Similar warning restrictions should be
103 // applied to malware sites tagged as "landing sites" (see "Types of 103 // applied to malware sites tagged as "landing sites" (see "Types of
104 // Malware sites" under 104 // Malware sites" under
105 // https://developers.google.com/safe-browsing/developers_guide_v3#UserWarni ngs). 105 // https://developers.google.com/safe-browsing/developers_guide_v3#UserWarni ngs).
106 safe_browsing::MalwarePatternType proto; 106 safe_browsing::MalwarePatternType proto;
107 if (resource.threat_type == SB_THREAT_TYPE_URL_UNWANTED || 107 if (resource.threat_type == SB_THREAT_TYPE_URL_UNWANTED ||
108 (resource.threat_type == SB_THREAT_TYPE_URL_MALWARE && 108 (resource.threat_type == SB_THREAT_TYPE_URL_MALWARE &&
109 !resource.threat_metadata.empty() && 109 !resource.threat_metadata.empty() &&
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 // A safebrowsing hit is sent after a blocking page for malware/phishing 197 // A safebrowsing hit is sent after a blocking page for malware/phishing
198 // or after the warning dialog for download urls, only for UMA users. 198 // or after the warning dialog for download urls, only for UMA users.
199 void SafeBrowsingUIManager::ReportSafeBrowsingHit( 199 void SafeBrowsingUIManager::ReportSafeBrowsingHit(
200 const GURL& malicious_url, 200 const GURL& malicious_url,
201 const GURL& page_url, 201 const GURL& page_url,
202 const GURL& referrer_url, 202 const GURL& referrer_url,
203 bool is_subresource, 203 bool is_subresource,
204 SBThreatType threat_type, 204 SBThreatType threat_type,
205 const std::string& post_data) { 205 const std::string& post_data) {
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 206 DCHECK_CURRENTLY_ON(BrowserThread::UI);
207 if (!CanReportStats()) 207 if (!CanReportStats())
208 return; 208 return;
209 209
210 BrowserThread::PostTask( 210 BrowserThread::PostTask(
211 BrowserThread::IO, FROM_HERE, 211 BrowserThread::IO, FROM_HERE,
212 base::Bind(&SafeBrowsingUIManager::ReportSafeBrowsingHitOnIOThread, this, 212 base::Bind(&SafeBrowsingUIManager::ReportSafeBrowsingHitOnIOThread, this,
213 malicious_url, page_url, referrer_url, is_subresource, 213 malicious_url, page_url, referrer_url, is_subresource,
214 threat_type, post_data)); 214 threat_type, post_data));
215 } 215 }
216 216
217 void SafeBrowsingUIManager::ReportInvalidCertificateChain( 217 void SafeBrowsingUIManager::ReportInvalidCertificateChain(
218 const std::string& hostname, 218 const std::string& hostname,
219 const net::SSLInfo& ssl_info, 219 const net::SSLInfo& ssl_info,
220 const base::Closure& callback) { 220 const base::Closure& callback) {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 221 DCHECK_CURRENTLY_ON(BrowserThread::UI);
222 BrowserThread::PostTaskAndReply( 222 BrowserThread::PostTaskAndReply(
223 BrowserThread::IO, FROM_HERE, 223 BrowserThread::IO, FROM_HERE,
224 base::Bind( 224 base::Bind(
225 &SafeBrowsingUIManager::ReportInvalidCertificateChainOnIOThread, this, 225 &SafeBrowsingUIManager::ReportInvalidCertificateChainOnIOThread, this,
226 hostname, ssl_info), 226 hostname, ssl_info),
227 callback); 227 callback);
228 } 228 }
229 229
230 void SafeBrowsingUIManager::AddObserver(Observer* observer) { 230 void SafeBrowsingUIManager::AddObserver(Observer* observer) {
231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 231 DCHECK_CURRENTLY_ON(BrowserThread::UI);
232 observer_list_.AddObserver(observer); 232 observer_list_.AddObserver(observer);
233 } 233 }
234 234
235 void SafeBrowsingUIManager::RemoveObserver(Observer* observer) { 235 void SafeBrowsingUIManager::RemoveObserver(Observer* observer) {
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 236 DCHECK_CURRENTLY_ON(BrowserThread::UI);
237 observer_list_.RemoveObserver(observer); 237 observer_list_.RemoveObserver(observer);
238 } 238 }
239 239
240 void SafeBrowsingUIManager::ReportSafeBrowsingHitOnIOThread( 240 void SafeBrowsingUIManager::ReportSafeBrowsingHitOnIOThread(
241 const GURL& malicious_url, 241 const GURL& malicious_url,
242 const GURL& page_url, 242 const GURL& page_url,
243 const GURL& referrer_url, 243 const GURL& referrer_url,
244 bool is_subresource, 244 bool is_subresource,
245 SBThreatType threat_type, 245 SBThreatType threat_type,
246 const std::string& post_data) { 246 const std::string& post_data) {
247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 247 DCHECK_CURRENTLY_ON(BrowserThread::IO);
248 248
249 // The service may delete the ping manager (i.e. when user disabling service, 249 // The service may delete the ping manager (i.e. when user disabling service,
250 // etc). This happens on the IO thread. 250 // etc). This happens on the IO thread.
251 if (sb_service_.get() == NULL || sb_service_->ping_manager() == NULL) 251 if (sb_service_.get() == NULL || sb_service_->ping_manager() == NULL)
252 return; 252 return;
253 253
254 DVLOG(1) << "ReportSafeBrowsingHit: " << malicious_url << " " << page_url 254 DVLOG(1) << "ReportSafeBrowsingHit: " << malicious_url << " " << page_url
255 << " " << referrer_url << " " << is_subresource << " " 255 << " " << referrer_url << " " << is_subresource << " "
256 << threat_type; 256 << threat_type;
257 sb_service_->ping_manager()->ReportSafeBrowsingHit( 257 sb_service_->ping_manager()->ReportSafeBrowsingHit(
258 malicious_url, page_url, 258 malicious_url, page_url,
259 referrer_url, is_subresource, 259 referrer_url, is_subresource,
260 threat_type, post_data); 260 threat_type, post_data);
261 } 261 }
262 262
263 void SafeBrowsingUIManager::ReportInvalidCertificateChainOnIOThread( 263 void SafeBrowsingUIManager::ReportInvalidCertificateChainOnIOThread(
264 const std::string& hostname, 264 const std::string& hostname,
265 const net::SSLInfo& ssl_info) { 265 const net::SSLInfo& ssl_info) {
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 266 DCHECK_CURRENTLY_ON(BrowserThread::IO);
267 267
268 // The service may delete the ping manager (i.e. when user disabling service, 268 // The service may delete the ping manager (i.e. when user disabling service,
269 // etc). This happens on the IO thread. 269 // etc). This happens on the IO thread.
270 if (!sb_service_ || !sb_service_->ping_manager()) 270 if (!sb_service_ || !sb_service_->ping_manager())
271 return; 271 return;
272 272
273 sb_service_->ping_manager()->ReportInvalidCertificateChain(hostname, 273 sb_service_->ping_manager()->ReportInvalidCertificateChain(hostname,
274 ssl_info); 274 ssl_info);
275 } 275 }
276 276
277 // If the user had opted-in to send MalwareDetails, this gets called 277 // If the user had opted-in to send MalwareDetails, this gets called
278 // when the report is ready. 278 // when the report is ready.
279 void SafeBrowsingUIManager::SendSerializedMalwareDetails( 279 void SafeBrowsingUIManager::SendSerializedMalwareDetails(
280 const std::string& serialized) { 280 const std::string& serialized) {
281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 281 DCHECK_CURRENTLY_ON(BrowserThread::IO);
282 282
283 // The service may delete the ping manager (i.e. when user disabling service, 283 // The service may delete the ping manager (i.e. when user disabling service,
284 // etc). This happens on the IO thread. 284 // etc). This happens on the IO thread.
285 if (sb_service_.get() == NULL || sb_service_->ping_manager() == NULL) 285 if (sb_service_.get() == NULL || sb_service_->ping_manager() == NULL)
286 return; 286 return;
287 287
288 if (!serialized.empty()) { 288 if (!serialized.empty()) {
289 DVLOG(1) << "Sending serialized malware details."; 289 DVLOG(1) << "Sending serialized malware details.";
290 sb_service_->ping_manager()->ReportMalwareDetails(serialized); 290 sb_service_->ping_manager()->ReportMalwareDetails(serialized);
291 } 291 }
292 } 292 }
293 293
294 void SafeBrowsingUIManager::UpdateWhitelist(const UnsafeResource& resource) { 294 void SafeBrowsingUIManager::UpdateWhitelist(const UnsafeResource& resource) {
295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 295 DCHECK_CURRENTLY_ON(BrowserThread::UI);
296 // Whitelist this domain and warning type for the given tab. 296 // Whitelist this domain and warning type for the given tab.
297 WhiteListedEntry entry; 297 WhiteListedEntry entry;
298 entry.render_process_host_id = resource.render_process_host_id; 298 entry.render_process_host_id = resource.render_process_host_id;
299 entry.render_view_id = resource.render_view_id; 299 entry.render_view_id = resource.render_view_id;
300 entry.domain = net::registry_controlled_domains::GetDomainAndRegistry( 300 entry.domain = net::registry_controlled_domains::GetDomainAndRegistry(
301 resource.url, 301 resource.url,
302 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); 302 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
303 entry.threat_type = resource.threat_type; 303 entry.threat_type = resource.threat_type;
304 white_listed_entries_.push_back(entry); 304 white_listed_entries_.push_back(entry);
305 } 305 }
306 306
307 bool SafeBrowsingUIManager::IsWhitelisted(const UnsafeResource& resource) { 307 bool SafeBrowsingUIManager::IsWhitelisted(const UnsafeResource& resource) {
308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 308 DCHECK_CURRENTLY_ON(BrowserThread::UI);
309 // Check if the user has already ignored our warning for this render_view 309 // Check if the user has already ignored our warning for this render_view
310 // and domain. 310 // and domain.
311 for (size_t i = 0; i < white_listed_entries_.size(); ++i) { 311 for (size_t i = 0; i < white_listed_entries_.size(); ++i) {
312 const WhiteListedEntry& entry = white_listed_entries_[i]; 312 const WhiteListedEntry& entry = white_listed_entries_[i];
313 if (entry.render_process_host_id == resource.render_process_host_id && 313 if (entry.render_process_host_id == resource.render_process_host_id &&
314 entry.render_view_id == resource.render_view_id && 314 entry.render_view_id == resource.render_view_id &&
315 // Threat type must be the same or they can either be client-side 315 // Threat type must be the same or they can either be client-side
316 // phishing/malware URL or a SafeBrowsing phishing/malware URL. 316 // phishing/malware URL or a SafeBrowsing phishing/malware URL.
317 // If we show one type of phishing/malware warning we don't want to show 317 // If we show one type of phishing/malware warning we don't want to show
318 // a second phishing/malware warning. 318 // a second phishing/malware warning.
319 (entry.threat_type == resource.threat_type || 319 (entry.threat_type == resource.threat_type ||
320 (entry.threat_type == SB_THREAT_TYPE_URL_PHISHING && 320 (entry.threat_type == SB_THREAT_TYPE_URL_PHISHING &&
321 resource.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) || 321 resource.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) ||
322 (entry.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL && 322 (entry.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL &&
323 resource.threat_type == SB_THREAT_TYPE_URL_PHISHING) || 323 resource.threat_type == SB_THREAT_TYPE_URL_PHISHING) ||
324 (entry.threat_type == SB_THREAT_TYPE_URL_MALWARE && 324 (entry.threat_type == SB_THREAT_TYPE_URL_MALWARE &&
325 resource.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) || 325 resource.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) ||
326 (entry.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL && 326 (entry.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL &&
327 resource.threat_type == SB_THREAT_TYPE_URL_MALWARE))) { 327 resource.threat_type == SB_THREAT_TYPE_URL_MALWARE))) {
328 return entry.domain == 328 return entry.domain ==
329 net::registry_controlled_domains::GetDomainAndRegistry( 329 net::registry_controlled_domains::GetDomainAndRegistry(
330 resource.url, 330 resource.url,
331 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); 331 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
332 } 332 }
333 } 333 }
334 return false; 334 return false;
335 } 335 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/sandboxed_zip_analyzer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698