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

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

Issue 2057433002: Replace the old URL format for PVer4 requests with the new format. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move #include to *.cc and use forward declaration in .h Created 4 years, 6 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 #include "net/http/http_request_headers.h"
12 13
13 using base::Time; 14 using base::Time;
14 using base::TimeDelta; 15 using base::TimeDelta;
15 16
16 namespace safe_browsing { 17 namespace safe_browsing {
17 18
18 // The Safe Browsing V4 server URL prefix. 19 // The Safe Browsing V4 server URL prefix.
19 const char kSbV4UrlPrefix[] = "https://safebrowsing.googleapis.com/v4"; 20 const char kSbV4UrlPrefix[] = "https://safebrowsing.googleapis.com/v4";
20 21
21 bool UpdateListIdentifier::operator==(const UpdateListIdentifier& other) const { 22 bool UpdateListIdentifier::operator==(const UpdateListIdentifier& other) const {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // static 71 // static
71 void V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode( 72 void V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode(
72 const char* metric_name, 73 const char* metric_name,
73 const net::URLRequestStatus& status, 74 const net::URLRequestStatus& status,
74 int response_code) { 75 int response_code) {
75 UMA_HISTOGRAM_SPARSE_SLOWLY( 76 UMA_HISTOGRAM_SPARSE_SLOWLY(
76 metric_name, status.is_success() ? response_code : status.error()); 77 metric_name, status.is_success() ? response_code : status.error());
77 } 78 }
78 79
79 // static 80 // static
80 // The API hash call uses the pver4 Safe Browsing server. 81 GURL V4ProtocolManagerUtil::GetRequestUrlAndUpdateHeaders(
81 GURL V4ProtocolManagerUtil::GetRequestUrl(const std::string& request_base64, 82 const std::string& request_base64,
82 const std::string& method_name, 83 const std::string& method_name,
83 const V4ProtocolConfig& config) { 84 const V4ProtocolConfig& config,
84 std::string url = 85 net::HttpRequestHeaders* headers) {
85 ComposeUrl(kSbV4UrlPrefix, method_name, request_base64, 86 UpdateHeaders(headers);
86 config.client_name, config.version, config.key_param); 87 return GURL(ComposeUrl(kSbV4UrlPrefix, method_name, request_base64,
87 return GURL(url); 88 config.key_param));
88 } 89 }
89 90
90 // static 91 // static
91 std::string V4ProtocolManagerUtil::ComposeUrl(const std::string& prefix, 92 std::string V4ProtocolManagerUtil::ComposeUrl(const std::string& prefix,
92 const std::string& method, 93 const std::string& method,
93 const std::string& request_base64, 94 const std::string& request_base64,
94 const std::string& client_id,
95 const std::string& version,
96 const std::string& key_param) { 95 const std::string& key_param) {
97 DCHECK(!prefix.empty() && !method.empty() && !client_id.empty() && 96 DCHECK(!prefix.empty() && !method.empty());
98 !version.empty()); 97 std::string url = base::StringPrintf(
99 std::string url = 98 "%s/%s?$req=%s&$ct=application/x-protobuf", prefix.c_str(),
100 base::StringPrintf("%s/%s/%s?alt=proto&client_id=%s&client_version=%s", 99 method.c_str(), request_base64.c_str());
101 prefix.c_str(), method.c_str(), request_base64.c_str(),
102 client_id.c_str(), version.c_str());
103 if (!key_param.empty()) { 100 if (!key_param.empty()) {
104 base::StringAppendF(&url, "&key=%s", 101 base::StringAppendF(&url, "&key=%s",
105 net::EscapeQueryParamValue(key_param, true).c_str()); 102 net::EscapeQueryParamValue(key_param, true).c_str());
106 } 103 }
107 return url; 104 return url;
108 } 105 }
109 106
107 // static
108 void V4ProtocolManagerUtil::UpdateHeaders(net::HttpRequestHeaders* headers) {
109 headers->SetHeaderIfMissing("X-HTTP-Method-Override", "POST");
Nathan Parker 2016/06/09 20:22:18 If we get an explanation for this, we should add i
vakh (use Gerrit instead) 2016/06/09 21:02:15 Done.
110 }
111
110 } // namespace safe_browsing 112 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698