| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 if (index) | 99 if (index) |
| 100 *index = i; | 100 *index = i; |
| 101 return threat; | 101 return threat; |
| 102 case UNWANTEDURL: | 102 case UNWANTEDURL: |
| 103 // UNWANTEDURL is considered less severe than other threats, keep | 103 // UNWANTEDURL is considered less severe than other threats, keep |
| 104 // looking. | 104 // looking. |
| 105 pending_threat = threat; | 105 pending_threat = threat; |
| 106 if (index) | 106 if (index) |
| 107 *index = i; | 107 *index = i; |
| 108 break; | 108 break; |
| 109 case RESOURCEBLACKLIST: |
| 110 // RESOURCEBLACKLIST is even less severe than UNWANTEDURL. |
| 111 if (pending_threat == INVALID) { |
| 112 pending_threat = threat; |
| 113 if (index) |
| 114 *index = i; |
| 115 } |
| 116 break; |
| 109 } | 117 } |
| 110 } | 118 } |
| 111 } | 119 } |
| 112 return pending_threat; | 120 return pending_threat; |
| 113 } | 121 } |
| 114 | 122 |
| 115 // Given a URL, compare all the possible host + path full hashes to the set of | 123 // Given a URL, compare all the possible host + path full hashes to the set of |
| 116 // provided full hashes. Returns the list id of the severest matching result | 124 // provided full hashes. Returns the list id of the severest matching result |
| 117 // from |full_hashes|, or INVALID if none match. | 125 // from |full_hashes|, or INVALID if none match. |
| 118 ListType GetUrlSeverestThreatListType( | 126 ListType GetUrlSeverestThreatListType( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 140 case DOWNLOADWHITELIST: // Falls through. | 148 case DOWNLOADWHITELIST: // Falls through. |
| 141 case INCLUSIONWHITELIST: // Falls through. | 149 case INCLUSIONWHITELIST: // Falls through. |
| 142 case EXTENSIONBLACKLIST: // Falls through. | 150 case EXTENSIONBLACKLIST: // Falls through. |
| 143 case IPBLACKLIST: | 151 case IPBLACKLIST: |
| 144 return threat; | 152 return threat; |
| 145 case UNWANTEDURL: | 153 case UNWANTEDURL: |
| 146 // UNWANTEDURL is considered less severe than other threats, keep | 154 // UNWANTEDURL is considered less severe than other threats, keep |
| 147 // looking. | 155 // looking. |
| 148 pending_threat = threat; | 156 pending_threat = threat; |
| 149 break; | 157 break; |
| 158 case RESOURCEBLACKLIST: |
| 159 // RESOURCEBLACKLIST is even less severe than UNWANTEDURL. |
| 160 if (pending_threat == INVALID) { |
| 161 pending_threat = threat; |
| 162 } |
| 163 break; |
| 150 } | 164 } |
| 151 } | 165 } |
| 152 return pending_threat; | 166 return pending_threat; |
| 153 } | 167 } |
| 154 | 168 |
| 155 SBThreatType GetThreatTypeFromListType(ListType list_type) { | 169 SBThreatType GetThreatTypeFromListType(ListType list_type) { |
| 156 switch (list_type) { | 170 switch (list_type) { |
| 157 case PHISH: | 171 case PHISH: |
| 158 return SB_THREAT_TYPE_URL_PHISHING; | 172 return SB_THREAT_TYPE_URL_PHISHING; |
| 159 case MALWARE: | 173 case MALWARE: |
| 160 return SB_THREAT_TYPE_URL_MALWARE; | 174 return SB_THREAT_TYPE_URL_MALWARE; |
| 161 case UNWANTEDURL: | 175 case UNWANTEDURL: |
| 162 return SB_THREAT_TYPE_URL_UNWANTED; | 176 return SB_THREAT_TYPE_URL_UNWANTED; |
| 163 case BINURL: | 177 case BINURL: |
| 164 return SB_THREAT_TYPE_BINARY_MALWARE_URL; | 178 return SB_THREAT_TYPE_BINARY_MALWARE_URL; |
| 165 case EXTENSIONBLACKLIST: | 179 case EXTENSIONBLACKLIST: |
| 166 return SB_THREAT_TYPE_EXTENSION; | 180 return SB_THREAT_TYPE_EXTENSION; |
| 181 case RESOURCEBLACKLIST: |
| 182 return SB_THREAT_TYPE_BLACKLISTED_RESOURCE; |
| 167 default: | 183 default: |
| 168 DVLOG(1) << "Unknown safe browsing list id " << list_type; | 184 DVLOG(1) << "Unknown safe browsing list id " << list_type; |
| 169 return SB_THREAT_TYPE_SAFE; | 185 return SB_THREAT_TYPE_SAFE; |
| 170 } | 186 } |
| 171 } | 187 } |
| 172 | 188 |
| 173 } // namespace | 189 } // namespace |
| 174 | 190 |
| 175 // static | 191 // static |
| 176 SBThreatType LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( | 192 SBThreatType LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 const scoped_refptr<SafeBrowsingService>& service) | 277 const scoped_refptr<SafeBrowsingService>& service) |
| 262 : sb_service_(service), | 278 : sb_service_(service), |
| 263 database_(NULL), | 279 database_(NULL), |
| 264 enabled_(false), | 280 enabled_(false), |
| 265 enable_download_protection_(false), | 281 enable_download_protection_(false), |
| 266 enable_csd_whitelist_(false), | 282 enable_csd_whitelist_(false), |
| 267 enable_download_whitelist_(false), | 283 enable_download_whitelist_(false), |
| 268 enable_extension_blacklist_(false), | 284 enable_extension_blacklist_(false), |
| 269 enable_ip_blacklist_(false), | 285 enable_ip_blacklist_(false), |
| 270 enable_unwanted_software_blacklist_(true), | 286 enable_unwanted_software_blacklist_(true), |
| 287 enable_resource_blacklist_(true), |
| 271 update_in_progress_(false), | 288 update_in_progress_(false), |
| 272 database_update_in_progress_(false), | 289 database_update_in_progress_(false), |
| 273 closing_database_(false), | 290 closing_database_(false), |
| 274 check_timeout_(base::TimeDelta::FromMilliseconds(kCheckTimeoutMs)) { | 291 check_timeout_(base::TimeDelta::FromMilliseconds(kCheckTimeoutMs)) { |
| 275 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 292 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 276 DCHECK(sb_service_.get() != NULL); | 293 DCHECK(sb_service_.get() != NULL); |
| 277 | 294 |
| 278 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 295 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 279 enable_download_protection_ = | 296 enable_download_protection_ = |
| 280 !cmdline->HasSwitch(switches::kSbDisableDownloadProtection); | 297 !cmdline->HasSwitch(switches::kSbDisableDownloadProtection); |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 790 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 774 | 791 |
| 775 if (database_) | 792 if (database_) |
| 776 return database_; | 793 return database_; |
| 777 | 794 |
| 778 const base::TimeTicks before = base::TimeTicks::Now(); | 795 const base::TimeTicks before = base::TimeTicks::Now(); |
| 779 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create( | 796 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create( |
| 780 safe_browsing_task_runner_, enable_download_protection_, | 797 safe_browsing_task_runner_, enable_download_protection_, |
| 781 enable_csd_whitelist_, enable_download_whitelist_, | 798 enable_csd_whitelist_, enable_download_whitelist_, |
| 782 enable_extension_blacklist_, enable_ip_blacklist_, | 799 enable_extension_blacklist_, enable_ip_blacklist_, |
| 783 enable_unwanted_software_blacklist_); | 800 enable_unwanted_software_blacklist_, |
| 801 enable_resource_blacklist_); |
| 784 | 802 |
| 785 database->Init(SafeBrowsingService::GetBaseFilename()); | 803 database->Init(SafeBrowsingService::GetBaseFilename()); |
| 786 { | 804 { |
| 787 // Acquiring the lock here guarantees correct ordering between the writes to | 805 // Acquiring the lock here guarantees correct ordering between the writes to |
| 788 // the new database object above, and the setting of |database_| below. | 806 // the new database object above, and the setting of |database_| below. |
| 789 base::AutoLock lock(database_lock_); | 807 base::AutoLock lock(database_lock_); |
| 790 database_ = database; | 808 database_ = database; |
| 791 } | 809 } |
| 792 | 810 |
| 793 BrowserThread::PostTask( | 811 BrowserThread::PostTask( |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 FROM_HERE, base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, | 1220 FROM_HERE, base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, |
| 1203 check->weak_ptr_factory_->GetWeakPtr(), check), | 1221 check->weak_ptr_factory_->GetWeakPtr(), check), |
| 1204 check_timeout_); | 1222 check_timeout_); |
| 1205 } | 1223 } |
| 1206 | 1224 |
| 1207 bool LocalSafeBrowsingDatabaseManager::download_protection_enabled() const { | 1225 bool LocalSafeBrowsingDatabaseManager::download_protection_enabled() const { |
| 1208 return enable_download_protection_; | 1226 return enable_download_protection_; |
| 1209 } | 1227 } |
| 1210 | 1228 |
| 1211 } // namespace safe_browsing | 1229 } // namespace safe_browsing |
| OLD | NEW |