Chromium Code Reviews| 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/browser/safe_browsing/ui_manager.h" | 32 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 33 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
| 34 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 36 #include "chrome/common/safe_browsing/file_type_policies.h" | 36 #include "chrome/common/safe_browsing/file_type_policies.h" |
| 37 #include "components/prefs/pref_change_registrar.h" | 37 #include "components/prefs/pref_change_registrar.h" |
| 38 #include "components/prefs/pref_service.h" | 38 #include "components/prefs/pref_service.h" |
| 39 #include "components/safe_browsing/common/safebrowsing_constants.h" | 39 #include "components/safe_browsing/common/safebrowsing_constants.h" |
| 40 #include "components/safe_browsing/common/safebrowsing_switches.h" | 40 #include "components/safe_browsing/common/safebrowsing_switches.h" |
| 41 #include "components/safe_browsing_db/database_manager.h" | 41 #include "components/safe_browsing_db/database_manager.h" |
| 42 #include "components/safe_browsing_db/safe_browsing_prefs.h" | |
| 43 #include "components/safe_browsing_db/v4_feature_list.h" | 42 #include "components/safe_browsing_db/v4_feature_list.h" |
| 44 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 43 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 45 #include "components/safe_browsing_db/v4_local_database_manager.h" | 44 #include "components/safe_browsing_db/v4_local_database_manager.h" |
| 46 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h " | 45 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h " |
| 47 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
| 48 #include "content/public/browser/cookie_store_factory.h" | 47 #include "content/public/browser/cookie_store_factory.h" |
| 49 #include "content/public/browser/notification_service.h" | 48 #include "content/public/browser/notification_service.h" |
| 50 #include "content/public/browser/resource_request_info.h" | 49 #include "content/public/browser/resource_request_info.h" |
| 51 #include "google_apis/google_api_keys.h" | 50 #include "google_apis/google_api_keys.h" |
| 52 #include "net/cookies/cookie_store.h" | 51 #include "net/cookies/cookie_store.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 | 289 |
| 291 // static | 290 // static |
| 292 SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { | 291 SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { |
| 293 if (!factory_) | 292 if (!factory_) |
| 294 factory_ = g_safe_browsing_service_factory_impl.Pointer(); | 293 factory_ = g_safe_browsing_service_factory_impl.Pointer(); |
| 295 return factory_->CreateSafeBrowsingService(); | 294 return factory_->CreateSafeBrowsingService(); |
| 296 } | 295 } |
| 297 | 296 |
| 298 SafeBrowsingService::SafeBrowsingService() | 297 SafeBrowsingService::SafeBrowsingService() |
| 299 : services_delegate_(ServicesDelegate::Create(this)), | 298 : services_delegate_(ServicesDelegate::Create(this)), |
| 299 estimated_extended_reporting_by_prefs_(SBER_LEVEL_OFF), | |
| 300 enabled_(false), | 300 enabled_(false), |
| 301 enabled_by_prefs_(false), | 301 enabled_by_prefs_(false), |
| 302 enabled_v4_only_(safe_browsing::V4FeatureList::IsV4OnlyEnabled()) {} | 302 enabled_v4_only_(safe_browsing::V4FeatureList::IsV4OnlyEnabled()) {} |
| 303 | 303 |
| 304 SafeBrowsingService::~SafeBrowsingService() { | 304 SafeBrowsingService::~SafeBrowsingService() { |
| 305 // We should have already been shut down. If we're still enabled, then the | 305 // We should have already been shut down. If we're still enabled, then the |
| 306 // database isn't going to be closed properly, which could lead to corruption. | 306 // database isn't going to be closed properly, which could lead to corruption. |
| 307 DCHECK(!enabled_); | 307 DCHECK(!enabled_); |
| 308 } | 308 } |
| 309 | 309 |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 default: | 664 default: |
| 665 NOTREACHED(); | 665 NOTREACHED(); |
| 666 } | 666 } |
| 667 } | 667 } |
| 668 | 668 |
| 669 void SafeBrowsingService::AddPrefService(PrefService* pref_service) { | 669 void SafeBrowsingService::AddPrefService(PrefService* pref_service) { |
| 670 DCHECK(prefs_map_.find(pref_service) == prefs_map_.end()); | 670 DCHECK(prefs_map_.find(pref_service) == prefs_map_.end()); |
| 671 std::unique_ptr<PrefChangeRegistrar> registrar = | 671 std::unique_ptr<PrefChangeRegistrar> registrar = |
| 672 base::MakeUnique<PrefChangeRegistrar>(); | 672 base::MakeUnique<PrefChangeRegistrar>(); |
| 673 registrar->Init(pref_service); | 673 registrar->Init(pref_service); |
| 674 registrar->Add(prefs::kSafeBrowsingEnabled, | 674 registrar->Add( |
| 675 base::Bind(&SafeBrowsingService::RefreshState, | 675 prefs::kSafeBrowsingEnabled, |
| 676 base::Unretained(this))); | 676 base::Bind(&SafeBrowsingService::RefreshState, base::Unretained(this))); |
| 677 // ClientSideDetectionService will need to be refresh the models | 677 // ClientSideDetectionService will need to be refresh the models |
| 678 // renderers have if extended-reporting changes. | 678 // renderers have if extended-reporting changes. |
| 679 registrar->Add( | 679 registrar->Add( |
| 680 prefs::kSafeBrowsingExtendedReportingEnabled, | 680 prefs::kSafeBrowsingExtendedReportingEnabled, |
| 681 base::Bind(&SafeBrowsingService::RefreshState, base::Unretained(this))); | 681 base::Bind(&SafeBrowsingService::RefreshState, base::Unretained(this))); |
| 682 registrar->Add( | 682 registrar->Add( |
| 683 prefs::kSafeBrowsingScoutReportingEnabled, | 683 prefs::kSafeBrowsingScoutReportingEnabled, |
| 684 base::Bind(&SafeBrowsingService::RefreshState, base::Unretained(this))); | 684 base::Bind(&SafeBrowsingService::RefreshState, base::Unretained(this))); |
| 685 prefs_map_[pref_service] = std::move(registrar); | 685 prefs_map_[pref_service] = std::move(registrar); |
| 686 RefreshState(); | 686 RefreshState(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 714 std::unique_ptr<SafeBrowsingService::ShutdownSubscription> | 714 std::unique_ptr<SafeBrowsingService::ShutdownSubscription> |
| 715 SafeBrowsingService::RegisterShutdownCallback( | 715 SafeBrowsingService::RegisterShutdownCallback( |
| 716 const base::Callback<void(void)>& callback) { | 716 const base::Callback<void(void)>& callback) { |
| 717 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 717 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 718 return shutdown_callback_list_.Add(callback); | 718 return shutdown_callback_list_.Add(callback); |
| 719 } | 719 } |
| 720 | 720 |
| 721 void SafeBrowsingService::RefreshState() { | 721 void SafeBrowsingService::RefreshState() { |
| 722 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 722 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 723 // Check if any profile requires the service to be active. | 723 // Check if any profile requires the service to be active. |
| 724 bool enable = false; | 724 enabled_by_prefs_ = false; |
| 725 estimated_extended_reporting_by_prefs_ = SBER_LEVEL_OFF; | |
| 725 for (const auto& pref : prefs_map_) { | 726 for (const auto& pref : prefs_map_) { |
| 726 if (pref.first->GetBoolean(prefs::kSafeBrowsingEnabled)) { | 727 if (pref.first->GetBoolean(prefs::kSafeBrowsingEnabled)) { |
| 727 enable = true; | 728 enabled_by_prefs_ = true; |
| 728 break; | 729 ExtendedReportingLevel erl = |
| 730 safe_browsing::GetExtendedReportingLevel(*pref.first); | |
| 731 if (erl != SBER_LEVEL_OFF) { | |
| 732 estimated_extended_reporting_by_prefs_ = erl; | |
|
lpz
2017/01/26 16:36:46
nit: would you perhaps care about finding the *max
vakh (use Gerrit instead)
2017/01/26 18:14:30
That would bias us towards Scout and I am not sure
| |
| 733 break; | |
| 734 } | |
| 729 } | 735 } |
| 730 } | 736 } |
| 731 | 737 |
| 732 enabled_by_prefs_ = enable; | 738 if (enabled_by_prefs_) |
| 733 | |
| 734 if (enable) | |
| 735 Start(); | 739 Start(); |
| 736 else | 740 else |
| 737 Stop(false); | 741 Stop(false); |
| 738 | 742 |
| 739 state_callback_list_.Notify(); | 743 state_callback_list_.Notify(); |
| 740 | 744 |
| 741 services_delegate_->RefreshState(enable); | 745 services_delegate_->RefreshState(enabled_by_prefs_); |
| 742 } | 746 } |
| 743 | 747 |
| 744 void SafeBrowsingService::SendSerializedDownloadReport( | 748 void SafeBrowsingService::SendSerializedDownloadReport( |
| 745 const std::string& report) { | 749 const std::string& report) { |
| 746 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 750 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 747 BrowserThread::PostTask( | 751 BrowserThread::PostTask( |
| 748 BrowserThread::IO, FROM_HERE, | 752 BrowserThread::IO, FROM_HERE, |
| 749 base::Bind(&SafeBrowsingService::OnSendSerializedDownloadReport, this, | 753 base::Bind(&SafeBrowsingService::OnSendSerializedDownloadReport, this, |
| 750 report)); | 754 report)); |
| 751 } | 755 } |
| 752 | 756 |
| 753 void SafeBrowsingService::OnSendSerializedDownloadReport( | 757 void SafeBrowsingService::OnSendSerializedDownloadReport( |
| 754 const std::string& report) { | 758 const std::string& report) { |
| 755 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 759 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 756 if (ping_manager()) | 760 if (ping_manager()) |
| 757 ping_manager()->ReportThreatDetails(report); | 761 ping_manager()->ReportThreatDetails(report); |
| 758 } | 762 } |
| 759 | 763 |
| 760 void SafeBrowsingService::ProcessResourceRequest( | 764 void SafeBrowsingService::ProcessResourceRequest( |
| 761 const ResourceRequestInfo& request) { | 765 const ResourceRequestInfo& request) { |
| 762 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 766 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 763 services_delegate_->ProcessResourceRequest(&request); | 767 services_delegate_->ProcessResourceRequest(&request); |
| 764 } | 768 } |
| 765 | 769 |
| 766 } // namespace safe_browsing | 770 } // namespace safe_browsing |
| OLD | NEW |