| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 | 476 |
| 469 void SafeBrowsingService::StartOnIOThread( | 477 void SafeBrowsingService::StartOnIOThread( |
| 470 net::URLRequestContextGetter* url_request_context_getter) { | 478 net::URLRequestContextGetter* url_request_context_getter) { |
| 471 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 479 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 472 if (enabled_) | 480 if (enabled_) |
| 473 return; | 481 return; |
| 474 enabled_ = true; | 482 enabled_ = true; |
| 475 | 483 |
| 476 SafeBrowsingProtocolConfig config = GetProtocolConfig(); | 484 SafeBrowsingProtocolConfig config = GetProtocolConfig(); |
| 477 | 485 |
| 478 #if defined(SAFE_BROWSING_DB_LOCAL) | 486 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) |
| 479 DCHECK(database_manager_.get()); | 487 DCHECK(database_manager_.get()); |
| 480 database_manager_->StartOnIOThread(); | 488 database_manager_->StartOnIOThread(); |
| 489 #endif |
| 481 | 490 |
| 491 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 482 DCHECK(!protocol_manager_); | 492 DCHECK(!protocol_manager_); |
| 493 DCHECK(database_manager_->GetProtocolManagerDelegate()), |
| 483 protocol_manager_ = SafeBrowsingProtocolManager::Create( | 494 protocol_manager_ = SafeBrowsingProtocolManager::Create( |
| 484 database_manager_.get(), url_request_context_getter, config); | 495 database_manager_->GetProtocolManagerDelegate(), |
| 496 url_request_context_getter, config); |
| 485 protocol_manager_->Initialize(); | 497 protocol_manager_->Initialize(); |
| 486 #endif | 498 #endif |
| 487 | 499 |
| 488 DCHECK(!ping_manager_); | 500 DCHECK(!ping_manager_); |
| 489 ping_manager_ = SafeBrowsingPingManager::Create( | 501 ping_manager_ = SafeBrowsingPingManager::Create( |
| 490 url_request_context_getter, config); | 502 url_request_context_getter, config); |
| 491 } | 503 } |
| 492 | 504 |
| 493 void SafeBrowsingService::StopOnIOThread(bool shutdown) { | 505 void SafeBrowsingService::StopOnIOThread(bool shutdown) { |
| 494 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 506 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 495 | 507 |
| 496 #if defined(SAFE_BROWSING_DB_LOCAL) | 508 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) |
| 497 database_manager_->StopOnIOThread(shutdown); | 509 database_manager_->StopOnIOThread(shutdown); |
| 498 #endif | 510 #endif |
| 499 ui_manager_->StopOnIOThread(shutdown); | 511 ui_manager_->StopOnIOThread(shutdown); |
| 500 | 512 |
| 501 if (enabled_) { | 513 if (enabled_) { |
| 502 enabled_ = false; | 514 enabled_ = false; |
| 503 | 515 |
| 504 #if defined(SAFE_BROWSING_DB_LOCAL) | 516 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 505 // This cancels all in-flight GetHash requests. Note that database_manager_ | 517 // This cancels all in-flight GetHash requests. Note that database_manager_ |
| 506 // relies on the protocol_manager_ so if the latter is destroyed, the | 518 // 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... |
| 593 else | 605 else |
| 594 Stop(false); | 606 Stop(false); |
| 595 | 607 |
| 596 #if defined(FULL_SAFE_BROWSING) | 608 #if defined(FULL_SAFE_BROWSING) |
| 597 if (csd_service_) | 609 if (csd_service_) |
| 598 csd_service_->SetEnabledAndRefreshState(enable); | 610 csd_service_->SetEnabledAndRefreshState(enable); |
| 599 if (download_service_) | 611 if (download_service_) |
| 600 download_service_->SetEnabled(enable); | 612 download_service_->SetEnabled(enable); |
| 601 #endif | 613 #endif |
| 602 } | 614 } |
| OLD | NEW |