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

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: also obsolete the histograms uffix 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // |full_hashes| should never contain INVALID as a |list_id|. 82 // |full_hashes| should never contain INVALID as a |list_id|.
83 NOTREACHED(); 83 NOTREACHED();
84 break; 84 break;
85 case safe_browsing_util::MALWARE: // Falls through. 85 case safe_browsing_util::MALWARE: // Falls through.
86 case safe_browsing_util::PHISH: // Falls through. 86 case safe_browsing_util::PHISH: // Falls through.
87 case safe_browsing_util::BINURL: // Falls through. 87 case safe_browsing_util::BINURL: // Falls through.
88 case safe_browsing_util::CSDWHITELIST: // Falls through. 88 case safe_browsing_util::CSDWHITELIST: // Falls through.
89 case safe_browsing_util::DOWNLOADWHITELIST: // Falls through. 89 case safe_browsing_util::DOWNLOADWHITELIST: // Falls through.
90 case safe_browsing_util::INCLUSIONWHITELIST: // Falls through. 90 case safe_browsing_util::INCLUSIONWHITELIST: // Falls through.
91 case safe_browsing_util::EXTENSIONBLACKLIST: // Falls through. 91 case safe_browsing_util::EXTENSIONBLACKLIST: // Falls through.
92 case safe_browsing_util::SIDEEFFECTFREEWHITELIST: // Falls through.
93 case safe_browsing_util::IPBLACKLIST: 92 case safe_browsing_util::IPBLACKLIST:
94 if (index) 93 if (index)
95 *index = i; 94 *index = i;
96 return threat; 95 return threat;
97 case safe_browsing_util::UNWANTEDURL: 96 case safe_browsing_util::UNWANTEDURL:
98 // UNWANTEDURL is considered less severe than other threats, keep 97 // UNWANTEDURL is considered less severe than other threats, keep
99 // looking. 98 // looking.
100 pending_threat = threat; 99 pending_threat = threat;
101 if (index) 100 if (index)
102 *index = i; 101 *index = i;
(...skipping 25 matching lines...) Expand all
128 case safe_browsing_util::INVALID: 127 case safe_browsing_util::INVALID:
129 // Ignore patterns with no matching threat. 128 // Ignore patterns with no matching threat.
130 break; 129 break;
131 case safe_browsing_util::MALWARE: // Falls through. 130 case safe_browsing_util::MALWARE: // Falls through.
132 case safe_browsing_util::PHISH: // Falls through. 131 case safe_browsing_util::PHISH: // Falls through.
133 case safe_browsing_util::BINURL: // Falls through. 132 case safe_browsing_util::BINURL: // Falls through.
134 case safe_browsing_util::CSDWHITELIST: // Falls through. 133 case safe_browsing_util::CSDWHITELIST: // Falls through.
135 case safe_browsing_util::DOWNLOADWHITELIST: // Falls through. 134 case safe_browsing_util::DOWNLOADWHITELIST: // Falls through.
136 case safe_browsing_util::INCLUSIONWHITELIST: // Falls through. 135 case safe_browsing_util::INCLUSIONWHITELIST: // Falls through.
137 case safe_browsing_util::EXTENSIONBLACKLIST: // Falls through. 136 case safe_browsing_util::EXTENSIONBLACKLIST: // Falls through.
138 case safe_browsing_util::SIDEEFFECTFREEWHITELIST: // Falls through.
139 case safe_browsing_util::IPBLACKLIST: 137 case safe_browsing_util::IPBLACKLIST:
140 return threat; 138 return threat;
141 case safe_browsing_util::UNWANTEDURL: 139 case safe_browsing_util::UNWANTEDURL:
142 // UNWANTEDURL is considered less severe than other threats, keep 140 // UNWANTEDURL is considered less severe than other threats, keep
143 // looking. 141 // looking.
144 pending_threat = threat; 142 pending_threat = threat;
145 break; 143 break;
146 } 144 }
147 } 145 }
148 return pending_threat; 146 return pending_threat;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 253
256 SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager( 254 SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager(
257 const scoped_refptr<SafeBrowsingService>& service) 255 const scoped_refptr<SafeBrowsingService>& service)
258 : sb_service_(service), 256 : sb_service_(service),
259 database_(NULL), 257 database_(NULL),
260 enabled_(false), 258 enabled_(false),
261 enable_download_protection_(false), 259 enable_download_protection_(false),
262 enable_csd_whitelist_(false), 260 enable_csd_whitelist_(false),
263 enable_download_whitelist_(false), 261 enable_download_whitelist_(false),
264 enable_extension_blacklist_(false), 262 enable_extension_blacklist_(false),
265 enable_side_effect_free_whitelist_(false),
266 enable_ip_blacklist_(false), 263 enable_ip_blacklist_(false),
267 enable_unwanted_software_blacklist_(false), 264 enable_unwanted_software_blacklist_(false),
268 update_in_progress_(false), 265 update_in_progress_(false),
269 database_update_in_progress_(false), 266 database_update_in_progress_(false),
270 closing_database_(false), 267 closing_database_(false),
271 check_timeout_(base::TimeDelta::FromMilliseconds(kCheckTimeoutMs)) { 268 check_timeout_(base::TimeDelta::FromMilliseconds(kCheckTimeoutMs)) {
272 DCHECK_CURRENTLY_ON(BrowserThread::UI); 269 DCHECK_CURRENTLY_ON(BrowserThread::UI);
273 DCHECK(sb_service_.get() != NULL); 270 DCHECK(sb_service_.get() != NULL);
274 271
275 // Android only supports a subset of FULL_SAFE_BROWSING. 272 // Android only supports a subset of FULL_SAFE_BROWSING.
(...skipping 11 matching lines...) Expand all
287 // TODO(noelutz): remove this boolean variable since it should always be true 284 // TODO(noelutz): remove this boolean variable since it should always be true
288 // if SafeBrowsing is enabled. Unfortunately, we have no test data for this 285 // if SafeBrowsing is enabled. Unfortunately, we have no test data for this
289 // list right now. This means that we need to be able to disable this list 286 // list right now. This means that we need to be able to disable this list
290 // for the SafeBrowsing test to pass. 287 // for the SafeBrowsing test to pass.
291 enable_download_whitelist_ = enable_csd_whitelist_; 288 enable_download_whitelist_ = enable_csd_whitelist_;
292 289
293 // TODO(kalman): there really shouldn't be a flag for this. 290 // TODO(kalman): there really shouldn't be a flag for this.
294 enable_extension_blacklist_ = 291 enable_extension_blacklist_ =
295 !cmdline->HasSwitch(switches::kSbDisableExtensionBlacklist); 292 !cmdline->HasSwitch(switches::kSbDisableExtensionBlacklist);
296 293
297 enable_side_effect_free_whitelist_ =
298 prerender::IsSideEffectFreeWhitelistEnabled() &&
299 !cmdline->HasSwitch(switches::kSbDisableSideEffectFreeWhitelist);
300
301 // The client-side IP blacklist feature is tightly integrated with client-side 294 // The client-side IP blacklist feature is tightly integrated with client-side
302 // phishing protection for now. 295 // phishing protection for now.
303 enable_ip_blacklist_ = enable_csd_whitelist_; 296 enable_ip_blacklist_ = enable_csd_whitelist_;
304 297
305 // The UwS blacklist feature is controlled by a flag for M40. 298 // The UwS blacklist feature is controlled by a flag for M40.
306 enable_unwanted_software_blacklist_ = 299 enable_unwanted_software_blacklist_ =
307 safe_browsing_util::GetUnwantedTrialGroup() > safe_browsing_util::UWS_OFF; 300 safe_browsing_util::GetUnwantedTrialGroup() > safe_browsing_util::UWS_OFF;
308
309 enum SideEffectFreeWhitelistStatus {
310 SIDE_EFFECT_FREE_WHITELIST_ENABLED,
311 SIDE_EFFECT_FREE_WHITELIST_DISABLED,
312 SIDE_EFFECT_FREE_WHITELIST_STATUS_MAX
313 };
314
315 SideEffectFreeWhitelistStatus side_effect_free_whitelist_status =
316 enable_side_effect_free_whitelist_ ? SIDE_EFFECT_FREE_WHITELIST_ENABLED :
317 SIDE_EFFECT_FREE_WHITELIST_DISABLED;
318
319 UMA_HISTOGRAM_ENUMERATION("SB2.SideEffectFreeWhitelistStatus",
320 side_effect_free_whitelist_status,
321 SIDE_EFFECT_FREE_WHITELIST_STATUS_MAX);
322 #endif 301 #endif
323 } 302 }
324 303
325 SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() { 304 SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() {
326 // The DCHECK is disabled due to crbug.com/438754. 305 // The DCHECK is disabled due to crbug.com/438754.
327 // DCHECK_CURRENTLY_ON(BrowserThread::UI); 306 // DCHECK_CURRENTLY_ON(BrowserThread::UI);
328 307
329 // We should have already been shut down. If we're still enabled, then the 308 // We should have already been shut down. If we're still enabled, then the
330 // database isn't going to be closed properly, which could lead to corruption. 309 // database isn't going to be closed properly, which could lead to corruption.
331 DCHECK(!enabled_); 310 DCHECK(!enabled_);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 client, 363 client,
385 safe_browsing_util::EXTENSIONBLACKLIST, 364 safe_browsing_util::EXTENSIONBLACKLIST,
386 std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION)); 365 std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION));
387 StartSafeBrowsingCheck( 366 StartSafeBrowsingCheck(
388 check, 367 check,
389 base::Bind(&SafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread, 368 base::Bind(&SafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread,
390 this, prefixes)); 369 this, prefixes));
391 return false; 370 return false;
392 } 371 }
393 372
394 bool SafeBrowsingDatabaseManager::CheckSideEffectFreeWhitelistUrl(
395 const GURL& url) {
396 if (!enabled_)
397 return false;
398
399 if (!CanCheckUrl(url))
400 return false;
401
402 return database_->ContainsSideEffectFreeWhitelistUrl(url);
403 }
404
405 bool SafeBrowsingDatabaseManager::MatchMalwareIP( 373 bool SafeBrowsingDatabaseManager::MatchMalwareIP(
406 const std::string& ip_address) { 374 const std::string& ip_address) {
407 DCHECK_CURRENTLY_ON(BrowserThread::IO); 375 DCHECK_CURRENTLY_ON(BrowserThread::IO);
408 if (!enabled_ || !enable_ip_blacklist_ || !MakeDatabaseAvailable()) { 376 if (!enabled_ || !enable_ip_blacklist_ || !MakeDatabaseAvailable()) {
409 return false; // Fail open. 377 return false; // Fail open.
410 } 378 }
411 return database_->ContainsMalwareIP(ip_address); 379 return database_->ContainsMalwareIP(ip_address);
412 } 380 }
413 381
414 bool SafeBrowsingDatabaseManager::MatchCsdWhitelistUrl(const GURL& url) { 382 bool SafeBrowsingDatabaseManager::MatchCsdWhitelistUrl(const GURL& url) {
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 760
793 if (database_) 761 if (database_)
794 return database_; 762 return database_;
795 startup_metric_utils::ScopedSlowStartupUMA 763 startup_metric_utils::ScopedSlowStartupUMA
796 scoped_timer("Startup.SlowStartupSafeBrowsingGetDatabase"); 764 scoped_timer("Startup.SlowStartupSafeBrowsingGetDatabase");
797 const base::TimeTicks before = base::TimeTicks::Now(); 765 const base::TimeTicks before = base::TimeTicks::Now();
798 766
799 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create( 767 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(
800 safe_browsing_task_runner_, enable_download_protection_, 768 safe_browsing_task_runner_, enable_download_protection_,
801 enable_csd_whitelist_, enable_download_whitelist_, 769 enable_csd_whitelist_, enable_download_whitelist_,
802 enable_extension_blacklist_, enable_side_effect_free_whitelist_, 770 enable_extension_blacklist_, enable_ip_blacklist_,
803 enable_ip_blacklist_, enable_unwanted_software_blacklist_); 771 enable_unwanted_software_blacklist_);
804 772
805 database->Init(SafeBrowsingService::GetBaseFilename()); 773 database->Init(SafeBrowsingService::GetBaseFilename());
806 { 774 {
807 // Acquiring the lock here guarantees correct ordering between the writes to 775 // Acquiring the lock here guarantees correct ordering between the writes to
808 // the new database object above, and the setting of |database_| below. 776 // the new database object above, and the setting of |database_| below.
809 base::AutoLock lock(database_lock_); 777 base::AutoLock lock(database_lock_);
810 database_ = database; 778 database_ = database;
811 } 779 }
812 780
813 BrowserThread::PostTask( 781 BrowserThread::PostTask(
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 1115
1148 base::PostTaskAndReplyWithResult( 1116 base::PostTaskAndReplyWithResult(
1149 safe_browsing_task_runner_.get(), FROM_HERE, task, 1117 safe_browsing_task_runner_.get(), FROM_HERE, task,
1150 base::Bind(&SafeBrowsingDatabaseManager::OnAsyncCheckDone, 1118 base::Bind(&SafeBrowsingDatabaseManager::OnAsyncCheckDone,
1151 check->weak_ptr_factory_->GetWeakPtr(), check)); 1119 check->weak_ptr_factory_->GetWeakPtr(), check));
1152 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 1120 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
1153 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, 1121 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback,
1154 check->weak_ptr_factory_->GetWeakPtr(), check), 1122 check->weak_ptr_factory_->GetWeakPtr(), check),
1155 check_timeout_); 1123 check_timeout_);
1156 } 1124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698