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

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

Issue 1727033003: v4_update_protocol_manager: Basic implementation with TODOs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporate review feedback. Created 4 years, 9 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_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"
11 #include "net/base/escape.h" 11 #include "net/base/escape.h"
12 12
13 using base::Time; 13 using base::Time;
14 using base::TimeDelta; 14 using base::TimeDelta;
15 15
16 namespace safe_browsing { 16 namespace safe_browsing {
17 17
18 // The Safe Browsing V4 server URL prefix. 18 // The Safe Browsing V4 server URL prefix.
19 const char kSbV4UrlPrefix[] = "https://safebrowsing.googleapis.com/v4"; 19 const char kSbV4UrlPrefix[] = "https://safebrowsing.googleapis.com/v4";
20 20
21 bool UpdateListIdentifier::operator==(const UpdateListIdentifier& other) const {
22 return platform_type == other.platform_type &&
23 threat_entry_type == other.threat_entry_type &&
24 threat_type == other.threat_type;
25 }
26
27 bool UpdateListIdentifier::operator!=(const UpdateListIdentifier& other) const {
28 return !operator==(other);
29 }
30
31 size_t UpdateListIdentifier::hash() const {
32 std::size_t first = std::hash<unsigned int>()(platform_type);
33 std::size_t second = std::hash<unsigned int>()(threat_entry_type);
34 std::size_t third = std::hash<unsigned int>()(threat_type);
35
36 std::size_t interim = base::HashInts(first, second);
37 return base::HashInts(interim, third);
38 }
39
21 // static 40 // static
22 // Backoff interval is MIN(((2^(n-1))*15 minutes) * (RAND + 1), 24 hours) where 41 // Backoff interval is MIN(((2^(n-1))*15 minutes) * (RAND + 1), 24 hours) where
23 // n is the number of consecutive errors. 42 // n is the number of consecutive errors.
24 base::TimeDelta V4ProtocolManagerUtil::GetNextBackOffInterval( 43 base::TimeDelta V4ProtocolManagerUtil::GetNextBackOffInterval(
25 size_t* error_count, 44 size_t* error_count,
26 size_t* multiplier) { 45 size_t* multiplier) {
27 DCHECK(multiplier && error_count); 46 DCHECK(multiplier && error_count);
28 (*error_count)++; 47 (*error_count)++;
29 if (*error_count > 1 && *error_count < 9) { 48 if (*error_count > 1 && *error_count < 9) {
30 // With error count 9 and above we will hit the 24 hour max interval. 49 // With error count 9 and above we will hit the 24 hour max interval.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 prefix.c_str(), method.c_str(), request_base64.c_str(), 96 prefix.c_str(), method.c_str(), request_base64.c_str(),
78 client_id.c_str(), version.c_str()); 97 client_id.c_str(), version.c_str());
79 if (!key_param.empty()) { 98 if (!key_param.empty()) {
80 base::StringAppendF(&url, "&key=%s", 99 base::StringAppendF(&url, "&key=%s",
81 net::EscapeQueryParamValue(key_param, true).c_str()); 100 net::EscapeQueryParamValue(key_param, true).c_str());
82 } 101 }
83 return url; 102 return url;
84 } 103 }
85 104
86 } // namespace safe_browsing 105 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_protocol_manager_util.h ('k') | components/safe_browsing_db/v4_update_protocol_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698