| 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 13 matching lines...) Expand all Loading... |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
| 27 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 27 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/profiles/profile_manager.h" | 29 #include "chrome/browser/profiles/profile_manager.h" |
| 30 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 30 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
| 31 #include "chrome/browser/safe_browsing/download_protection_service.h" | 31 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 32 #include "chrome/browser/safe_browsing/ping_manager.h" | 32 #include "chrome/browser/safe_browsing/ping_manager.h" |
| 33 #include "chrome/browser/safe_browsing/protocol_manager.h" | 33 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 34 #include "chrome/browser/safe_browsing/protocol_manager_helper.h" |
| 34 #include "chrome/browser/safe_browsing/ui_manager.h" | 35 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 35 #include "chrome/common/chrome_constants.h" | 36 #include "chrome/common/chrome_constants.h" |
| 36 #include "chrome/common/chrome_paths.h" | 37 #include "chrome/common/chrome_paths.h" |
| 37 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 39 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 40 #include "components/prefs/pref_change_registrar.h" | 41 #include "components/prefs/pref_change_registrar.h" |
| 41 #include "components/prefs/pref_service.h" | 42 #include "components/prefs/pref_service.h" |
| 42 #include "components/safe_browsing_db/database_manager.h" | 43 #include "components/safe_browsing_db/database_manager.h" |
| 44 #include "components/safe_browsing_db/v4_get_hash_protocol_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" |
| 49 #include "google_apis/google_api_keys.h" |
| 47 #include "net/cookies/cookie_store.h" | 50 #include "net/cookies/cookie_store.h" |
| 48 #include "net/extras/sqlite/cookie_crypto_delegate.h" | 51 #include "net/extras/sqlite/cookie_crypto_delegate.h" |
| 49 #include "net/url_request/url_request_context.h" | 52 #include "net/url_request/url_request_context.h" |
| 50 #include "net/url_request/url_request_context_getter.h" | 53 #include "net/url_request/url_request_context_getter.h" |
| 51 | 54 |
| 52 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
| 53 #include "chrome/installer/util/browser_distribution.h" | 56 #include "chrome/installer/util/browser_distribution.h" |
| 54 #endif | 57 #endif |
| 55 | 58 |
| 56 #if defined(SAFE_BROWSING_DB_LOCAL) | 59 #if defined(SAFE_BROWSING_DB_LOCAL) |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 if (resource_request_detector_) | 395 if (resource_request_detector_) |
| 393 resource_request_detector_->OnResourceRequest(request); | 396 resource_request_detector_->OnResourceRequest(request); |
| 394 #endif | 397 #endif |
| 395 } | 398 } |
| 396 | 399 |
| 397 SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() { | 400 SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() { |
| 398 return new SafeBrowsingUIManager(this); | 401 return new SafeBrowsingUIManager(this); |
| 399 } | 402 } |
| 400 | 403 |
| 401 SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() { | 404 SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() { |
| 405 V4GetHashProtocolConfig config = GetV4GetHashProtocolConfig(); |
| 402 #if defined(SAFE_BROWSING_DB_LOCAL) | 406 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 403 return new LocalSafeBrowsingDatabaseManager(this); | 407 return new LocalSafeBrowsingDatabaseManager(this, |
| 408 url_request_context_getter_.get(), config); |
| 404 #elif defined(SAFE_BROWSING_DB_REMOTE) | 409 #elif defined(SAFE_BROWSING_DB_REMOTE) |
| 405 return new RemoteSafeBrowsingDatabaseManager(); | 410 return new RemoteSafeBrowsingDatabaseManager( |
| 411 url_request_context_getter_.get(), config); |
| 406 #else | 412 #else |
| 407 return NULL; | 413 return NULL; |
| 408 #endif | 414 #endif |
| 409 } | 415 } |
| 410 | 416 |
| 411 #if defined(FULL_SAFE_BROWSING) | 417 #if defined(FULL_SAFE_BROWSING) |
| 412 IncidentReportingService* | 418 IncidentReportingService* |
| 413 SafeBrowsingService::CreateIncidentReportingService() { | 419 SafeBrowsingService::CreateIncidentReportingService() { |
| 414 return new IncidentReportingService( | 420 return new IncidentReportingService( |
| 415 this, url_request_context_getter_); | 421 this, url_request_context_getter_); |
| 416 } | 422 } |
| 417 #endif | 423 #endif |
| 418 | 424 |
| 419 void SafeBrowsingService::RegisterAllDelayedAnalysis() { | 425 void SafeBrowsingService::RegisterAllDelayedAnalysis() { |
| 420 #if defined(FULL_SAFE_BROWSING) | 426 #if defined(FULL_SAFE_BROWSING) |
| 421 RegisterBinaryIntegrityAnalysis(); | 427 RegisterBinaryIntegrityAnalysis(); |
| 422 RegisterBlacklistLoadAnalysis(); | 428 RegisterBlacklistLoadAnalysis(); |
| 423 RegisterVariationsSeedSignatureAnalysis(); | 429 RegisterVariationsSeedSignatureAnalysis(); |
| 424 #else | 430 #else |
| 425 NOTREACHED(); | 431 NOTREACHED(); |
| 426 #endif | 432 #endif |
| 427 } | 433 } |
| 428 | 434 |
| 429 SafeBrowsingProtocolConfig SafeBrowsingService::GetProtocolConfig() const { | 435 SafeBrowsingProtocolConfig SafeBrowsingService::GetProtocolConfig() const { |
| 430 SafeBrowsingProtocolConfig config; | 436 SafeBrowsingProtocolConfig config; |
| 431 // On Windows, get the safe browsing client name from the browser | 437 config.client_name = GetProtocolConfigClientName(); |
| 432 // distribution classes in installer util. These classes don't yet have | |
| 433 // an analog on non-Windows builds so just keep the name specified here. | |
| 434 #if defined(OS_WIN) | |
| 435 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
| 436 config.client_name = dist->GetSafeBrowsingName(); | |
| 437 #else | |
| 438 #if defined(GOOGLE_CHROME_BUILD) | |
| 439 config.client_name = "googlechrome"; | |
| 440 #else | |
| 441 config.client_name = "chromium"; | |
| 442 #endif | |
| 443 | 438 |
| 444 // Mark client string to allow server to differentiate mobile. | |
| 445 #if defined(OS_ANDROID) | |
| 446 config.client_name.append("-a"); | |
| 447 #elif defined(OS_IOS) | |
| 448 config.client_name.append("-i"); | |
| 449 #endif | |
| 450 | |
| 451 #endif // defined(OS_WIN) | |
| 452 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 439 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 453 config.disable_auto_update = | 440 config.disable_auto_update = |
| 454 cmdline->HasSwitch(switches::kSbDisableAutoUpdate) || | 441 cmdline->HasSwitch(switches::kSbDisableAutoUpdate) || |
| 455 cmdline->HasSwitch(switches::kDisableBackgroundNetworking); | 442 cmdline->HasSwitch(switches::kDisableBackgroundNetworking); |
| 456 config.url_prefix = kSbDefaultURLPrefix; | 443 config.url_prefix = kSbDefaultURLPrefix; |
| 457 config.backup_connect_error_url_prefix = kSbBackupConnectErrorURLPrefix; | 444 config.backup_connect_error_url_prefix = kSbBackupConnectErrorURLPrefix; |
| 458 config.backup_http_error_url_prefix = kSbBackupHttpErrorURLPrefix; | 445 config.backup_http_error_url_prefix = kSbBackupHttpErrorURLPrefix; |
| 459 config.backup_network_error_url_prefix = kSbBackupNetworkErrorURLPrefix; | 446 config.backup_network_error_url_prefix = kSbBackupNetworkErrorURLPrefix; |
| 460 | 447 |
| 461 return config; | 448 return config; |
| 462 } | 449 } |
| 463 | 450 |
| 451 V4GetHashProtocolConfig |
| 452 SafeBrowsingService::GetV4GetHashProtocolConfig() const { |
| 453 V4GetHashProtocolConfig config; |
| 454 config.client_name = GetProtocolConfigClientName(); |
| 455 config.version = SafeBrowsingProtocolManagerHelper::Version(); |
| 456 config.key_param = google_apis::GetAPIKey();; |
| 457 |
| 458 return config; |
| 459 } |
| 460 |
| 461 std::string SafeBrowsingService::GetProtocolConfigClientName() const { |
| 462 std::string client_name; |
| 463 // On Windows, get the safe browsing client name from the browser |
| 464 // distribution classes in installer util. These classes don't yet have |
| 465 // an analog on non-Windows builds so just keep the name specified here. |
| 466 #if defined(OS_WIN) |
| 467 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 468 client_name = dist->GetSafeBrowsingName(); |
| 469 #else |
| 470 #if defined(GOOGLE_CHROME_BUILD) |
| 471 client_name = "googlechrome"; |
| 472 #else |
| 473 client_name = "chromium"; |
| 474 #endif |
| 475 |
| 476 // Mark client string to allow server to differentiate mobile. |
| 477 #if defined(OS_ANDROID) |
| 478 client_name.append("-a"); |
| 479 #elif defined(OS_IOS) |
| 480 client_name.append("-i"); |
| 481 #endif |
| 482 |
| 483 #endif // defined(OS_WIN) |
| 484 |
| 485 return client_name; |
| 486 } |
| 487 |
| 464 // Any tests that create a DatabaseManager that isn't derived from | 488 // Any tests that create a DatabaseManager that isn't derived from |
| 465 // LocalSafeBrowsingDatabaseManager should override this to return NULL. | 489 // LocalSafeBrowsingDatabaseManager should override this to return NULL. |
| 466 SafeBrowsingProtocolManagerDelegate* | 490 SafeBrowsingProtocolManagerDelegate* |
| 467 SafeBrowsingService::GetProtocolManagerDelegate() { | 491 SafeBrowsingService::GetProtocolManagerDelegate() { |
| 468 #if defined(SAFE_BROWSING_DB_LOCAL) | 492 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 469 return static_cast<LocalSafeBrowsingDatabaseManager*>( | 493 return static_cast<LocalSafeBrowsingDatabaseManager*>( |
| 470 database_manager_.get()); | 494 database_manager_.get()); |
| 471 #else | 495 #else |
| 472 NOTREACHED(); | 496 NOTREACHED(); |
| 473 return NULL; | 497 return NULL; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 } | 669 } |
| 646 | 670 |
| 647 void SafeBrowsingService::OnSendDownloadRecoveryReport( | 671 void SafeBrowsingService::OnSendDownloadRecoveryReport( |
| 648 const std::string& report) { | 672 const std::string& report) { |
| 649 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 673 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 650 if (ping_manager()) | 674 if (ping_manager()) |
| 651 ping_manager()->ReportThreatDetails(report); | 675 ping_manager()->ReportThreatDetails(report); |
| 652 } | 676 } |
| 653 | 677 |
| 654 } // namespace safe_browsing | 678 } // namespace safe_browsing |
| OLD | NEW |