| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
| 45 #include "net/cookies/cookie_monster.h" | 45 #include "net/cookies/cookie_monster.h" |
| 46 #include "net/extras/sqlite/cookie_crypto_delegate.h" | 46 #include "net/extras/sqlite/cookie_crypto_delegate.h" |
| 47 #include "net/url_request/url_request_context.h" | 47 #include "net/url_request/url_request_context.h" |
| 48 #include "net/url_request/url_request_context_getter.h" | 48 #include "net/url_request/url_request_context_getter.h" |
| 49 | 49 |
| 50 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 51 #include "chrome/installer/util/browser_distribution.h" | 51 #include "chrome/installer/util/browser_distribution.h" |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 55 #include "chrome/browser/safe_browsing/local_database_manager.h" |
| 56 #elif defined(SAFE_BROWSING_DB_REMOTE) |
| 57 #include "chrome/browser/safe_browsing/remote_database_manager.h" |
| 58 #endif |
| 59 |
| 54 #if defined(FULL_SAFE_BROWSING) | 60 #if defined(FULL_SAFE_BROWSING) |
| 55 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_analy
zer.h" | 61 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_analy
zer.h" |
| 56 #include "chrome/browser/safe_browsing/incident_reporting/blacklist_load_analyze
r.h" | 62 #include "chrome/browser/safe_browsing/incident_reporting/blacklist_load_analyze
r.h" |
| 57 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" | 63 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" |
| 58 #include "chrome/browser/safe_browsing/incident_reporting/off_domain_inclusion_d
etector.h" | 64 #include "chrome/browser/safe_browsing/incident_reporting/off_domain_inclusion_d
etector.h" |
| 59 #include "chrome/browser/safe_browsing/incident_reporting/resource_request_detec
tor.h" | 65 #include "chrome/browser/safe_browsing/incident_reporting/resource_request_detec
tor.h" |
| 60 #include "chrome/browser/safe_browsing/incident_reporting/variations_seed_signat
ure_analyzer.h" | 66 #include "chrome/browser/safe_browsing/incident_reporting/variations_seed_signat
ure_analyzer.h" |
| 61 #endif | 67 #endif |
| 62 | 68 |
| 63 using content::BrowserThread; | 69 using content::BrowserThread; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 242 |
| 237 if (IsIncidentReportingServiceEnabled()) { | 243 if (IsIncidentReportingServiceEnabled()) { |
| 238 incident_service_.reset(new safe_browsing::IncidentReportingService( | 244 incident_service_.reset(new safe_browsing::IncidentReportingService( |
| 239 this, url_request_context_getter_)); | 245 this, url_request_context_getter_)); |
| 240 resource_request_detector_.reset(new safe_browsing::ResourceRequestDetector( | 246 resource_request_detector_.reset(new safe_browsing::ResourceRequestDetector( |
| 241 incident_service_->GetIncidentReceiver())); | 247 incident_service_->GetIncidentReceiver())); |
| 242 } | 248 } |
| 243 | 249 |
| 244 off_domain_inclusion_detector_.reset( | 250 off_domain_inclusion_detector_.reset( |
| 245 new safe_browsing::OffDomainInclusionDetector(database_manager_)); | 251 new safe_browsing::OffDomainInclusionDetector(database_manager_)); |
| 246 #endif // !defined(OS_ANDROID) | 252 #endif // !defined(FULL_SAFE_BROWSING) |
| 247 | 253 |
| 248 // Track the safe browsing preference of existing profiles. | 254 // Track the safe browsing preference of existing profiles. |
| 249 // The SafeBrowsingService will be started if any existing profile has the | 255 // The SafeBrowsingService will be started if any existing profile has the |
| 250 // preference enabled. It will also listen for updates to the preferences. | 256 // preference enabled. It will also listen for updates to the preferences. |
| 251 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 257 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 252 if (profile_manager) { | 258 if (profile_manager) { |
| 253 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 259 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| 254 for (size_t i = 0; i < profiles.size(); ++i) { | 260 for (size_t i = 0; i < profiles.size(); ++i) { |
| 255 if (profiles[i]->IsOffTheRecord()) | 261 if (profiles[i]->IsOffTheRecord()) |
| 256 continue; | 262 continue; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 resource_request_detector_->OnResourceRequest(request); | 378 resource_request_detector_->OnResourceRequest(request); |
| 373 #endif | 379 #endif |
| 374 } | 380 } |
| 375 | 381 |
| 376 SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() { | 382 SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() { |
| 377 return new SafeBrowsingUIManager(this); | 383 return new SafeBrowsingUIManager(this); |
| 378 } | 384 } |
| 379 | 385 |
| 380 SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() { | 386 SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() { |
| 381 #if defined(SAFE_BROWSING_DB_LOCAL) | 387 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 382 return new SafeBrowsingDatabaseManager(this); | 388 return new LocalSafeBrowsingDatabaseManager(this); |
| 389 #elif defined(SAFE_BROWSING_DB_REMOTE) |
| 390 return new RemoteSafeBrowsingDatabaseManager(); |
| 383 #else | 391 #else |
| 384 return NULL; | 392 return NULL; |
| 385 #endif | 393 #endif |
| 386 } | 394 } |
| 387 | 395 |
| 388 void SafeBrowsingService::RegisterAllDelayedAnalysis() { | 396 void SafeBrowsingService::RegisterAllDelayedAnalysis() { |
| 389 #if defined(FULL_SAFE_BROWSING) | 397 #if defined(FULL_SAFE_BROWSING) |
| 390 safe_browsing::RegisterBinaryIntegrityAnalysis(); | 398 safe_browsing::RegisterBinaryIntegrityAnalysis(); |
| 391 safe_browsing::RegisterBlacklistLoadAnalysis(); | 399 safe_browsing::RegisterBlacklistLoadAnalysis(); |
| 392 safe_browsing::RegisterVariationsSeedSignatureAnalysis(); | 400 safe_browsing::RegisterVariationsSeedSignatureAnalysis(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 cmdline->HasSwitch(switches::kSbDisableAutoUpdate) || | 467 cmdline->HasSwitch(switches::kSbDisableAutoUpdate) || |
| 460 cmdline->HasSwitch(switches::kDisableBackgroundNetworking); | 468 cmdline->HasSwitch(switches::kDisableBackgroundNetworking); |
| 461 config.url_prefix = kSbDefaultURLPrefix; | 469 config.url_prefix = kSbDefaultURLPrefix; |
| 462 config.backup_connect_error_url_prefix = kSbBackupConnectErrorURLPrefix; | 470 config.backup_connect_error_url_prefix = kSbBackupConnectErrorURLPrefix; |
| 463 config.backup_http_error_url_prefix = kSbBackupHttpErrorURLPrefix; | 471 config.backup_http_error_url_prefix = kSbBackupHttpErrorURLPrefix; |
| 464 config.backup_network_error_url_prefix = kSbBackupNetworkErrorURLPrefix; | 472 config.backup_network_error_url_prefix = kSbBackupNetworkErrorURLPrefix; |
| 465 | 473 |
| 466 return config; | 474 return config; |
| 467 } | 475 } |
| 468 | 476 |
| 477 // Any tests that create a DatabaseManager that isn't derived from |
| 478 // LocalSafeBrowsingDatabaseManager should override this to return NULL. |
| 479 SafeBrowsingProtocolManagerDelegate* |
| 480 SafeBrowsingService::GetProtocolManagerDelegate() { |
| 481 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 482 return static_cast<LocalSafeBrowsingDatabaseManager*>( |
| 483 database_manager_.get()); |
| 484 #else |
| 485 NOTREACHED(); |
| 486 return NULL; |
| 487 #endif |
| 488 } |
| 489 |
| 469 void SafeBrowsingService::StartOnIOThread( | 490 void SafeBrowsingService::StartOnIOThread( |
| 470 net::URLRequestContextGetter* url_request_context_getter) { | 491 net::URLRequestContextGetter* url_request_context_getter) { |
| 471 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 492 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 472 if (enabled_) | 493 if (enabled_) |
| 473 return; | 494 return; |
| 474 enabled_ = true; | 495 enabled_ = true; |
| 475 | 496 |
| 476 SafeBrowsingProtocolConfig config = GetProtocolConfig(); | 497 SafeBrowsingProtocolConfig config = GetProtocolConfig(); |
| 477 | 498 |
| 478 #if defined(SAFE_BROWSING_DB_LOCAL) | 499 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) |
| 479 DCHECK(database_manager_.get()); | 500 DCHECK(database_manager_.get()); |
| 480 database_manager_->StartOnIOThread(); | 501 database_manager_->StartOnIOThread(); |
| 502 #endif |
| 481 | 503 |
| 482 DCHECK(!protocol_manager_); | 504 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 483 protocol_manager_ = SafeBrowsingProtocolManager::Create( | 505 SafeBrowsingProtocolManagerDelegate* protocol_manager_delegate = |
| 484 database_manager_.get(), url_request_context_getter, config); | 506 GetProtocolManagerDelegate(); |
| 485 protocol_manager_->Initialize(); | 507 if (protocol_manager_delegate) { |
| 508 protocol_manager_ = SafeBrowsingProtocolManager::Create( |
| 509 protocol_manager_delegate, url_request_context_getter, config); |
| 510 protocol_manager_->Initialize(); |
| 511 } |
| 486 #endif | 512 #endif |
| 487 | 513 |
| 488 DCHECK(!ping_manager_); | 514 DCHECK(!ping_manager_); |
| 489 ping_manager_ = SafeBrowsingPingManager::Create( | 515 ping_manager_ = SafeBrowsingPingManager::Create( |
| 490 url_request_context_getter, config); | 516 url_request_context_getter, config); |
| 491 } | 517 } |
| 492 | 518 |
| 493 void SafeBrowsingService::StopOnIOThread(bool shutdown) { | 519 void SafeBrowsingService::StopOnIOThread(bool shutdown) { |
| 494 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 520 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 495 | 521 |
| 496 #if defined(SAFE_BROWSING_DB_LOCAL) | 522 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) |
| 497 database_manager_->StopOnIOThread(shutdown); | 523 database_manager_->StopOnIOThread(shutdown); |
| 498 #endif | 524 #endif |
| 499 ui_manager_->StopOnIOThread(shutdown); | 525 ui_manager_->StopOnIOThread(shutdown); |
| 500 | 526 |
| 501 if (enabled_) { | 527 if (enabled_) { |
| 502 enabled_ = false; | 528 enabled_ = false; |
| 503 | 529 |
| 504 #if defined(SAFE_BROWSING_DB_LOCAL) | 530 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 505 // This cancels all in-flight GetHash requests. Note that database_manager_ | 531 // This cancels all in-flight GetHash requests. Note that database_manager_ |
| 506 // 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 |
| 507 // former must be stopped. | 533 // former must be stopped. |
| 508 delete protocol_manager_; | 534 if (protocol_manager_) { |
| 509 protocol_manager_ = NULL; | 535 delete protocol_manager_; |
| 536 protocol_manager_ = NULL; |
| 537 } |
| 510 #endif | 538 #endif |
| 511 delete ping_manager_; | 539 delete ping_manager_; |
| 512 ping_manager_ = NULL; | 540 ping_manager_ = NULL; |
| 513 } | 541 } |
| 514 } | 542 } |
| 515 | 543 |
| 516 void SafeBrowsingService::Start() { | 544 void SafeBrowsingService::Start() { |
| 517 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 545 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 518 | 546 |
| 519 BrowserThread::PostTask( | 547 BrowserThread::PostTask( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 else | 616 else |
| 589 Stop(false); | 617 Stop(false); |
| 590 | 618 |
| 591 #if defined(FULL_SAFE_BROWSING) | 619 #if defined(FULL_SAFE_BROWSING) |
| 592 if (csd_service_) | 620 if (csd_service_) |
| 593 csd_service_->SetEnabledAndRefreshState(enable); | 621 csd_service_->SetEnabledAndRefreshState(enable); |
| 594 if (download_service_) | 622 if (download_service_) |
| 595 download_service_->SetEnabled(enable); | 623 download_service_->SetEnabled(enable); |
| 596 #endif | 624 #endif |
| 597 } | 625 } |
| OLD | NEW |