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

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

Issue 2467673002: Update histogram names to follow the usual PVer4 format: SafeBrowsing.V4* (Closed)
Patch Set: nparker@ review Created 4 years, 1 month 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
« no previous file with comments | « no previous file | components/safe_browsing_db/v4_update_protocol_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/public/browser/browser_thread.h"
15 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
16 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
17 #include "net/http/http_status_code.h" 17 #include "net/http/http_status_code.h"
18 #include "net/url_request/url_fetcher.h" 18 #include "net/url_request/url_fetcher.h"
19 #include "net/url_request/url_request_context_getter.h" 19 #include "net/url_request/url_request_context_getter.h"
20 20
21 using base::Time; 21 using base::Time;
22 using base::TimeDelta; 22 using base::TimeDelta;
23 using content::BrowserThread; 23 using content::BrowserThread;
24 24
25 namespace { 25 namespace {
26 26
27 // Record a GetHash result. 27 // Record a GetHash result.
28 void RecordGetHashResult(safe_browsing::V4OperationResult result) { 28 void RecordGetHashResult(safe_browsing::V4OperationResult result) {
29 UMA_HISTOGRAM_ENUMERATION( 29 UMA_HISTOGRAM_ENUMERATION(
30 "SafeBrowsing.GetV4HashResult", result, 30 "SafeBrowsing.V4GetHash.Result", result,
31 safe_browsing::V4OperationResult::OPERATION_RESULT_MAX); 31 safe_browsing::V4OperationResult::OPERATION_RESULT_MAX);
32 } 32 }
33 33
34 // Enumerate parsing failures for histogramming purposes. DO NOT CHANGE 34 // Enumerate parsing failures for histogramming purposes. DO NOT CHANGE
35 // THE ORDERING OF THESE VALUES. 35 // THE ORDERING OF THESE VALUES.
36 enum ParseResultType { 36 enum ParseResultType {
37 // Error parsing the protocol buffer from a string. 37 // Error parsing the protocol buffer from a string.
38 PARSE_FROM_STRING_ERROR = 0, 38 PARSE_FROM_STRING_ERROR = 0,
39 39
40 // A match in the response had an unexpected THREAT_ENTRY_TYPE. 40 // A match in the response had an unexpected THREAT_ENTRY_TYPE.
(...skipping 19 matching lines...) Expand all
60 // A match in the response had no information in the threat field. 60 // A match in the response had no information in the threat field.
61 NO_THREAT_ERROR = 7, 61 NO_THREAT_ERROR = 7,
62 62
63 // Memory space for histograms is determined by the max. ALWAYS 63 // Memory space for histograms is determined by the max. ALWAYS
64 // ADD NEW VALUES BEFORE THIS ONE. 64 // ADD NEW VALUES BEFORE THIS ONE.
65 PARSE_RESULT_TYPE_MAX = 8, 65 PARSE_RESULT_TYPE_MAX = 8,
66 }; 66 };
67 67
68 // Record parsing errors of a GetHash result. 68 // Record parsing errors of a GetHash result.
69 void RecordParseGetHashResult(ParseResultType result_type) { 69 void RecordParseGetHashResult(ParseResultType result_type) {
70 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.ParseV4HashResult", result_type, 70 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4GetHash.Parse.Result", result_type,
71 PARSE_RESULT_TYPE_MAX); 71 PARSE_RESULT_TYPE_MAX);
72 } 72 }
73 73
74 // Enumerate full hash cache hits/misses for histogramming purposes. 74 // Enumerate full hash cache hits/misses for histogramming purposes.
75 // DO NOT CHANGE THE ORDERING OF THESE VALUES. 75 // DO NOT CHANGE THE ORDERING OF THESE VALUES.
76 enum V4FullHashCacheResultType { 76 enum V4FullHashCacheResultType {
77 // Full hashes for which there is no cache hit. 77 // Full hashes for which there is no cache hit.
78 FULL_HASH_CACHE_MISS = 0, 78 FULL_HASH_CACHE_MISS = 0,
79 79
80 // Full hashes with a cache hit. 80 // Full hashes with a cache hit.
81 FULL_HASH_CACHE_HIT = 1, 81 FULL_HASH_CACHE_HIT = 1,
82 82
83 // Full hashes with a negative cache hit. 83 // Full hashes with a negative cache hit.
84 FULL_HASH_NEGATIVE_CACHE_HIT = 2, 84 FULL_HASH_NEGATIVE_CACHE_HIT = 2,
85 85
86 // Memory space for histograms is determined by the max. ALWAYS 86 // Memory space for histograms is determined by the max. ALWAYS
87 // ADD NEW VALUES BEFORE THIS ONE. 87 // ADD NEW VALUES BEFORE THIS ONE.
88 FULL_HASH_CACHE_RESULT_MAX 88 FULL_HASH_CACHE_RESULT_MAX
89 }; 89 };
90 90
91 // Record a full hash cache hit result. 91 // Record a full hash cache hit result.
92 void RecordV4FullHashCacheResult(V4FullHashCacheResultType result_type) { 92 void RecordV4FullHashCacheResult(V4FullHashCacheResultType result_type) {
93 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4FullHashCacheResult", result_type, 93 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4GetHash.CacheHit.Result",
94 FULL_HASH_CACHE_RESULT_MAX); 94 result_type, FULL_HASH_CACHE_RESULT_MAX);
95 } 95 }
96 96
97 // Enumerate GetHash hits/misses for histogramming purposes. DO NOT CHANGE THE 97 // Enumerate GetHash hits/misses for histogramming purposes. DO NOT CHANGE THE
98 // ORDERING OF THESE VALUES. 98 // ORDERING OF THESE VALUES.
99 enum V4GetHashCheckResultType { 99 enum V4GetHashCheckResultType {
100 // Successful responses which returned no full hashes. 100 // Successful responses which returned no full hashes.
101 GET_HASH_CHECK_EMPTY = 0, 101 GET_HASH_CHECK_EMPTY = 0,
102 102
103 // Successful responses for which one or more of the full hashes matched. 103 // Successful responses for which one or more of the full hashes matched.
104 GET_HASH_CHECK_HIT = 1, 104 GET_HASH_CHECK_HIT = 1,
105 105
106 // Successful responses which weren't empty but have no matches. 106 // Successful responses which weren't empty but have no matches.
107 GET_HASH_CHECK_MISS = 2, 107 GET_HASH_CHECK_MISS = 2,
108 108
109 // Memory space for histograms is determined by the max. ALWAYS 109 // Memory space for histograms is determined by the max. ALWAYS
110 // ADD NEW VALUES BEFORE THIS ONE. 110 // ADD NEW VALUES BEFORE THIS ONE.
111 GET_HASH_CHECK_RESULT_MAX 111 GET_HASH_CHECK_RESULT_MAX
112 }; 112 };
113 113
114 // Record a GetHash hit result. 114 // Record a GetHash hit result.
115 void RecordV4GetHashCheckResult(V4GetHashCheckResultType result_type) { 115 void RecordV4GetHashCheckResult(V4GetHashCheckResultType result_type) {
116 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4GetHashCheckResult", result_type, 116 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4GetHash.Check.Result", result_type,
117 GET_HASH_CHECK_RESULT_MAX); 117 GET_HASH_CHECK_RESULT_MAX);
118 } 118 }
119 119
120 const char kPermission[] = "permission"; 120 const char kPermission[] = "permission";
121 const char kPhaPatternType[] = "pha_pattern_type"; 121 const char kPhaPatternType[] = "pha_pattern_type";
122 const char kMalwarePatternType[] = "malware_pattern_type"; 122 const char kMalwarePatternType[] = "malware_pattern_type";
123 const char kSePatternType[] = "se_pattern_type"; 123 const char kSePatternType[] = "se_pattern_type";
124 const char kLanding[] = "LANDING"; 124 const char kLanding[] = "LANDING";
125 const char kDistribution[] = "DISTRIBUTION"; 125 const char kDistribution[] = "DISTRIBUTION";
126 const char kSocialEngineeringAds[] = "SOCIAL_ENGINEERING_ADS"; 126 const char kSocialEngineeringAds[] = "SOCIAL_ENGINEERING_ADS";
127 const char kSocialEngineeringLanding[] = "SOCIAL_ENGINEERING_LANDING"; 127 const char kSocialEngineeringLanding[] = "SOCIAL_ENGINEERING_LANDING";
128 const char kPhishing[] = "PHISHING"; 128 const char kPhishing[] = "PHISHING";
129 129
130 } // namespace 130 } // namespace
131 131
132 namespace safe_browsing { 132 namespace safe_browsing {
133 133
134 const char kUmaV4HashResponseMetricName[] =
135 "SafeBrowsing.GetV4HashHttpResponseOrErrorCode";
136
137 // The default V4GetHashProtocolManagerFactory. 134 // The default V4GetHashProtocolManagerFactory.
138 class V4GetHashProtocolManagerFactoryImpl 135 class V4GetHashProtocolManagerFactoryImpl
139 : public V4GetHashProtocolManagerFactory { 136 : public V4GetHashProtocolManagerFactory {
140 public: 137 public:
141 V4GetHashProtocolManagerFactoryImpl() {} 138 V4GetHashProtocolManagerFactoryImpl() {}
142 ~V4GetHashProtocolManagerFactoryImpl() override {} 139 ~V4GetHashProtocolManagerFactoryImpl() override {}
143 std::unique_ptr<V4GetHashProtocolManager> CreateProtocolManager( 140 std::unique_ptr<V4GetHashProtocolManager> CreateProtocolManager(
144 net::URLRequestContextGetter* request_context_getter, 141 net::URLRequestContextGetter* request_context_getter,
145 const StoresToCheck& stores_to_check, 142 const StoresToCheck& stores_to_check,
146 const V4ProtocolConfig& config) override { 143 const V4ProtocolConfig& config) override {
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 const net::URLFetcher* source) { 686 const net::URLFetcher* source) {
690 DCHECK(CalledOnValidThread()); 687 DCHECK(CalledOnValidThread());
691 DCHECK_CURRENTLY_ON(BrowserThread::IO); 688 DCHECK_CURRENTLY_ON(BrowserThread::IO);
692 689
693 PendingHashRequests::iterator it = pending_hash_requests_.find(source); 690 PendingHashRequests::iterator it = pending_hash_requests_.find(source);
694 DCHECK(it != pending_hash_requests_.end()) << "Request not found"; 691 DCHECK(it != pending_hash_requests_.end()) << "Request not found";
695 692
696 int response_code = source->GetResponseCode(); 693 int response_code = source->GetResponseCode();
697 net::URLRequestStatus status = source->GetStatus(); 694 net::URLRequestStatus status = source->GetStatus();
698 V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode( 695 V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode(
699 kUmaV4HashResponseMetricName, status, response_code); 696 "SafeBrowsing.V4GetHash.Network.Result", status, response_code);
700 697
701 std::vector<FullHashInfo> full_hash_infos; 698 std::vector<FullHashInfo> full_hash_infos;
702 Time negative_cache_expire; 699 Time negative_cache_expire;
703 if (status.is_success() && response_code == net::HTTP_OK) { 700 if (status.is_success() && response_code == net::HTTP_OK) {
704 RecordGetHashResult(V4OperationResult::STATUS_200); 701 RecordGetHashResult(V4OperationResult::STATUS_200);
705 ResetGetHashErrors(); 702 ResetGetHashErrors();
706 std::string data; 703 std::string data;
707 source->GetResponseAsString(&data); 704 source->GetResponseAsString(&data);
708 if (!ParseHashResponse(data, &full_hash_infos, &negative_cache_expire)) { 705 if (!ParseHashResponse(data, &full_hash_infos, &negative_cache_expire)) {
709 full_hash_infos.clear(); 706 full_hash_infos.clear();
710 RecordGetHashResult(V4OperationResult::PARSE_ERROR); 707 RecordGetHashResult(V4OperationResult::PARSE_ERROR);
711 } 708 }
712 } else { 709 } else {
713 HandleGetHashError(clock_->Now()); 710 HandleGetHashError(clock_->Now());
714 711
715 DVLOG(1) << "SafeBrowsing GetEncodedFullHashes request for: " 712 DVLOG(1) << "SafeBrowsing GetEncodedFullHashes request for: "
716 << source->GetURL() << " failed with error: " << status.error() 713 << source->GetURL() << " failed with error: " << status.error()
717 << " and response code: " << response_code; 714 << " and response code: " << response_code;
718 715
719 if (status.status() == net::URLRequestStatus::FAILED) { 716 if (status.status() == net::URLRequestStatus::FAILED) {
720 RecordGetHashResult(V4OperationResult::NETWORK_ERROR); 717 RecordGetHashResult(V4OperationResult::NETWORK_ERROR);
721 } else { 718 } else {
722 RecordGetHashResult(V4OperationResult::HTTP_ERROR); 719 RecordGetHashResult(V4OperationResult::HTTP_ERROR);
723 } 720 }
724 } 721 }
725 722
726 const std::unique_ptr<FullHashCallbackInfo>& fhci = it->second; 723 const std::unique_ptr<FullHashCallbackInfo>& fhci = it->second;
727 UMA_HISTOGRAM_LONG_TIMES("SafeBrowsing.V4GetHashNetwork.Time", 724 UMA_HISTOGRAM_LONG_TIMES("SafeBrowsing.V4GetHash.Network.Time",
728 clock_->Now() - fhci->network_start_time); 725 clock_->Now() - fhci->network_start_time);
729 UpdateCache(fhci->prefixes_requested, full_hash_infos, negative_cache_expire); 726 UpdateCache(fhci->prefixes_requested, full_hash_infos, negative_cache_expire);
730 MergeResults(fhci->full_hash_to_store_and_hash_prefixes, full_hash_infos, 727 MergeResults(fhci->full_hash_to_store_and_hash_prefixes, full_hash_infos,
731 &fhci->cached_full_hash_infos); 728 &fhci->cached_full_hash_infos);
732 729
733 fhci->callback.Run(fhci->cached_full_hash_infos); 730 fhci->callback.Run(fhci->cached_full_hash_infos);
734 731
735 pending_hash_requests_.erase(it); 732 pending_hash_requests_.erase(it);
736 } 733 }
737 734
738 #ifndef DEBUG 735 #ifndef DEBUG
739 std::ostream& operator<<(std::ostream& os, const FullHashInfo& fhi) { 736 std::ostream& operator<<(std::ostream& os, const FullHashInfo& fhi) {
740 os << "{full_hash: " << fhi.full_hash << "; list_id: " << fhi.list_id 737 os << "{full_hash: " << fhi.full_hash << "; list_id: " << fhi.list_id
741 << "; positive_expiry: " << fhi.positive_expiry 738 << "; positive_expiry: " << fhi.positive_expiry
742 << "; metadata.api_permissions.size(): " 739 << "; metadata.api_permissions.size(): "
743 << fhi.metadata.api_permissions.size() << "}"; 740 << fhi.metadata.api_permissions.size() << "}";
744 return os; 741 return os;
745 } 742 }
746 #endif 743 #endif
747 744
748 } // namespace safe_browsing 745 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | components/safe_browsing_db/v4_update_protocol_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698