OLD | NEW |
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 Loading... |
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 namespace ProtocolManagerHelper { |
| 226 |
| 227 std::string Version() { |
| 228 if (version_info::GetVersionNumber().empty()) |
| 229 return "0.1"; |
| 230 else |
| 231 return version_info::GetVersionNumber(); |
| 232 } |
| 233 |
| 234 std::string ComposeUrl(const std::string& prefix, |
| 235 const std::string& method, |
| 236 const std::string& client_name, |
| 237 const std::string& version, |
| 238 const std::string& additional_query) { |
| 239 DCHECK(!prefix.empty() && !method.empty() && !client_name.empty() && |
| 240 !version.empty()); |
| 241 std::string url = |
| 242 base::StringPrintf("%s/%s?client=%s&appver=%s&pver=3.0", prefix.c_str(), |
| 243 method.c_str(), client_name.c_str(), version.c_str()); |
| 244 std::string api_key = google_apis::GetAPIKey(); |
| 245 if (!api_key.empty()) { |
| 246 base::StringAppendF(&url, "&key=%s", |
| 247 net::EscapeQueryParamValue(api_key, true).c_str()); |
| 248 } |
| 249 if (!additional_query.empty()) { |
| 250 DCHECK(url.find("?") != std::string::npos); |
| 251 url.append("&"); |
| 252 url.append(additional_query); |
| 253 } |
| 254 return url; |
| 255 } |
| 256 |
| 257 std::string ComposeUrl(const std::string& prefix, |
| 258 const std::string& method, |
| 259 const std::string& client_name, |
| 260 const std::string& version, |
| 261 const std::string& additional_query, |
| 262 ExtendedReportingLevel reporting_level) { |
| 263 std::string url = |
| 264 ComposeUrl(prefix, method, client_name, version, additional_query); |
| 265 url.append(base::StringPrintf("&ext=%d", reporting_level)); |
| 266 return url; |
| 267 } |
| 268 |
| 269 } // namespace ProtocolManagerHelper |
| 270 |
207 } // namespace safe_browsing | 271 } // namespace safe_browsing |
OLD | NEW |