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