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