- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / safe_browsing / protocol_manager_helper.cc
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 "chrome/common/chrome_version_info.h"
16 #include "chrome/common/env_vars.h"
17 #include "google_apis/google_api_keys.h"
18 #include "net/base/escape.h"
19
20 SafeBrowsingProtocolConfig::SafeBrowsingProtocolConfig()
21     : disable_auto_update(false) {
22 }
23
24 SafeBrowsingProtocolConfig::~SafeBrowsingProtocolConfig() {
25 }
26
27 // static
28 std::string SafeBrowsingProtocolManagerHelper::Version() {
29   chrome::VersionInfo version_info;
30   if (!version_info.is_valid() || version_info.Version().empty())
31     return "0.1";
32   else
33     return version_info.Version();
34 }
35
36 // static
37 std::string SafeBrowsingProtocolManagerHelper::ComposeUrl(
38     const std::string& prefix, const std::string& method,
39     const std::string& client_name, const std::string& version,
40     const std::string& additional_query) {
41   DCHECK(!prefix.empty() && !method.empty() &&
42          !client_name.empty() && !version.empty());
43   std::string url = base::StringPrintf("%s/%s?client=%s&appver=%s&pver=2.2",
44                                        prefix.c_str(), method.c_str(),
45                                        client_name.c_str(), version.c_str());
46   std::string api_key = google_apis::GetAPIKey();
47   if (!api_key.empty()) {
48     base::StringAppendF(&url, "&key=%s",
49                         net::EscapeQueryParamValue(api_key, true).c_str());
50   }
51   if (!additional_query.empty()) {
52     DCHECK(url.find("?") != std::string::npos);
53     url.append("&");
54     url.append(additional_query);
55   }
56   return url;
57 }