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/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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 } | 61 } |
62 | 62 |
63 bool IsExpectedThreat( | 63 bool IsExpectedThreat( |
64 const SBThreatType threat_type, | 64 const SBThreatType threat_type, |
65 const std::vector<SBThreatType>& expected_threats) { | 65 const std::vector<SBThreatType>& expected_threats) { |
66 return expected_threats.end() != std::find(expected_threats.begin(), | 66 return expected_threats.end() != std::find(expected_threats.begin(), |
67 expected_threats.end(), | 67 expected_threats.end(), |
68 threat_type); | 68 threat_type); |
69 } | 69 } |
70 | 70 |
71 // Return the list id from the first result in |full_hashes| which matches | 71 // Return the severest list id from the results in |full_hashes| which matches |
72 // |hash|, or INVALID if none match. | 72 // |hash|, or INVALID if none match. |
73 safe_browsing_util::ListType GetHashThreatListType( | 73 safe_browsing_util::ListType GetHashSeverestThreatListType( |
74 const SBFullHash& hash, | 74 const SBFullHash& hash, |
75 const std::vector<SBFullHashResult>& full_hashes, | 75 const std::vector<SBFullHashResult>& full_hashes, |
76 size_t* index) { | 76 size_t* index) { |
77 | |
78 safe_browsing_util::ListType severest_threat = safe_browsing_util::INVALID; | |
mattm
2014/11/12 03:24:30
name is a bit confusing since it's not used for th
gab
2014/11/12 16:05:08
Done.
| |
77 for (size_t i = 0; i < full_hashes.size(); ++i) { | 79 for (size_t i = 0; i < full_hashes.size(); ++i) { |
78 if (SBFullHashEqual(hash, full_hashes[i].hash)) { | 80 if (SBFullHashEqual(hash, full_hashes[i].hash)) { |
79 if (index) | 81 const safe_browsing_util::ListType threat = |
80 *index = i; | 82 static_cast<safe_browsing_util::ListType>(full_hashes[i].list_id); |
81 return static_cast<safe_browsing_util::ListType>(full_hashes[i].list_id); | 83 switch (threat) { |
84 case safe_browsing_util::INVALID: | |
85 // |full_hashes| should never contain INVALID as a |list_id|. | |
86 NOTREACHED(); | |
87 break; | |
88 case safe_browsing_util::MALWARE: // Fall through. | |
89 case safe_browsing_util::PHISH: // Fall through. | |
90 case safe_browsing_util::BINURL: // Fall through. | |
91 case safe_browsing_util::CSDWHITELIST: // Fall through. | |
92 case safe_browsing_util::DOWNLOADWHITELIST: // Fall through. | |
93 case safe_browsing_util::EXTENSIONBLACKLIST: // Fall through. | |
94 case safe_browsing_util::SIDEEFFECTFREEWHITELIST: // Fall through. | |
95 case safe_browsing_util::IPBLACKLIST: | |
96 if (index) | |
97 *index = i; | |
98 return threat; | |
99 case safe_browsing_util::UNWANTEDURL: | |
100 // UNWANTEDURL is considered less severe than other threats, keep | |
101 // looking. | |
102 severest_threat = threat; | |
103 if (index) | |
104 *index = i; | |
105 break; | |
106 } | |
82 } | 107 } |
83 } | 108 } |
84 return safe_browsing_util::INVALID; | 109 return severest_threat; |
85 } | 110 } |
86 | 111 |
87 // Given a URL, compare all the possible host + path full hashes to the set of | 112 // Given a URL, compare all the possible host + path full hashes to the set of |
88 // provided full hashes. Returns the list id of the a matching result from | 113 // provided full hashes. Returns the list id of the severest matching result |
89 // |full_hashes|, or INVALID if none match. | 114 // from |full_hashes|, or INVALID if none match. |
90 safe_browsing_util::ListType GetUrlThreatListType( | 115 safe_browsing_util::ListType GetUrlSeverestThreatListType( |
91 const GURL& url, | 116 const GURL& url, |
92 const std::vector<SBFullHashResult>& full_hashes, | 117 const std::vector<SBFullHashResult>& full_hashes, |
93 size_t* index) { | 118 size_t* index) { |
94 if (full_hashes.empty()) | 119 if (full_hashes.empty()) |
95 return safe_browsing_util::INVALID; | 120 return safe_browsing_util::INVALID; |
96 | 121 |
97 std::vector<std::string> patterns; | 122 std::vector<std::string> patterns; |
98 safe_browsing_util::GeneratePatternsToCheck(url, &patterns); | 123 safe_browsing_util::GeneratePatternsToCheck(url, &patterns); |
99 | 124 |
125 safe_browsing_util::ListType severest_threat = safe_browsing_util::INVALID; | |
100 for (size_t i = 0; i < patterns.size(); ++i) { | 126 for (size_t i = 0; i < patterns.size(); ++i) { |
101 safe_browsing_util::ListType threat = GetHashThreatListType( | 127 safe_browsing_util::ListType threat = GetHashSeverestThreatListType( |
102 SBFullHashForString(patterns[i]), full_hashes, index); | 128 SBFullHashForString(patterns[i]), full_hashes, index); |
103 if (threat != safe_browsing_util::INVALID) | 129 switch (threat) { |
104 return threat; | 130 case safe_browsing_util::INVALID: |
131 // Ignore patterns with no matching threat. | |
132 break; | |
133 case safe_browsing_util::MALWARE: // Fall through. | |
134 case safe_browsing_util::PHISH: // Fall through. | |
135 case safe_browsing_util::BINURL: // Fall through. | |
136 case safe_browsing_util::CSDWHITELIST: // Fall through. | |
137 case safe_browsing_util::DOWNLOADWHITELIST: // Fall through. | |
138 case safe_browsing_util::EXTENSIONBLACKLIST: // Fall through. | |
139 case safe_browsing_util::SIDEEFFECTFREEWHITELIST: // Fall through. | |
140 case safe_browsing_util::IPBLACKLIST: | |
141 return threat; | |
142 case safe_browsing_util::UNWANTEDURL: | |
143 // UNWANTEDURL is considered less severe than other threats, keep | |
144 // looking. | |
145 severest_threat = threat; | |
146 break; | |
147 } | |
105 } | 148 } |
106 return safe_browsing_util::INVALID; | 149 return severest_threat; |
107 } | 150 } |
108 | 151 |
109 SBThreatType GetThreatTypeFromListType(safe_browsing_util::ListType list_type) { | 152 SBThreatType GetThreatTypeFromListType(safe_browsing_util::ListType list_type) { |
110 switch (list_type) { | 153 switch (list_type) { |
111 case safe_browsing_util::PHISH: | 154 case safe_browsing_util::PHISH: |
112 return SB_THREAT_TYPE_URL_PHISHING; | 155 return SB_THREAT_TYPE_URL_PHISHING; |
113 case safe_browsing_util::MALWARE: | 156 case safe_browsing_util::MALWARE: |
114 return SB_THREAT_TYPE_URL_MALWARE; | 157 return SB_THREAT_TYPE_URL_MALWARE; |
158 case safe_browsing_util::UNWANTEDURL: | |
159 return SB_THREAT_TYPE_URL_UNWANTED; | |
115 case safe_browsing_util::BINURL: | 160 case safe_browsing_util::BINURL: |
116 return SB_THREAT_TYPE_BINARY_MALWARE_URL; | 161 return SB_THREAT_TYPE_BINARY_MALWARE_URL; |
117 case safe_browsing_util::EXTENSIONBLACKLIST: | 162 case safe_browsing_util::EXTENSIONBLACKLIST: |
118 return SB_THREAT_TYPE_EXTENSION; | 163 return SB_THREAT_TYPE_EXTENSION; |
119 default: | 164 default: |
120 DVLOG(1) << "Unknown safe browsing list id " << list_type; | 165 DVLOG(1) << "Unknown safe browsing list id " << list_type; |
121 return SB_THREAT_TYPE_SAFE; | 166 return SB_THREAT_TYPE_SAFE; |
122 } | 167 } |
123 } | 168 } |
124 | 169 |
125 } // namespace | 170 } // namespace |
126 | 171 |
127 // static | 172 // static |
128 SBThreatType SafeBrowsingDatabaseManager::GetHashThreatType( | 173 SBThreatType SafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
129 const SBFullHash& hash, | 174 const SBFullHash& hash, |
130 const std::vector<SBFullHashResult>& full_hashes) { | 175 const std::vector<SBFullHashResult>& full_hashes) { |
131 return GetThreatTypeFromListType( | 176 return GetThreatTypeFromListType( |
132 GetHashThreatListType(hash, full_hashes, NULL)); | 177 GetHashSeverestThreatListType(hash, full_hashes, NULL)); |
133 } | 178 } |
134 | 179 |
135 // static | 180 // static |
136 SBThreatType SafeBrowsingDatabaseManager::GetUrlThreatType( | 181 SBThreatType SafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
137 const GURL& url, | 182 const GURL& url, |
138 const std::vector<SBFullHashResult>& full_hashes, | 183 const std::vector<SBFullHashResult>& full_hashes, |
139 size_t* index) { | 184 size_t* index) { |
140 return GetThreatTypeFromListType( | 185 return GetThreatTypeFromListType( |
141 GetUrlThreatListType(url, full_hashes, index)); | 186 GetUrlSeverestThreatListType(url, full_hashes, index)); |
142 } | 187 } |
143 | 188 |
144 SafeBrowsingDatabaseManager::SafeBrowsingCheck::SafeBrowsingCheck( | 189 SafeBrowsingDatabaseManager::SafeBrowsingCheck::SafeBrowsingCheck( |
145 const std::vector<GURL>& urls, | 190 const std::vector<GURL>& urls, |
146 const std::vector<SBFullHash>& full_hashes, | 191 const std::vector<SBFullHash>& full_hashes, |
147 Client* client, | 192 Client* client, |
148 safe_browsing_util::ListType check_type, | 193 safe_browsing_util::ListType check_type, |
149 const std::vector<SBThreatType>& expected_threats) | 194 const std::vector<SBThreatType>& expected_threats) |
150 : urls(urls), | 195 : urls(urls), |
151 url_results(urls.size(), SB_THREAT_TYPE_SAFE), | 196 url_results(urls.size(), SB_THREAT_TYPE_SAFE), |
(...skipping 12 matching lines...) Expand all Loading... | |
164 | 209 |
165 void SafeBrowsingDatabaseManager::Client::OnSafeBrowsingResult( | 210 void SafeBrowsingDatabaseManager::Client::OnSafeBrowsingResult( |
166 const SafeBrowsingCheck& check) { | 211 const SafeBrowsingCheck& check) { |
167 DCHECK_EQ(check.urls.size(), check.url_results.size()); | 212 DCHECK_EQ(check.urls.size(), check.url_results.size()); |
168 DCHECK_EQ(check.full_hashes.size(), check.full_hash_results.size()); | 213 DCHECK_EQ(check.full_hashes.size(), check.full_hash_results.size()); |
169 if (!check.urls.empty()) { | 214 if (!check.urls.empty()) { |
170 DCHECK(check.full_hashes.empty()); | 215 DCHECK(check.full_hashes.empty()); |
171 switch (check.check_type) { | 216 switch (check.check_type) { |
172 case safe_browsing_util::MALWARE: | 217 case safe_browsing_util::MALWARE: |
173 case safe_browsing_util::PHISH: | 218 case safe_browsing_util::PHISH: |
219 case safe_browsing_util::UNWANTEDURL: | |
174 DCHECK_EQ(1u, check.urls.size()); | 220 DCHECK_EQ(1u, check.urls.size()); |
175 OnCheckBrowseUrlResult( | 221 OnCheckBrowseUrlResult( |
176 check.urls[0], check.url_results[0], check.url_metadata[0]); | 222 check.urls[0], check.url_results[0], check.url_metadata[0]); |
177 break; | 223 break; |
178 case safe_browsing_util::BINURL: | 224 case safe_browsing_util::BINURL: |
179 DCHECK_EQ(check.urls.size(), check.url_results.size()); | 225 DCHECK_EQ(check.urls.size(), check.url_results.size()); |
180 OnCheckDownloadUrlResult( | 226 OnCheckDownloadUrlResult( |
181 check.urls, | 227 check.urls, |
182 *std::max_element(check.url_results.begin(), | 228 *std::max_element(check.url_results.begin(), |
183 check.url_results.end())); | 229 check.url_results.end())); |
(...skipping 26 matching lines...) Expand all Loading... | |
210 const scoped_refptr<SafeBrowsingService>& service) | 256 const scoped_refptr<SafeBrowsingService>& service) |
211 : sb_service_(service), | 257 : sb_service_(service), |
212 database_(NULL), | 258 database_(NULL), |
213 enabled_(false), | 259 enabled_(false), |
214 enable_download_protection_(false), | 260 enable_download_protection_(false), |
215 enable_csd_whitelist_(false), | 261 enable_csd_whitelist_(false), |
216 enable_download_whitelist_(false), | 262 enable_download_whitelist_(false), |
217 enable_extension_blacklist_(false), | 263 enable_extension_blacklist_(false), |
218 enable_side_effect_free_whitelist_(false), | 264 enable_side_effect_free_whitelist_(false), |
219 enable_ip_blacklist_(false), | 265 enable_ip_blacklist_(false), |
266 enable_unwanted_software_blacklist_(false), | |
220 update_in_progress_(false), | 267 update_in_progress_(false), |
221 database_update_in_progress_(false), | 268 database_update_in_progress_(false), |
222 closing_database_(false), | 269 closing_database_(false), |
223 check_timeout_(base::TimeDelta::FromMilliseconds(kCheckTimeoutMs)) { | 270 check_timeout_(base::TimeDelta::FromMilliseconds(kCheckTimeoutMs)) { |
224 DCHECK(sb_service_.get() != NULL); | 271 DCHECK(sb_service_.get() != NULL); |
225 | 272 |
226 // Android only supports a subset of FULL_SAFE_BROWSING. | 273 // Android only supports a subset of FULL_SAFE_BROWSING. |
227 // TODO(shess): This shouldn't be OS-driven <http://crbug.com/394379> | 274 // TODO(shess): This shouldn't be OS-driven <http://crbug.com/394379> |
228 #if !defined(OS_ANDROID) | 275 #if !defined(OS_ANDROID) |
229 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 276 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
(...skipping 16 matching lines...) Expand all Loading... | |
246 !cmdline->HasSwitch(switches::kSbDisableExtensionBlacklist); | 293 !cmdline->HasSwitch(switches::kSbDisableExtensionBlacklist); |
247 | 294 |
248 enable_side_effect_free_whitelist_ = | 295 enable_side_effect_free_whitelist_ = |
249 prerender::IsSideEffectFreeWhitelistEnabled() && | 296 prerender::IsSideEffectFreeWhitelistEnabled() && |
250 !cmdline->HasSwitch(switches::kSbDisableSideEffectFreeWhitelist); | 297 !cmdline->HasSwitch(switches::kSbDisableSideEffectFreeWhitelist); |
251 | 298 |
252 // The client-side IP blacklist feature is tightly integrated with client-side | 299 // The client-side IP blacklist feature is tightly integrated with client-side |
253 // phishing protection for now. | 300 // phishing protection for now. |
254 enable_ip_blacklist_ = enable_csd_whitelist_; | 301 enable_ip_blacklist_ = enable_csd_whitelist_; |
255 | 302 |
303 // TODO(gab): Gate this on the same experiment that will soon control the UwS | |
304 // URL UI. | |
305 enable_unwanted_software_blacklist_ = true; | |
306 | |
256 enum SideEffectFreeWhitelistStatus { | 307 enum SideEffectFreeWhitelistStatus { |
257 SIDE_EFFECT_FREE_WHITELIST_ENABLED, | 308 SIDE_EFFECT_FREE_WHITELIST_ENABLED, |
258 SIDE_EFFECT_FREE_WHITELIST_DISABLED, | 309 SIDE_EFFECT_FREE_WHITELIST_DISABLED, |
259 SIDE_EFFECT_FREE_WHITELIST_STATUS_MAX | 310 SIDE_EFFECT_FREE_WHITELIST_STATUS_MAX |
260 }; | 311 }; |
261 | 312 |
262 SideEffectFreeWhitelistStatus side_effect_free_whitelist_status = | 313 SideEffectFreeWhitelistStatus side_effect_free_whitelist_status = |
263 enable_side_effect_free_whitelist_ ? SIDE_EFFECT_FREE_WHITELIST_ENABLED : | 314 enable_side_effect_free_whitelist_ ? SIDE_EFFECT_FREE_WHITELIST_ENABLED : |
264 SIDE_EFFECT_FREE_WHITELIST_DISABLED; | 315 SIDE_EFFECT_FREE_WHITELIST_DISABLED; |
265 | 316 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
403 if (!enabled_) | 454 if (!enabled_) |
404 return true; | 455 return true; |
405 | 456 |
406 if (!CanCheckUrl(url)) | 457 if (!CanCheckUrl(url)) |
407 return true; | 458 return true; |
408 | 459 |
409 std::vector<SBThreatType> expected_threats; | 460 std::vector<SBThreatType> expected_threats; |
410 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); | 461 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); |
411 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); | 462 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); |
463 expected_threats.push_back(SB_THREAT_TYPE_URL_UNWANTED); | |
412 | 464 |
413 const base::TimeTicks start = base::TimeTicks::Now(); | 465 const base::TimeTicks start = base::TimeTicks::Now(); |
414 if (!MakeDatabaseAvailable()) { | 466 if (!MakeDatabaseAvailable()) { |
415 QueuedCheck queued_check(safe_browsing_util::MALWARE, // or PHISH | 467 QueuedCheck queued_check(safe_browsing_util::MALWARE, // or PHISH |
416 client, | 468 client, |
417 url, | 469 url, |
418 expected_threats, | 470 expected_threats, |
419 start); | 471 start); |
420 queued_checks_.push_back(queued_check); | 472 queued_checks_.push_back(queued_check); |
421 return false; | 473 return false; |
422 } | 474 } |
423 | 475 |
424 std::vector<SBPrefix> prefix_hits; | 476 // Cache hits should be the same for both (as verified by the DCHECK below). |
477 // TODO(gab): Refactor SafeBrowsingDatabase to avoid depending on this here. | |
425 std::vector<SBFullHashResult> cache_hits; | 478 std::vector<SBFullHashResult> cache_hits; |
426 | 479 |
427 bool prefix_match = | 480 std::vector<SBPrefix> browse_prefix_hits; |
428 database_->ContainsBrowseUrl(url, &prefix_hits, &cache_hits); | 481 bool browse_prefix_match = database_->ContainsBrowseUrl( |
482 url, &browse_prefix_hits, &cache_hits); | |
483 | |
484 std::vector<SBPrefix> unwanted_prefix_hits; | |
485 std::vector<SBFullHashResult> other_cache_hits; | |
mattm
2014/11/12 03:24:30
unused_cache_hits ?
gab
2014/11/12 16:05:08
Done.
| |
486 bool unwanted_prefix_match = database_->ContainsUnwantedSoftwareUrl( | |
487 url, &unwanted_prefix_hits, &other_cache_hits); | |
488 | |
489 #if defined(OS_WIN) | |
490 // TODO(gab): Figure out why this doesn't pass on non-win compilers (padding?) | |
491 // leave it here as Win-only for now to ensure changes to SBFullHashResult's | |
492 // format are at least caught by some bots... | |
mattm
2014/11/12 03:24:30
It's not win specific, but it is padding, yes. Ex
gab
2014/11/12 16:05:08
Removed.
| |
493 static_assert(sizeof(SBFullHashResult) == sizeof(SBFullHash) + sizeof(int) + | |
494 sizeof(std::string), | |
495 "Need to update equality predicate below."); | |
496 #endif | |
497 DCHECK(cache_hits.size() == other_cache_hits.size() && | |
498 std::equal(cache_hits.begin(), cache_hits.end(), | |
499 other_cache_hits.begin(), | |
500 [](const SBFullHashResult& a, const SBFullHashResult& b) { | |
501 return SBFullHashEqual(a.hash, b.hash) && | |
502 a.list_id == b.list_id && a.metadata == b.metadata; | |
503 })); | |
mattm
2014/11/12 03:24:30
Technically the cache hits could be different, sin
gab
2014/11/12 16:05:08
Good catch, removed.
| |
504 | |
505 // Merge the two pre-sorted prefix hits lists. | |
506 // TODO(gab): Refactor SafeBrowsingDatabase for it to return this merged list | |
507 // by default rather than building it here. | |
508 DCHECK(std::is_sorted(browse_prefix_hits.begin(), browse_prefix_hits.end())); | |
509 DCHECK(std::is_sorted(unwanted_prefix_hits.begin(), | |
gab
2014/11/12 16:05:08
Also removed these two checks as std::is_sorted is
| |
510 unwanted_prefix_hits.end())); | |
511 std::vector<SBPrefix> prefix_hits( | |
512 browse_prefix_hits.size() + unwanted_prefix_hits.size()); | |
513 std::merge(browse_prefix_hits.begin(), browse_prefix_hits.end(), | |
514 unwanted_prefix_hits.begin(), unwanted_prefix_hits.end(), | |
515 prefix_hits.begin()); | |
516 prefix_hits.erase(std::unique(prefix_hits.begin(), prefix_hits.end()), | |
517 prefix_hits.end()); | |
429 | 518 |
430 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", base::TimeTicks::Now() - start); | 519 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", base::TimeTicks::Now() - start); |
431 | 520 |
432 if (!prefix_match) | 521 if (!browse_prefix_match && !unwanted_prefix_match) |
433 return true; // URL is okay. | 522 return true; // URL is okay. |
434 | 523 |
435 // Needs to be asynchronous, since we could be in the constructor of a | 524 // Needs to be asynchronous, since we could be in the constructor of a |
436 // ResourceDispatcherHost event handler which can't pause there. | 525 // ResourceDispatcherHost event handler which can't pause there. |
437 SafeBrowsingCheck* check = new SafeBrowsingCheck(std::vector<GURL>(1, url), | 526 // This check will ping the Safe Browsing servers and get all lists which it |
438 std::vector<SBFullHash>(), | 527 // matches. These lists will then be filtered against the |expected_threats| |
439 client, | 528 // and the result callback for MALWARE (which is the same as for PHISH and |
440 safe_browsing_util::MALWARE, | 529 // UNWANTEDURL) will eventually be invoked with the final decision. |
441 expected_threats); | 530 SafeBrowsingCheck* check = |
531 new SafeBrowsingCheck(std::vector<GURL>(1, url), | |
532 std::vector<SBFullHash>(), | |
533 client, | |
534 safe_browsing_util::MALWARE, | |
535 expected_threats); | |
442 check->need_get_hash = cache_hits.empty(); | 536 check->need_get_hash = cache_hits.empty(); |
443 check->prefix_hits.swap(prefix_hits); | 537 check->prefix_hits.swap(prefix_hits); |
444 check->cache_hits.swap(cache_hits); | 538 check->cache_hits.swap(cache_hits); |
445 checks_.insert(check); | 539 checks_.insert(check); |
446 | 540 |
447 BrowserThread::PostTask( | 541 BrowserThread::PostTask( |
448 BrowserThread::IO, FROM_HERE, | 542 BrowserThread::IO, FROM_HERE, |
449 base::Bind(&SafeBrowsingDatabaseManager::OnCheckDone, this, check)); | 543 base::Bind(&SafeBrowsingDatabaseManager::OnCheckDone, this, check)); |
450 | 544 |
451 return false; | 545 return false; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 startup_metric_utils::ScopedSlowStartupUMA | 792 startup_metric_utils::ScopedSlowStartupUMA |
699 scoped_timer("Startup.SlowStartupSafeBrowsingGetDatabase"); | 793 scoped_timer("Startup.SlowStartupSafeBrowsingGetDatabase"); |
700 const base::TimeTicks before = base::TimeTicks::Now(); | 794 const base::TimeTicks before = base::TimeTicks::Now(); |
701 | 795 |
702 SafeBrowsingDatabase* database = | 796 SafeBrowsingDatabase* database = |
703 SafeBrowsingDatabase::Create(enable_download_protection_, | 797 SafeBrowsingDatabase::Create(enable_download_protection_, |
704 enable_csd_whitelist_, | 798 enable_csd_whitelist_, |
705 enable_download_whitelist_, | 799 enable_download_whitelist_, |
706 enable_extension_blacklist_, | 800 enable_extension_blacklist_, |
707 enable_side_effect_free_whitelist_, | 801 enable_side_effect_free_whitelist_, |
708 enable_ip_blacklist_); | 802 enable_ip_blacklist_, |
803 enable_unwanted_software_blacklist_); | |
709 | 804 |
710 database->Init(SafeBrowsingService::GetBaseFilename()); | 805 database->Init(SafeBrowsingService::GetBaseFilename()); |
711 { | 806 { |
712 // Acquiring the lock here guarantees correct ordering between the writes to | 807 // Acquiring the lock here guarantees correct ordering between the writes to |
713 // the new database object above, and the setting of |databse_| below. | 808 // the new database object above, and the setting of |databse_| below. |
714 base::AutoLock lock(database_lock_); | 809 base::AutoLock lock(database_lock_); |
715 database_ = database; | 810 database_ = database; |
716 } | 811 } |
717 | 812 |
718 BrowserThread::PostTask( | 813 BrowserThread::PostTask( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
764 bool is_download = check->check_type == safe_browsing_util::BINURL; | 859 bool is_download = check->check_type == safe_browsing_util::BINURL; |
765 sb_service_->protocol_manager()->GetFullHash( | 860 sb_service_->protocol_manager()->GetFullHash( |
766 check->prefix_hits, | 861 check->prefix_hits, |
767 base::Bind(&SafeBrowsingDatabaseManager::HandleGetHashResults, | 862 base::Bind(&SafeBrowsingDatabaseManager::HandleGetHashResults, |
768 base::Unretained(this), | 863 base::Unretained(this), |
769 check), | 864 check), |
770 is_download); | 865 is_download); |
771 } else { | 866 } else { |
772 // We may have cached results for previous GetHash queries. Since | 867 // We may have cached results for previous GetHash queries. Since |
773 // this data comes from cache, don't histogram hits. | 868 // this data comes from cache, don't histogram hits. |
774 bool is_threat = HandleOneCheck(check, check->cache_hits); | 869 HandleOneCheck(check, check->cache_hits); |
775 // cache_hits should only contain hits for a fullhash we searched for, so if | |
776 // we got to this point it should always result in a threat match. | |
777 DCHECK(is_threat); | |
778 } | 870 } |
779 } | 871 } |
780 | 872 |
781 void SafeBrowsingDatabaseManager::GetAllChunksFromDatabase( | 873 void SafeBrowsingDatabaseManager::GetAllChunksFromDatabase( |
782 GetChunksCallback callback) { | 874 GetChunksCallback callback) { |
783 DCHECK_EQ(base::MessageLoop::current(), | 875 DCHECK_EQ(base::MessageLoop::current(), |
784 safe_browsing_thread_->message_loop()); | 876 safe_browsing_thread_->message_loop()); |
785 | 877 |
786 bool database_error = true; | 878 bool database_error = true; |
787 std::vector<SBListChunkRanges> lists; | 879 std::vector<SBListChunkRanges> lists; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
933 } | 1025 } |
934 | 1026 |
935 bool SafeBrowsingDatabaseManager::HandleOneCheck( | 1027 bool SafeBrowsingDatabaseManager::HandleOneCheck( |
936 SafeBrowsingCheck* check, | 1028 SafeBrowsingCheck* check, |
937 const std::vector<SBFullHashResult>& full_hashes) { | 1029 const std::vector<SBFullHashResult>& full_hashes) { |
938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1030 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
939 DCHECK(check); | 1031 DCHECK(check); |
940 | 1032 |
941 bool is_threat = false; | 1033 bool is_threat = false; |
942 | 1034 |
943 // TODO(shess): GetHashThreadListType() contains a loop, | 1035 // TODO(shess): GetHashSeverestThreadListType() contains a loop, |
944 // GetUrlThreatListType() a loop around that loop. Having another loop out | 1036 // GetUrlSeverestThreatListType() a loop around that loop. Having another |
945 // here concerns me. It is likely that SAFE is an expected outcome, which | 1037 // loop out here concerns me. It is likely that SAFE is an expected outcome, |
946 // means all of those loops run to completion. Refactoring this to generate a | 1038 // which means all of those loops run to completion. Refactoring this to |
947 // set of sorted items to compare in sequence would probably improve things. | 1039 // generate a set of sorted items to compare in sequence would probably |
1040 // improve things. | |
948 // | 1041 // |
949 // Additionally, the set of patterns generated from the urls is very similar | 1042 // Additionally, the set of patterns generated from the urls is very similar |
950 // to the patterns generated in ContainsBrowseUrl() and other database checks, | 1043 // to the patterns generated in ContainsBrowseUrl() and other database checks, |
951 // which are called from this code. Refactoring that across the checks could | 1044 // which are called from this code. Refactoring that across the checks could |
952 // interact well with batching the checks here. | 1045 // interact well with batching the checks here. |
953 | 1046 |
954 for (size_t i = 0; i < check->urls.size(); ++i) { | 1047 for (size_t i = 0; i < check->urls.size(); ++i) { |
955 size_t threat_index; | 1048 size_t threat_index; |
956 SBThreatType threat = | 1049 SBThreatType threat = |
957 GetUrlThreatType(check->urls[i], full_hashes, &threat_index); | 1050 GetUrlSeverestThreatType(check->urls[i], full_hashes, &threat_index); |
958 if (threat != SB_THREAT_TYPE_SAFE && | 1051 if (threat != SB_THREAT_TYPE_SAFE && |
959 IsExpectedThreat(threat, check->expected_threats)) { | 1052 IsExpectedThreat(threat, check->expected_threats)) { |
mattm
2014/11/12 03:24:30
Hmm, I suppose ideally the severest threat should
gab
2014/11/12 16:05:08
Good point. Since this is an existing problem thou
| |
960 check->url_results[i] = threat; | 1053 check->url_results[i] = threat; |
961 check->url_metadata[i] = full_hashes[threat_index].metadata; | 1054 check->url_metadata[i] = full_hashes[threat_index].metadata; |
962 is_threat = true; | 1055 is_threat = true; |
963 } | 1056 } |
964 } | 1057 } |
965 | 1058 |
966 for (size_t i = 0; i < check->full_hashes.size(); ++i) { | 1059 for (size_t i = 0; i < check->full_hashes.size(); ++i) { |
967 SBThreatType threat = GetHashThreatType(check->full_hashes[i], full_hashes); | 1060 SBThreatType threat = GetHashSeverestThreatType(check->full_hashes[i], |
1061 full_hashes); | |
968 if (threat != SB_THREAT_TYPE_SAFE && | 1062 if (threat != SB_THREAT_TYPE_SAFE && |
969 IsExpectedThreat(threat, check->expected_threats)) { | 1063 IsExpectedThreat(threat, check->expected_threats)) { |
970 check->full_hash_results[i] = threat; | 1064 check->full_hash_results[i] = threat; |
971 is_threat = true; | 1065 is_threat = true; |
972 } | 1066 } |
973 } | 1067 } |
974 | 1068 |
975 SafeBrowsingCheckDone(check); | 1069 SafeBrowsingCheckDone(check); |
976 return is_threat; | 1070 return is_threat; |
977 } | 1071 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1074 new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); | 1168 new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); |
1075 checks_.insert(check); | 1169 checks_.insert(check); |
1076 | 1170 |
1077 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task); | 1171 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task); |
1078 | 1172 |
1079 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 1173 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
1080 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, | 1174 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, |
1081 check->timeout_factory_->GetWeakPtr(), check), | 1175 check->timeout_factory_->GetWeakPtr(), check), |
1082 check_timeout_); | 1176 check_timeout_); |
1083 } | 1177 } |
OLD | NEW |