| 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 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 5 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/metrics/sparse_histogram.h" | 8 #include "base/metrics/sparse_histogram.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 size_t UpdateListIdentifier::hash() const { | 31 size_t UpdateListIdentifier::hash() const { |
| 32 std::size_t first = std::hash<unsigned int>()(platform_type); | 32 std::size_t first = std::hash<unsigned int>()(platform_type); |
| 33 std::size_t second = std::hash<unsigned int>()(threat_entry_type); | 33 std::size_t second = std::hash<unsigned int>()(threat_entry_type); |
| 34 std::size_t third = std::hash<unsigned int>()(threat_type); | 34 std::size_t third = std::hash<unsigned int>()(threat_type); |
| 35 | 35 |
| 36 std::size_t interim = base::HashInts(first, second); | 36 std::size_t interim = base::HashInts(first, second); |
| 37 return base::HashInts(interim, third); | 37 return base::HashInts(interim, third); |
| 38 } | 38 } |
| 39 | 39 |
| 40 V4ProtocolConfig::V4ProtocolConfig() : disable_auto_update(false) {} |
| 41 |
| 42 V4ProtocolConfig::~V4ProtocolConfig() {} |
| 43 |
| 40 // static | 44 // static |
| 41 // Backoff interval is MIN(((2^(n-1))*15 minutes) * (RAND + 1), 24 hours) where | 45 // Backoff interval is MIN(((2^(n-1))*15 minutes) * (RAND + 1), 24 hours) where |
| 42 // n is the number of consecutive errors. | 46 // n is the number of consecutive errors. |
| 43 base::TimeDelta V4ProtocolManagerUtil::GetNextBackOffInterval( | 47 base::TimeDelta V4ProtocolManagerUtil::GetNextBackOffInterval( |
| 44 size_t* error_count, | 48 size_t* error_count, |
| 45 size_t* multiplier) { | 49 size_t* multiplier) { |
| 46 DCHECK(multiplier && error_count); | 50 DCHECK(multiplier && error_count); |
| 47 (*error_count)++; | 51 (*error_count)++; |
| 48 if (*error_count > 1 && *error_count < 9) { | 52 if (*error_count > 1 && *error_count < 9) { |
| 49 // With error count 9 and above we will hit the 24 hour max interval. | 53 // With error count 9 and above we will hit the 24 hour max interval. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 65 void V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode( | 69 void V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode( |
| 66 const char* metric_name, | 70 const char* metric_name, |
| 67 const net::URLRequestStatus& status, | 71 const net::URLRequestStatus& status, |
| 68 int response_code) { | 72 int response_code) { |
| 69 UMA_HISTOGRAM_SPARSE_SLOWLY( | 73 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 70 metric_name, status.is_success() ? response_code : status.error()); | 74 metric_name, status.is_success() ? response_code : status.error()); |
| 71 } | 75 } |
| 72 | 76 |
| 73 // static | 77 // static |
| 74 // The API hash call uses the pver4 Safe Browsing server. | 78 // The API hash call uses the pver4 Safe Browsing server. |
| 75 GURL V4ProtocolManagerUtil::GetRequestUrl( | 79 GURL V4ProtocolManagerUtil::GetRequestUrl(const std::string& request_base64, |
| 76 const std::string& request_base64, const std::string& method_name, | 80 const std::string& method_name, |
| 77 const V4ProtocolConfig& config) { | 81 const V4ProtocolConfig& config) { |
| 78 std::string url = | 82 std::string url = |
| 79 ComposeUrl(kSbV4UrlPrefix, method_name, request_base64, | 83 ComposeUrl(kSbV4UrlPrefix, method_name, request_base64, |
| 80 config.client_name, config.version, config.key_param); | 84 config.client_name, config.version, config.key_param); |
| 81 return GURL(url); | 85 return GURL(url); |
| 82 } | 86 } |
| 83 | 87 |
| 84 // static | 88 // static |
| 85 std::string V4ProtocolManagerUtil::ComposeUrl( | 89 std::string V4ProtocolManagerUtil::ComposeUrl(const std::string& prefix, |
| 86 const std::string& prefix, | 90 const std::string& method, |
| 87 const std::string& method, | 91 const std::string& request_base64, |
| 88 const std::string& request_base64, | 92 const std::string& client_id, |
| 89 const std::string& client_id, | 93 const std::string& version, |
| 90 const std::string& version, | 94 const std::string& key_param) { |
| 91 const std::string& key_param) { | |
| 92 DCHECK(!prefix.empty() && !method.empty() && !client_id.empty() && | 95 DCHECK(!prefix.empty() && !method.empty() && !client_id.empty() && |
| 93 !version.empty()); | 96 !version.empty()); |
| 94 std::string url = | 97 std::string url = |
| 95 base::StringPrintf("%s/%s/%s?alt=proto&client_id=%s&client_version=%s", | 98 base::StringPrintf("%s/%s/%s?alt=proto&client_id=%s&client_version=%s", |
| 96 prefix.c_str(), method.c_str(), request_base64.c_str(), | 99 prefix.c_str(), method.c_str(), request_base64.c_str(), |
| 97 client_id.c_str(), version.c_str()); | 100 client_id.c_str(), version.c_str()); |
| 98 if (!key_param.empty()) { | 101 if (!key_param.empty()) { |
| 99 base::StringAppendF(&url, "&key=%s", | 102 base::StringAppendF(&url, "&key=%s", |
| 100 net::EscapeQueryParamValue(key_param, true).c_str()); | 103 net::EscapeQueryParamValue(key_param, true).c_str()); |
| 101 } | 104 } |
| 102 return url; | 105 return url; |
| 103 } | 106 } |
| 104 | 107 |
| 105 } // namespace safe_browsing | 108 } // namespace safe_browsing |
| OLD | NEW |