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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_service.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
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/safe_browsing_service.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 SafeBrowsingService* sb_service) 128 SafeBrowsingService* sb_service)
129 : sb_service_(sb_service), 129 : sb_service_(sb_service),
130 network_task_runner_( 130 network_task_runner_(
131 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) { 131 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) {
132 } 132 }
133 133
134 SafeBrowsingURLRequestContextGetter::~SafeBrowsingURLRequestContextGetter() {} 134 SafeBrowsingURLRequestContextGetter::~SafeBrowsingURLRequestContextGetter() {}
135 135
136 net::URLRequestContext* 136 net::URLRequestContext*
137 SafeBrowsingURLRequestContextGetter::GetURLRequestContext() { 137 SafeBrowsingURLRequestContextGetter::GetURLRequestContext() {
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 138 DCHECK_CURRENTLY_ON(BrowserThread::IO);
139 DCHECK(sb_service_->url_request_context_.get()); 139 DCHECK(sb_service_->url_request_context_.get());
140 140
141 return sb_service_->url_request_context_.get(); 141 return sb_service_->url_request_context_.get();
142 } 142 }
143 143
144 scoped_refptr<base::SingleThreadTaskRunner> 144 scoped_refptr<base::SingleThreadTaskRunner>
145 SafeBrowsingURLRequestContextGetter::GetNetworkTaskRunner() const { 145 SafeBrowsingURLRequestContextGetter::GetNetworkTaskRunner() const {
146 return network_task_runner_; 146 return network_task_runner_;
147 } 147 }
148 148
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 url_request_context_getter_ = NULL; 296 url_request_context_getter_ = NULL;
297 BrowserThread::PostNonNestableTask( 297 BrowserThread::PostNonNestableTask(
298 BrowserThread::IO, FROM_HERE, 298 BrowserThread::IO, FROM_HERE,
299 base::Bind(&SafeBrowsingService::DestroyURLRequestContextOnIOThread, 299 base::Bind(&SafeBrowsingService::DestroyURLRequestContextOnIOThread,
300 this)); 300 this));
301 } 301 }
302 302
303 // Binhash verification is only enabled for UMA users for now. 303 // Binhash verification is only enabled for UMA users for now.
304 bool SafeBrowsingService::DownloadBinHashNeeded() const { 304 bool SafeBrowsingService::DownloadBinHashNeeded() const {
305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 305 DCHECK_CURRENTLY_ON(BrowserThread::UI);
306 306
307 #if defined(FULL_SAFE_BROWSING) 307 #if defined(FULL_SAFE_BROWSING)
308 return (database_manager_->download_protection_enabled() && 308 return (database_manager_->download_protection_enabled() &&
309 ui_manager_->CanReportStats()) || 309 ui_manager_->CanReportStats()) ||
310 (download_protection_service() && 310 (download_protection_service() &&
311 download_protection_service()->enabled()); 311 download_protection_service()->enabled());
312 #else 312 #else
313 return false; 313 return false;
314 #endif 314 #endif
315 } 315 }
316 316
317 net::URLRequestContextGetter* SafeBrowsingService::url_request_context() { 317 net::URLRequestContextGetter* SafeBrowsingService::url_request_context() {
318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 318 DCHECK_CURRENTLY_ON(BrowserThread::UI);
319 return url_request_context_getter_.get(); 319 return url_request_context_getter_.get();
320 } 320 }
321 321
322 const scoped_refptr<SafeBrowsingUIManager>& 322 const scoped_refptr<SafeBrowsingUIManager>&
323 SafeBrowsingService::ui_manager() const { 323 SafeBrowsingService::ui_manager() const {
324 return ui_manager_; 324 return ui_manager_;
325 } 325 }
326 326
327 const scoped_refptr<SafeBrowsingDatabaseManager>& 327 const scoped_refptr<SafeBrowsingDatabaseManager>&
328 SafeBrowsingService::database_manager() const { 328 SafeBrowsingService::database_manager() const {
329 return database_manager_; 329 return database_manager_;
330 } 330 }
331 331
332 SafeBrowsingProtocolManager* SafeBrowsingService::protocol_manager() const { 332 SafeBrowsingProtocolManager* SafeBrowsingService::protocol_manager() const {
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 333 DCHECK_CURRENTLY_ON(BrowserThread::IO);
334 return protocol_manager_; 334 return protocol_manager_;
335 } 335 }
336 336
337 SafeBrowsingPingManager* SafeBrowsingService::ping_manager() const { 337 SafeBrowsingPingManager* SafeBrowsingService::ping_manager() const {
338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 338 DCHECK_CURRENTLY_ON(BrowserThread::IO);
339 return ping_manager_; 339 return ping_manager_;
340 } 340 }
341 341
342 scoped_ptr<TrackedPreferenceValidationDelegate> 342 scoped_ptr<TrackedPreferenceValidationDelegate>
343 SafeBrowsingService::CreatePreferenceValidationDelegate( 343 SafeBrowsingService::CreatePreferenceValidationDelegate(
344 Profile* profile) const { 344 Profile* profile) const {
345 #if defined(FULL_SAFE_BROWSING) 345 #if defined(FULL_SAFE_BROWSING)
346 if (incident_service_) 346 if (incident_service_)
347 return incident_service_->CreatePreferenceValidationDelegate(profile); 347 return incident_service_->CreatePreferenceValidationDelegate(profile);
348 #endif 348 #endif
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 NOTREACHED(); 395 NOTREACHED();
396 #endif 396 #endif
397 } 397 }
398 398
399 void SafeBrowsingService::InitURLRequestContextOnIOThread( 399 void SafeBrowsingService::InitURLRequestContextOnIOThread(
400 net::URLRequestContextGetter* system_url_request_context_getter) { 400 net::URLRequestContextGetter* system_url_request_context_getter) {
401 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. 401 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed.
402 tracked_objects::ScopedTracker tracking_profile1( 402 tracked_objects::ScopedTracker tracking_profile1(
403 FROM_HERE_WITH_EXPLICIT_FUNCTION( 403 FROM_HERE_WITH_EXPLICIT_FUNCTION(
404 "455469 SafeBrowsingService::InitURLRequestContextOnIOThread 1")); 404 "455469 SafeBrowsingService::InitURLRequestContextOnIOThread 1"));
405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 405 DCHECK_CURRENTLY_ON(BrowserThread::IO);
406 DCHECK(!url_request_context_.get()); 406 DCHECK(!url_request_context_.get());
407 407
408 scoped_refptr<net::CookieStore> cookie_store( 408 scoped_refptr<net::CookieStore> cookie_store(
409 content::CreateCookieStore( 409 content::CreateCookieStore(
410 content::CookieStoreConfig( 410 content::CookieStoreConfig(
411 CookieFilePath(), 411 CookieFilePath(),
412 content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, 412 content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
413 NULL, 413 NULL,
414 NULL))); 414 NULL)));
415 415
416 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. 416 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed.
417 tracked_objects::ScopedTracker tracking_profile2( 417 tracked_objects::ScopedTracker tracking_profile2(
418 FROM_HERE_WITH_EXPLICIT_FUNCTION( 418 FROM_HERE_WITH_EXPLICIT_FUNCTION(
419 "455469 SafeBrowsingService::InitURLRequestContextOnIOThread 2")); 419 "455469 SafeBrowsingService::InitURLRequestContextOnIOThread 2"));
420 url_request_context_.reset(new net::URLRequestContext); 420 url_request_context_.reset(new net::URLRequestContext);
421 // |system_url_request_context_getter| may be NULL during tests. 421 // |system_url_request_context_getter| may be NULL during tests.
422 if (system_url_request_context_getter) { 422 if (system_url_request_context_getter) {
423 url_request_context_->CopyFrom( 423 url_request_context_->CopyFrom(
424 system_url_request_context_getter->GetURLRequestContext()); 424 system_url_request_context_getter->GetURLRequestContext());
425 } 425 }
426 url_request_context_->set_cookie_store(cookie_store.get()); 426 url_request_context_->set_cookie_store(cookie_store.get());
427 } 427 }
428 428
429 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { 429 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() {
430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 430 DCHECK_CURRENTLY_ON(BrowserThread::IO);
431 431
432 url_request_context_->AssertNoURLRequests(); 432 url_request_context_->AssertNoURLRequests();
433 433
434 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where 434 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where
435 // url_request_context_getter_ is cleared, since the URLRequestContextGetter 435 // url_request_context_getter_ is cleared, since the URLRequestContextGetter
436 // will PostTask to IOTread to delete itself. 436 // will PostTask to IOTread to delete itself.
437 using base::debug::LeakTracker; 437 using base::debug::LeakTracker;
438 LeakTracker<SafeBrowsingURLRequestContextGetter>::CheckForLeaks(); 438 LeakTracker<SafeBrowsingURLRequestContextGetter>::CheckForLeaks();
439 439
440 url_request_context_.reset(); 440 url_request_context_.reset();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 474
475 return config; 475 return config;
476 } 476 }
477 477
478 void SafeBrowsingService::StartOnIOThread( 478 void SafeBrowsingService::StartOnIOThread(
479 net::URLRequestContextGetter* url_request_context_getter) { 479 net::URLRequestContextGetter* url_request_context_getter) {
480 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. 480 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed.
481 tracked_objects::ScopedTracker tracking_profile1( 481 tracked_objects::ScopedTracker tracking_profile1(
482 FROM_HERE_WITH_EXPLICIT_FUNCTION( 482 FROM_HERE_WITH_EXPLICIT_FUNCTION(
483 "455469 SafeBrowsingService::StartOnIOThread 1")); 483 "455469 SafeBrowsingService::StartOnIOThread 1"));
484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 484 DCHECK_CURRENTLY_ON(BrowserThread::IO);
485 if (enabled_) 485 if (enabled_)
486 return; 486 return;
487 enabled_ = true; 487 enabled_ = true;
488 488
489 SafeBrowsingProtocolConfig config = GetProtocolConfig(); 489 SafeBrowsingProtocolConfig config = GetProtocolConfig();
490 490
491 #if defined(SAFE_BROWSING_DB_LOCAL) 491 #if defined(SAFE_BROWSING_DB_LOCAL)
492 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. 492 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed.
493 tracked_objects::ScopedTracker tracking_profile2( 493 tracked_objects::ScopedTracker tracking_profile2(
494 FROM_HERE_WITH_EXPLICIT_FUNCTION( 494 FROM_HERE_WITH_EXPLICIT_FUNCTION(
(...skipping 15 matching lines...) Expand all
510 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. 510 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed.
511 tracked_objects::ScopedTracker tracking_profile4( 511 tracked_objects::ScopedTracker tracking_profile4(
512 FROM_HERE_WITH_EXPLICIT_FUNCTION( 512 FROM_HERE_WITH_EXPLICIT_FUNCTION(
513 "455469 SafeBrowsingService::StartOnIOThread 4")); 513 "455469 SafeBrowsingService::StartOnIOThread 4"));
514 DCHECK(!ping_manager_); 514 DCHECK(!ping_manager_);
515 ping_manager_ = SafeBrowsingPingManager::Create( 515 ping_manager_ = SafeBrowsingPingManager::Create(
516 url_request_context_getter, config); 516 url_request_context_getter, config);
517 } 517 }
518 518
519 void SafeBrowsingService::StopOnIOThread(bool shutdown) { 519 void SafeBrowsingService::StopOnIOThread(bool shutdown) {
520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 520 DCHECK_CURRENTLY_ON(BrowserThread::IO);
521 521
522 #if defined(SAFE_BROWSING_DB_LOCAL) 522 #if defined(SAFE_BROWSING_DB_LOCAL)
523 database_manager_->StopOnIOThread(shutdown); 523 database_manager_->StopOnIOThread(shutdown);
524 #endif 524 #endif
525 ui_manager_->StopOnIOThread(shutdown); 525 ui_manager_->StopOnIOThread(shutdown);
526 526
527 if (enabled_) { 527 if (enabled_) {
528 enabled_ = false; 528 enabled_ = false;
529 529
530 #if defined(SAFE_BROWSING_DB_LOCAL) 530 #if defined(SAFE_BROWSING_DB_LOCAL)
531 // This cancels all in-flight GetHash requests. Note that database_manager_ 531 // This cancels all in-flight GetHash requests. Note that database_manager_
532 // relies on the protocol_manager_ so if the latter is destroyed, the 532 // relies on the protocol_manager_ so if the latter is destroyed, the
533 // former must be stopped. 533 // former must be stopped.
534 delete protocol_manager_; 534 delete protocol_manager_;
535 protocol_manager_ = NULL; 535 protocol_manager_ = NULL;
536 #endif 536 #endif
537 delete ping_manager_; 537 delete ping_manager_;
538 ping_manager_ = NULL; 538 ping_manager_ = NULL;
539 } 539 }
540 } 540 }
541 541
542 void SafeBrowsingService::Start() { 542 void SafeBrowsingService::Start() {
543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 543 DCHECK_CURRENTLY_ON(BrowserThread::UI);
544 544
545 BrowserThread::PostTask( 545 BrowserThread::PostTask(
546 BrowserThread::IO, FROM_HERE, 546 BrowserThread::IO, FROM_HERE,
547 base::Bind(&SafeBrowsingService::StartOnIOThread, this, 547 base::Bind(&SafeBrowsingService::StartOnIOThread, this,
548 url_request_context_getter_)); 548 url_request_context_getter_));
549 } 549 }
550 550
551 void SafeBrowsingService::Stop(bool shutdown) { 551 void SafeBrowsingService::Stop(bool shutdown) {
552 BrowserThread::PostTask( 552 BrowserThread::PostTask(
553 BrowserThread::IO, FROM_HERE, 553 BrowserThread::IO, FROM_HERE,
554 base::Bind(&SafeBrowsingService::StopOnIOThread, this, shutdown)); 554 base::Bind(&SafeBrowsingService::StopOnIOThread, this, shutdown));
555 } 555 }
556 556
557 void SafeBrowsingService::Observe(int type, 557 void SafeBrowsingService::Observe(int type,
558 const content::NotificationSource& source, 558 const content::NotificationSource& source,
559 const content::NotificationDetails& details) { 559 const content::NotificationDetails& details) {
560 switch (type) { 560 switch (type) {
561 case chrome::NOTIFICATION_PROFILE_CREATED: { 561 case chrome::NOTIFICATION_PROFILE_CREATED: {
562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 562 DCHECK_CURRENTLY_ON(BrowserThread::UI);
563 Profile* profile = content::Source<Profile>(source).ptr(); 563 Profile* profile = content::Source<Profile>(source).ptr();
564 if (!profile->IsOffTheRecord()) 564 if (!profile->IsOffTheRecord())
565 AddPrefService(profile->GetPrefs()); 565 AddPrefService(profile->GetPrefs());
566 break; 566 break;
567 } 567 }
568 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 568 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 569 DCHECK_CURRENTLY_ON(BrowserThread::UI);
570 Profile* profile = content::Source<Profile>(source).ptr(); 570 Profile* profile = content::Source<Profile>(source).ptr();
571 if (!profile->IsOffTheRecord()) 571 if (!profile->IsOffTheRecord())
572 RemovePrefService(profile->GetPrefs()); 572 RemovePrefService(profile->GetPrefs());
573 break; 573 break;
574 } 574 }
575 default: 575 default:
576 NOTREACHED(); 576 NOTREACHED();
577 } 577 }
578 } 578 }
579 579
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 else 619 else
620 Stop(false); 620 Stop(false);
621 621
622 #if defined(FULL_SAFE_BROWSING) 622 #if defined(FULL_SAFE_BROWSING)
623 if (csd_service_) 623 if (csd_service_)
624 csd_service_->SetEnabledAndRefreshState(enable); 624 csd_service_->SetEnabledAndRefreshState(enable);
625 if (download_service_) 625 if (download_service_)
626 download_service_->SetEnabled(enable); 626 download_service_->SetEnabled(enable);
627 #endif 627 #endif
628 } 628 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service.h ('k') | chrome/browser/safe_browsing/sandboxed_zip_analyzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698