| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/safe_browsing/protocol_manager_helper.h" | |
| 6 | |
| 7 #ifndef NDEBUG | |
| 8 #include "base/base64.h" | |
| 9 #endif | |
| 10 #include "base/environment.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/stl_util.h" | |
| 13 #include "base/strings/string_util.h" | |
| 14 #include "base/strings/stringprintf.h" | |
| 15 #include "components/version_info/version_info.h" | |
| 16 #include "google_apis/google_api_keys.h" | |
| 17 #include "net/base/escape.h" | |
| 18 | |
| 19 namespace safe_browsing { | |
| 20 | |
| 21 SafeBrowsingProtocolConfig::SafeBrowsingProtocolConfig() | |
| 22 : disable_auto_update(false) {} | |
| 23 | |
| 24 SafeBrowsingProtocolConfig::SafeBrowsingProtocolConfig( | |
| 25 const SafeBrowsingProtocolConfig& other) = default; | |
| 26 | |
| 27 SafeBrowsingProtocolConfig::~SafeBrowsingProtocolConfig() {} | |
| 28 | |
| 29 // static | |
| 30 std::string SafeBrowsingProtocolManagerHelper::Version() { | |
| 31 if (version_info::GetVersionNumber().empty()) | |
| 32 return "0.1"; | |
| 33 else | |
| 34 return version_info::GetVersionNumber(); | |
| 35 } | |
| 36 | |
| 37 // static | |
| 38 std::string SafeBrowsingProtocolManagerHelper::ComposeUrl( | |
| 39 const std::string& prefix, | |
| 40 const std::string& method, | |
| 41 const std::string& client_name, | |
| 42 const std::string& version, | |
| 43 const std::string& additional_query) { | |
| 44 DCHECK(!prefix.empty() && !method.empty() && | |
| 45 !client_name.empty() && !version.empty()); | |
| 46 std::string url = base::StringPrintf("%s/%s?client=%s&appver=%s&pver=3.0", | |
| 47 prefix.c_str(), method.c_str(), | |
| 48 client_name.c_str(), version.c_str()); | |
| 49 std::string api_key = google_apis::GetAPIKey(); | |
| 50 if (!api_key.empty()) { | |
| 51 base::StringAppendF(&url, "&key=%s", | |
| 52 net::EscapeQueryParamValue(api_key, true).c_str()); | |
| 53 } | |
| 54 if (!additional_query.empty()) { | |
| 55 DCHECK(url.find("?") != std::string::npos); | |
| 56 url.append("&"); | |
| 57 url.append(additional_query); | |
| 58 } | |
| 59 return url; | |
| 60 } | |
| 61 | |
| 62 // static | |
| 63 std::string SafeBrowsingProtocolManagerHelper::ComposeUrl( | |
| 64 const std::string& prefix, | |
| 65 const std::string& method, | |
| 66 const std::string& client_name, | |
| 67 const std::string& version, | |
| 68 const std::string& additional_query, | |
| 69 ExtendedReportingLevel reporting_level) { | |
| 70 std::string url = | |
| 71 ComposeUrl(prefix, method, client_name, version, additional_query); | |
| 72 url.append(base::StringPrintf("&ext=%d", reporting_level)); | |
| 73 return url; | |
| 74 } | |
| 75 | |
| 76 } // namespace safe_browsing | |
| OLD | NEW |