Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / safe_browsing / protocol_manager_helper.cc
blob8c399cb59541d723ce1fdb3b766f95bce0dc4e70
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.
5 #include "chrome/browser/safe_browsing/protocol_manager_helper.h"
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 "chrome/common/env_vars.h"
16 #include "components/version_info/version_info.h"
17 #include "google_apis/google_api_keys.h"
18 #include "net/base/escape.h"
20 SafeBrowsingProtocolConfig::SafeBrowsingProtocolConfig()
21 : disable_auto_update(false)
22 #if defined(OS_ANDROID)
23 , disable_connection_check(false)
24 #endif
28 SafeBrowsingProtocolConfig::~SafeBrowsingProtocolConfig() {
31 // static
32 std::string SafeBrowsingProtocolManagerHelper::Version() {
33 if (version_info::GetVersionNumber().empty())
34 return "0.1";
35 else
36 return version_info::GetVersionNumber();
39 // static
40 std::string SafeBrowsingProtocolManagerHelper::ComposeUrl(
41 const std::string& prefix,
42 const std::string& method,
43 const std::string& client_name,
44 const std::string& version,
45 const std::string& additional_query) {
46 DCHECK(!prefix.empty() && !method.empty() &&
47 !client_name.empty() && !version.empty());
48 std::string url = base::StringPrintf("%s/%s?client=%s&appver=%s&pver=3.0",
49 prefix.c_str(), method.c_str(),
50 client_name.c_str(), version.c_str());
51 std::string api_key = google_apis::GetAPIKey();
52 if (!api_key.empty()) {
53 base::StringAppendF(&url, "&key=%s",
54 net::EscapeQueryParamValue(api_key, true).c_str());
56 if (!additional_query.empty()) {
57 DCHECK(url.find("?") != std::string::npos);
58 url.append("&");
59 url.append(additional_query);
61 return url;
64 // static
65 std::string SafeBrowsingProtocolManagerHelper::ComposeUrl(
66 const std::string& prefix,
67 const std::string& method,
68 const std::string& client_name,
69 const std::string& version,
70 const std::string& additional_query,
71 bool is_extended_reporting) {
72 std::string url =
73 ComposeUrl(prefix, method, client_name, version, additional_query);
74 if (is_extended_reporting) {
75 url.append("&ext=1");
76 } else {
77 url.append("&ext=0");
79 return url;