OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // This file should not be build on Android but is currently getting built. | 5 // This file should not be build on Android but is currently getting built. |
6 // TODO(vakh): Fix that: http://crbug.com/621647 | 6 // TODO(vakh): Fix that: http://crbug.com/621647 |
7 | 7 |
8 #include "components/safe_browsing_db/v4_local_database_manager.h" | 8 #include "components/safe_browsing_db/v4_local_database_manager.h" |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 | 16 |
17 using content::BrowserThread; | 17 using content::BrowserThread; |
18 | 18 |
19 namespace safe_browsing { | 19 namespace safe_browsing { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const ThreatSeverity kLeastSeverity = | 23 const ThreatSeverity kLeastSeverity = |
24 std::numeric_limits<ThreatSeverity>::max(); | 24 std::numeric_limits<ThreatSeverity>::max(); |
25 | 25 |
26 // TODO(vakh): Implement this to populate the vector appopriately. | 26 // TODO(vakh): Implement this to populate the vector appopriately. |
27 // Filed as http://crbug.com/608075 | 27 // Filed as http://crbug.com/608075 |
28 // Any stores added/removed to/from here likely need an update in | 28 // Any stores added/removed to/from here likely need an update in |
29 // GetSBThreatTypeForList and GetThreatSeverity. | 29 // GetThreatSeverity. |
30 // TODO(vakh): Add a compile-time check or DCHECK to enforce this. | 30 // TODO(vakh): Add a compile-time check or DCHECK to enforce this. |
31 StoreIdAndFileNames GetStoreIdAndFileNames() { | 31 StoreIdAndFileNames GetStoreIdAndFileNames() { |
32 return StoreIdAndFileNames( | 32 return StoreIdAndFileNames( |
33 {StoreIdAndFileName(GetUrlMalwareId(), "UrlMalware.store"), | 33 {StoreIdAndFileName(GetUrlMalwareId(), "UrlMalware.store"), |
34 StoreIdAndFileName(GetUrlSocEngId(), "UrlSoceng.store")}); | 34 StoreIdAndFileName(GetUrlSocEngId(), "UrlSoceng.store")}); |
35 } | 35 } |
36 | 36 |
37 // Returns the SBThreatType corresponding to a given SafeBrowsing list. | 37 // Returns the SBThreatType corresponding to a given SafeBrowsing list. |
38 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id) { | 38 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id) { |
39 if (list_id == GetChromeUrlApiId()) { | 39 SBThreatType sb_threat_type = list_id.sb_threat_type(); |
40 return SB_THREAT_TYPE_API_ABUSE; | 40 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type); |
41 } else if (list_id == GetUrlMalwareId()) { | 41 return sb_threat_type; |
42 return SB_THREAT_TYPE_URL_MALWARE; | |
43 } else if (list_id == GetUrlSocEngId()) { | |
44 return SB_THREAT_TYPE_URL_PHISHING; | |
45 } else { | |
46 NOTREACHED() << "Unknown list encountered in GetSBThreatTypeForList"; | |
47 return SB_THREAT_TYPE_SAFE; | |
48 } | |
49 } | 42 } |
50 | 43 |
51 // Returns the severity information about a given SafeBrowsing list. The lowest | 44 // Returns the severity information about a given SafeBrowsing list. The lowest |
52 // value is 0, which represents the most severe list. | 45 // value is 0, which represents the most severe list. |
53 ThreatSeverity GetThreatSeverity(const ListIdentifier& list_id) { | 46 ThreatSeverity GetThreatSeverity(const ListIdentifier& list_id) { |
54 switch (list_id.threat_type) { | 47 switch (list_id.threat_type()) { |
55 case MALWARE_THREAT: | 48 case MALWARE_THREAT: |
56 case SOCIAL_ENGINEERING_PUBLIC: | 49 case SOCIAL_ENGINEERING_PUBLIC: |
57 return 0; | 50 return 0; |
58 case API_ABUSE: | 51 case API_ABUSE: |
59 return 1; | 52 return 1; |
60 default: | 53 default: |
61 NOTREACHED() << "Unexpected ThreatType encountered in GetThreatSeverity"; | 54 NOTREACHED() << "Unexpected ThreatType encountered in GetThreatSeverity"; |
62 return kLeastSeverity; | 55 return kLeastSeverity; |
63 } | 56 } |
64 } | 57 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 206 } |
214 } | 207 } |
215 | 208 |
216 if (full_hash_to_store_and_hash_prefixes.empty()) { | 209 if (full_hash_to_store_and_hash_prefixes.empty()) { |
217 return true; | 210 return true; |
218 } else { | 211 } else { |
219 std::unique_ptr<PendingCheck> pending_check = | 212 std::unique_ptr<PendingCheck> pending_check = |
220 base::MakeUnique<PendingCheck>( | 213 base::MakeUnique<PendingCheck>( |
221 client, ClientCallbackType::CHECK_BROWSE_URL, url); | 214 client, ClientCallbackType::CHECK_BROWSE_URL, url); |
222 | 215 |
| 216 pending_clients_.insert(client); |
| 217 |
223 v4_get_hash_protocol_manager_->GetFullHashes( | 218 v4_get_hash_protocol_manager_->GetFullHashes( |
224 full_hash_to_store_and_hash_prefixes, | 219 full_hash_to_store_and_hash_prefixes, |
225 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, | 220 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, |
226 base::Unretained(this), base::Passed(&pending_check))); | 221 base::Unretained(this), base::Passed(&pending_check))); |
227 | 222 |
228 pending_clients_.insert(client); | |
229 | |
230 return false; | 223 return false; |
231 } | 224 } |
232 } else { | 225 } else { |
233 // TODO(vakh): Queue the check and process it when the database becomes | 226 // TODO(vakh): Queue the check and process it when the database becomes |
234 // ready. | 227 // ready. |
235 return false; | 228 return false; |
236 } | 229 } |
237 } | 230 } |
238 | 231 |
239 // static | 232 // static |
(...skipping 24 matching lines...) Expand all Loading... |
264 DCHECK(pending_clients_.empty()); | 257 DCHECK(pending_clients_.empty()); |
265 return; | 258 return; |
266 } | 259 } |
267 | 260 |
268 auto it = pending_clients_.find(pending_check->client); | 261 auto it = pending_clients_.find(pending_check->client); |
269 if (it == pending_clients_.end()) { | 262 if (it == pending_clients_.end()) { |
270 // The check has since been cancelled. | 263 // The check has since been cancelled. |
271 return; | 264 return; |
272 } | 265 } |
273 | 266 |
274 if (full_hash_infos.empty()) { | 267 // Find out the most severe threat, if any, to report to the client. |
275 // The resource is not known to be unsafe. Respond right away. | |
276 RespondToClient(std::move(pending_check)); | |
277 return; | |
278 } | |
279 | |
280 GetSeverestThreatTypeAndMetadata(&pending_check->result_threat_type, | 268 GetSeverestThreatTypeAndMetadata(&pending_check->result_threat_type, |
281 &pending_check->url_metadata, | 269 &pending_check->url_metadata, |
282 full_hash_infos); | 270 full_hash_infos); |
283 | |
284 RespondToClient(std::move(pending_check)); | 271 RespondToClient(std::move(pending_check)); |
285 pending_clients_.erase(it); | 272 pending_clients_.erase(it); |
286 } | 273 } |
287 | 274 |
288 void V4LocalDatabaseManager::RespondToClient( | 275 void V4LocalDatabaseManager::RespondToClient( |
289 std::unique_ptr<PendingCheck> pending_check) { | 276 std::unique_ptr<PendingCheck> pending_check) { |
290 DCHECK(pending_check.get()); | 277 DCHECK(pending_check.get()); |
291 DCHECK_EQ(ClientCallbackType::CHECK_BROWSE_URL, | 278 DCHECK_EQ(ClientCallbackType::CHECK_BROWSE_URL, |
292 pending_check->client_callback_type); | 279 pending_check->client_callback_type); |
293 // TODO(vakh): Implement this skeleton. | 280 // TODO(vakh): Implement this skeleton. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 std::unordered_set<ListIdentifier> | 394 std::unordered_set<ListIdentifier> |
408 V4LocalDatabaseManager::GetStoresForFullHashRequests() { | 395 V4LocalDatabaseManager::GetStoresForFullHashRequests() { |
409 std::unordered_set<ListIdentifier> stores_for_full_hash; | 396 std::unordered_set<ListIdentifier> stores_for_full_hash; |
410 for (auto it : store_id_file_names_) { | 397 for (auto it : store_id_file_names_) { |
411 stores_for_full_hash.insert(it.list_id); | 398 stores_for_full_hash.insert(it.list_id); |
412 } | 399 } |
413 return stores_for_full_hash; | 400 return stores_for_full_hash; |
414 } | 401 } |
415 | 402 |
416 } // namespace safe_browsing | 403 } // namespace safe_browsing |
OLD | NEW |