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

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

Issue 2650973005: Componentize ping_manager (Closed)
Patch Set: fix deps Created 3 years, 10 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 (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/util.h" 5 #include "components/safe_browsing_db/util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #ifndef NDEBUG
10 #include "base/base64.h"
11 #endif
12 #include "base/environment.h"
13 #include "base/logging.h"
9 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/stl_util.h"
16 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h"
10 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
19 #include "components/version_info/version_info.h"
11 #include "crypto/sha2.h" 20 #include "crypto/sha2.h"
21 #include "google_apis/google_api_keys.h"
12 #include "net/base/escape.h" 22 #include "net/base/escape.h"
13 #include "url/gurl.h" 23 #include "url/gurl.h"
14 24
15 namespace safe_browsing { 25 namespace safe_browsing {
16 26
17 // Utility functions ----------------------------------------------------------- 27 // Utility functions -----------------------------------------------------------
18 28
19 namespace { 29 namespace {
20 30
21 bool IsKnownList(const std::string& name) { 31 bool IsKnownList(const std::string& name) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // also match with /foo/bar and /foo?bar. Hence, for every path 207 // also match with /foo/bar and /foo?bar. Hence, for every path
198 // that ends in '/' we also add the path without the slash. 208 // that ends in '/' we also add the path without the slash.
199 if (include_whitelist_hashes && path.size() > 1 && path.back() == '/') { 209 if (include_whitelist_hashes && path.size() > 1 && path.back() == '/') {
200 full_hashes->push_back(SBFullHashForString( 210 full_hashes->push_back(SBFullHashForString(
201 host + path.substr(0, path.size() - 1))); 211 host + path.substr(0, path.size() - 1)));
202 } 212 }
203 } 213 }
204 } 214 }
205 } 215 }
206 216
217 SafeBrowsingProtocolConfig::SafeBrowsingProtocolConfig()
218 : disable_auto_update(false) {}
219
220 SafeBrowsingProtocolConfig::SafeBrowsingProtocolConfig(
221 const SafeBrowsingProtocolConfig& other) = default;
222
223 SafeBrowsingProtocolConfig::~SafeBrowsingProtocolConfig() {}
224
225 std::string Version() {
226 if (version_info::GetVersionNumber().empty())
227 return "0.1";
228 else
229 return version_info::GetVersionNumber();
230 }
231
232 std::string ComposeUrl(const std::string& prefix,
233 const std::string& method,
234 const std::string& client_name,
235 const std::string& version,
236 const std::string& additional_query) {
237 DCHECK(!prefix.empty() && !method.empty() && !client_name.empty() &&
238 !version.empty());
239 std::string url =
240 base::StringPrintf("%s/%s?client=%s&appver=%s&pver=3.0", prefix.c_str(),
241 method.c_str(), client_name.c_str(), version.c_str());
242 std::string api_key = google_apis::GetAPIKey();
243 if (!api_key.empty()) {
244 base::StringAppendF(&url, "&key=%s",
245 net::EscapeQueryParamValue(api_key, true).c_str());
246 }
247 if (!additional_query.empty()) {
248 DCHECK(url.find("?") != std::string::npos);
249 url.append("&");
250 url.append(additional_query);
251 }
252 return url;
253 }
254
255 std::string ComposeUrl(const std::string& prefix,
256 const std::string& method,
257 const std::string& client_name,
258 const std::string& version,
259 const std::string& additional_query,
260 ExtendedReportingLevel reporting_level) {
261 std::string url =
262 ComposeUrl(prefix, method, client_name, version, additional_query);
263 url.append(base::StringPrintf("&ext=%d", reporting_level));
264 return url;
265 }
266
207 } // namespace safe_browsing 267 } // namespace safe_browsing
OLDNEW
« components/safe_browsing_db/util.h ('K') | « components/safe_browsing_db/util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698