Chromium Code Reviews| 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"; |
| 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 base::TimeDelta diff = TimeTicks::Now() - before; | |
| 366 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", diff); | |
| 367 UMA_HISTOGRAM_CUSTOM_TIMES("SafeBrowsing.V4GetPrefixMatches.Time", diff, | |
| 368 base::TimeDelta::FromMicroseconds(100), | |
|
Nathan Parker
2016/10/22 00:24:55
Does this generate a log or linear scale of bucket
vakh (use Gerrit instead)
2016/10/22 01:34:34
Done. The comments for UMA_HISTOGRAM_CUSTOM_TIMES
Scott Hess - ex-Googler
2016/10/24 19:24:22
Log scale unless you're doing something special.
| |
| 369 base::TimeDelta::FromSeconds(20), 50); | |
| 370 return !full_hash_to_store_and_hash_prefixes->empty(); | |
| 363 } | 371 } |
| 364 | 372 |
| 365 void V4LocalDatabaseManager::GetSeverestThreatTypeAndMetadata( | 373 void V4LocalDatabaseManager::GetSeverestThreatTypeAndMetadata( |
| 366 SBThreatType* result_threat_type, | 374 SBThreatType* result_threat_type, |
| 367 ThreatMetadata* metadata, | 375 ThreatMetadata* metadata, |
| 368 const std::vector<FullHashInfo>& full_hash_infos) { | 376 const std::vector<FullHashInfo>& full_hash_infos) { |
| 369 DCHECK(result_threat_type); | 377 DCHECK(result_threat_type); |
| 370 DCHECK(metadata); | 378 DCHECK(metadata); |
| 371 | 379 |
| 372 ThreatSeverity most_severe_yet = kLeastSeverity; | 380 ThreatSeverity most_severe_yet = kLeastSeverity; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 402 void V4LocalDatabaseManager::OnFullHashResponse( | 410 void V4LocalDatabaseManager::OnFullHashResponse( |
| 403 std::unique_ptr<PendingCheck> pending_check, | 411 std::unique_ptr<PendingCheck> pending_check, |
| 404 const std::vector<FullHashInfo>& full_hash_infos) { | 412 const std::vector<FullHashInfo>& full_hash_infos) { |
| 405 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 413 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 406 | 414 |
| 407 if (!enabled_) { | 415 if (!enabled_) { |
| 408 DCHECK(pending_clients_.empty()); | 416 DCHECK(pending_clients_.empty()); |
| 409 return; | 417 return; |
| 410 } | 418 } |
| 411 | 419 |
| 420 // TODO(vakh): Consider changing the following histogram name to be | |
| 421 // SafeBrowsing.V4GetFullHashOverNetwork.Time once PVer3 code is removed. | |
| 422 UMA_HISTOGRAM_LONG_TIMES( | |
| 423 "SB2.Network", TimeTicks::Now() - pending_check->full_hash_check_start); | |
| 412 auto it = pending_clients_.find(pending_check->client); | 424 auto it = pending_clients_.find(pending_check->client); |
| 413 if (it == pending_clients_.end()) { | 425 if (it == pending_clients_.end()) { |
| 414 // The check has since been cancelled. | 426 // The check has since been cancelled. |
| 415 return; | 427 return; |
| 416 } | 428 } |
| 417 | 429 |
| 418 // Find out the most severe threat, if any, to report to the client. | 430 // Find out the most severe threat, if any, to report to the client. |
| 419 GetSeverestThreatTypeAndMetadata(&pending_check->result_threat_type, | 431 GetSeverestThreatTypeAndMetadata(&pending_check->result_threat_type, |
| 420 &pending_check->url_metadata, | 432 &pending_check->url_metadata, |
| 421 full_hash_infos); | 433 full_hash_infos); |
| 422 pending_clients_.erase(it); | 434 pending_clients_.erase(it); |
| 423 RespondToClient(std::move(pending_check)); | 435 RespondToClient(std::move(pending_check)); |
| 424 } | 436 } |
| 425 | 437 |
| 426 void V4LocalDatabaseManager::PerformFullHashCheck( | 438 void V4LocalDatabaseManager::PerformFullHashCheck( |
| 427 std::unique_ptr<PendingCheck> check, | 439 std::unique_ptr<PendingCheck> check, |
| 428 const FullHashToStoreAndHashPrefixesMap& | 440 const FullHashToStoreAndHashPrefixesMap& |
| 429 full_hash_to_store_and_hash_prefixes) { | 441 full_hash_to_store_and_hash_prefixes) { |
| 430 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 442 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 431 | 443 |
| 432 DCHECK(enabled_); | 444 DCHECK(enabled_); |
| 433 DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); | 445 DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); |
| 434 | 446 |
| 435 pending_clients_.insert(check->client); | 447 pending_clients_.insert(check->client); |
| 436 | 448 |
| 449 // Set the start time for the network request (or the response from cache). | |
| 450 check->full_hash_check_start = TimeTicks::Now(); | |
|
Nathan Parker
2016/10/22 00:24:55
Ah, so this will won't distinguish network calls v
vakh (use Gerrit instead)
2016/10/22 01:34:34
Done.
| |
| 451 | |
| 437 v4_get_hash_protocol_manager_->GetFullHashes( | 452 v4_get_hash_protocol_manager_->GetFullHashes( |
| 438 full_hash_to_store_and_hash_prefixes, | 453 full_hash_to_store_and_hash_prefixes, |
| 439 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, | 454 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, |
| 440 weak_factory_.GetWeakPtr(), base::Passed(std::move(check)))); | 455 weak_factory_.GetWeakPtr(), base::Passed(std::move(check)))); |
| 441 } | 456 } |
| 442 | 457 |
| 443 void V4LocalDatabaseManager::ProcessQueuedChecks() { | 458 void V4LocalDatabaseManager::ProcessQueuedChecks() { |
| 444 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 459 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 445 for (auto& it : queued_checks_) { | 460 for (auto& it : queued_checks_) { |
| 446 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; | 461 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 } | 523 } |
| 509 | 524 |
| 510 void V4LocalDatabaseManager::UpdateRequestCompleted( | 525 void V4LocalDatabaseManager::UpdateRequestCompleted( |
| 511 std::unique_ptr<ParsedServerResponse> parsed_server_response) { | 526 std::unique_ptr<ParsedServerResponse> parsed_server_response) { |
| 512 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 527 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 513 v4_database_->ApplyUpdate(std::move(parsed_server_response), | 528 v4_database_->ApplyUpdate(std::move(parsed_server_response), |
| 514 db_updated_callback_); | 529 db_updated_callback_); |
| 515 } | 530 } |
| 516 | 531 |
| 517 } // namespace safe_browsing | 532 } // namespace safe_browsing |
| OLD | NEW |