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