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 "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/metrics/histogram_macros.h" | |
16 #include "components/safe_browsing_db/v4_feature_list.h" | 17 #include "components/safe_browsing_db/v4_feature_list.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 | 19 |
19 using content::BrowserThread; | 20 using content::BrowserThread; |
21 using base::TimeTicks; | |
20 | 22 |
21 namespace safe_browsing { | 23 namespace safe_browsing { |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 const ThreatSeverity kLeastSeverity = | 27 const ThreatSeverity kLeastSeverity = |
26 std::numeric_limits<ThreatSeverity>::max(); | 28 std::numeric_limits<ThreatSeverity>::max(); |
27 | 29 |
28 ListInfos GetListInfos() { | 30 ListInfos GetListInfos() { |
29 // NOTE(vakh): When adding a store here, add the corresponding store-specific | 31 // NOTE(vakh): When adding a store here, add the corresponding store-specific |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 } | 332 } |
331 | 333 |
332 bool V4LocalDatabaseManager::GetPrefixMatches( | 334 bool V4LocalDatabaseManager::GetPrefixMatches( |
333 const std::unique_ptr<PendingCheck>& check, | 335 const std::unique_ptr<PendingCheck>& check, |
334 FullHashToStoreAndHashPrefixesMap* full_hash_to_store_and_hash_prefixes) { | 336 FullHashToStoreAndHashPrefixesMap* full_hash_to_store_and_hash_prefixes) { |
335 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 337 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
336 | 338 |
337 DCHECK(enabled_); | 339 DCHECK(enabled_); |
338 DCHECK(v4_database_); | 340 DCHECK(v4_database_); |
339 DCHECK_GT(ClientCallbackType::CHECK_MAX, check->client_callback_type); | 341 DCHECK_GT(ClientCallbackType::CHECK_MAX, check->client_callback_type); |
342 full_hash_to_store_and_hash_prefixes->clear(); | |
340 | 343 |
344 const base::TimeTicks before = TimeTicks::Now(); | |
341 if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL) { | 345 if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL) { |
342 std::unordered_set<FullHash> full_hashes; | 346 std::unordered_set<FullHash> full_hashes; |
343 V4ProtocolManagerUtil::UrlToFullHashes(check->url, &full_hashes); | 347 V4ProtocolManagerUtil::UrlToFullHashes(check->url, &full_hashes); |
344 | 348 |
345 StoreAndHashPrefixes matched_store_and_hash_prefixes; | 349 StoreAndHashPrefixes matched_store_and_hash_prefixes; |
346 for (const auto& full_hash : full_hashes) { | 350 for (const auto& full_hash : full_hashes) { |
347 matched_store_and_hash_prefixes.clear(); | 351 matched_store_and_hash_prefixes.clear(); |
348 v4_database_->GetStoresMatchingFullHash(full_hash, check->stores_to_check, | 352 v4_database_->GetStoresMatchingFullHash(full_hash, check->stores_to_check, |
349 &matched_store_and_hash_prefixes); | 353 &matched_store_and_hash_prefixes); |
350 if (!matched_store_and_hash_prefixes.empty()) { | 354 if (!matched_store_and_hash_prefixes.empty()) { |
351 (*full_hash_to_store_and_hash_prefixes)[full_hash] = | 355 (*full_hash_to_store_and_hash_prefixes)[full_hash] = |
352 matched_store_and_hash_prefixes; | 356 matched_store_and_hash_prefixes; |
353 } | 357 } |
354 } | 358 } |
355 | 359 } else { |
356 // No hash prefixes found in the local database so that resource must be | 360 NOTREACHED() << "Unexpected client_callback_type encountered"; |
Scott Hess - ex-Googler
2016/10/24 19:24:22
Is this case guaranteed to be nominal to nonexiste
| |
357 // safe. | |
358 return !full_hash_to_store_and_hash_prefixes->empty(); | |
359 } | 361 } |
360 | 362 |
361 NOTREACHED() << "Unexpected client_callback_type encountered"; | 363 // TODO(vakh): Only log SafeBrowsing.V4GetPrefixMatches.Time once PVer3 code |
362 return false; | 364 // is removed. |
365 // NOTE(vakh): This doesn't distinguish which stores it's searching through. | |
366 // However, the vast majority of the entries in this histogram will be from | |
367 // searching the three CHECK_BROWSE_URL stores. | |
368 base::TimeDelta diff = TimeTicks::Now() - before; | |
369 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", diff); | |
370 UMA_HISTOGRAM_CUSTOM_TIMES("SafeBrowsing.V4GetPrefixMatches.Time", diff, | |
371 base::TimeDelta::FromMicroseconds(20), | |
372 base::TimeDelta::FromSeconds(1), 50); | |
373 return !full_hash_to_store_and_hash_prefixes->empty(); | |
363 } | 374 } |
364 | 375 |
365 void V4LocalDatabaseManager::GetSeverestThreatTypeAndMetadata( | 376 void V4LocalDatabaseManager::GetSeverestThreatTypeAndMetadata( |
366 SBThreatType* result_threat_type, | 377 SBThreatType* result_threat_type, |
367 ThreatMetadata* metadata, | 378 ThreatMetadata* metadata, |
368 const std::vector<FullHashInfo>& full_hash_infos) { | 379 const std::vector<FullHashInfo>& full_hash_infos) { |
369 DCHECK(result_threat_type); | 380 DCHECK(result_threat_type); |
370 DCHECK(metadata); | 381 DCHECK(metadata); |
371 | 382 |
372 ThreatSeverity most_severe_yet = kLeastSeverity; | 383 ThreatSeverity most_severe_yet = kLeastSeverity; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 } | 519 } |
509 | 520 |
510 void V4LocalDatabaseManager::UpdateRequestCompleted( | 521 void V4LocalDatabaseManager::UpdateRequestCompleted( |
511 std::unique_ptr<ParsedServerResponse> parsed_server_response) { | 522 std::unique_ptr<ParsedServerResponse> parsed_server_response) { |
512 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 523 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
513 v4_database_->ApplyUpdate(std::move(parsed_server_response), | 524 v4_database_->ApplyUpdate(std::move(parsed_server_response), |
514 db_updated_callback_); | 525 db_updated_callback_); |
515 } | 526 } |
516 | 527 |
517 } // namespace safe_browsing | 528 } // namespace safe_browsing |
OLD | NEW |