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, NULL, config); |
404 #elif defined(SAFE_BROWSING_DB_REMOTE) | 408 #elif defined(SAFE_BROWSING_DB_REMOTE) |
405 return new RemoteSafeBrowsingDatabaseManager(); | 409 return new RemoteSafeBrowsingDatabaseManager(NULL, config); |
406 #else | 410 #else |
407 return NULL; | 411 return NULL; |
408 #endif | 412 #endif |
409 } | 413 } |
410 | 414 |
411 #if defined(FULL_SAFE_BROWSING) | 415 #if defined(FULL_SAFE_BROWSING) |
412 IncidentReportingService* | 416 IncidentReportingService* |
413 SafeBrowsingService::CreateIncidentReportingService() { | 417 SafeBrowsingService::CreateIncidentReportingService() { |
414 return new IncidentReportingService( | 418 return new IncidentReportingService( |
415 this, url_request_context_getter_); | 419 this, url_request_context_getter_); |
416 } | 420 } |
417 #endif | 421 #endif |
418 | 422 |
419 void SafeBrowsingService::RegisterAllDelayedAnalysis() { | 423 void SafeBrowsingService::RegisterAllDelayedAnalysis() { |
420 #if defined(FULL_SAFE_BROWSING) | 424 #if defined(FULL_SAFE_BROWSING) |
421 RegisterBinaryIntegrityAnalysis(); | 425 RegisterBinaryIntegrityAnalysis(); |
422 RegisterBlacklistLoadAnalysis(); | 426 RegisterBlacklistLoadAnalysis(); |
423 RegisterVariationsSeedSignatureAnalysis(); | 427 RegisterVariationsSeedSignatureAnalysis(); |
424 #else | 428 #else |
425 NOTREACHED(); | 429 NOTREACHED(); |
426 #endif | 430 #endif |
427 } | 431 } |
428 | 432 |
429 SafeBrowsingProtocolConfig SafeBrowsingService::GetProtocolConfig() const { | 433 SafeBrowsingProtocolConfig SafeBrowsingService::GetProtocolConfig() const { |
430 SafeBrowsingProtocolConfig config; | 434 SafeBrowsingProtocolConfig config; |
431 // On Windows, get the safe browsing client name from the browser | 435 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 | 436 |
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(); | 437 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
453 config.disable_auto_update = | 438 config.disable_auto_update = |
454 cmdline->HasSwitch(switches::kSbDisableAutoUpdate) || | 439 cmdline->HasSwitch(switches::kSbDisableAutoUpdate) || |
455 cmdline->HasSwitch(switches::kDisableBackgroundNetworking); | 440 cmdline->HasSwitch(switches::kDisableBackgroundNetworking); |
456 config.url_prefix = kSbDefaultURLPrefix; | 441 config.url_prefix = kSbDefaultURLPrefix; |
457 config.backup_connect_error_url_prefix = kSbBackupConnectErrorURLPrefix; | 442 config.backup_connect_error_url_prefix = kSbBackupConnectErrorURLPrefix; |
458 config.backup_http_error_url_prefix = kSbBackupHttpErrorURLPrefix; | 443 config.backup_http_error_url_prefix = kSbBackupHttpErrorURLPrefix; |
459 config.backup_network_error_url_prefix = kSbBackupNetworkErrorURLPrefix; | 444 config.backup_network_error_url_prefix = kSbBackupNetworkErrorURLPrefix; |
460 | 445 |
461 return config; | 446 return config; |
462 } | 447 } |
463 | 448 |
| 449 V4GetHashProtocolConfig |
| 450 SafeBrowsingService::GetV4GetHashProtocolConfig() const { |
| 451 V4GetHashProtocolConfig config; |
| 452 config.client_name = GetProtocolConfigClientName(); |
| 453 config.version = SafeBrowsingProtocolManagerHelper::Version(); |
| 454 config.key_param = google_apis::GetAPIKey();; |
| 455 |
| 456 return config; |
| 457 } |
| 458 |
| 459 std::string SafeBrowsingService::GetProtocolConfigClientName() const { |
| 460 std::string client_name; |
| 461 // On Windows, get the safe browsing client name from the browser |
| 462 // distribution classes in installer util. These classes don't yet have |
| 463 // an analog on non-Windows builds so just keep the name specified here. |
| 464 #if defined(OS_WIN) |
| 465 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 466 client_name = dist->GetSafeBrowsingName(); |
| 467 #else |
| 468 #if defined(GOOGLE_CHROME_BUILD) |
| 469 client_name = "googlechrome"; |
| 470 #else |
| 471 client_name = "chromium"; |
| 472 #endif |
| 473 |
| 474 // Mark client string to allow server to differentiate mobile. |
| 475 #if defined(OS_ANDROID) |
| 476 client_name.append("-a"); |
| 477 #elif defined(OS_IOS) |
| 478 client_name.append("-i"); |
| 479 #endif |
| 480 |
| 481 #endif // defined(OS_WIN) |
| 482 |
| 483 return client_name; |
| 484 } |
| 485 |
464 // Any tests that create a DatabaseManager that isn't derived from | 486 // Any tests that create a DatabaseManager that isn't derived from |
465 // LocalSafeBrowsingDatabaseManager should override this to return NULL. | 487 // LocalSafeBrowsingDatabaseManager should override this to return NULL. |
466 SafeBrowsingProtocolManagerDelegate* | 488 SafeBrowsingProtocolManagerDelegate* |
467 SafeBrowsingService::GetProtocolManagerDelegate() { | 489 SafeBrowsingService::GetProtocolManagerDelegate() { |
468 #if defined(SAFE_BROWSING_DB_LOCAL) | 490 #if defined(SAFE_BROWSING_DB_LOCAL) |
469 return static_cast<LocalSafeBrowsingDatabaseManager*>( | 491 return static_cast<LocalSafeBrowsingDatabaseManager*>( |
470 database_manager_.get()); | 492 database_manager_.get()); |
471 #else | 493 #else |
472 NOTREACHED(); | 494 NOTREACHED(); |
473 return NULL; | 495 return NULL; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 } | 667 } |
646 | 668 |
647 void SafeBrowsingService::OnSendDownloadRecoveryReport( | 669 void SafeBrowsingService::OnSendDownloadRecoveryReport( |
648 const std::string& report) { | 670 const std::string& report) { |
649 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 671 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
650 if (ping_manager()) | 672 if (ping_manager()) |
651 ping_manager()->ReportThreatDetails(report); | 673 ping_manager()->ReportThreatDetails(report); |
652 } | 674 } |
653 | 675 |
654 } // namespace safe_browsing | 676 } // namespace safe_browsing |
OLD | NEW |