Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: chrome/browser/safe_browsing/database_manager.cc

Issue 1073633002: Remove PrerenderLocalPredictor, part 2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prerender-local-predictor-1
Patch Set: rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/database_manager.h" 5 #include "chrome/browser/safe_browsing/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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // |full_hashes| should never contain INVALID as a |list_id|. 81 // |full_hashes| should never contain INVALID as a |list_id|.
82 NOTREACHED(); 82 NOTREACHED();
83 break; 83 break;
84 case safe_browsing_util::MALWARE: // Falls through. 84 case safe_browsing_util::MALWARE: // Falls through.
85 case safe_browsing_util::PHISH: // Falls through. 85 case safe_browsing_util::PHISH: // Falls through.
86 case safe_browsing_util::BINURL: // Falls through. 86 case safe_browsing_util::BINURL: // Falls through.
87 case safe_browsing_util::CSDWHITELIST: // Falls through. 87 case safe_browsing_util::CSDWHITELIST: // Falls through.
88 case safe_browsing_util::DOWNLOADWHITELIST: // Falls through. 88 case safe_browsing_util::DOWNLOADWHITELIST: // Falls through.
89 case safe_browsing_util::INCLUSIONWHITELIST: // Falls through. 89 case safe_browsing_util::INCLUSIONWHITELIST: // Falls through.
90 case safe_browsing_util::EXTENSIONBLACKLIST: // Falls through. 90 case safe_browsing_util::EXTENSIONBLACKLIST: // Falls through.
91 case safe_browsing_util::SIDEEFFECTFREEWHITELIST: // Falls through.
92 case safe_browsing_util::IPBLACKLIST: 91 case safe_browsing_util::IPBLACKLIST:
93 if (index) 92 if (index)
94 *index = i; 93 *index = i;
95 return threat; 94 return threat;
96 case safe_browsing_util::UNWANTEDURL: 95 case safe_browsing_util::UNWANTEDURL:
97 // UNWANTEDURL is considered less severe than other threats, keep 96 // UNWANTEDURL is considered less severe than other threats, keep
98 // looking. 97 // looking.
99 pending_threat = threat; 98 pending_threat = threat;
100 if (index) 99 if (index)
101 *index = i; 100 *index = i;
(...skipping 25 matching lines...) Expand all
127 case safe_browsing_util::INVALID: 126 case safe_browsing_util::INVALID:
128 // Ignore patterns with no matching threat. 127 // Ignore patterns with no matching threat.
129 break; 128 break;
130 case safe_browsing_util::MALWARE: // Falls through. 129 case safe_browsing_util::MALWARE: // Falls through.
131 case safe_browsing_util::PHISH: // Falls through. 130 case safe_browsing_util::PHISH: // Falls through.
132 case safe_browsing_util::BINURL: // Falls through. 131 case safe_browsing_util::BINURL: // Falls through.
133 case safe_browsing_util::CSDWHITELIST: // Falls through. 132 case safe_browsing_util::CSDWHITELIST: // Falls through.
134 case safe_browsing_util::DOWNLOADWHITELIST: // Falls through. 133 case safe_browsing_util::DOWNLOADWHITELIST: // Falls through.
135 case safe_browsing_util::INCLUSIONWHITELIST: // Falls through. 134 case safe_browsing_util::INCLUSIONWHITELIST: // Falls through.
136 case safe_browsing_util::EXTENSIONBLACKLIST: // Falls through. 135 case safe_browsing_util::EXTENSIONBLACKLIST: // Falls through.
137 case safe_browsing_util::SIDEEFFECTFREEWHITELIST: // Falls through.
138 case safe_browsing_util::IPBLACKLIST: 136 case safe_browsing_util::IPBLACKLIST:
139 return threat; 137 return threat;
140 case safe_browsing_util::UNWANTEDURL: 138 case safe_browsing_util::UNWANTEDURL:
141 // UNWANTEDURL is considered less severe than other threats, keep 139 // UNWANTEDURL is considered less severe than other threats, keep
142 // looking. 140 // looking.
143 pending_threat = threat; 141 pending_threat = threat;
144 break; 142 break;
145 } 143 }
146 } 144 }
147 return pending_threat; 145 return pending_threat;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 252
255 SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager( 253 SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager(
256 const scoped_refptr<SafeBrowsingService>& service) 254 const scoped_refptr<SafeBrowsingService>& service)
257 : sb_service_(service), 255 : sb_service_(service),
258 database_(NULL), 256 database_(NULL),
259 enabled_(false), 257 enabled_(false),
260 enable_download_protection_(false), 258 enable_download_protection_(false),
261 enable_csd_whitelist_(false), 259 enable_csd_whitelist_(false),
262 enable_download_whitelist_(false), 260 enable_download_whitelist_(false),
263 enable_extension_blacklist_(false), 261 enable_extension_blacklist_(false),
264 enable_side_effect_free_whitelist_(false),
265 enable_ip_blacklist_(false), 262 enable_ip_blacklist_(false),
266 enable_unwanted_software_blacklist_(false), 263 enable_unwanted_software_blacklist_(false),
267 update_in_progress_(false), 264 update_in_progress_(false),
268 database_update_in_progress_(false), 265 database_update_in_progress_(false),
269 closing_database_(false), 266 closing_database_(false),
270 check_timeout_(base::TimeDelta::FromMilliseconds(kCheckTimeoutMs)) { 267 check_timeout_(base::TimeDelta::FromMilliseconds(kCheckTimeoutMs)) {
271 DCHECK_CURRENTLY_ON(BrowserThread::UI); 268 DCHECK_CURRENTLY_ON(BrowserThread::UI);
272 DCHECK(sb_service_.get() != NULL); 269 DCHECK(sb_service_.get() != NULL);
273 270
274 // Android only supports a subset of FULL_SAFE_BROWSING. 271 // Android only supports a subset of FULL_SAFE_BROWSING.
(...skipping 11 matching lines...) Expand all
286 // TODO(noelutz): remove this boolean variable since it should always be true 283 // TODO(noelutz): remove this boolean variable since it should always be true
287 // if SafeBrowsing is enabled. Unfortunately, we have no test data for this 284 // if SafeBrowsing is enabled. Unfortunately, we have no test data for this
288 // list right now. This means that we need to be able to disable this list 285 // list right now. This means that we need to be able to disable this list
289 // for the SafeBrowsing test to pass. 286 // for the SafeBrowsing test to pass.
290 enable_download_whitelist_ = enable_csd_whitelist_; 287 enable_download_whitelist_ = enable_csd_whitelist_;
291 288
292 // TODO(kalman): there really shouldn't be a flag for this. 289 // TODO(kalman): there really shouldn't be a flag for this.
293 enable_extension_blacklist_ = 290 enable_extension_blacklist_ =
294 !cmdline->HasSwitch(switches::kSbDisableExtensionBlacklist); 291 !cmdline->HasSwitch(switches::kSbDisableExtensionBlacklist);
295 292
296 enable_side_effect_free_whitelist_ =
297 prerender::IsSideEffectFreeWhitelistEnabled() &&
298 !cmdline->HasSwitch(switches::kSbDisableSideEffectFreeWhitelist);
299
300 // The client-side IP blacklist feature is tightly integrated with client-side 293 // The client-side IP blacklist feature is tightly integrated with client-side
301 // phishing protection for now. 294 // phishing protection for now.
302 enable_ip_blacklist_ = enable_csd_whitelist_; 295 enable_ip_blacklist_ = enable_csd_whitelist_;
303 296
304 // The UwS blacklist feature is controlled by a flag for M40. 297 // The UwS blacklist feature is controlled by a flag for M40.
305 enable_unwanted_software_blacklist_ = 298 enable_unwanted_software_blacklist_ =
306 safe_browsing_util::GetUnwantedTrialGroup() > safe_browsing_util::UWS_OFF; 299 safe_browsing_util::GetUnwantedTrialGroup() > safe_browsing_util::UWS_OFF;
307
308 enum SideEffectFreeWhitelistStatus {
309 SIDE_EFFECT_FREE_WHITELIST_ENABLED,
310 SIDE_EFFECT_FREE_WHITELIST_DISABLED,
311 SIDE_EFFECT_FREE_WHITELIST_STATUS_MAX
312 };
313
314 SideEffectFreeWhitelistStatus side_effect_free_whitelist_status =
315 enable_side_effect_free_whitelist_ ? SIDE_EFFECT_FREE_WHITELIST_ENABLED :
316 SIDE_EFFECT_FREE_WHITELIST_DISABLED;
317
318 UMA_HISTOGRAM_ENUMERATION("SB2.SideEffectFreeWhitelistStatus",
319 side_effect_free_whitelist_status,
320 SIDE_EFFECT_FREE_WHITELIST_STATUS_MAX);
321 #endif 300 #endif
322 } 301 }
323 302
324 SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() { 303 SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() {
325 // The DCHECK is disabled due to crbug.com/438754. 304 // The DCHECK is disabled due to crbug.com/438754.
326 // DCHECK_CURRENTLY_ON(BrowserThread::UI); 305 // DCHECK_CURRENTLY_ON(BrowserThread::UI);
327 306
328 // We should have already been shut down. If we're still enabled, then the 307 // We should have already been shut down. If we're still enabled, then the
329 // database isn't going to be closed properly, which could lead to corruption. 308 // database isn't going to be closed properly, which could lead to corruption.
330 DCHECK(!enabled_); 309 DCHECK(!enabled_);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 client, 362 client,
384 safe_browsing_util::EXTENSIONBLACKLIST, 363 safe_browsing_util::EXTENSIONBLACKLIST,
385 std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION)); 364 std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION));
386 StartSafeBrowsingCheck( 365 StartSafeBrowsingCheck(
387 check, 366 check,
388 base::Bind(&SafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread, 367 base::Bind(&SafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread,
389 this, prefixes)); 368 this, prefixes));
390 return false; 369 return false;
391 } 370 }
392 371
393 bool SafeBrowsingDatabaseManager::CheckSideEffectFreeWhitelistUrl(
394 const GURL& url) {
395 if (!enabled_)
396 return false;
397
398 if (!CanCheckUrl(url))
399 return false;
400
401 return database_->ContainsSideEffectFreeWhitelistUrl(url);
402 }
403
404 bool SafeBrowsingDatabaseManager::MatchMalwareIP( 372 bool SafeBrowsingDatabaseManager::MatchMalwareIP(
405 const std::string& ip_address) { 373 const std::string& ip_address) {
406 DCHECK_CURRENTLY_ON(BrowserThread::IO); 374 DCHECK_CURRENTLY_ON(BrowserThread::IO);
407 if (!enabled_ || !enable_ip_blacklist_ || !MakeDatabaseAvailable()) { 375 if (!enabled_ || !enable_ip_blacklist_ || !MakeDatabaseAvailable()) {
408 return false; // Fail open. 376 return false; // Fail open.
409 } 377 }
410 return database_->ContainsMalwareIP(ip_address); 378 return database_->ContainsMalwareIP(ip_address);
411 } 379 }
412 380
413 bool SafeBrowsingDatabaseManager::MatchCsdWhitelistUrl(const GURL& url) { 381 bool SafeBrowsingDatabaseManager::MatchCsdWhitelistUrl(const GURL& url) {
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 750
783 if (database_) 751 if (database_)
784 return database_; 752 return database_;
785 startup_metric_utils::ScopedSlowStartupUMA 753 startup_metric_utils::ScopedSlowStartupUMA
786 scoped_timer("Startup.SlowStartupSafeBrowsingGetDatabase"); 754 scoped_timer("Startup.SlowStartupSafeBrowsingGetDatabase");
787 const base::TimeTicks before = base::TimeTicks::Now(); 755 const base::TimeTicks before = base::TimeTicks::Now();
788 756
789 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create( 757 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(
790 safe_browsing_task_runner_, enable_download_protection_, 758 safe_browsing_task_runner_, enable_download_protection_,
791 enable_csd_whitelist_, enable_download_whitelist_, 759 enable_csd_whitelist_, enable_download_whitelist_,
792 enable_extension_blacklist_, enable_side_effect_free_whitelist_, 760 enable_extension_blacklist_, enable_ip_blacklist_,
793 enable_ip_blacklist_, enable_unwanted_software_blacklist_); 761 enable_unwanted_software_blacklist_);
794 762
795 database->Init(SafeBrowsingService::GetBaseFilename()); 763 database->Init(SafeBrowsingService::GetBaseFilename());
796 { 764 {
797 // Acquiring the lock here guarantees correct ordering between the writes to 765 // Acquiring the lock here guarantees correct ordering between the writes to
798 // the new database object above, and the setting of |database_| below. 766 // the new database object above, and the setting of |database_| below.
799 base::AutoLock lock(database_lock_); 767 base::AutoLock lock(database_lock_);
800 database_ = database; 768 database_ = database;
801 } 769 }
802 770
803 BrowserThread::PostTask( 771 BrowserThread::PostTask(
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 1105
1138 base::PostTaskAndReplyWithResult( 1106 base::PostTaskAndReplyWithResult(
1139 safe_browsing_task_runner_.get(), FROM_HERE, task, 1107 safe_browsing_task_runner_.get(), FROM_HERE, task,
1140 base::Bind(&SafeBrowsingDatabaseManager::OnAsyncCheckDone, 1108 base::Bind(&SafeBrowsingDatabaseManager::OnAsyncCheckDone,
1141 check->weak_ptr_factory_->GetWeakPtr(), check)); 1109 check->weak_ptr_factory_->GetWeakPtr(), check));
1142 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 1110 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
1143 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, 1111 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback,
1144 check->weak_ptr_factory_->GetWeakPtr(), check), 1112 check->weak_ptr_factory_->GetWeakPtr(), check),
1145 check_timeout_); 1113 check_timeout_);
1146 } 1114 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/database_manager.h ('k') | chrome/browser/safe_browsing/safe_browsing_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698