| OLD | NEW |
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
| 46 #include "net/cookies/cookie_monster.h" | 46 #include "net/cookies/cookie_monster.h" |
| 47 #include "net/extras/sqlite/cookie_crypto_delegate.h" | 47 #include "net/extras/sqlite/cookie_crypto_delegate.h" |
| 48 #include "net/url_request/url_request_context.h" | 48 #include "net/url_request/url_request_context.h" |
| 49 #include "net/url_request/url_request_context_getter.h" | 49 #include "net/url_request/url_request_context_getter.h" |
| 50 | 50 |
| 51 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
| 52 #include "chrome/installer/util/browser_distribution.h" | 52 #include "chrome/installer/util/browser_distribution.h" |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 56 #include "chrome/browser/safe_browsing/local_database_manager.h" |
| 57 #elif defined(SAFE_BROWSING_DB_REMOTE) |
| 58 #include "chrome/browser/safe_browsing/remote_database_manager.h" |
| 59 #endif |
| 60 |
| 55 #if defined(FULL_SAFE_BROWSING) | 61 #if defined(FULL_SAFE_BROWSING) |
| 56 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_analy
zer.h" | 62 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_analy
zer.h" |
| 57 #include "chrome/browser/safe_browsing/incident_reporting/blacklist_load_analyze
r.h" | 63 #include "chrome/browser/safe_browsing/incident_reporting/blacklist_load_analyze
r.h" |
| 58 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" | 64 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" |
| 59 #include "chrome/browser/safe_browsing/incident_reporting/off_domain_inclusion_d
etector.h" | 65 #include "chrome/browser/safe_browsing/incident_reporting/off_domain_inclusion_d
etector.h" |
| 60 #include "chrome/browser/safe_browsing/incident_reporting/resource_request_detec
tor.h" | 66 #include "chrome/browser/safe_browsing/incident_reporting/resource_request_detec
tor.h" |
| 61 #include "chrome/browser/safe_browsing/incident_reporting/variations_seed_signat
ure_analyzer.h" | 67 #include "chrome/browser/safe_browsing/incident_reporting/variations_seed_signat
ure_analyzer.h" |
| 62 #endif | 68 #endif |
| 63 | 69 |
| 64 using content::BrowserThread; | 70 using content::BrowserThread; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 243 |
| 238 if (IsIncidentReportingServiceEnabled()) { | 244 if (IsIncidentReportingServiceEnabled()) { |
| 239 incident_service_.reset(new safe_browsing::IncidentReportingService( | 245 incident_service_.reset(new safe_browsing::IncidentReportingService( |
| 240 this, url_request_context_getter_)); | 246 this, url_request_context_getter_)); |
| 241 resource_request_detector_.reset(new safe_browsing::ResourceRequestDetector( | 247 resource_request_detector_.reset(new safe_browsing::ResourceRequestDetector( |
| 242 incident_service_->GetIncidentReceiver())); | 248 incident_service_->GetIncidentReceiver())); |
| 243 } | 249 } |
| 244 | 250 |
| 245 off_domain_inclusion_detector_.reset( | 251 off_domain_inclusion_detector_.reset( |
| 246 new safe_browsing::OffDomainInclusionDetector(database_manager_)); | 252 new safe_browsing::OffDomainInclusionDetector(database_manager_)); |
| 247 #endif // !defined(OS_ANDROID) | 253 #endif // !defined(FULL_SAFE_BROWSING) |
| 248 | 254 |
| 249 // Track the safe browsing preference of existing profiles. | 255 // Track the safe browsing preference of existing profiles. |
| 250 // The SafeBrowsingService will be started if any existing profile has the | 256 // The SafeBrowsingService will be started if any existing profile has the |
| 251 // preference enabled. It will also listen for updates to the preferences. | 257 // preference enabled. It will also listen for updates to the preferences. |
| 252 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 258 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 253 if (profile_manager) { | 259 if (profile_manager) { |
| 254 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 260 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| 255 for (size_t i = 0; i < profiles.size(); ++i) { | 261 for (size_t i = 0; i < profiles.size(); ++i) { |
| 256 if (profiles[i]->IsOffTheRecord()) | 262 if (profiles[i]->IsOffTheRecord()) |
| 257 continue; | 263 continue; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 resource_request_detector_->OnResourceRequest(request); | 379 resource_request_detector_->OnResourceRequest(request); |
| 374 #endif | 380 #endif |
| 375 } | 381 } |
| 376 | 382 |
| 377 SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() { | 383 SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() { |
| 378 return new SafeBrowsingUIManager(this); | 384 return new SafeBrowsingUIManager(this); |
| 379 } | 385 } |
| 380 | 386 |
| 381 SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() { | 387 SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() { |
| 382 #if defined(SAFE_BROWSING_DB_LOCAL) | 388 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 383 return new SafeBrowsingDatabaseManager(this); | 389 return new LocalSafeBrowsingDatabaseManager(this); |
| 390 #elif defined(SAFE_BROWSING_DB_REMOTE) |
| 391 return new RemoteSafeBrowsingDatabaseManager(); |
| 384 #else | 392 #else |
| 385 return NULL; | 393 return NULL; |
| 386 #endif | 394 #endif |
| 387 } | 395 } |
| 388 | 396 |
| 389 void SafeBrowsingService::RegisterAllDelayedAnalysis() { | 397 void SafeBrowsingService::RegisterAllDelayedAnalysis() { |
| 390 #if defined(FULL_SAFE_BROWSING) | 398 #if defined(FULL_SAFE_BROWSING) |
| 391 safe_browsing::RegisterBinaryIntegrityAnalysis(); | 399 safe_browsing::RegisterBinaryIntegrityAnalysis(); |
| 392 safe_browsing::RegisterBlacklistLoadAnalysis(); | 400 safe_browsing::RegisterBlacklistLoadAnalysis(); |
| 393 safe_browsing::RegisterVariationsSeedSignatureAnalysis(); | 401 safe_browsing::RegisterVariationsSeedSignatureAnalysis(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 tracked_objects::ScopedTracker tracking_profile1( | 489 tracked_objects::ScopedTracker tracking_profile1( |
| 482 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 490 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 483 "455469 SafeBrowsingService::StartOnIOThread 1")); | 491 "455469 SafeBrowsingService::StartOnIOThread 1")); |
| 484 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 492 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 485 if (enabled_) | 493 if (enabled_) |
| 486 return; | 494 return; |
| 487 enabled_ = true; | 495 enabled_ = true; |
| 488 | 496 |
| 489 SafeBrowsingProtocolConfig config = GetProtocolConfig(); | 497 SafeBrowsingProtocolConfig config = GetProtocolConfig(); |
| 490 | 498 |
| 491 #if defined(SAFE_BROWSING_DB_LOCAL) | 499 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) |
| 492 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. | 500 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. |
| 493 tracked_objects::ScopedTracker tracking_profile2( | 501 tracked_objects::ScopedTracker tracking_profile2( |
| 494 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 502 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 495 "455469 SafeBrowsingService::StartOnIOThread 2")); | 503 "455469 SafeBrowsingService::StartOnIOThread 2")); |
| 496 | 504 |
| 497 DCHECK(database_manager_.get()); | 505 DCHECK(database_manager_.get()); |
| 498 database_manager_->StartOnIOThread(); | 506 database_manager_->StartOnIOThread(); |
| 507 #endif |
| 499 | 508 |
| 509 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 500 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. | 510 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. |
| 501 tracked_objects::ScopedTracker tracking_profile3( | 511 tracked_objects::ScopedTracker tracking_profile3( |
| 502 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 512 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 503 "455469 SafeBrowsingService::StartOnIOThread 3")); | 513 "455469 SafeBrowsingService::StartOnIOThread 3")); |
| 504 DCHECK(!protocol_manager_); | 514 DCHECK(!protocol_manager_); |
| 515 DCHECK(database_manager_->GetProtocolManagerDelegate()), |
| 505 protocol_manager_ = SafeBrowsingProtocolManager::Create( | 516 protocol_manager_ = SafeBrowsingProtocolManager::Create( |
| 506 database_manager_.get(), url_request_context_getter, config); | 517 database_manager_->GetProtocolManagerDelegate(), |
| 518 url_request_context_getter, config); |
| 507 protocol_manager_->Initialize(); | 519 protocol_manager_->Initialize(); |
| 508 #endif | 520 #endif |
| 509 | 521 |
| 510 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. | 522 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455469 is fixed. |
| 511 tracked_objects::ScopedTracker tracking_profile4( | 523 tracked_objects::ScopedTracker tracking_profile4( |
| 512 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 524 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 513 "455469 SafeBrowsingService::StartOnIOThread 4")); | 525 "455469 SafeBrowsingService::StartOnIOThread 4")); |
| 514 DCHECK(!ping_manager_); | 526 DCHECK(!ping_manager_); |
| 515 ping_manager_ = SafeBrowsingPingManager::Create( | 527 ping_manager_ = SafeBrowsingPingManager::Create( |
| 516 url_request_context_getter, config); | 528 url_request_context_getter, config); |
| 517 } | 529 } |
| 518 | 530 |
| 519 void SafeBrowsingService::StopOnIOThread(bool shutdown) { | 531 void SafeBrowsingService::StopOnIOThread(bool shutdown) { |
| 520 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 532 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 521 | 533 |
| 522 #if defined(SAFE_BROWSING_DB_LOCAL) | 534 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) |
| 523 database_manager_->StopOnIOThread(shutdown); | 535 database_manager_->StopOnIOThread(shutdown); |
| 524 #endif | 536 #endif |
| 525 ui_manager_->StopOnIOThread(shutdown); | 537 ui_manager_->StopOnIOThread(shutdown); |
| 526 | 538 |
| 527 if (enabled_) { | 539 if (enabled_) { |
| 528 enabled_ = false; | 540 enabled_ = false; |
| 529 | 541 |
| 530 #if defined(SAFE_BROWSING_DB_LOCAL) | 542 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 531 // This cancels all in-flight GetHash requests. Note that database_manager_ | 543 // This cancels all in-flight GetHash requests. Note that database_manager_ |
| 532 // relies on the protocol_manager_ so if the latter is destroyed, the | 544 // relies on the protocol_manager_ so if the latter is destroyed, the |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 else | 631 else |
| 620 Stop(false); | 632 Stop(false); |
| 621 | 633 |
| 622 #if defined(FULL_SAFE_BROWSING) | 634 #if defined(FULL_SAFE_BROWSING) |
| 623 if (csd_service_) | 635 if (csd_service_) |
| 624 csd_service_->SetEnabledAndRefreshState(enable); | 636 csd_service_->SetEnabledAndRefreshState(enable); |
| 625 if (download_service_) | 637 if (download_service_) |
| 626 download_service_->SetEnabled(enable); | 638 download_service_->SetEnabled(enable); |
| 627 #endif | 639 #endif |
| 628 } | 640 } |
| OLD | NEW |