| 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 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_EMPTY; | 60 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_EMPTY; |
| 61 } else if (hit) { | 61 } else if (hit) { |
| 62 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_HIT; | 62 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_HIT; |
| 63 } else { | 63 } else { |
| 64 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_MISS; | 64 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_MISS; |
| 65 } | 65 } |
| 66 bool is_download = check_type == BINURL; | 66 bool is_download = check_type == BINURL; |
| 67 SafeBrowsingProtocolManager::RecordGetHashResult(is_download, result); | 67 SafeBrowsingProtocolManager::RecordGetHashResult(is_download, result); |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool IsExpectedThreat( | 70 bool IsExpectedThreat(const SBThreatType threat_type, |
| 71 const SBThreatType threat_type, | 71 const std::vector<SBThreatType>& expected_threats) { |
| 72 const std::vector<SBThreatType>& expected_threats) { | |
| 73 return expected_threats.end() != std::find(expected_threats.begin(), | 72 return expected_threats.end() != std::find(expected_threats.begin(), |
| 74 expected_threats.end(), | 73 expected_threats.end(), |
| 75 threat_type); | 74 threat_type); |
| 76 } | 75 } |
| 77 | 76 |
| 78 // Returns threat level of the list. Lists with lower threat levels are more | 77 // Returns threat level of the list. Lists with lower threat levels are more |
| 79 // severe than lists with higher threat levels. Zero is the severest threat | 78 // severe than lists with higher threat levels. Zero is the severest threat |
| 80 // level possible. | 79 // level possible. |
| 81 int GetThreatSeverity(ListType threat) { | 80 int GetThreatSeverity(ListType threat) { |
| 82 switch (threat) { | 81 switch (threat) { |
| 83 case MALWARE: // Falls through. | 82 case MALWARE: // Falls through. |
| 84 case PHISH: // Falls through. | 83 case PHISH: // Falls through. |
| 85 case BINURL: // Falls through. | 84 case BINURL: // Falls through. |
| 86 case CSDWHITELIST: // Falls through. | 85 case CSDWHITELIST: // Falls through. |
| 87 case DOWNLOADWHITELIST: // Falls through. | 86 case DOWNLOADWHITELIST: // Falls through. |
| 88 case INCLUSIONWHITELIST: // Falls through. | 87 case INCLUSIONWHITELIST: // Falls through. |
| 89 case MODULEWHITELIST: // Falls through. | 88 case MODULEWHITELIST: // Falls through. |
| 90 case EXTENSIONBLACKLIST: // Falls through. | 89 case EXTENSIONBLACKLIST: // Falls through. |
| 91 case IPBLACKLIST: | 90 case IPBLACKLIST: |
| 92 return 0; | 91 return 0; |
| 93 case UNWANTEDURL: | 92 case UNWANTEDURL: |
| 94 // UNWANTEDURL is considered less severe than other threats. | 93 // UNWANTEDURL is considered less severe than other threats. |
| 95 return 1; | 94 return 1; |
| 96 case RESOURCEBLACKLIST: | 95 case RESOURCEBLACKLIST: |
| 97 // RESOURCEBLACKLIST is even less severe than UNWANTEDURL. | 96 // RESOURCEBLACKLIST is even less severe than UNWANTEDURL. |
| 98 return 2; | 97 return 2; |
| 99 case INVALID: | 98 case INVALID: |
| 100 return std::numeric_limits<int>::max(); | 99 return std::numeric_limits<int>::max(); |
| 101 } | 100 } |
| 102 NOTREACHED(); | 101 NOTREACHED(); |
| 103 return -1; | 102 return -1; |
| 104 } | 103 } |
| 105 | 104 |
| 106 // Return the severest list id from the results in |full_hashes| which matches | 105 // Return the severest list id from the results in |full_hashes| which matches |
| 107 // |hash|, or INVALID if none match. | 106 // |hash|, or INVALID if none match. |
| 108 ListType GetHashSeverestThreatListType( | 107 ListType GetHashSeverestThreatListType( |
| 109 const SBFullHash& hash, | 108 const SBFullHash& hash, |
| 110 const std::vector<SBFullHashResult>& full_hashes, | 109 const std::vector<SBFullHashResult>& full_hashes, |
| 111 size_t* index) { | 110 size_t* index) { |
| 112 ListType pending_threat = INVALID; | 111 ListType pending_threat = INVALID; |
| 113 int pending_threat_severity = GetThreatSeverity(INVALID); | 112 int pending_threat_severity = GetThreatSeverity(INVALID); |
| 114 for (size_t i = 0; i < full_hashes.size(); ++i) { | 113 for (size_t i = 0; i < full_hashes.size(); ++i) { |
| 115 if (SBFullHashEqual(hash, full_hashes[i].hash)) { | 114 if (SBFullHashEqual(hash, full_hashes[i].hash)) { |
| 116 const ListType threat = | 115 const ListType threat = static_cast<ListType>(full_hashes[i].list_id); |
| 117 static_cast<ListType>(full_hashes[i].list_id); | |
| 118 int threat_severity = GetThreatSeverity(threat); | 116 int threat_severity = GetThreatSeverity(threat); |
| 119 if (threat_severity < pending_threat_severity) { | 117 if (threat_severity < pending_threat_severity) { |
| 120 pending_threat = threat; | 118 pending_threat = threat; |
| 121 pending_threat_severity = threat_severity; | 119 pending_threat_severity = threat_severity; |
| 122 if (index) | 120 if (index) |
| 123 *index = i; | 121 *index = i; |
| 124 } | 122 } |
| 125 if (pending_threat_severity == 0) | 123 if (pending_threat_severity == 0) |
| 126 return pending_threat; | 124 return pending_threat; |
| 127 } | 125 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 full_hashes(full_hashes), | 208 full_hashes(full_hashes), |
| 211 full_hash_results(full_hashes.size(), SB_THREAT_TYPE_SAFE), | 209 full_hash_results(full_hashes.size(), SB_THREAT_TYPE_SAFE), |
| 212 client(client), | 210 client(client), |
| 213 need_get_hash(false), | 211 need_get_hash(false), |
| 214 check_type(check_type), | 212 check_type(check_type), |
| 215 expected_threats(expected_threats) { | 213 expected_threats(expected_threats) { |
| 216 DCHECK_EQ(urls.empty(), !full_hashes.empty()) | 214 DCHECK_EQ(urls.empty(), !full_hashes.empty()) |
| 217 << "Exactly one of urls and full_hashes must be set"; | 215 << "Exactly one of urls and full_hashes must be set"; |
| 218 } | 216 } |
| 219 | 217 |
| 220 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck::~SafeBrowsingCheck() { | 218 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck::~SafeBrowsingCheck() {} |
| 221 } | |
| 222 | 219 |
| 223 void LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck:: | 220 void LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck:: |
| 224 OnSafeBrowsingResult() { | 221 OnSafeBrowsingResult() { |
| 225 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 222 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 226 | 223 |
| 227 DCHECK(client); | 224 DCHECK(client); |
| 228 DCHECK_EQ(urls.size(), url_results.size()); | 225 DCHECK_EQ(urls.size(), url_results.size()); |
| 229 DCHECK_EQ(full_hashes.size(), full_hash_results.size()); | 226 DCHECK_EQ(full_hashes.size(), full_hash_results.size()); |
| 230 if (!urls.empty()) { | 227 if (!urls.empty()) { |
| 231 DCHECK(full_hashes.empty()); | 228 DCHECK(full_hashes.empty()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 248 url_hit_hash[0]); | 245 url_hit_hash[0]); |
| 249 break; | 246 break; |
| 250 default: | 247 default: |
| 251 NOTREACHED(); | 248 NOTREACHED(); |
| 252 } | 249 } |
| 253 } else if (!full_hashes.empty()) { | 250 } else if (!full_hashes.empty()) { |
| 254 switch (check_type) { | 251 switch (check_type) { |
| 255 case EXTENSIONBLACKLIST: { | 252 case EXTENSIONBLACKLIST: { |
| 256 std::set<std::string> unsafe_extension_ids; | 253 std::set<std::string> unsafe_extension_ids; |
| 257 for (size_t i = 0; i < full_hashes.size(); ++i) { | 254 for (size_t i = 0; i < full_hashes.size(); ++i) { |
| 258 std::string extension_id = | 255 std::string extension_id = SBFullHashToString(full_hashes[i]); |
| 259 SBFullHashToString(full_hashes[i]); | |
| 260 if (full_hash_results[i] == SB_THREAT_TYPE_EXTENSION) | 256 if (full_hash_results[i] == SB_THREAT_TYPE_EXTENSION) |
| 261 unsafe_extension_ids.insert(extension_id); | 257 unsafe_extension_ids.insert(extension_id); |
| 262 } | 258 } |
| 263 client->OnCheckExtensionsResult(unsafe_extension_ids); | 259 client->OnCheckExtensionsResult(unsafe_extension_ids); |
| 264 break; | 260 break; |
| 265 } | 261 } |
| 266 default: | 262 default: |
| 267 NOTREACHED(); | 263 NOTREACHED(); |
| 268 } | 264 } |
| 269 } else { | 265 } else { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 return false; | 332 return false; |
| 337 } | 333 } |
| 338 | 334 |
| 339 bool LocalSafeBrowsingDatabaseManager::CanCheckResourceType( | 335 bool LocalSafeBrowsingDatabaseManager::CanCheckResourceType( |
| 340 content::ResourceType resource_type) const { | 336 content::ResourceType resource_type) const { |
| 341 // We check all types since most checks are fast. | 337 // We check all types since most checks are fast. |
| 342 return true; | 338 return true; |
| 343 } | 339 } |
| 344 | 340 |
| 345 bool LocalSafeBrowsingDatabaseManager::CanCheckUrl(const GURL& url) const { | 341 bool LocalSafeBrowsingDatabaseManager::CanCheckUrl(const GURL& url) const { |
| 346 return url.SchemeIs(url::kFtpScheme) || | 342 return url.SchemeIs(url::kFtpScheme) || url.SchemeIs(url::kHttpScheme) || |
| 347 url.SchemeIs(url::kHttpScheme) || | |
| 348 url.SchemeIs(url::kHttpsScheme); | 343 url.SchemeIs(url::kHttpsScheme); |
| 349 } | 344 } |
| 350 | 345 |
| 351 bool LocalSafeBrowsingDatabaseManager::CheckDownloadUrl( | 346 bool LocalSafeBrowsingDatabaseManager::CheckDownloadUrl( |
| 352 const std::vector<GURL>& url_chain, | 347 const std::vector<GURL>& url_chain, |
| 353 Client* client) { | 348 Client* client) { |
| 354 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 349 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 355 if (!enabled_ || !enable_download_protection_) | 350 if (!enabled_ || !enable_download_protection_) |
| 356 return true; | 351 return true; |
| 357 | 352 |
| 358 // We need to check the database for url prefix, and later may fetch the url | 353 // We need to check the database for url prefix, and later may fetch the url |
| 359 // from the safebrowsing backends. These need to be asynchronous. | 354 // from the safebrowsing backends. These need to be asynchronous. |
| 360 SafeBrowsingCheck* check = | 355 SafeBrowsingCheck* check = new SafeBrowsingCheck( |
| 361 new SafeBrowsingCheck(url_chain, | 356 url_chain, std::vector<SBFullHash>(), client, BINURL, |
| 362 std::vector<SBFullHash>(), | 357 std::vector<SBThreatType>(1, SB_THREAT_TYPE_BINARY_MALWARE_URL)); |
| 363 client, | |
| 364 BINURL, | |
| 365 std::vector<SBThreatType>(1, | |
| 366 SB_THREAT_TYPE_BINARY_MALWARE_URL)); | |
| 367 std::vector<SBPrefix> prefixes; | 358 std::vector<SBPrefix> prefixes; |
| 368 SafeBrowsingDatabase::GetDownloadUrlPrefixes(url_chain, &prefixes); | 359 SafeBrowsingDatabase::GetDownloadUrlPrefixes(url_chain, &prefixes); |
| 369 StartSafeBrowsingCheck( | 360 StartSafeBrowsingCheck( |
| 370 check, | 361 check, |
| 371 base::Bind(&LocalSafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread, | 362 base::Bind(&LocalSafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread, |
| 372 this, prefixes)); | 363 this, prefixes)); |
| 373 return false; | 364 return false; |
| 374 } | 365 } |
| 375 | 366 |
| 376 bool LocalSafeBrowsingDatabaseManager::CheckExtensionIDs( | 367 bool LocalSafeBrowsingDatabaseManager::CheckExtensionIDs( |
| 377 const std::set<std::string>& extension_ids, Client* client) { | 368 const std::set<std::string>& extension_ids, |
| 369 Client* client) { |
| 378 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 370 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 379 | 371 |
| 380 if (!enabled_ || !enable_extension_blacklist_) | 372 if (!enabled_ || !enable_extension_blacklist_) |
| 381 return true; | 373 return true; |
| 382 | 374 |
| 383 std::vector<SBFullHash> extension_id_hashes; | 375 std::vector<SBFullHash> extension_id_hashes; |
| 384 std::transform(extension_ids.begin(), extension_ids.end(), | 376 std::transform(extension_ids.begin(), extension_ids.end(), |
| 385 std::back_inserter(extension_id_hashes), | 377 std::back_inserter(extension_id_hashes), StringToSBFullHash); |
| 386 StringToSBFullHash); | |
| 387 std::vector<SBPrefix> prefixes; | 378 std::vector<SBPrefix> prefixes; |
| 388 for (const SBFullHash& hash : extension_id_hashes) | 379 for (const SBFullHash& hash : extension_id_hashes) |
| 389 prefixes.push_back(hash.prefix); | 380 prefixes.push_back(hash.prefix); |
| 390 | 381 |
| 391 SafeBrowsingCheck* check = new SafeBrowsingCheck( | 382 SafeBrowsingCheck* check = new SafeBrowsingCheck( |
| 392 std::vector<GURL>(), | 383 std::vector<GURL>(), extension_id_hashes, client, EXTENSIONBLACKLIST, |
| 393 extension_id_hashes, | |
| 394 client, | |
| 395 EXTENSIONBLACKLIST, | |
| 396 std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION)); | 384 std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION)); |
| 397 StartSafeBrowsingCheck( | 385 StartSafeBrowsingCheck( |
| 398 check, | 386 check, |
| 399 base::Bind(&LocalSafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread, | 387 base::Bind(&LocalSafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread, |
| 400 this, prefixes)); | 388 this, prefixes)); |
| 401 return false; | 389 return false; |
| 402 } | 390 } |
| 403 | 391 |
| 404 bool LocalSafeBrowsingDatabaseManager::CheckResourceUrl( | 392 bool LocalSafeBrowsingDatabaseManager::CheckResourceUrl(const GURL& url, |
| 405 const GURL& url, Client* client) { | 393 Client* client) { |
| 406 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 394 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 407 | 395 |
| 408 if (!enabled_ || !CanCheckUrl(url)) | 396 if (!enabled_ || !CanCheckUrl(url)) |
| 409 return true; | 397 return true; |
| 410 | 398 |
| 411 std::vector<SBThreatType> expected_threats = | 399 std::vector<SBThreatType> expected_threats = { |
| 412 {SB_THREAT_TYPE_BLACKLISTED_RESOURCE}; | 400 SB_THREAT_TYPE_BLACKLISTED_RESOURCE}; |
| 413 | 401 |
| 414 if (!MakeDatabaseAvailable()) { | 402 if (!MakeDatabaseAvailable()) { |
| 415 QueuedCheck queued_check(RESOURCEBLACKLIST, client, url, | 403 QueuedCheck queued_check(RESOURCEBLACKLIST, client, url, expected_threats, |
| 416 expected_threats, base::TimeTicks::Now()); | 404 base::TimeTicks::Now()); |
| 417 queued_checks_.push_back(queued_check); | 405 queued_checks_.push_back(queued_check); |
| 418 return false; | 406 return false; |
| 419 } | 407 } |
| 420 | 408 |
| 421 SafeBrowsingCheck* check = | 409 SafeBrowsingCheck* check = |
| 422 new SafeBrowsingCheck({url}, std::vector<SBFullHash>(), client, | 410 new SafeBrowsingCheck({url}, std::vector<SBFullHash>(), client, |
| 423 RESOURCEBLACKLIST, expected_threats); | 411 RESOURCEBLACKLIST, expected_threats); |
| 424 | 412 |
| 425 std::vector<SBPrefix> prefixes; | 413 std::vector<SBPrefix> prefixes; |
| 426 SafeBrowsingDatabase::GetDownloadUrlPrefixes(check->urls, &prefixes); | 414 SafeBrowsingDatabase::GetDownloadUrlPrefixes(check->urls, &prefixes); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 485 |
| 498 bool LocalSafeBrowsingDatabaseManager::IsCsdWhitelistKillSwitchOn() { | 486 bool LocalSafeBrowsingDatabaseManager::IsCsdWhitelistKillSwitchOn() { |
| 499 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 487 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 500 if (!enabled_ || !MakeDatabaseAvailable()) { | 488 if (!enabled_ || !MakeDatabaseAvailable()) { |
| 501 return true; | 489 return true; |
| 502 } | 490 } |
| 503 return database_->IsCsdWhitelistKillSwitchOn(); | 491 return database_->IsCsdWhitelistKillSwitchOn(); |
| 504 } | 492 } |
| 505 | 493 |
| 506 bool LocalSafeBrowsingDatabaseManager::CheckBrowseUrl(const GURL& url, | 494 bool LocalSafeBrowsingDatabaseManager::CheckBrowseUrl(const GURL& url, |
| 507 Client* client) { | 495 Client* client) { |
| 508 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 496 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 509 if (!enabled_) | 497 if (!enabled_) |
| 510 return true; | 498 return true; |
| 511 | 499 |
| 512 if (!CanCheckUrl(url)) | 500 if (!CanCheckUrl(url)) |
| 513 return true; | 501 return true; |
| 514 | 502 |
| 515 std::vector<SBThreatType> expected_threats; | 503 std::vector<SBThreatType> expected_threats; |
| 516 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); | 504 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); |
| 517 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); | 505 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); |
| 518 expected_threats.push_back(SB_THREAT_TYPE_URL_UNWANTED); | 506 expected_threats.push_back(SB_THREAT_TYPE_URL_UNWANTED); |
| 519 | 507 |
| 520 const base::TimeTicks start = base::TimeTicks::Now(); | 508 const base::TimeTicks start = base::TimeTicks::Now(); |
| 521 if (!MakeDatabaseAvailable()) { | 509 if (!MakeDatabaseAvailable()) { |
| 522 QueuedCheck queued_check(MALWARE, // or PHISH | 510 QueuedCheck queued_check(MALWARE, // or PHISH |
| 523 client, | 511 client, url, expected_threats, start); |
| 524 url, | |
| 525 expected_threats, | |
| 526 start); | |
| 527 queued_checks_.push_back(queued_check); | 512 queued_checks_.push_back(queued_check); |
| 528 return false; | 513 return false; |
| 529 } | 514 } |
| 530 | 515 |
| 531 // Cache hits should, in general, be the same for both (ignoring potential | 516 // Cache hits should, in general, be the same for both (ignoring potential |
| 532 // cache evictions in the second call for entries that were just about to be | 517 // cache evictions in the second call for entries that were just about to be |
| 533 // evicted in the first call). | 518 // evicted in the first call). |
| 534 // TODO(gab): Refactor SafeBrowsingDatabase to avoid depending on this here. | 519 // TODO(gab): Refactor SafeBrowsingDatabase to avoid depending on this here. |
| 535 std::vector<SBFullHashResult> cache_hits; | 520 std::vector<SBFullHashResult> cache_hits; |
| 536 | 521 |
| 537 std::vector<SBFullHash> full_hashes; | 522 std::vector<SBFullHash> full_hashes; |
| 538 UrlToFullHashes(url, false, &full_hashes); | 523 UrlToFullHashes(url, false, &full_hashes); |
| 539 | 524 |
| 540 std::vector<SBPrefix> browse_prefix_hits; | 525 std::vector<SBPrefix> browse_prefix_hits; |
| 541 bool browse_prefix_match = database_->ContainsBrowseHashes( | 526 bool browse_prefix_match = database_->ContainsBrowseHashes( |
| 542 full_hashes, &browse_prefix_hits, &cache_hits); | 527 full_hashes, &browse_prefix_hits, &cache_hits); |
| 543 | 528 |
| 544 std::vector<SBPrefix> unwanted_prefix_hits; | 529 std::vector<SBPrefix> unwanted_prefix_hits; |
| 545 std::vector<SBFullHashResult> unused_cache_hits; | 530 std::vector<SBFullHashResult> unused_cache_hits; |
| 546 bool unwanted_prefix_match = database_->ContainsUnwantedSoftwareHashes( | 531 bool unwanted_prefix_match = database_->ContainsUnwantedSoftwareHashes( |
| 547 full_hashes, &unwanted_prefix_hits, &unused_cache_hits); | 532 full_hashes, &unwanted_prefix_hits, &unused_cache_hits); |
| 548 | 533 |
| 549 // Merge the two pre-sorted prefix hits lists. | 534 // Merge the two pre-sorted prefix hits lists. |
| 550 // TODO(gab): Refactor SafeBrowsingDatabase for it to return this merged list | 535 // TODO(gab): Refactor SafeBrowsingDatabase for it to return this merged list |
| 551 // by default rather than building it here. | 536 // by default rather than building it here. |
| 552 std::vector<SBPrefix> prefix_hits(browse_prefix_hits.size() + | 537 std::vector<SBPrefix> prefix_hits(browse_prefix_hits.size() + |
| 553 unwanted_prefix_hits.size()); | 538 unwanted_prefix_hits.size()); |
| 554 std::merge(browse_prefix_hits.begin(), | 539 std::merge(browse_prefix_hits.begin(), browse_prefix_hits.end(), |
| 555 browse_prefix_hits.end(), | 540 unwanted_prefix_hits.begin(), unwanted_prefix_hits.end(), |
| 556 unwanted_prefix_hits.begin(), | |
| 557 unwanted_prefix_hits.end(), | |
| 558 prefix_hits.begin()); | 541 prefix_hits.begin()); |
| 559 prefix_hits.erase(std::unique(prefix_hits.begin(), prefix_hits.end()), | 542 prefix_hits.erase(std::unique(prefix_hits.begin(), prefix_hits.end()), |
| 560 prefix_hits.end()); | 543 prefix_hits.end()); |
| 561 | 544 |
| 562 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", base::TimeTicks::Now() - start); | 545 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", base::TimeTicks::Now() - start); |
| 563 | 546 |
| 564 if (!browse_prefix_match && !unwanted_prefix_match) | 547 if (!browse_prefix_match && !unwanted_prefix_match) |
| 565 return true; // URL is okay. | 548 return true; // URL is okay. |
| 566 | 549 |
| 567 // Needs to be asynchronous, since we could be in the constructor of a | 550 // Needs to be asynchronous, since we could be in the constructor of a |
| 568 // ResourceDispatcherHost event handler which can't pause there. | 551 // ResourceDispatcherHost event handler which can't pause there. |
| 569 // This check will ping the Safe Browsing servers and get all lists which it | 552 // This check will ping the Safe Browsing servers and get all lists which it |
| 570 // matches. These lists will then be filtered against the |expected_threats| | 553 // matches. These lists will then be filtered against the |expected_threats| |
| 571 // and the result callback for MALWARE (which is the same as for PHISH and | 554 // and the result callback for MALWARE (which is the same as for PHISH and |
| 572 // UNWANTEDURL) will eventually be invoked with the final decision. | 555 // UNWANTEDURL) will eventually be invoked with the final decision. |
| 573 SafeBrowsingCheck* check = new SafeBrowsingCheck(std::vector<GURL>(1, url), | 556 SafeBrowsingCheck* check = new SafeBrowsingCheck( |
| 574 std::vector<SBFullHash>(), | 557 std::vector<GURL>(1, url), std::vector<SBFullHash>(), client, MALWARE, |
| 575 client, | 558 expected_threats); |
| 576 MALWARE, | |
| 577 expected_threats); | |
| 578 check->need_get_hash = cache_hits.empty(); | 559 check->need_get_hash = cache_hits.empty(); |
| 579 check->prefix_hits.swap(prefix_hits); | 560 check->prefix_hits.swap(prefix_hits); |
| 580 check->cache_hits.swap(cache_hits); | 561 check->cache_hits.swap(cache_hits); |
| 581 checks_.insert(check); | 562 checks_.insert(check); |
| 582 | 563 |
| 583 BrowserThread::PostTask( | 564 BrowserThread::PostTask( |
| 584 BrowserThread::IO, FROM_HERE, | 565 BrowserThread::IO, FROM_HERE, |
| 585 base::Bind(&LocalSafeBrowsingDatabaseManager::OnCheckDone, this, check)); | 566 base::Bind(&LocalSafeBrowsingDatabaseManager::OnCheckDone, this, check)); |
| 586 | 567 |
| 587 return false; | 568 return false; |
| 588 } | 569 } |
| 589 | 570 |
| 590 void LocalSafeBrowsingDatabaseManager::CancelCheck(Client* client) { | 571 void LocalSafeBrowsingDatabaseManager::CancelCheck(Client* client) { |
| 591 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 572 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 592 for (CurrentChecks::iterator i = checks_.begin(); i != checks_.end(); ++i) { | 573 for (CurrentChecks::iterator i = checks_.begin(); i != checks_.end(); ++i) { |
| 593 // We can't delete matching checks here because the db thread has a copy of | 574 // We can't delete matching checks here because the db thread has a copy of |
| 594 // the pointer. Instead, we simply NULL out the client, and when the db | 575 // the pointer. Instead, we simply NULL out the client, and when the db |
| 595 // thread calls us back, we'll clean up the check. | 576 // thread calls us back, we'll clean up the check. |
| 596 if ((*i)->client == client) | 577 if ((*i)->client == client) |
| 597 (*i)->client = NULL; | 578 (*i)->client = NULL; |
| 598 } | 579 } |
| 599 | 580 |
| 600 // Scan the queued clients store. Clients may be here if they requested a URL | 581 // Scan the queued clients store. Clients may be here if they requested a URL |
| 601 // check before the database has finished loading. | 582 // check before the database has finished loading. |
| 602 for (std::deque<QueuedCheck>::iterator it(queued_checks_.begin()); | 583 for (std::deque<QueuedCheck>::iterator it(queued_checks_.begin()); |
| 603 it != queued_checks_.end(); ) { | 584 it != queued_checks_.end();) { |
| 604 // In this case it's safe to delete matches entirely since nothing has a | 585 // In this case it's safe to delete matches entirely since nothing has a |
| 605 // pointer to them. | 586 // pointer to them. |
| 606 if (it->client == client) | 587 if (it->client == client) |
| 607 it = queued_checks_.erase(it); | 588 it = queued_checks_.erase(it); |
| 608 else | 589 else |
| 609 ++it; | 590 ++it; |
| 610 } | 591 } |
| 611 } | 592 } |
| 612 | 593 |
| 613 void LocalSafeBrowsingDatabaseManager::HandleGetHashResults( | 594 void LocalSafeBrowsingDatabaseManager::HandleGetHashResults( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 634 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 654 DCHECK(enabled_); | 635 DCHECK(enabled_); |
| 655 DCHECK(!callback.is_null()); | 636 DCHECK(!callback.is_null()); |
| 656 safe_browsing_task_runner_->PostTask( | 637 safe_browsing_task_runner_->PostTask( |
| 657 FROM_HERE, | 638 FROM_HERE, |
| 658 base::Bind(&LocalSafeBrowsingDatabaseManager::AddDatabaseChunks, this, | 639 base::Bind(&LocalSafeBrowsingDatabaseManager::AddDatabaseChunks, this, |
| 659 list, base::Passed(&chunks), callback)); | 640 list, base::Passed(&chunks), callback)); |
| 660 } | 641 } |
| 661 | 642 |
| 662 void LocalSafeBrowsingDatabaseManager::DeleteChunks( | 643 void LocalSafeBrowsingDatabaseManager::DeleteChunks( |
| 663 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { | 644 scoped_ptr<std::vector<SBChunkDelete>> chunk_deletes) { |
| 664 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 645 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 665 DCHECK(enabled_); | 646 DCHECK(enabled_); |
| 666 safe_browsing_task_runner_->PostTask( | 647 safe_browsing_task_runner_->PostTask( |
| 667 FROM_HERE, | 648 FROM_HERE, |
| 668 base::Bind(&LocalSafeBrowsingDatabaseManager::DeleteDatabaseChunks, this, | 649 base::Bind(&LocalSafeBrowsingDatabaseManager::DeleteDatabaseChunks, this, |
| 669 base::Passed(&chunk_deletes))); | 650 base::Passed(&chunk_deletes))); |
| 670 } | 651 } |
| 671 | 652 |
| 672 void LocalSafeBrowsingDatabaseManager::UpdateStarted() { | 653 void LocalSafeBrowsingDatabaseManager::UpdateStarted() { |
| 673 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 654 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 689 } | 670 } |
| 690 | 671 |
| 691 void LocalSafeBrowsingDatabaseManager::ResetDatabase() { | 672 void LocalSafeBrowsingDatabaseManager::ResetDatabase() { |
| 692 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 673 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 693 DCHECK(enabled_); | 674 DCHECK(enabled_); |
| 694 safe_browsing_task_runner_->PostTask( | 675 safe_browsing_task_runner_->PostTask( |
| 695 FROM_HERE, | 676 FROM_HERE, |
| 696 base::Bind(&LocalSafeBrowsingDatabaseManager::OnResetDatabase, this)); | 677 base::Bind(&LocalSafeBrowsingDatabaseManager::OnResetDatabase, this)); |
| 697 } | 678 } |
| 698 | 679 |
| 680 void LocalSafeBrowsingDatabaseManager::UpdateRequestCompleted( |
| 681 const std::vector<ListUpdateResponse>& responses) { |
| 682 // TODO(vakh): Updates downloaded. Store them on disk and record new state. |
| 683 } |
| 684 |
| 699 void LocalSafeBrowsingDatabaseManager::StartOnIOThread( | 685 void LocalSafeBrowsingDatabaseManager::StartOnIOThread( |
| 700 net::URLRequestContextGetter* request_context_getter, | 686 net::URLRequestContextGetter* request_context_getter, |
| 701 const V4ProtocolConfig& config) { | 687 const V4ProtocolConfig& config) { |
| 702 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 688 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 703 SafeBrowsingDatabaseManager::StartOnIOThread(request_context_getter, config); | 689 SafeBrowsingDatabaseManager::StartOnIOThread(request_context_getter, config); |
| 704 | 690 |
| 691 V4UpdateCallback callback = |
| 692 base::Bind(&LocalSafeBrowsingDatabaseManager::UpdateRequestCompleted, |
| 693 base::Unretained(this)); |
| 694 v4_update_protocol_manager_ = V4UpdateProtocolManager::Create( |
| 695 request_context_getter, config, current_list_states_, callback); |
| 696 |
| 705 if (enabled_) | 697 if (enabled_) |
| 706 return; | 698 return; |
| 707 | 699 |
| 708 // Only get a new task runner if there isn't one already. If the service has | 700 // Only get a new task runner if there isn't one already. If the service has |
| 709 // previously been started and stopped, a task runner could already exist. | 701 // previously been started and stopped, a task runner could already exist. |
| 710 if (!safe_browsing_task_runner_) { | 702 if (!safe_browsing_task_runner_) { |
| 711 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 703 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
| 712 safe_browsing_task_runner_ = | 704 safe_browsing_task_runner_ = |
| 713 pool->GetSequencedTaskRunnerWithShutdownBehavior( | 705 pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 714 pool->GetSequenceToken(), | 706 pool->GetSequenceToken(), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 742 LocalSafeBrowsingDatabaseManager::QueuedCheck::QueuedCheck( | 734 LocalSafeBrowsingDatabaseManager::QueuedCheck::QueuedCheck( |
| 743 const ListType check_type, | 735 const ListType check_type, |
| 744 Client* client, | 736 Client* client, |
| 745 const GURL& url, | 737 const GURL& url, |
| 746 const std::vector<SBThreatType>& expected_threats, | 738 const std::vector<SBThreatType>& expected_threats, |
| 747 const base::TimeTicks& start) | 739 const base::TimeTicks& start) |
| 748 : check_type(check_type), | 740 : check_type(check_type), |
| 749 client(client), | 741 client(client), |
| 750 url(url), | 742 url(url), |
| 751 expected_threats(expected_threats), | 743 expected_threats(expected_threats), |
| 752 start(start) { | 744 start(start) {} |
| 753 } | |
| 754 | 745 |
| 755 LocalSafeBrowsingDatabaseManager::QueuedCheck::QueuedCheck( | 746 LocalSafeBrowsingDatabaseManager::QueuedCheck::QueuedCheck( |
| 756 const QueuedCheck& other) = default; | 747 const QueuedCheck& other) = default; |
| 757 | 748 |
| 758 LocalSafeBrowsingDatabaseManager::QueuedCheck::~QueuedCheck() { | 749 LocalSafeBrowsingDatabaseManager::QueuedCheck::~QueuedCheck() {} |
| 759 } | |
| 760 | 750 |
| 761 void LocalSafeBrowsingDatabaseManager::DoStopOnIOThread() { | 751 void LocalSafeBrowsingDatabaseManager::DoStopOnIOThread() { |
| 762 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 752 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 763 | 753 |
| 764 if (!enabled_) | 754 if (!enabled_) |
| 765 return; | 755 return; |
| 766 | 756 |
| 767 enabled_ = false; | 757 enabled_ = false; |
| 768 | 758 |
| 769 // Delete queued checks, calling back any clients with 'SB_THREAT_TYPE_SAFE'. | 759 // Delete queued checks, calling back any clients with 'SB_THREAT_TYPE_SAFE'. |
| 770 while (!queued_checks_.empty()) { | 760 while (!queued_checks_.empty()) { |
| 771 QueuedCheck queued = queued_checks_.front(); | 761 QueuedCheck queued = queued_checks_.front(); |
| 772 if (queued.client) { | 762 if (queued.client) { |
| 773 SafeBrowsingCheck sb_check(std::vector<GURL>(1, queued.url), | 763 SafeBrowsingCheck sb_check(std::vector<GURL>(1, queued.url), |
| 774 std::vector<SBFullHash>(), | 764 std::vector<SBFullHash>(), queued.client, |
| 775 queued.client, | 765 queued.check_type, queued.expected_threats); |
| 776 queued.check_type, | |
| 777 queued.expected_threats); | |
| 778 sb_check.OnSafeBrowsingResult(); | 766 sb_check.OnSafeBrowsingResult(); |
| 779 } | 767 } |
| 780 queued_checks_.pop_front(); | 768 queued_checks_.pop_front(); |
| 781 } | 769 } |
| 782 | 770 |
| 783 // Close the database. Cases to avoid: | 771 // Close the database. Cases to avoid: |
| 784 // * If |closing_database_| is true, continuing will queue up a second | 772 // * If |closing_database_| is true, continuing will queue up a second |
| 785 // request, |closing_database_| will be reset after handling the first | 773 // request, |closing_database_| will be reset after handling the first |
| 786 // request, and if any functions on the db thread recreate the database, we | 774 // request, and if any functions on the db thread recreate the database, we |
| 787 // could start using it on the IO thread and then have the second request | 775 // could start using it on the IO thread and then have the second request |
| 788 // handler delete it out from under us. | 776 // handler delete it out from under us. |
| 789 // * If |database_| is NULL, then either no creation request is in flight, in | 777 // * If |database_| is NULL, then either no creation request is in flight, in |
| 790 // which case we don't need to do anything, or one is in flight, in which | 778 // which case we don't need to do anything, or one is in flight, in which |
| 791 // case the database will be recreated before our deletion request is | 779 // case the database will be recreated before our deletion request is |
| 792 // handled, and could be used on the IO thread in that time period, leading | 780 // handled, and could be used on the IO thread in that time period, leading |
| 793 // to the same problem as above. | 781 // to the same problem as above. |
| 794 // Checking DatabaseAvailable() avoids both of these. | 782 // Checking DatabaseAvailable() avoids both of these. |
| 795 if (DatabaseAvailable()) { | 783 if (DatabaseAvailable()) { |
| 796 closing_database_ = true; | 784 closing_database_ = true; |
| 797 safe_browsing_task_runner_->PostTask( | 785 safe_browsing_task_runner_->PostTask( |
| 798 FROM_HERE, | 786 FROM_HERE, |
| 799 base::Bind(&LocalSafeBrowsingDatabaseManager::OnCloseDatabase, this)); | 787 base::Bind(&LocalSafeBrowsingDatabaseManager::OnCloseDatabase, this)); |
| 800 } | 788 } |
| 801 | 789 |
| 802 // Delete pending checks, calling back any clients with 'SB_THREAT_TYPE_SAFE'. | 790 // Delete pending checks, calling back any clients with 'SB_THREAT_TYPE_SAFE'. |
| 803 // We have to do this after the db thread returns because methods on it can | 791 // We have to do this after the db thread returns because methods on it can |
| 804 // have copies of these pointers, so deleting them might lead to accessing | 792 // have copies of these pointers, so deleting them might lead to accessing |
| 805 // garbage. | 793 // garbage. |
| 806 for (CurrentChecks::iterator it = checks_.begin(); | 794 for (CurrentChecks::iterator it = checks_.begin(); it != checks_.end(); |
| 807 it != checks_.end(); ++it) { | 795 ++it) { |
| 808 SafeBrowsingCheck* check = *it; | 796 SafeBrowsingCheck* check = *it; |
| 809 if (check->client) | 797 if (check->client) |
| 810 check->OnSafeBrowsingResult(); | 798 check->OnSafeBrowsingResult(); |
| 811 } | 799 } |
| 812 STLDeleteElements(&checks_); | 800 STLDeleteElements(&checks_); |
| 813 | 801 |
| 814 gethash_requests_.clear(); | 802 gethash_requests_.clear(); |
| 803 |
| 804 // Delete the V4UpdateProtocolManager. |
| 805 // This cancels any in-flight update request. |
| 806 if (v4_update_protocol_manager_.get()) { |
| 807 v4_update_protocol_manager_.reset(); |
| 808 } |
| 815 } | 809 } |
| 816 | 810 |
| 817 bool LocalSafeBrowsingDatabaseManager::DatabaseAvailable() const { | 811 bool LocalSafeBrowsingDatabaseManager::DatabaseAvailable() const { |
| 818 base::AutoLock lock(database_lock_); | 812 base::AutoLock lock(database_lock_); |
| 819 return !closing_database_ && (database_ != NULL); | 813 return !closing_database_ && (database_ != NULL); |
| 820 } | 814 } |
| 821 | 815 |
| 822 bool LocalSafeBrowsingDatabaseManager::MakeDatabaseAvailable() { | 816 bool LocalSafeBrowsingDatabaseManager::MakeDatabaseAvailable() { |
| 823 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 817 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 824 DCHECK(enabled_); | 818 DCHECK(enabled_); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 while (!queued_checks_.empty()) { | 1013 while (!queued_checks_.empty()) { |
| 1020 QueuedCheck check = queued_checks_.front(); | 1014 QueuedCheck check = queued_checks_.front(); |
| 1021 DCHECK(!check.start.is_null()); | 1015 DCHECK(!check.start.is_null()); |
| 1022 LOCAL_HISTOGRAM_TIMES("SB.QueueDelay", | 1016 LOCAL_HISTOGRAM_TIMES("SB.QueueDelay", |
| 1023 base::TimeTicks::Now() - check.start); | 1017 base::TimeTicks::Now() - check.start); |
| 1024 // If CheckUrl() determines the URL is safe immediately, it doesn't call the | 1018 // If CheckUrl() determines the URL is safe immediately, it doesn't call the |
| 1025 // client's handler function (because normally it's being directly called by | 1019 // client's handler function (because normally it's being directly called by |
| 1026 // the client). Since we're not the client, we have to convey this result. | 1020 // the client). Since we're not the client, we have to convey this result. |
| 1027 if (check.client && CheckBrowseUrl(check.url, check.client)) { | 1021 if (check.client && CheckBrowseUrl(check.url, check.client)) { |
| 1028 SafeBrowsingCheck sb_check(std::vector<GURL>(1, check.url), | 1022 SafeBrowsingCheck sb_check(std::vector<GURL>(1, check.url), |
| 1029 std::vector<SBFullHash>(), | 1023 std::vector<SBFullHash>(), check.client, |
| 1030 check.client, | 1024 check.check_type, check.expected_threats); |
| 1031 check.check_type, | |
| 1032 check.expected_threats); | |
| 1033 sb_check.OnSafeBrowsingResult(); | 1025 sb_check.OnSafeBrowsingResult(); |
| 1034 } | 1026 } |
| 1035 queued_checks_.pop_front(); | 1027 queued_checks_.pop_front(); |
| 1036 } | 1028 } |
| 1037 } | 1029 } |
| 1038 | 1030 |
| 1039 void LocalSafeBrowsingDatabaseManager::AddDatabaseChunks( | 1031 void LocalSafeBrowsingDatabaseManager::AddDatabaseChunks( |
| 1040 const std::string& list_name, | 1032 const std::string& list_name, |
| 1041 scoped_ptr<std::vector<scoped_ptr<SBChunkData>>> chunks, | 1033 scoped_ptr<std::vector<scoped_ptr<SBChunkData>>> chunks, |
| 1042 AddChunksCallback callback) { | 1034 AddChunksCallback callback) { |
| 1043 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 1035 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 1044 if (chunks) | 1036 if (chunks) |
| 1045 GetDatabase()->InsertChunks(list_name, *chunks); | 1037 GetDatabase()->InsertChunks(list_name, *chunks); |
| 1046 BrowserThread::PostTask( | 1038 BrowserThread::PostTask( |
| 1047 BrowserThread::IO, FROM_HERE, | 1039 BrowserThread::IO, FROM_HERE, |
| 1048 base::Bind(&LocalSafeBrowsingDatabaseManager::OnAddChunksComplete, this, | 1040 base::Bind(&LocalSafeBrowsingDatabaseManager::OnAddChunksComplete, this, |
| 1049 callback)); | 1041 callback)); |
| 1050 } | 1042 } |
| 1051 | 1043 |
| 1052 void LocalSafeBrowsingDatabaseManager::DeleteDatabaseChunks( | 1044 void LocalSafeBrowsingDatabaseManager::DeleteDatabaseChunks( |
| 1053 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { | 1045 scoped_ptr<std::vector<SBChunkDelete>> chunk_deletes) { |
| 1054 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 1046 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 1055 if (chunk_deletes) | 1047 if (chunk_deletes) |
| 1056 GetDatabase()->DeleteChunks(*chunk_deletes); | 1048 GetDatabase()->DeleteChunks(*chunk_deletes); |
| 1057 } | 1049 } |
| 1058 | 1050 |
| 1059 void LocalSafeBrowsingDatabaseManager::DatabaseUpdateFinished( | 1051 void LocalSafeBrowsingDatabaseManager::DatabaseUpdateFinished( |
| 1060 bool update_succeeded) { | 1052 bool update_succeeded) { |
| 1061 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 1053 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 1062 GetDatabase()->UpdateFinished(update_succeeded); | 1054 GetDatabase()->UpdateFinished(update_succeeded); |
| 1063 DCHECK(database_update_in_progress_); | 1055 DCHECK(database_update_in_progress_); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 } | 1139 } |
| 1148 } | 1140 } |
| 1149 | 1141 |
| 1150 if (expected_full_hashes.empty()) { | 1142 if (expected_full_hashes.empty()) { |
| 1151 SafeBrowsingCheckDone(check); | 1143 SafeBrowsingCheckDone(check); |
| 1152 return false; | 1144 return false; |
| 1153 } | 1145 } |
| 1154 | 1146 |
| 1155 for (size_t i = 0; i < check->urls.size(); ++i) { | 1147 for (size_t i = 0; i < check->urls.size(); ++i) { |
| 1156 size_t threat_index; | 1148 size_t threat_index; |
| 1157 SBThreatType threat = GetUrlSeverestThreatType(check->urls[i], | 1149 SBThreatType threat = GetUrlSeverestThreatType( |
| 1158 expected_full_hashes, | 1150 check->urls[i], expected_full_hashes, &threat_index); |
| 1159 &threat_index); | |
| 1160 if (threat != SB_THREAT_TYPE_SAFE) { | 1151 if (threat != SB_THREAT_TYPE_SAFE) { |
| 1161 check->url_results[i] = threat; | 1152 check->url_results[i] = threat; |
| 1162 check->url_metadata[i] = expected_full_hashes[threat_index].metadata; | 1153 check->url_metadata[i] = expected_full_hashes[threat_index].metadata; |
| 1163 const SBFullHash& hash = expected_full_hashes[threat_index].hash; | 1154 const SBFullHash& hash = expected_full_hashes[threat_index].hash; |
| 1164 check->url_hit_hash[i] = std::string(hash.full_hash, | 1155 check->url_hit_hash[i] = |
| 1165 arraysize(hash.full_hash)); | 1156 std::string(hash.full_hash, arraysize(hash.full_hash)); |
| 1166 is_threat = true; | 1157 is_threat = true; |
| 1167 } | 1158 } |
| 1168 } | 1159 } |
| 1169 | 1160 |
| 1170 for (size_t i = 0; i < check->full_hashes.size(); ++i) { | 1161 for (size_t i = 0; i < check->full_hashes.size(); ++i) { |
| 1171 SBThreatType threat = | 1162 SBThreatType threat = |
| 1172 GetHashSeverestThreatType(check->full_hashes[i], expected_full_hashes); | 1163 GetHashSeverestThreatType(check->full_hashes[i], expected_full_hashes); |
| 1173 if (threat != SB_THREAT_TYPE_SAFE) { | 1164 if (threat != SB_THREAT_TYPE_SAFE) { |
| 1174 check->full_hash_results[i] = threat; | 1165 check->full_hash_results[i] = threat; |
| 1175 is_threat = true; | 1166 is_threat = true; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 FROM_HERE, base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, | 1270 FROM_HERE, base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, |
| 1280 check->weak_ptr_factory_->GetWeakPtr(), check), | 1271 check->weak_ptr_factory_->GetWeakPtr(), check), |
| 1281 check_timeout_); | 1272 check_timeout_); |
| 1282 } | 1273 } |
| 1283 | 1274 |
| 1284 bool LocalSafeBrowsingDatabaseManager::download_protection_enabled() const { | 1275 bool LocalSafeBrowsingDatabaseManager::download_protection_enabled() const { |
| 1285 return enable_download_protection_; | 1276 return enable_download_protection_; |
| 1286 } | 1277 } |
| 1287 | 1278 |
| 1288 } // namespace safe_browsing | 1279 } // namespace safe_browsing |
| OLD | NEW |