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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 case INVALID: | 87 case INVALID: |
88 // |full_hashes| should never contain INVALID as a |list_id|. | 88 // |full_hashes| should never contain INVALID as a |list_id|. |
89 NOTREACHED(); | 89 NOTREACHED(); |
90 break; | 90 break; |
91 case MALWARE: // Falls through. | 91 case MALWARE: // Falls through. |
92 case PHISH: // Falls through. | 92 case PHISH: // Falls through. |
93 case BINURL: // Falls through. | 93 case BINURL: // Falls through. |
94 case CSDWHITELIST: // Falls through. | 94 case CSDWHITELIST: // Falls through. |
95 case DOWNLOADWHITELIST: // Falls through. | 95 case DOWNLOADWHITELIST: // Falls through. |
96 case INCLUSIONWHITELIST: // Falls through. | 96 case INCLUSIONWHITELIST: // Falls through. |
| 97 case MODULEWHITELIST: // Falls through. |
97 case EXTENSIONBLACKLIST: // Falls through. | 98 case EXTENSIONBLACKLIST: // Falls through. |
98 case IPBLACKLIST: | 99 case IPBLACKLIST: |
99 if (index) | 100 if (index) |
100 *index = i; | 101 *index = i; |
101 return threat; | 102 return threat; |
102 case UNWANTEDURL: | 103 case UNWANTEDURL: |
103 // UNWANTEDURL is considered less severe than other threats, keep | 104 // UNWANTEDURL is considered less severe than other threats, keep |
104 // looking. | 105 // looking. |
105 pending_threat = threat; | 106 pending_threat = threat; |
106 if (index) | 107 if (index) |
(...skipping 25 matching lines...) Expand all Loading... |
132 switch (threat) { | 133 switch (threat) { |
133 case INVALID: | 134 case INVALID: |
134 // Ignore patterns with no matching threat. | 135 // Ignore patterns with no matching threat. |
135 break; | 136 break; |
136 case MALWARE: // Falls through. | 137 case MALWARE: // Falls through. |
137 case PHISH: // Falls through. | 138 case PHISH: // Falls through. |
138 case BINURL: // Falls through. | 139 case BINURL: // Falls through. |
139 case CSDWHITELIST: // Falls through. | 140 case CSDWHITELIST: // Falls through. |
140 case DOWNLOADWHITELIST: // Falls through. | 141 case DOWNLOADWHITELIST: // Falls through. |
141 case INCLUSIONWHITELIST: // Falls through. | 142 case INCLUSIONWHITELIST: // Falls through. |
| 143 case MODULEWHITELIST: // Falls through. |
142 case EXTENSIONBLACKLIST: // Falls through. | 144 case EXTENSIONBLACKLIST: // Falls through. |
143 case IPBLACKLIST: | 145 case IPBLACKLIST: |
144 return threat; | 146 return threat; |
145 case UNWANTEDURL: | 147 case UNWANTEDURL: |
146 // UNWANTEDURL is considered less severe than other threats, keep | 148 // UNWANTEDURL is considered less severe than other threats, keep |
147 // looking. | 149 // looking. |
148 pending_threat = threat; | 150 pending_threat = threat; |
149 break; | 151 break; |
150 } | 152 } |
151 } | 153 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 const scoped_refptr<SafeBrowsingService>& service) | 263 const scoped_refptr<SafeBrowsingService>& service) |
262 : sb_service_(service), | 264 : sb_service_(service), |
263 database_(NULL), | 265 database_(NULL), |
264 enabled_(false), | 266 enabled_(false), |
265 enable_download_protection_(false), | 267 enable_download_protection_(false), |
266 enable_csd_whitelist_(false), | 268 enable_csd_whitelist_(false), |
267 enable_download_whitelist_(false), | 269 enable_download_whitelist_(false), |
268 enable_extension_blacklist_(false), | 270 enable_extension_blacklist_(false), |
269 enable_ip_blacklist_(false), | 271 enable_ip_blacklist_(false), |
270 enable_unwanted_software_blacklist_(true), | 272 enable_unwanted_software_blacklist_(true), |
| 273 enable_module_whitelist_(true), |
271 update_in_progress_(false), | 274 update_in_progress_(false), |
272 database_update_in_progress_(false), | 275 database_update_in_progress_(false), |
273 closing_database_(false), | 276 closing_database_(false), |
274 check_timeout_(base::TimeDelta::FromMilliseconds(kCheckTimeoutMs)) { | 277 check_timeout_(base::TimeDelta::FromMilliseconds(kCheckTimeoutMs)) { |
275 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 278 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
276 DCHECK(sb_service_.get() != NULL); | 279 DCHECK(sb_service_.get() != NULL); |
277 | 280 |
278 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 281 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
279 enable_download_protection_ = | 282 enable_download_protection_ = |
280 !cmdline->HasSwitch(switches::kSbDisableDownloadProtection); | 283 !cmdline->HasSwitch(switches::kSbDisableDownloadProtection); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 } | 429 } |
427 | 430 |
428 bool LocalSafeBrowsingDatabaseManager::MatchInclusionWhitelistUrl( | 431 bool LocalSafeBrowsingDatabaseManager::MatchInclusionWhitelistUrl( |
429 const GURL& url) { | 432 const GURL& url) { |
430 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 433 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
431 if (!enabled_ || !MakeDatabaseAvailable()) | 434 if (!enabled_ || !MakeDatabaseAvailable()) |
432 return true; | 435 return true; |
433 return database_->ContainsInclusionWhitelistedUrl(url); | 436 return database_->ContainsInclusionWhitelistedUrl(url); |
434 } | 437 } |
435 | 438 |
| 439 bool LocalSafeBrowsingDatabaseManager::MatchModuleWhitelistString( |
| 440 const std::string& str) { |
| 441 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 442 if (!enabled_ || !enable_module_whitelist_ || !MakeDatabaseAvailable()) { |
| 443 return true; |
| 444 } |
| 445 return database_->ContainsModuleWhitelistedString(str); |
| 446 } |
| 447 |
436 bool LocalSafeBrowsingDatabaseManager::IsMalwareKillSwitchOn() { | 448 bool LocalSafeBrowsingDatabaseManager::IsMalwareKillSwitchOn() { |
437 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 449 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
438 if (!enabled_ || !MakeDatabaseAvailable()) { | 450 if (!enabled_ || !MakeDatabaseAvailable()) { |
439 return true; | 451 return true; |
440 } | 452 } |
441 return database_->IsMalwareIPMatchKillSwitchOn(); | 453 return database_->IsMalwareIPMatchKillSwitchOn(); |
442 } | 454 } |
443 | 455 |
444 bool LocalSafeBrowsingDatabaseManager::IsCsdWhitelistKillSwitchOn() { | 456 bool LocalSafeBrowsingDatabaseManager::IsCsdWhitelistKillSwitchOn() { |
445 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 457 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 785 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
774 | 786 |
775 if (database_) | 787 if (database_) |
776 return database_; | 788 return database_; |
777 | 789 |
778 const base::TimeTicks before = base::TimeTicks::Now(); | 790 const base::TimeTicks before = base::TimeTicks::Now(); |
779 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create( | 791 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create( |
780 safe_browsing_task_runner_, enable_download_protection_, | 792 safe_browsing_task_runner_, enable_download_protection_, |
781 enable_csd_whitelist_, enable_download_whitelist_, | 793 enable_csd_whitelist_, enable_download_whitelist_, |
782 enable_extension_blacklist_, enable_ip_blacklist_, | 794 enable_extension_blacklist_, enable_ip_blacklist_, |
783 enable_unwanted_software_blacklist_); | 795 enable_unwanted_software_blacklist_, enable_module_whitelist_); |
784 | 796 |
785 database->Init(SafeBrowsingService::GetBaseFilename()); | 797 database->Init(SafeBrowsingService::GetBaseFilename()); |
786 { | 798 { |
787 // Acquiring the lock here guarantees correct ordering between the writes to | 799 // Acquiring the lock here guarantees correct ordering between the writes to |
788 // the new database object above, and the setting of |database_| below. | 800 // the new database object above, and the setting of |database_| below. |
789 base::AutoLock lock(database_lock_); | 801 base::AutoLock lock(database_lock_); |
790 database_ = database; | 802 database_ = database; |
791 } | 803 } |
792 | 804 |
793 BrowserThread::PostTask( | 805 BrowserThread::PostTask( |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 FROM_HERE, base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, | 1214 FROM_HERE, base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, |
1203 check->weak_ptr_factory_->GetWeakPtr(), check), | 1215 check->weak_ptr_factory_->GetWeakPtr(), check), |
1204 check_timeout_); | 1216 check_timeout_); |
1205 } | 1217 } |
1206 | 1218 |
1207 bool LocalSafeBrowsingDatabaseManager::download_protection_enabled() const { | 1219 bool LocalSafeBrowsingDatabaseManager::download_protection_enabled() const { |
1208 return enable_download_protection_; | 1220 return enable_download_protection_; |
1209 } | 1221 } |
1210 | 1222 |
1211 } // namespace safe_browsing | 1223 } // namespace safe_browsing |
OLD | NEW |