Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: components/safe_browsing_db/v4_local_database_manager.cc

Issue 2441923003: PVer4: Add UMA metrics for time taken to: load DB, do prefix check, (Closed)
Patch Set: git rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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): Consider changing the following histogram name to be
362 return false; 364 // SafeBrowsing.V4GetPrefixMatches.Time once PVer3 code is removed.
365 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", TimeTicks::Now() - before);
Nathan Parker 2016/10/21 20:21:19 This is almost always < 1 ms. I think we should l
vakh (use Gerrit instead) 2016/10/21 22:54:04 Done.
366 return !full_hash_to_store_and_hash_prefixes->empty();
363 } 367 }
364 368
365 void V4LocalDatabaseManager::GetSeverestThreatTypeAndMetadata( 369 void V4LocalDatabaseManager::GetSeverestThreatTypeAndMetadata(
366 SBThreatType* result_threat_type, 370 SBThreatType* result_threat_type,
367 ThreatMetadata* metadata, 371 ThreatMetadata* metadata,
368 const std::vector<FullHashInfo>& full_hash_infos) { 372 const std::vector<FullHashInfo>& full_hash_infos) {
369 DCHECK(result_threat_type); 373 DCHECK(result_threat_type);
370 DCHECK(metadata); 374 DCHECK(metadata);
371 375
372 ThreatSeverity most_severe_yet = kLeastSeverity; 376 ThreatSeverity most_severe_yet = kLeastSeverity;
(...skipping 29 matching lines...) Expand all
402 void V4LocalDatabaseManager::OnFullHashResponse( 406 void V4LocalDatabaseManager::OnFullHashResponse(
403 std::unique_ptr<PendingCheck> pending_check, 407 std::unique_ptr<PendingCheck> pending_check,
404 const std::vector<FullHashInfo>& full_hash_infos) { 408 const std::vector<FullHashInfo>& full_hash_infos) {
405 DCHECK_CURRENTLY_ON(BrowserThread::IO); 409 DCHECK_CURRENTLY_ON(BrowserThread::IO);
406 410
407 if (!enabled_) { 411 if (!enabled_) {
408 DCHECK(pending_clients_.empty()); 412 DCHECK(pending_clients_.empty());
409 return; 413 return;
410 } 414 }
411 415
416 // TODO(vakh): Consider changing the following histogram name to be
417 // SafeBrowsing.V4GetFullHashOverNetwork.Time once PVer3 code is removed.
Nathan Parker 2016/10/21 20:21:19 an aside: There is a SafeBrowsing.GetV4HashResult.
vakh (use Gerrit instead) 2016/10/21 22:54:04 Yes, I need to correct the metrics in that file. O
418 UMA_HISTOGRAM_LONG_TIMES("SB2.Network",
419 TimeTicks::Now() - pending_check->start);
412 auto it = pending_clients_.find(pending_check->client); 420 auto it = pending_clients_.find(pending_check->client);
413 if (it == pending_clients_.end()) { 421 if (it == pending_clients_.end()) {
414 // The check has since been cancelled. 422 // The check has since been cancelled.
415 return; 423 return;
416 } 424 }
417 425
418 // Find out the most severe threat, if any, to report to the client. 426 // Find out the most severe threat, if any, to report to the client.
419 GetSeverestThreatTypeAndMetadata(&pending_check->result_threat_type, 427 GetSeverestThreatTypeAndMetadata(&pending_check->result_threat_type,
420 &pending_check->url_metadata, 428 &pending_check->url_metadata,
421 full_hash_infos); 429 full_hash_infos);
422 pending_clients_.erase(it); 430 pending_clients_.erase(it);
423 RespondToClient(std::move(pending_check)); 431 RespondToClient(std::move(pending_check));
424 } 432 }
425 433
426 void V4LocalDatabaseManager::PerformFullHashCheck( 434 void V4LocalDatabaseManager::PerformFullHashCheck(
427 std::unique_ptr<PendingCheck> check, 435 std::unique_ptr<PendingCheck> check,
428 const FullHashToStoreAndHashPrefixesMap& 436 const FullHashToStoreAndHashPrefixesMap&
429 full_hash_to_store_and_hash_prefixes) { 437 full_hash_to_store_and_hash_prefixes) {
430 DCHECK_CURRENTLY_ON(BrowserThread::IO); 438 DCHECK_CURRENTLY_ON(BrowserThread::IO);
431 439
432 DCHECK(enabled_); 440 DCHECK(enabled_);
433 DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); 441 DCHECK(!full_hash_to_store_and_hash_prefixes.empty());
434 442
435 pending_clients_.insert(check->client); 443 pending_clients_.insert(check->client);
436 444
445 // Set the start time for the network request.
446 check->start = TimeTicks::Now();
447
437 v4_get_hash_protocol_manager_->GetFullHashes( 448 v4_get_hash_protocol_manager_->GetFullHashes(
438 full_hash_to_store_and_hash_prefixes, 449 full_hash_to_store_and_hash_prefixes,
439 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse, 450 base::Bind(&V4LocalDatabaseManager::OnFullHashResponse,
440 weak_factory_.GetWeakPtr(), base::Passed(std::move(check)))); 451 weak_factory_.GetWeakPtr(), base::Passed(std::move(check))));
441 } 452 }
442 453
443 void V4LocalDatabaseManager::ProcessQueuedChecks() { 454 void V4LocalDatabaseManager::ProcessQueuedChecks() {
444 DCHECK_CURRENTLY_ON(BrowserThread::IO); 455 DCHECK_CURRENTLY_ON(BrowserThread::IO);
445 for (auto& it : queued_checks_) { 456 for (auto& it : queued_checks_) {
446 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; 457 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698