| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 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/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
| 35 #include "components/safe_browsing_db/util.h" | 35 #include "components/safe_browsing_db/util.h" |
| 36 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 38 #include "url/url_constants.h" | 38 #include "url/url_constants.h" |
| 39 | 39 |
| 40 using content::BrowserThread; | 40 using content::BrowserThread; |
| 41 | 41 |
| 42 namespace safe_browsing { |
| 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 44 // Timeout for match checks, e.g. download URLs, hashes. | 46 // Timeout for match checks, e.g. download URLs, hashes. |
| 45 const int kCheckTimeoutMs = 10000; | 47 const int kCheckTimeoutMs = 10000; |
| 46 | 48 |
| 47 // Records disposition information about the check. |hit| should be | 49 // Records disposition information about the check. |hit| should be |
| 48 // |true| if there were any prefix hits in |full_hashes|. | 50 // |true| if there were any prefix hits in |full_hashes|. |
| 49 void RecordGetHashCheckStatus( | 51 void RecordGetHashCheckStatus( |
| 50 bool hit, | 52 bool hit, |
| 51 safe_browsing::ListType check_type, | 53 ListType check_type, |
| 52 const std::vector<SBFullHashResult>& full_hashes) { | 54 const std::vector<SBFullHashResult>& full_hashes) { |
| 53 SafeBrowsingProtocolManager::ResultType result; | 55 SafeBrowsingProtocolManager::ResultType result; |
| 54 if (full_hashes.empty()) { | 56 if (full_hashes.empty()) { |
| 55 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_EMPTY; | 57 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_EMPTY; |
| 56 } else if (hit) { | 58 } else if (hit) { |
| 57 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_HIT; | 59 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_HIT; |
| 58 } else { | 60 } else { |
| 59 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_MISS; | 61 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_MISS; |
| 60 } | 62 } |
| 61 bool is_download = check_type == safe_browsing::BINURL; | 63 bool is_download = check_type == BINURL; |
| 62 SafeBrowsingProtocolManager::RecordGetHashResult(is_download, result); | 64 SafeBrowsingProtocolManager::RecordGetHashResult(is_download, result); |
| 63 } | 65 } |
| 64 | 66 |
| 65 bool IsExpectedThreat( | 67 bool IsExpectedThreat( |
| 66 const SBThreatType threat_type, | 68 const SBThreatType threat_type, |
| 67 const std::vector<SBThreatType>& expected_threats) { | 69 const std::vector<SBThreatType>& expected_threats) { |
| 68 return expected_threats.end() != std::find(expected_threats.begin(), | 70 return expected_threats.end() != std::find(expected_threats.begin(), |
| 69 expected_threats.end(), | 71 expected_threats.end(), |
| 70 threat_type); | 72 threat_type); |
| 71 } | 73 } |
| 72 | 74 |
| 73 // Return the severest list id from the results in |full_hashes| which matches | 75 // Return the severest list id from the results in |full_hashes| which matches |
| 74 // |hash|, or INVALID if none match. | 76 // |hash|, or INVALID if none match. |
| 75 safe_browsing::ListType GetHashSeverestThreatListType( | 77 ListType GetHashSeverestThreatListType( |
| 76 const SBFullHash& hash, | 78 const SBFullHash& hash, |
| 77 const std::vector<SBFullHashResult>& full_hashes, | 79 const std::vector<SBFullHashResult>& full_hashes, |
| 78 size_t* index) { | 80 size_t* index) { |
| 79 safe_browsing::ListType pending_threat = safe_browsing::INVALID; | 81 ListType pending_threat = INVALID; |
| 80 for (size_t i = 0; i < full_hashes.size(); ++i) { | 82 for (size_t i = 0; i < full_hashes.size(); ++i) { |
| 81 if (safe_browsing::SBFullHashEqual(hash, full_hashes[i].hash)) { | 83 if (SBFullHashEqual(hash, full_hashes[i].hash)) { |
| 82 const safe_browsing::ListType threat = | 84 const ListType threat = |
| 83 static_cast<safe_browsing::ListType>(full_hashes[i].list_id); | 85 static_cast<ListType>(full_hashes[i].list_id); |
| 84 switch (threat) { | 86 switch (threat) { |
| 85 case safe_browsing::INVALID: | 87 case INVALID: |
| 86 // |full_hashes| should never contain INVALID as a |list_id|. | 88 // |full_hashes| should never contain INVALID as a |list_id|. |
| 87 NOTREACHED(); | 89 NOTREACHED(); |
| 88 break; | 90 break; |
| 89 case safe_browsing::MALWARE: // Falls through. | 91 case MALWARE: // Falls through. |
| 90 case safe_browsing::PHISH: // Falls through. | 92 case PHISH: // Falls through. |
| 91 case safe_browsing::BINURL: // Falls through. | 93 case BINURL: // Falls through. |
| 92 case safe_browsing::CSDWHITELIST: // Falls through. | 94 case CSDWHITELIST: // Falls through. |
| 93 case safe_browsing::DOWNLOADWHITELIST: // Falls through. | 95 case DOWNLOADWHITELIST: // Falls through. |
| 94 case safe_browsing::INCLUSIONWHITELIST: // Falls through. | 96 case INCLUSIONWHITELIST: // Falls through. |
| 95 case safe_browsing::EXTENSIONBLACKLIST: // Falls through. | 97 case EXTENSIONBLACKLIST: // Falls through. |
| 96 case safe_browsing::IPBLACKLIST: | 98 case IPBLACKLIST: |
| 97 if (index) | 99 if (index) |
| 98 *index = i; | 100 *index = i; |
| 99 return threat; | 101 return threat; |
| 100 case safe_browsing::UNWANTEDURL: | 102 case UNWANTEDURL: |
| 101 // UNWANTEDURL is considered less severe than other threats, keep | 103 // UNWANTEDURL is considered less severe than other threats, keep |
| 102 // looking. | 104 // looking. |
| 103 pending_threat = threat; | 105 pending_threat = threat; |
| 104 if (index) | 106 if (index) |
| 105 *index = i; | 107 *index = i; |
| 106 break; | 108 break; |
| 107 } | 109 } |
| 108 } | 110 } |
| 109 } | 111 } |
| 110 return pending_threat; | 112 return pending_threat; |
| 111 } | 113 } |
| 112 | 114 |
| 113 // Given a URL, compare all the possible host + path full hashes to the set of | 115 // Given a URL, compare all the possible host + path full hashes to the set of |
| 114 // provided full hashes. Returns the list id of the severest matching result | 116 // provided full hashes. Returns the list id of the severest matching result |
| 115 // from |full_hashes|, or INVALID if none match. | 117 // from |full_hashes|, or INVALID if none match. |
| 116 safe_browsing::ListType GetUrlSeverestThreatListType( | 118 ListType GetUrlSeverestThreatListType( |
| 117 const GURL& url, | 119 const GURL& url, |
| 118 const std::vector<SBFullHashResult>& full_hashes, | 120 const std::vector<SBFullHashResult>& full_hashes, |
| 119 size_t* index) { | 121 size_t* index) { |
| 120 if (full_hashes.empty()) | 122 if (full_hashes.empty()) |
| 121 return safe_browsing::INVALID; | 123 return INVALID; |
| 122 | 124 |
| 123 std::vector<std::string> patterns; | 125 std::vector<std::string> patterns; |
| 124 safe_browsing::GeneratePatternsToCheck(url, &patterns); | 126 GeneratePatternsToCheck(url, &patterns); |
| 125 | 127 |
| 126 safe_browsing::ListType pending_threat = safe_browsing::INVALID; | 128 ListType pending_threat = INVALID; |
| 127 for (size_t i = 0; i < patterns.size(); ++i) { | 129 for (size_t i = 0; i < patterns.size(); ++i) { |
| 128 safe_browsing::ListType threat = GetHashSeverestThreatListType( | 130 ListType threat = GetHashSeverestThreatListType( |
| 129 safe_browsing::SBFullHashForString(patterns[i]), full_hashes, index); | 131 SBFullHashForString(patterns[i]), full_hashes, index); |
| 130 switch (threat) { | 132 switch (threat) { |
| 131 case safe_browsing::INVALID: | 133 case INVALID: |
| 132 // Ignore patterns with no matching threat. | 134 // Ignore patterns with no matching threat. |
| 133 break; | 135 break; |
| 134 case safe_browsing::MALWARE: // Falls through. | 136 case MALWARE: // Falls through. |
| 135 case safe_browsing::PHISH: // Falls through. | 137 case PHISH: // Falls through. |
| 136 case safe_browsing::BINURL: // Falls through. | 138 case BINURL: // Falls through. |
| 137 case safe_browsing::CSDWHITELIST: // Falls through. | 139 case CSDWHITELIST: // Falls through. |
| 138 case safe_browsing::DOWNLOADWHITELIST: // Falls through. | 140 case DOWNLOADWHITELIST: // Falls through. |
| 139 case safe_browsing::INCLUSIONWHITELIST: // Falls through. | 141 case INCLUSIONWHITELIST: // Falls through. |
| 140 case safe_browsing::EXTENSIONBLACKLIST: // Falls through. | 142 case EXTENSIONBLACKLIST: // Falls through. |
| 141 case safe_browsing::IPBLACKLIST: | 143 case IPBLACKLIST: |
| 142 return threat; | 144 return threat; |
| 143 case safe_browsing::UNWANTEDURL: | 145 case UNWANTEDURL: |
| 144 // UNWANTEDURL is considered less severe than other threats, keep | 146 // UNWANTEDURL is considered less severe than other threats, keep |
| 145 // looking. | 147 // looking. |
| 146 pending_threat = threat; | 148 pending_threat = threat; |
| 147 break; | 149 break; |
| 148 } | 150 } |
| 149 } | 151 } |
| 150 return pending_threat; | 152 return pending_threat; |
| 151 } | 153 } |
| 152 | 154 |
| 153 SBThreatType GetThreatTypeFromListType(safe_browsing::ListType list_type) { | 155 SBThreatType GetThreatTypeFromListType(ListType list_type) { |
| 154 switch (list_type) { | 156 switch (list_type) { |
| 155 case safe_browsing::PHISH: | 157 case PHISH: |
| 156 return SB_THREAT_TYPE_URL_PHISHING; | 158 return SB_THREAT_TYPE_URL_PHISHING; |
| 157 case safe_browsing::MALWARE: | 159 case MALWARE: |
| 158 return SB_THREAT_TYPE_URL_MALWARE; | 160 return SB_THREAT_TYPE_URL_MALWARE; |
| 159 case safe_browsing::UNWANTEDURL: | 161 case UNWANTEDURL: |
| 160 return SB_THREAT_TYPE_URL_UNWANTED; | 162 return SB_THREAT_TYPE_URL_UNWANTED; |
| 161 case safe_browsing::BINURL: | 163 case BINURL: |
| 162 return SB_THREAT_TYPE_BINARY_MALWARE_URL; | 164 return SB_THREAT_TYPE_BINARY_MALWARE_URL; |
| 163 case safe_browsing::EXTENSIONBLACKLIST: | 165 case EXTENSIONBLACKLIST: |
| 164 return SB_THREAT_TYPE_EXTENSION; | 166 return SB_THREAT_TYPE_EXTENSION; |
| 165 default: | 167 default: |
| 166 DVLOG(1) << "Unknown safe browsing list id " << list_type; | 168 DVLOG(1) << "Unknown safe browsing list id " << list_type; |
| 167 return SB_THREAT_TYPE_SAFE; | 169 return SB_THREAT_TYPE_SAFE; |
| 168 } | 170 } |
| 169 } | 171 } |
| 170 | 172 |
| 171 } // namespace | 173 } // namespace |
| 172 | 174 |
| 173 // static | 175 // static |
| (...skipping 10 matching lines...) Expand all Loading... |
| 184 const std::vector<SBFullHashResult>& full_hashes, | 186 const std::vector<SBFullHashResult>& full_hashes, |
| 185 size_t* index) { | 187 size_t* index) { |
| 186 return GetThreatTypeFromListType( | 188 return GetThreatTypeFromListType( |
| 187 GetUrlSeverestThreatListType(url, full_hashes, index)); | 189 GetUrlSeverestThreatListType(url, full_hashes, index)); |
| 188 } | 190 } |
| 189 | 191 |
| 190 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck::SafeBrowsingCheck( | 192 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck::SafeBrowsingCheck( |
| 191 const std::vector<GURL>& urls, | 193 const std::vector<GURL>& urls, |
| 192 const std::vector<SBFullHash>& full_hashes, | 194 const std::vector<SBFullHash>& full_hashes, |
| 193 Client* client, | 195 Client* client, |
| 194 safe_browsing::ListType check_type, | 196 ListType check_type, |
| 195 const std::vector<SBThreatType>& expected_threats) | 197 const std::vector<SBThreatType>& expected_threats) |
| 196 : urls(urls), | 198 : urls(urls), |
| 197 url_results(urls.size(), SB_THREAT_TYPE_SAFE), | 199 url_results(urls.size(), SB_THREAT_TYPE_SAFE), |
| 198 url_metadata(urls.size()), | 200 url_metadata(urls.size()), |
| 199 full_hashes(full_hashes), | 201 full_hashes(full_hashes), |
| 200 full_hash_results(full_hashes.size(), SB_THREAT_TYPE_SAFE), | 202 full_hash_results(full_hashes.size(), SB_THREAT_TYPE_SAFE), |
| 201 client(client), | 203 client(client), |
| 202 need_get_hash(false), | 204 need_get_hash(false), |
| 203 check_type(check_type), | 205 check_type(check_type), |
| 204 expected_threats(expected_threats) { | 206 expected_threats(expected_threats) { |
| 205 DCHECK_EQ(urls.empty(), !full_hashes.empty()) | 207 DCHECK_EQ(urls.empty(), !full_hashes.empty()) |
| 206 << "Exactly one of urls and full_hashes must be set"; | 208 << "Exactly one of urls and full_hashes must be set"; |
| 207 } | 209 } |
| 208 | 210 |
| 209 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck::~SafeBrowsingCheck() { | 211 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck::~SafeBrowsingCheck() { |
| 210 } | 212 } |
| 211 | 213 |
| 212 void LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck:: | 214 void LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck:: |
| 213 OnSafeBrowsingResult() { | 215 OnSafeBrowsingResult() { |
| 214 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 216 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 215 | 217 |
| 216 DCHECK(client); | 218 DCHECK(client); |
| 217 DCHECK_EQ(urls.size(), url_results.size()); | 219 DCHECK_EQ(urls.size(), url_results.size()); |
| 218 DCHECK_EQ(full_hashes.size(), full_hash_results.size()); | 220 DCHECK_EQ(full_hashes.size(), full_hash_results.size()); |
| 219 if (!urls.empty()) { | 221 if (!urls.empty()) { |
| 220 DCHECK(full_hashes.empty()); | 222 DCHECK(full_hashes.empty()); |
| 221 switch (check_type) { | 223 switch (check_type) { |
| 222 case safe_browsing::MALWARE: | 224 case MALWARE: |
| 223 case safe_browsing::PHISH: | 225 case PHISH: |
| 224 case safe_browsing::UNWANTEDURL: | 226 case UNWANTEDURL: |
| 225 DCHECK_EQ(1u, urls.size()); | 227 DCHECK_EQ(1u, urls.size()); |
| 226 client->OnCheckBrowseUrlResult(urls[0], url_results[0], | 228 client->OnCheckBrowseUrlResult(urls[0], url_results[0], |
| 227 url_metadata[0]); | 229 url_metadata[0]); |
| 228 break; | 230 break; |
| 229 case safe_browsing::BINURL: | 231 case BINURL: |
| 230 DCHECK_EQ(urls.size(), url_results.size()); | 232 DCHECK_EQ(urls.size(), url_results.size()); |
| 231 client->OnCheckDownloadUrlResult( | 233 client->OnCheckDownloadUrlResult( |
| 232 urls, *std::max_element(url_results.begin(), url_results.end())); | 234 urls, *std::max_element(url_results.begin(), url_results.end())); |
| 233 break; | 235 break; |
| 234 default: | 236 default: |
| 235 NOTREACHED(); | 237 NOTREACHED(); |
| 236 } | 238 } |
| 237 } else if (!full_hashes.empty()) { | 239 } else if (!full_hashes.empty()) { |
| 238 switch (check_type) { | 240 switch (check_type) { |
| 239 case safe_browsing::EXTENSIONBLACKLIST: { | 241 case EXTENSIONBLACKLIST: { |
| 240 std::set<std::string> unsafe_extension_ids; | 242 std::set<std::string> unsafe_extension_ids; |
| 241 for (size_t i = 0; i < full_hashes.size(); ++i) { | 243 for (size_t i = 0; i < full_hashes.size(); ++i) { |
| 242 std::string extension_id = | 244 std::string extension_id = |
| 243 safe_browsing::SBFullHashToString(full_hashes[i]); | 245 SBFullHashToString(full_hashes[i]); |
| 244 if (full_hash_results[i] == SB_THREAT_TYPE_EXTENSION) | 246 if (full_hash_results[i] == SB_THREAT_TYPE_EXTENSION) |
| 245 unsafe_extension_ids.insert(extension_id); | 247 unsafe_extension_ids.insert(extension_id); |
| 246 } | 248 } |
| 247 client->OnCheckExtensionsResult(unsafe_extension_ids); | 249 client->OnCheckExtensionsResult(unsafe_extension_ids); |
| 248 break; | 250 break; |
| 249 } | 251 } |
| 250 default: | 252 default: |
| 251 NOTREACHED(); | 253 NOTREACHED(); |
| 252 } | 254 } |
| 253 } else { | 255 } else { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 334 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 333 if (!enabled_ || !enable_download_protection_) | 335 if (!enabled_ || !enable_download_protection_) |
| 334 return true; | 336 return true; |
| 335 | 337 |
| 336 // We need to check the database for url prefix, and later may fetch the url | 338 // We need to check the database for url prefix, and later may fetch the url |
| 337 // from the safebrowsing backends. These need to be asynchronous. | 339 // from the safebrowsing backends. These need to be asynchronous. |
| 338 SafeBrowsingCheck* check = | 340 SafeBrowsingCheck* check = |
| 339 new SafeBrowsingCheck(url_chain, | 341 new SafeBrowsingCheck(url_chain, |
| 340 std::vector<SBFullHash>(), | 342 std::vector<SBFullHash>(), |
| 341 client, | 343 client, |
| 342 safe_browsing::BINURL, | 344 BINURL, |
| 343 std::vector<SBThreatType>(1, | 345 std::vector<SBThreatType>(1, |
| 344 SB_THREAT_TYPE_BINARY_MALWARE_URL)); | 346 SB_THREAT_TYPE_BINARY_MALWARE_URL)); |
| 345 std::vector<SBPrefix> prefixes; | 347 std::vector<SBPrefix> prefixes; |
| 346 SafeBrowsingDatabase::GetDownloadUrlPrefixes(url_chain, &prefixes); | 348 SafeBrowsingDatabase::GetDownloadUrlPrefixes(url_chain, &prefixes); |
| 347 StartSafeBrowsingCheck( | 349 StartSafeBrowsingCheck( |
| 348 check, | 350 check, |
| 349 base::Bind(&LocalSafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread, | 351 base::Bind(&LocalSafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread, |
| 350 this, prefixes)); | 352 this, prefixes)); |
| 351 return false; | 353 return false; |
| 352 } | 354 } |
| 353 | 355 |
| 354 bool LocalSafeBrowsingDatabaseManager::CheckExtensionIDs( | 356 bool LocalSafeBrowsingDatabaseManager::CheckExtensionIDs( |
| 355 const std::set<std::string>& extension_ids, | 357 const std::set<std::string>& extension_ids, Client* client) { |
| 356 Client* client) { | |
| 357 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 358 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 358 | 359 |
| 359 if (!enabled_ || !enable_extension_blacklist_) | 360 if (!enabled_ || !enable_extension_blacklist_) |
| 360 return true; | 361 return true; |
| 361 | 362 |
| 362 std::vector<SBFullHash> extension_id_hashes; | 363 std::vector<SBFullHash> extension_id_hashes; |
| 363 std::transform(extension_ids.begin(), extension_ids.end(), | 364 std::transform(extension_ids.begin(), extension_ids.end(), |
| 364 std::back_inserter(extension_id_hashes), | 365 std::back_inserter(extension_id_hashes), |
| 365 safe_browsing::StringToSBFullHash); | 366 StringToSBFullHash); |
| 366 std::vector<SBPrefix> prefixes; | 367 std::vector<SBPrefix> prefixes; |
| 367 for (const SBFullHash& hash : extension_id_hashes) | 368 for (const SBFullHash& hash : extension_id_hashes) |
| 368 prefixes.push_back(hash.prefix); | 369 prefixes.push_back(hash.prefix); |
| 369 | 370 |
| 370 SafeBrowsingCheck* check = new SafeBrowsingCheck( | 371 SafeBrowsingCheck* check = new SafeBrowsingCheck( |
| 371 std::vector<GURL>(), | 372 std::vector<GURL>(), |
| 372 extension_id_hashes, | 373 extension_id_hashes, |
| 373 client, | 374 client, |
| 374 safe_browsing::EXTENSIONBLACKLIST, | 375 EXTENSIONBLACKLIST, |
| 375 std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION)); | 376 std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION)); |
| 376 StartSafeBrowsingCheck( | 377 StartSafeBrowsingCheck( |
| 377 check, | 378 check, |
| 378 base::Bind(&LocalSafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread, | 379 base::Bind(&LocalSafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread, |
| 379 this, prefixes)); | 380 this, prefixes)); |
| 380 return false; | 381 return false; |
| 381 } | 382 } |
| 382 | 383 |
| 383 bool LocalSafeBrowsingDatabaseManager::MatchMalwareIP( | 384 bool LocalSafeBrowsingDatabaseManager::MatchMalwareIP( |
| 384 const std::string& ip_address) { | 385 const std::string& ip_address) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 if (!CanCheckUrl(url)) | 453 if (!CanCheckUrl(url)) |
| 453 return true; | 454 return true; |
| 454 | 455 |
| 455 std::vector<SBThreatType> expected_threats; | 456 std::vector<SBThreatType> expected_threats; |
| 456 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); | 457 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); |
| 457 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); | 458 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); |
| 458 expected_threats.push_back(SB_THREAT_TYPE_URL_UNWANTED); | 459 expected_threats.push_back(SB_THREAT_TYPE_URL_UNWANTED); |
| 459 | 460 |
| 460 const base::TimeTicks start = base::TimeTicks::Now(); | 461 const base::TimeTicks start = base::TimeTicks::Now(); |
| 461 if (!MakeDatabaseAvailable()) { | 462 if (!MakeDatabaseAvailable()) { |
| 462 QueuedCheck queued_check(safe_browsing::MALWARE, // or PHISH | 463 QueuedCheck queued_check(MALWARE, // or PHISH |
| 463 client, | 464 client, |
| 464 url, | 465 url, |
| 465 expected_threats, | 466 expected_threats, |
| 466 start); | 467 start); |
| 467 queued_checks_.push_back(queued_check); | 468 queued_checks_.push_back(queued_check); |
| 468 return false; | 469 return false; |
| 469 } | 470 } |
| 470 | 471 |
| 471 // Cache hits should, in general, be the same for both (ignoring potential | 472 // Cache hits should, in general, be the same for both (ignoring potential |
| 472 // cache evictions in the second call for entries that were just about to be | 473 // cache evictions in the second call for entries that were just about to be |
| (...skipping 30 matching lines...) Expand all Loading... |
| 503 | 504 |
| 504 // Needs to be asynchronous, since we could be in the constructor of a | 505 // Needs to be asynchronous, since we could be in the constructor of a |
| 505 // ResourceDispatcherHost event handler which can't pause there. | 506 // ResourceDispatcherHost event handler which can't pause there. |
| 506 // This check will ping the Safe Browsing servers and get all lists which it | 507 // This check will ping the Safe Browsing servers and get all lists which it |
| 507 // matches. These lists will then be filtered against the |expected_threats| | 508 // matches. These lists will then be filtered against the |expected_threats| |
| 508 // and the result callback for MALWARE (which is the same as for PHISH and | 509 // and the result callback for MALWARE (which is the same as for PHISH and |
| 509 // UNWANTEDURL) will eventually be invoked with the final decision. | 510 // UNWANTEDURL) will eventually be invoked with the final decision. |
| 510 SafeBrowsingCheck* check = new SafeBrowsingCheck(std::vector<GURL>(1, url), | 511 SafeBrowsingCheck* check = new SafeBrowsingCheck(std::vector<GURL>(1, url), |
| 511 std::vector<SBFullHash>(), | 512 std::vector<SBFullHash>(), |
| 512 client, | 513 client, |
| 513 safe_browsing::MALWARE, | 514 MALWARE, |
| 514 expected_threats); | 515 expected_threats); |
| 515 check->need_get_hash = cache_hits.empty(); | 516 check->need_get_hash = cache_hits.empty(); |
| 516 check->prefix_hits.swap(prefix_hits); | 517 check->prefix_hits.swap(prefix_hits); |
| 517 check->cache_hits.swap(cache_hits); | 518 check->cache_hits.swap(cache_hits); |
| 518 checks_.insert(check); | 519 checks_.insert(check); |
| 519 | 520 |
| 520 BrowserThread::PostTask( | 521 BrowserThread::PostTask( |
| 521 BrowserThread::IO, FROM_HERE, | 522 BrowserThread::IO, FROM_HERE, |
| 522 base::Bind(&LocalSafeBrowsingDatabaseManager::OnCheckDone, this, check)); | 523 base::Bind(&LocalSafeBrowsingDatabaseManager::OnCheckDone, this, check)); |
| 523 | 524 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 void LocalSafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished( | 666 void LocalSafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished( |
| 666 bool update_succeeded) { | 667 bool update_succeeded) { |
| 667 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 668 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 668 content::NotificationService::current()->Notify( | 669 content::NotificationService::current()->Notify( |
| 669 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, | 670 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, |
| 670 content::Source<SafeBrowsingDatabaseManager>(this), | 671 content::Source<SafeBrowsingDatabaseManager>(this), |
| 671 content::Details<bool>(&update_succeeded)); | 672 content::Details<bool>(&update_succeeded)); |
| 672 } | 673 } |
| 673 | 674 |
| 674 LocalSafeBrowsingDatabaseManager::QueuedCheck::QueuedCheck( | 675 LocalSafeBrowsingDatabaseManager::QueuedCheck::QueuedCheck( |
| 675 const safe_browsing::ListType check_type, | 676 const ListType check_type, |
| 676 Client* client, | 677 Client* client, |
| 677 const GURL& url, | 678 const GURL& url, |
| 678 const std::vector<SBThreatType>& expected_threats, | 679 const std::vector<SBThreatType>& expected_threats, |
| 679 const base::TimeTicks& start) | 680 const base::TimeTicks& start) |
| 680 : check_type(check_type), | 681 : check_type(check_type), |
| 681 client(client), | 682 client(client), |
| 682 url(url), | 683 url(url), |
| 683 expected_threats(expected_threats), | 684 expected_threats(expected_threats), |
| 684 start(start) { | 685 start(start) { |
| 685 } | 686 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 return is_extended_reporting; | 866 return is_extended_reporting; |
| 866 } | 867 } |
| 867 | 868 |
| 868 void LocalSafeBrowsingDatabaseManager::RequestFullHash( | 869 void LocalSafeBrowsingDatabaseManager::RequestFullHash( |
| 869 SafeBrowsingCheck* check) { | 870 SafeBrowsingCheck* check) { |
| 870 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 871 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 871 | 872 |
| 872 if (!enabled_) | 873 if (!enabled_) |
| 873 return; | 874 return; |
| 874 | 875 |
| 875 bool is_download = check->check_type == safe_browsing::BINURL; | 876 bool is_download = check->check_type == BINURL; |
| 876 sb_service_->protocol_manager()->GetFullHash( | 877 sb_service_->protocol_manager()->GetFullHash( |
| 877 check->prefix_hits, | 878 check->prefix_hits, |
| 878 base::Bind(&LocalSafeBrowsingDatabaseManager::HandleGetHashResults, | 879 base::Bind(&LocalSafeBrowsingDatabaseManager::HandleGetHashResults, |
| 879 base::Unretained(this), check), | 880 base::Unretained(this), check), |
| 880 is_download, check->is_extended_reporting); | 881 is_download, check->is_extended_reporting); |
| 881 } | 882 } |
| 882 | 883 |
| 883 void LocalSafeBrowsingDatabaseManager::GetAllChunksFromDatabase( | 884 void LocalSafeBrowsingDatabaseManager::GetAllChunksFromDatabase( |
| 884 GetChunksCallback callback) { | 885 GetChunksCallback callback) { |
| 885 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 886 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 void LocalSafeBrowsingDatabaseManager::OnResetDatabase() { | 1019 void LocalSafeBrowsingDatabaseManager::OnResetDatabase() { |
| 1019 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 1020 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); |
| 1020 | 1021 |
| 1021 GetDatabase()->ResetDatabase(); | 1022 GetDatabase()->ResetDatabase(); |
| 1022 } | 1023 } |
| 1023 | 1024 |
| 1024 void LocalSafeBrowsingDatabaseManager::OnHandleGetHashResults( | 1025 void LocalSafeBrowsingDatabaseManager::OnHandleGetHashResults( |
| 1025 SafeBrowsingCheck* check, | 1026 SafeBrowsingCheck* check, |
| 1026 const std::vector<SBFullHashResult>& full_hashes) { | 1027 const std::vector<SBFullHashResult>& full_hashes) { |
| 1027 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1028 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1028 safe_browsing::ListType check_type = check->check_type; | 1029 ListType check_type = check->check_type; |
| 1029 SBPrefix prefix = check->prefix_hits[0]; | 1030 SBPrefix prefix = check->prefix_hits[0]; |
| 1030 GetHashRequests::iterator it = gethash_requests_.find(prefix); | 1031 GetHashRequests::iterator it = gethash_requests_.find(prefix); |
| 1031 if (check->prefix_hits.size() > 1 || it == gethash_requests_.end()) { | 1032 if (check->prefix_hits.size() > 1 || it == gethash_requests_.end()) { |
| 1032 const bool hit = HandleOneCheck(check, full_hashes); | 1033 const bool hit = HandleOneCheck(check, full_hashes); |
| 1033 RecordGetHashCheckStatus(hit, check_type, full_hashes); | 1034 RecordGetHashCheckStatus(hit, check_type, full_hashes); |
| 1034 return; | 1035 return; |
| 1035 } | 1036 } |
| 1036 | 1037 |
| 1037 // Call back all interested parties, noting if any has a hit. | 1038 // Call back all interested parties, noting if any has a hit. |
| 1038 GetHashRequestors& requestors = it->second; | 1039 GetHashRequestors& requestors = it->second; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 check->weak_ptr_factory_->GetWeakPtr(), check)); | 1183 check->weak_ptr_factory_->GetWeakPtr(), check)); |
| 1183 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1184 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1184 FROM_HERE, base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, | 1185 FROM_HERE, base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, |
| 1185 check->weak_ptr_factory_->GetWeakPtr(), check), | 1186 check->weak_ptr_factory_->GetWeakPtr(), check), |
| 1186 check_timeout_); | 1187 check_timeout_); |
| 1187 } | 1188 } |
| 1188 | 1189 |
| 1189 bool LocalSafeBrowsingDatabaseManager::download_protection_enabled() const { | 1190 bool LocalSafeBrowsingDatabaseManager::download_protection_enabled() const { |
| 1190 return enable_download_protection_; | 1191 return enable_download_protection_; |
| 1191 } | 1192 } |
| 1193 |
| 1194 } // namespace safe_browsing |
| OLD | NEW |