Chromium Code Reviews| Index: components/safe_browsing_db/util.cc |
| diff --git a/components/safe_browsing_db/util.cc b/components/safe_browsing_db/util.cc |
| index 0f38dee61bde5dabba15fa793e4b05d8b5f6032d..b59573c0adbbd7f330a269d03120ab07116e22af 100644 |
| --- a/components/safe_browsing_db/util.cc |
| +++ b/components/safe_browsing_db/util.cc |
| @@ -6,9 +6,19 @@ |
| #include <stddef.h> |
| +#ifndef NDEBUG |
| +#include "base/base64.h" |
| +#endif |
| +#include "base/environment.h" |
| +#include "base/logging.h" |
| #include "base/macros.h" |
| +#include "base/stl_util.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/trace_event/trace_event.h" |
| +#include "components/version_info/version_info.h" |
| #include "crypto/sha2.h" |
| +#include "google_apis/google_api_keys.h" |
| #include "net/base/escape.h" |
| #include "url/gurl.h" |
| @@ -204,4 +214,58 @@ void UrlToFullHashes(const GURL& url, |
| } |
| } |
| +SafeBrowsingProtocolConfig::SafeBrowsingProtocolConfig() |
| + : disable_auto_update(false) {} |
| + |
| +SafeBrowsingProtocolConfig::SafeBrowsingProtocolConfig( |
| + const SafeBrowsingProtocolConfig& other) = default; |
| + |
| +SafeBrowsingProtocolConfig::~SafeBrowsingProtocolConfig() {} |
| + |
| +namespace ProtocolManagerHelper { |
| + |
| +std::string Version() { |
| + if (version_info::GetVersionNumber().empty()) |
| + return "0.1"; |
|
Nico
2017/02/14 18:58:40
Huh? Why even have this function? Why is 0.1 a goo
Jialiu Lin
2017/02/14 19:01:19
Honestly, I don't know. I simply copied this funct
|
| + else |
| + return version_info::GetVersionNumber(); |
| +} |
| + |
| +std::string ComposeUrl(const std::string& prefix, |
| + const std::string& method, |
| + const std::string& client_name, |
| + const std::string& version, |
| + const std::string& additional_query) { |
| + DCHECK(!prefix.empty() && !method.empty() && !client_name.empty() && |
| + !version.empty()); |
| + std::string url = |
| + base::StringPrintf("%s/%s?client=%s&appver=%s&pver=3.0", prefix.c_str(), |
| + method.c_str(), client_name.c_str(), version.c_str()); |
| + std::string api_key = google_apis::GetAPIKey(); |
| + if (!api_key.empty()) { |
| + base::StringAppendF(&url, "&key=%s", |
| + net::EscapeQueryParamValue(api_key, true).c_str()); |
| + } |
| + if (!additional_query.empty()) { |
| + DCHECK(url.find("?") != std::string::npos); |
| + url.append("&"); |
| + url.append(additional_query); |
| + } |
| + return url; |
| +} |
| + |
| +std::string ComposeUrl(const std::string& prefix, |
| + const std::string& method, |
| + const std::string& client_name, |
| + const std::string& version, |
| + const std::string& additional_query, |
| + ExtendedReportingLevel reporting_level) { |
| + std::string url = |
| + ComposeUrl(prefix, method, client_name, version, additional_query); |
| + url.append(base::StringPrintf("&ext=%d", reporting_level)); |
| + return url; |
| +} |
| + |
| +} // namespace ProtocolManagerHelper |
| + |
| } // namespace safe_browsing |