| 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/local_database_manager.h" | 5 #include "chrome/browser/safe_browsing/local_database_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 } else { | 869 } else { |
| 870 // We may have cached results for previous GetHash queries. Since | 870 // We may have cached results for previous GetHash queries. Since |
| 871 // this data comes from cache, don't histogram hits. | 871 // this data comes from cache, don't histogram hits. |
| 872 HandleOneCheck(check, check->cache_hits); | 872 HandleOneCheck(check, check->cache_hits); |
| 873 } | 873 } |
| 874 } | 874 } |
| 875 | 875 |
| 876 void LocalSafeBrowsingDatabaseManager::OnRequestFullHash( | 876 void LocalSafeBrowsingDatabaseManager::OnRequestFullHash( |
| 877 SafeBrowsingCheck* check) { | 877 SafeBrowsingCheck* check) { |
| 878 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 878 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 879 check->is_extended_reporting = GetExtendedReporting(); | 879 check->extended_reporting_level = GetExtendedReporting(); |
| 880 BrowserThread::PostTask( | 880 BrowserThread::PostTask( |
| 881 BrowserThread::IO, FROM_HERE, | 881 BrowserThread::IO, FROM_HERE, |
| 882 base::Bind(&LocalSafeBrowsingDatabaseManager::RequestFullHash, this, | 882 base::Bind(&LocalSafeBrowsingDatabaseManager::RequestFullHash, this, |
| 883 check)); | 883 check)); |
| 884 } | 884 } |
| 885 | 885 |
| 886 bool LocalSafeBrowsingDatabaseManager::GetExtendedReporting() { | 886 ExtendedReportingLevel |
| 887 LocalSafeBrowsingDatabaseManager::GetExtendedReporting() { |
| 887 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 888 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 888 | 889 |
| 889 // Determine if the last used profile is opted into extended reporting. | 890 // Determine if the last used profile is opted into extended reporting. |
| 890 // Note: It is possible that the last used profile is not the one triggers | 891 // Note: It is possible that the last used profile is not the one triggers |
| 891 // the hash request, but not very likely. | 892 // the hash request, but not very likely. |
| 892 bool is_extended_reporting = false; | 893 ExtendedReportingLevel extended_reporting_level = SBER_LEVEL_OFF; |
| 893 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 894 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 894 if (profile_manager) { | 895 if (profile_manager) { |
| 895 Profile* profile = profile_manager->GetLastUsedProfile(); | 896 Profile* profile = profile_manager->GetLastUsedProfile(); |
| 896 is_extended_reporting = | 897 extended_reporting_level = |
| 897 profile && IsExtendedReportingEnabled(*profile->GetPrefs()); | 898 profile ? GetExtendedReportingLevel(*profile->GetPrefs()) |
| 899 : SBER_LEVEL_OFF; |
| 898 } | 900 } |
| 899 return is_extended_reporting; | 901 return extended_reporting_level; |
| 900 } | 902 } |
| 901 | 903 |
| 902 void LocalSafeBrowsingDatabaseManager::RequestFullHash( | 904 void LocalSafeBrowsingDatabaseManager::RequestFullHash( |
| 903 SafeBrowsingCheck* check) { | 905 SafeBrowsingCheck* check) { |
| 904 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 906 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 905 | 907 |
| 906 if (!enabled_) | 908 if (!enabled_) |
| 907 return; | 909 return; |
| 908 | 910 |
| 909 bool is_download = check->check_type == BINURL; | 911 bool is_download = check->check_type == BINURL; |
| 910 sb_service_->protocol_manager()->GetFullHash( | 912 sb_service_->protocol_manager()->GetFullHash( |
| 911 check->prefix_hits, | 913 check->prefix_hits, |
| 912 base::Bind(&LocalSafeBrowsingDatabaseManager::HandleGetHashResults, | 914 base::Bind(&LocalSafeBrowsingDatabaseManager::HandleGetHashResults, |
| 913 base::Unretained(this), check), | 915 base::Unretained(this), check), |
| 914 is_download, check->is_extended_reporting); | 916 is_download, check->extended_reporting_level); |
| 915 } | 917 } |
| 916 | 918 |
| 917 void LocalSafeBrowsingDatabaseManager::GetAllChunksFromDatabase( | 919 void LocalSafeBrowsingDatabaseManager::GetAllChunksFromDatabase( |
| 918 GetChunksCallback callback) { | 920 GetChunksCallback callback) { |
| 919 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 921 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 920 | 922 |
| 921 bool database_error = true; | 923 bool database_error = true; |
| 922 std::vector<SBListChunkRanges> lists; | 924 std::vector<SBListChunkRanges> lists; |
| 923 DCHECK(!database_update_in_progress_); | 925 DCHECK(!database_update_in_progress_); |
| 924 database_update_in_progress_ = true; | 926 database_update_in_progress_ = true; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 935 &LocalSafeBrowsingDatabaseManager::BeforeGetAllChunksFromDatabase, | 937 &LocalSafeBrowsingDatabaseManager::BeforeGetAllChunksFromDatabase, |
| 936 this, lists, database_error, callback)); | 938 this, lists, database_error, callback)); |
| 937 } | 939 } |
| 938 | 940 |
| 939 void LocalSafeBrowsingDatabaseManager::BeforeGetAllChunksFromDatabase( | 941 void LocalSafeBrowsingDatabaseManager::BeforeGetAllChunksFromDatabase( |
| 940 const std::vector<SBListChunkRanges>& lists, | 942 const std::vector<SBListChunkRanges>& lists, |
| 941 bool database_error, | 943 bool database_error, |
| 942 GetChunksCallback callback) { | 944 GetChunksCallback callback) { |
| 943 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 945 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 944 | 946 |
| 945 bool is_extended_reporting = GetExtendedReporting(); | 947 ExtendedReportingLevel extended_reporting_level = GetExtendedReporting(); |
| 946 | 948 |
| 947 BrowserThread::PostTask( | 949 BrowserThread::PostTask( |
| 948 BrowserThread::IO, FROM_HERE, | 950 BrowserThread::IO, FROM_HERE, |
| 949 base::Bind(&LocalSafeBrowsingDatabaseManager::OnGetAllChunksFromDatabase, | 951 base::Bind(&LocalSafeBrowsingDatabaseManager::OnGetAllChunksFromDatabase, |
| 950 this, lists, database_error, is_extended_reporting, callback)); | 952 this, lists, database_error, extended_reporting_level, |
| 953 callback)); |
| 951 } | 954 } |
| 952 | 955 |
| 953 void LocalSafeBrowsingDatabaseManager::OnGetAllChunksFromDatabase( | 956 void LocalSafeBrowsingDatabaseManager::OnGetAllChunksFromDatabase( |
| 954 const std::vector<SBListChunkRanges>& lists, | 957 const std::vector<SBListChunkRanges>& lists, |
| 955 bool database_error, | 958 bool database_error, |
| 956 bool is_extended_reporting, | 959 ExtendedReportingLevel reporting_level, |
| 957 GetChunksCallback callback) { | 960 GetChunksCallback callback) { |
| 958 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 961 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 959 if (enabled_) | 962 if (enabled_) |
| 960 callback.Run(lists, database_error, is_extended_reporting); | 963 callback.Run(lists, database_error, reporting_level); |
| 961 } | 964 } |
| 962 | 965 |
| 963 void LocalSafeBrowsingDatabaseManager::OnAddChunksComplete( | 966 void LocalSafeBrowsingDatabaseManager::OnAddChunksComplete( |
| 964 AddChunksCallback callback) { | 967 AddChunksCallback callback) { |
| 965 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 968 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 966 if (enabled_) | 969 if (enabled_) |
| 967 callback.Run(); | 970 callback.Run(); |
| 968 } | 971 } |
| 969 | 972 |
| 970 void LocalSafeBrowsingDatabaseManager::DatabaseLoadComplete() { | 973 void LocalSafeBrowsingDatabaseManager::DatabaseLoadComplete() { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, | 1242 base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, |
| 1240 check_ptr->weak_ptr_factory_->GetWeakPtr(), check_ptr), | 1243 check_ptr->weak_ptr_factory_->GetWeakPtr(), check_ptr), |
| 1241 check_timeout_); | 1244 check_timeout_); |
| 1242 } | 1245 } |
| 1243 | 1246 |
| 1244 bool LocalSafeBrowsingDatabaseManager::IsDownloadProtectionEnabled() const { | 1247 bool LocalSafeBrowsingDatabaseManager::IsDownloadProtectionEnabled() const { |
| 1245 return enable_download_protection_; | 1248 return enable_download_protection_; |
| 1246 } | 1249 } |
| 1247 | 1250 |
| 1248 } // namespace safe_browsing | 1251 } // namespace safe_browsing |
| OLD | NEW |