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

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

Issue 2349603003: V4LDBM: Get response from GetHashManager, detect severest result (Closed)
Patch Set: Incorporate nparker@'s feedback Created 4 years, 3 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 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" 5 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base64url.h" 9 #include "base/base64url.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/timer/timer.h" 13 #include "base/timer/timer.h"
14 #include "content/public/browser/browser_thread.h"
14 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
15 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
16 #include "net/http/http_status_code.h" 17 #include "net/http/http_status_code.h"
17 #include "net/url_request/url_fetcher.h" 18 #include "net/url_request/url_fetcher.h"
18 #include "net/url_request/url_request_context_getter.h" 19 #include "net/url_request/url_request_context_getter.h"
19 20
20 using base::Time; 21 using base::Time;
21 using base::TimeDelta; 22 using base::TimeDelta;
23 using content::BrowserThread;
22 24
23 namespace { 25 namespace {
24 26
25 // Record a GetHash result. 27 // Record a GetHash result.
26 void RecordGetHashResult(safe_browsing::V4OperationResult result) { 28 void RecordGetHashResult(safe_browsing::V4OperationResult result) {
27 UMA_HISTOGRAM_ENUMERATION( 29 UMA_HISTOGRAM_ENUMERATION(
28 "SafeBrowsing.GetV4HashResult", result, 30 "SafeBrowsing.GetV4HashResult", result,
29 safe_browsing::V4OperationResult::OPERATION_RESULT_MAX); 31 safe_browsing::V4OperationResult::OPERATION_RESULT_MAX);
30 } 32 }
31 33
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 250
249 void V4GetHashProtocolManager::ClearCache() { 251 void V4GetHashProtocolManager::ClearCache() {
250 DCHECK(CalledOnValidThread()); 252 DCHECK(CalledOnValidThread());
251 full_hash_cache_.clear(); 253 full_hash_cache_.clear();
252 } 254 }
253 255
254 void V4GetHashProtocolManager::GetFullHashes( 256 void V4GetHashProtocolManager::GetFullHashes(
255 const FullHashToStoreAndHashPrefixesMap& 257 const FullHashToStoreAndHashPrefixesMap&
256 full_hash_to_store_and_hash_prefixes, 258 full_hash_to_store_and_hash_prefixes,
257 FullHashCallback callback) { 259 FullHashCallback callback) {
260 DCHECK_CURRENTLY_ON(BrowserThread::IO);
258 DCHECK(CalledOnValidThread()); 261 DCHECK(CalledOnValidThread());
259 DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); 262 DCHECK(!full_hash_to_store_and_hash_prefixes.empty());
260 263
261 std::vector<HashPrefix> prefixes_to_request; 264 std::vector<HashPrefix> prefixes_to_request;
262 std::vector<FullHashInfo> cached_full_hash_infos; 265 std::vector<FullHashInfo> cached_full_hash_infos;
263 GetFullHashCachedResults(full_hash_to_store_and_hash_prefixes, Time::Now(), 266 GetFullHashCachedResults(full_hash_to_store_and_hash_prefixes, Time::Now(),
264 &prefixes_to_request, &cached_full_hash_infos); 267 &prefixes_to_request, &cached_full_hash_infos);
265 268
266 if (prefixes_to_request.empty()) { 269 if (prefixes_to_request.empty()) {
267 // 100% cache hits (positive or negative) so we can call the callback right 270 // 100% cache hits (positive or negative) so we can call the callback right
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 302
300 fetcher->SetExtraRequestHeaders(headers.ToString()); 303 fetcher->SetExtraRequestHeaders(headers.ToString());
301 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); 304 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
302 fetcher->SetRequestContext(request_context_getter_.get()); 305 fetcher->SetRequestContext(request_context_getter_.get());
303 fetcher->Start(); 306 fetcher->Start();
304 } 307 }
305 308
306 void V4GetHashProtocolManager::GetFullHashesWithApis( 309 void V4GetHashProtocolManager::GetFullHashesWithApis(
307 const GURL& url, 310 const GURL& url,
308 ThreatMetadataForApiCallback api_callback) { 311 ThreatMetadataForApiCallback api_callback) {
312 DCHECK_CURRENTLY_ON(BrowserThread::IO);
309 DCHECK(url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme)); 313 DCHECK(url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme));
310 314
311 std::unordered_set<FullHash> full_hashes; 315 std::unordered_set<FullHash> full_hashes;
312 V4ProtocolManagerUtil::UrlToFullHashes(url, &full_hashes); 316 V4ProtocolManagerUtil::UrlToFullHashes(url, &full_hashes);
313 317
314 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; 318 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes;
315 for (const FullHash& full_hash : full_hashes) { 319 for (const FullHash& full_hash : full_hashes) {
316 HashPrefix prefix; 320 HashPrefix prefix;
317 bool result = 321 bool result =
318 V4ProtocolManagerUtil::FullHashToSmallestHashPrefix(full_hash, &prefix); 322 V4ProtocolManagerUtil::FullHashToSmallestHashPrefix(full_hash, &prefix);
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 624
621 void V4GetHashProtocolManager::SetClockForTests( 625 void V4GetHashProtocolManager::SetClockForTests(
622 std::unique_ptr<base::Clock> clock) { 626 std::unique_ptr<base::Clock> clock) {
623 clock_ = std::move(clock); 627 clock_ = std::move(clock);
624 } 628 }
625 629
626 void V4GetHashProtocolManager::UpdateCache( 630 void V4GetHashProtocolManager::UpdateCache(
627 const std::vector<HashPrefix>& prefixes_requested, 631 const std::vector<HashPrefix>& prefixes_requested,
628 const std::vector<FullHashInfo>& full_hash_infos, 632 const std::vector<FullHashInfo>& full_hash_infos,
629 const Time& negative_cache_expire) { 633 const Time& negative_cache_expire) {
634 DCHECK_CURRENTLY_ON(BrowserThread::IO);
635
630 // If negative_cache_expire is null, don't cache the results since it's not 636 // If negative_cache_expire is null, don't cache the results since it's not
631 // clear till what time they should be considered valid. 637 // clear till what time they should be considered valid.
632 if (negative_cache_expire.is_null()) { 638 if (negative_cache_expire.is_null()) {
633 return; 639 return;
634 } 640 }
635 641
636 for (const HashPrefix& prefix : prefixes_requested) { 642 for (const HashPrefix& prefix : prefixes_requested) {
637 // Create or reset the cached result for this prefix. 643 // Create or reset the cached result for this prefix.
638 CachedHashPrefixInfo& chpi = full_hash_cache_[prefix]; 644 CachedHashPrefixInfo& chpi = full_hash_cache_[prefix];
639 chpi.full_hash_infos.clear(); 645 chpi.full_hash_infos.clear();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 RecordV4GetHashCheckResult(GET_HASH_CHECK_MISS); 681 RecordV4GetHashCheckResult(GET_HASH_CHECK_MISS);
676 } 682 }
677 } 683 }
678 684
679 // net::URLFetcherDelegate implementation ---------------------------------- 685 // net::URLFetcherDelegate implementation ----------------------------------
680 686
681 // SafeBrowsing request responses are handled here. 687 // SafeBrowsing request responses are handled here.
682 void V4GetHashProtocolManager::OnURLFetchComplete( 688 void V4GetHashProtocolManager::OnURLFetchComplete(
683 const net::URLFetcher* source) { 689 const net::URLFetcher* source) {
684 DCHECK(CalledOnValidThread()); 690 DCHECK(CalledOnValidThread());
691 DCHECK_CURRENTLY_ON(BrowserThread::IO);
685 692
686 PendingHashRequests::iterator it = pending_hash_requests_.find(source); 693 PendingHashRequests::iterator it = pending_hash_requests_.find(source);
687 DCHECK(it != pending_hash_requests_.end()) << "Request not found"; 694 DCHECK(it != pending_hash_requests_.end()) << "Request not found";
688 695
689 int response_code = source->GetResponseCode(); 696 int response_code = source->GetResponseCode();
690 net::URLRequestStatus status = source->GetStatus(); 697 net::URLRequestStatus status = source->GetStatus();
691 V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode( 698 V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode(
692 kUmaV4HashResponseMetricName, status, response_code); 699 kUmaV4HashResponseMetricName, status, response_code);
693 700
694 std::vector<FullHashInfo> full_hash_infos; 701 std::vector<FullHashInfo> full_hash_infos;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 std::ostream& operator<<(std::ostream& os, const FullHashInfo& fhi) { 737 std::ostream& operator<<(std::ostream& os, const FullHashInfo& fhi) {
731 os << "{full_hash: " << fhi.full_hash << "; list_id: " << fhi.list_id 738 os << "{full_hash: " << fhi.full_hash << "; list_id: " << fhi.list_id
732 << "; positive_expiry: " << fhi.positive_expiry 739 << "; positive_expiry: " << fhi.positive_expiry
733 << "; metadata.api_permissions.size(): " 740 << "; metadata.api_permissions.size(): "
734 << fhi.metadata.api_permissions.size() << "}"; 741 << fhi.metadata.api_permissions.size() << "}";
735 return os; 742 return os;
736 } 743 }
737 #endif 744 #endif
738 745
739 } // namespace safe_browsing 746 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698