| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
| 33 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/common/safe_browsing/file_type_policies.h" | 35 #include "chrome/common/safe_browsing/file_type_policies.h" |
| 36 #include "components/prefs/pref_change_registrar.h" | 36 #include "components/prefs/pref_change_registrar.h" |
| 37 #include "components/prefs/pref_service.h" | 37 #include "components/prefs/pref_service.h" |
| 38 #include "components/safe_browsing/common/safebrowsing_constants.h" | 38 #include "components/safe_browsing/common/safebrowsing_constants.h" |
| 39 #include "components/safe_browsing/common/safebrowsing_switches.h" | 39 #include "components/safe_browsing/common/safebrowsing_switches.h" |
| 40 #include "components/safe_browsing_db/database_manager.h" | 40 #include "components/safe_browsing_db/database_manager.h" |
| 41 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 41 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
| 42 #include "components/safe_browsing_db/v4_feature_list.h" |
| 42 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 43 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 44 #include "components/safe_browsing_db/v4_local_database_manager.h" |
| 43 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h
" | 45 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h
" |
| 44 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
| 45 #include "content/public/browser/cookie_store_factory.h" | 47 #include "content/public/browser/cookie_store_factory.h" |
| 46 #include "content/public/browser/notification_service.h" | 48 #include "content/public/browser/notification_service.h" |
| 47 #include "content/public/browser/resource_request_info.h" | 49 #include "content/public/browser/resource_request_info.h" |
| 48 #include "google_apis/google_api_keys.h" | 50 #include "google_apis/google_api_keys.h" |
| 49 #include "net/cookies/cookie_store.h" | 51 #include "net/cookies/cookie_store.h" |
| 50 #include "net/extras/sqlite/cookie_crypto_delegate.h" | 52 #include "net/extras/sqlite/cookie_crypto_delegate.h" |
| 51 #include "net/extras/sqlite/sqlite_channel_id_store.h" | 53 #include "net/extras/sqlite/sqlite_channel_id_store.h" |
| 52 #include "net/http/http_network_layer.h" | 54 #include "net/http/http_network_layer.h" |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // static | 279 // static |
| 278 SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { | 280 SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { |
| 279 if (!factory_) | 281 if (!factory_) |
| 280 factory_ = g_safe_browsing_service_factory_impl.Pointer(); | 282 factory_ = g_safe_browsing_service_factory_impl.Pointer(); |
| 281 return factory_->CreateSafeBrowsingService(); | 283 return factory_->CreateSafeBrowsingService(); |
| 282 } | 284 } |
| 283 | 285 |
| 284 SafeBrowsingService::SafeBrowsingService() | 286 SafeBrowsingService::SafeBrowsingService() |
| 285 : services_delegate_(ServicesDelegate::Create(this)), | 287 : services_delegate_(ServicesDelegate::Create(this)), |
| 286 enabled_(false), | 288 enabled_(false), |
| 287 enabled_by_prefs_(false) {} | 289 enabled_by_prefs_(false), |
| 290 enabled_v4_only_(safe_browsing::V4FeatureList::IsV4OnlyEnabled()) {} |
| 288 | 291 |
| 289 SafeBrowsingService::~SafeBrowsingService() { | 292 SafeBrowsingService::~SafeBrowsingService() { |
| 290 // We should have already been shut down. If we're still enabled, then the | 293 // We should have already been shut down. If we're still enabled, then the |
| 291 // database isn't going to be closed properly, which could lead to corruption. | 294 // database isn't going to be closed properly, which could lead to corruption. |
| 292 DCHECK(!enabled_); | 295 DCHECK(!enabled_); |
| 293 } | 296 } |
| 294 | 297 |
| 295 void SafeBrowsingService::Initialize() { | 298 void SafeBrowsingService::Initialize() { |
| 296 // Ensure FileTypePolicies's Singleton is instantiated during startup. | 299 // Ensure FileTypePolicies's Singleton is instantiated during startup. |
| 297 // This guarantees we'll log UMA metrics about its state. | 300 // This guarantees we'll log UMA metrics about its state. |
| 298 FileTypePolicies::GetInstance(); | 301 FileTypePolicies::GetInstance(); |
| 299 | 302 |
| 300 url_request_context_getter_ = new SafeBrowsingURLRequestContextGetter( | 303 url_request_context_getter_ = new SafeBrowsingURLRequestContextGetter( |
| 301 g_browser_process->system_request_context()); | 304 g_browser_process->system_request_context()); |
| 302 | 305 |
| 303 ui_manager_ = CreateUIManager(); | 306 ui_manager_ = CreateUIManager(); |
| 304 | 307 |
| 305 database_manager_ = CreateDatabaseManager(); | 308 if (!enabled_v4_only_) { |
| 309 database_manager_ = CreateDatabaseManager(); |
| 310 } |
| 306 | 311 |
| 307 services_delegate_->Initialize(); | 312 services_delegate_->Initialize(); |
| 308 services_delegate_->InitializeCsdService(url_request_context_getter_.get()); | 313 services_delegate_->InitializeCsdService(url_request_context_getter_.get()); |
| 309 | 314 |
| 310 // Track the safe browsing preference of existing profiles. | 315 // Track the safe browsing preference of existing profiles. |
| 311 // The SafeBrowsingService will be started if any existing profile has the | 316 // The SafeBrowsingService will be started if any existing profile has the |
| 312 // preference enabled. It will also listen for updates to the preferences. | 317 // preference enabled. It will also listen for updates to the preferences. |
| 313 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 318 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 314 if (profile_manager) { | 319 if (profile_manager) { |
| 315 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 320 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // has to be released now rather than in the destructor because it can only | 363 // has to be released now rather than in the destructor because it can only |
| 359 // be deleted on the IOThread, and the SafeBrowsingService outlives the IO | 364 // be deleted on the IOThread, and the SafeBrowsingService outlives the IO |
| 360 // thread. | 365 // thread. |
| 361 url_request_context_getter_ = nullptr; | 366 url_request_context_getter_ = nullptr; |
| 362 } | 367 } |
| 363 | 368 |
| 364 bool SafeBrowsingService::DownloadBinHashNeeded() const { | 369 bool SafeBrowsingService::DownloadBinHashNeeded() const { |
| 365 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 370 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 366 | 371 |
| 367 #if defined(FULL_SAFE_BROWSING) | 372 #if defined(FULL_SAFE_BROWSING) |
| 368 return database_manager_->IsDownloadProtectionEnabled() || | 373 return database_manager()->IsDownloadProtectionEnabled() || |
| 369 (download_protection_service() && | 374 (download_protection_service() && |
| 370 download_protection_service()->enabled()); | 375 download_protection_service()->enabled()); |
| 371 #else | 376 #else |
| 372 return false; | 377 return false; |
| 373 #endif | 378 #endif |
| 374 } | 379 } |
| 375 | 380 |
| 376 net::URLRequestContextGetter* SafeBrowsingService::url_request_context() { | 381 net::URLRequestContextGetter* SafeBrowsingService::url_request_context() { |
| 377 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 382 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 378 return url_request_context_getter_.get(); | 383 return url_request_context_getter_.get(); |
| 379 } | 384 } |
| 380 | 385 |
| 381 const scoped_refptr<SafeBrowsingUIManager>& | 386 const scoped_refptr<SafeBrowsingUIManager>& |
| 382 SafeBrowsingService::ui_manager() const { | 387 SafeBrowsingService::ui_manager() const { |
| 383 return ui_manager_; | 388 return ui_manager_; |
| 384 } | 389 } |
| 385 | 390 |
| 386 const scoped_refptr<SafeBrowsingDatabaseManager>& | 391 const scoped_refptr<SafeBrowsingDatabaseManager>& |
| 387 SafeBrowsingService::database_manager() const { | 392 SafeBrowsingService::database_manager() const { |
| 388 return database_manager_; | 393 return enabled_v4_only_ ? v4_local_database_manager() : database_manager_; |
| 389 } | 394 } |
| 390 | 395 |
| 391 SafeBrowsingProtocolManager* SafeBrowsingService::protocol_manager() const { | 396 SafeBrowsingProtocolManager* SafeBrowsingService::protocol_manager() const { |
| 392 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 397 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 393 #if defined(SAFE_BROWSING_DB_LOCAL) | 398 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 399 DCHECK(!enabled_v4_only_); |
| 394 return protocol_manager_.get(); | 400 return protocol_manager_.get(); |
| 395 #else | 401 #else |
| 396 return nullptr; | 402 return nullptr; |
| 397 #endif | 403 #endif |
| 398 } | 404 } |
| 399 | 405 |
| 400 SafeBrowsingPingManager* SafeBrowsingService::ping_manager() const { | 406 SafeBrowsingPingManager* SafeBrowsingService::ping_manager() const { |
| 401 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 407 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 402 return ping_manager_.get(); | 408 return ping_manager_.get(); |
| 403 } | 409 } |
| 404 | 410 |
| 405 const scoped_refptr<V4LocalDatabaseManager>& | 411 const scoped_refptr<SafeBrowsingDatabaseManager>& |
| 406 SafeBrowsingService::v4_local_database_manager() const { | 412 SafeBrowsingService::v4_local_database_manager() const { |
| 407 return services_delegate_->v4_local_database_manager(); | 413 return services_delegate_->v4_local_database_manager(); |
| 408 } | 414 } |
| 409 | 415 |
| 410 std::unique_ptr<TrackedPreferenceValidationDelegate> | 416 std::unique_ptr<TrackedPreferenceValidationDelegate> |
| 411 SafeBrowsingService::CreatePreferenceValidationDelegate( | 417 SafeBrowsingService::CreatePreferenceValidationDelegate( |
| 412 Profile* profile) const { | 418 Profile* profile) const { |
| 413 return services_delegate_->CreatePreferenceValidationDelegate(profile); | 419 return services_delegate_->CreatePreferenceValidationDelegate(profile); |
| 414 } | 420 } |
| 415 | 421 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 return new RemoteSafeBrowsingDatabaseManager(); | 459 return new RemoteSafeBrowsingDatabaseManager(); |
| 454 #else | 460 #else |
| 455 return NULL; | 461 return NULL; |
| 456 #endif | 462 #endif |
| 457 } | 463 } |
| 458 | 464 |
| 459 void SafeBrowsingService::RegisterAllDelayedAnalysis() { | 465 void SafeBrowsingService::RegisterAllDelayedAnalysis() { |
| 460 #if defined(FULL_SAFE_BROWSING) | 466 #if defined(FULL_SAFE_BROWSING) |
| 461 RegisterBinaryIntegrityAnalysis(); | 467 RegisterBinaryIntegrityAnalysis(); |
| 462 RegisterBlacklistLoadAnalysis(); | 468 RegisterBlacklistLoadAnalysis(); |
| 463 RegisterModuleLoadAnalysis(database_manager_); | 469 RegisterModuleLoadAnalysis(database_manager()); |
| 464 RegisterVariationsSeedSignatureAnalysis(); | 470 RegisterVariationsSeedSignatureAnalysis(); |
| 465 #endif | 471 #endif |
| 466 } | 472 } |
| 467 | 473 |
| 468 SafeBrowsingProtocolConfig SafeBrowsingService::GetProtocolConfig() const { | 474 SafeBrowsingProtocolConfig SafeBrowsingService::GetProtocolConfig() const { |
| 469 SafeBrowsingProtocolConfig config; | 475 SafeBrowsingProtocolConfig config; |
| 470 config.client_name = GetProtocolConfigClientName(); | 476 config.client_name = GetProtocolConfigClientName(); |
| 471 | 477 |
| 472 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 478 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 473 config.disable_auto_update = | 479 config.disable_auto_update = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 #endif // defined(OS_WIN) | 519 #endif // defined(OS_WIN) |
| 514 | 520 |
| 515 return client_name; | 521 return client_name; |
| 516 } | 522 } |
| 517 | 523 |
| 518 // Any tests that create a DatabaseManager that isn't derived from | 524 // Any tests that create a DatabaseManager that isn't derived from |
| 519 // LocalSafeBrowsingDatabaseManager should override this to return NULL. | 525 // LocalSafeBrowsingDatabaseManager should override this to return NULL. |
| 520 SafeBrowsingProtocolManagerDelegate* | 526 SafeBrowsingProtocolManagerDelegate* |
| 521 SafeBrowsingService::GetProtocolManagerDelegate() { | 527 SafeBrowsingService::GetProtocolManagerDelegate() { |
| 522 #if defined(SAFE_BROWSING_DB_LOCAL) | 528 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 529 DCHECK(!enabled_v4_only_); |
| 523 return static_cast<LocalSafeBrowsingDatabaseManager*>( | 530 return static_cast<LocalSafeBrowsingDatabaseManager*>( |
| 524 database_manager_.get()); | 531 database_manager_.get()); |
| 525 #else | 532 #else |
| 526 NOTREACHED(); | 533 NOTREACHED(); |
| 527 return NULL; | 534 return NULL; |
| 528 #endif | 535 #endif |
| 529 } | 536 } |
| 530 | 537 |
| 531 void SafeBrowsingService::StartOnIOThread( | 538 void SafeBrowsingService::StartOnIOThread( |
| 532 net::URLRequestContextGetter* url_request_context_getter) { | 539 net::URLRequestContextGetter* url_request_context_getter) { |
| 533 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 540 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 534 if (enabled_) | 541 if (enabled_) |
| 535 return; | 542 return; |
| 536 enabled_ = true; | 543 enabled_ = true; |
| 537 | 544 |
| 538 SafeBrowsingProtocolConfig config = GetProtocolConfig(); | 545 SafeBrowsingProtocolConfig config = GetProtocolConfig(); |
| 539 V4ProtocolConfig v4_config = GetV4ProtocolConfig(); | 546 V4ProtocolConfig v4_config = GetV4ProtocolConfig(); |
| 540 | 547 |
| 541 services_delegate_->StartOnIOThread(url_request_context_getter, v4_config); | 548 services_delegate_->StartOnIOThread(url_request_context_getter, v4_config); |
| 542 | 549 |
| 543 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) | 550 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) |
| 544 DCHECK(database_manager_.get()); | 551 if (!enabled_v4_only_) { |
| 545 database_manager_->StartOnIOThread(url_request_context_getter, v4_config); | 552 DCHECK(database_manager_.get()); |
| 553 database_manager_->StartOnIOThread(url_request_context_getter, v4_config); |
| 554 } |
| 546 #endif | 555 #endif |
| 547 | 556 |
| 548 #if defined(SAFE_BROWSING_DB_LOCAL) | 557 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 549 SafeBrowsingProtocolManagerDelegate* protocol_manager_delegate = | 558 if (!enabled_v4_only_) { |
| 550 GetProtocolManagerDelegate(); | 559 SafeBrowsingProtocolManagerDelegate* protocol_manager_delegate = |
| 551 if (protocol_manager_delegate) { | 560 GetProtocolManagerDelegate(); |
| 552 protocol_manager_ = SafeBrowsingProtocolManager::Create( | 561 if (protocol_manager_delegate) { |
| 553 protocol_manager_delegate, url_request_context_getter, config); | 562 protocol_manager_ = SafeBrowsingProtocolManager::Create( |
| 554 protocol_manager_->Initialize(); | 563 protocol_manager_delegate, url_request_context_getter, config); |
| 564 protocol_manager_->Initialize(); |
| 565 } |
| 555 } | 566 } |
| 556 #endif | 567 #endif |
| 557 | 568 |
| 558 DCHECK(!ping_manager_); | 569 DCHECK(!ping_manager_); |
| 559 ping_manager_ = SafeBrowsingPingManager::Create( | 570 ping_manager_ = SafeBrowsingPingManager::Create( |
| 560 url_request_context_getter, config); | 571 url_request_context_getter, config); |
| 561 } | 572 } |
| 562 | 573 |
| 563 void SafeBrowsingService::StopOnIOThread(bool shutdown) { | 574 void SafeBrowsingService::StopOnIOThread(bool shutdown) { |
| 564 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 575 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 565 | 576 |
| 566 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) | 577 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) |
| 567 database_manager_->StopOnIOThread(shutdown); | 578 if (!enabled_v4_only_) { |
| 579 database_manager_->StopOnIOThread(shutdown); |
| 580 } |
| 568 #endif | 581 #endif |
| 569 ui_manager_->StopOnIOThread(shutdown); | 582 ui_manager_->StopOnIOThread(shutdown); |
| 570 | 583 |
| 571 services_delegate_->StopOnIOThread(shutdown); | 584 services_delegate_->StopOnIOThread(shutdown); |
| 572 | 585 |
| 573 if (enabled_) { | 586 if (enabled_) { |
| 574 enabled_ = false; | 587 enabled_ = false; |
| 575 | 588 |
| 576 #if defined(SAFE_BROWSING_DB_LOCAL) | 589 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 577 // This cancels all in-flight GetHash requests. Note that | 590 // This cancels all in-flight GetHash requests. Note that |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 ping_manager()->ReportThreatDetails(report); | 718 ping_manager()->ReportThreatDetails(report); |
| 706 } | 719 } |
| 707 | 720 |
| 708 void SafeBrowsingService::ProcessResourceRequest( | 721 void SafeBrowsingService::ProcessResourceRequest( |
| 709 const ResourceRequestInfo& request) { | 722 const ResourceRequestInfo& request) { |
| 710 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 723 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 711 services_delegate_->ProcessResourceRequest(&request); | 724 services_delegate_->ProcessResourceRequest(&request); |
| 712 } | 725 } |
| 713 | 726 |
| 714 } // namespace safe_browsing | 727 } // namespace safe_browsing |
| OLD | NEW |