Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: components/data_reduction_proxy/core/common/data_reduction_proxy_util.cc

Issue 2104143002: Refactoring client/version to util (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/data_reduction_proxy/core/common/data_reduction_proxy_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/data_reduction_proxy/core/common/data_reduction_proxy_util.cc
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_util.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_util.cc
index b691faf0b538ca80680385d7c864e1e4b942d37e..043664b7713b972702d5464835cdd0b9505e7e09 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_util.cc
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_util.cc
@@ -1,37 +1,101 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_util.h"
+#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
+#include "base/version.h"
+#include "components/data_reduction_proxy/core/common/version.h"
#include "net/base/url_util.h"
#include "net/proxy/proxy_config.h"
#include "net/proxy/proxy_info.h"
#if defined(USE_GOOGLE_API_KEYS)
#include "google_apis/google_api_keys.h"
#endif
namespace data_reduction_proxy {
namespace {
#if defined(USE_GOOGLE_API_KEYS)
// Used in all Data Reduction Proxy URLs to specify API Key.
const char kApiKeyName[] = "key";
#endif
} // namespace
namespace util {
+const char* ChromiumVersion() {
+ // Assert at compile time that the Chromium version is at least somewhat
+ // properly formed, e.g. the version string is at least as long as "0.0.0.0",
+ // and starts and ends with numeric digits. This is to prevent another
+ // regression like http://crbug.com/595471.
+ static_assert(arraysize(PRODUCT_VERSION) >= arraysize("0.0.0.0") &&
+ '0' <= PRODUCT_VERSION[0] && PRODUCT_VERSION[0] <= '9' &&
+ '0' <= PRODUCT_VERSION[arraysize(PRODUCT_VERSION) - 2] &&
+ PRODUCT_VERSION[arraysize(PRODUCT_VERSION) - 2] <= '9',
+ "PRODUCT_VERSION must be a string of the form "
+ "'MAJOR.MINOR.BUILD.PATCH', e.g. '1.2.3.4'. "
+ "PRODUCT_VERSION='" PRODUCT_VERSION "' is badly formed.");
+
+ return PRODUCT_VERSION;
+}
+
+void GetChromiumBuildAndPatch(const std::string& version_string,
+ std::string* build,
+ std::string* patch) {
+ base::Version version(version_string);
+ DCHECK(version.IsValid());
+ DCHECK_EQ(4U, version.components().size());
+
+ *build = base::Uint64ToString(version.components()[2]);
+ *patch = base::Uint64ToString(version.components()[3]);
+}
+
+const char* GetStringForClient(Client client) {
+ switch (client) {
+ case Client::UNKNOWN:
+ return "";
+ case Client::CRONET_ANDROID:
+ return "cronet";
+ case Client::WEBVIEW_ANDROID:
+ return "webview";
+ case Client::CHROME_ANDROID:
+ return "android";
+ case Client::CHROME_IOS:
+ return "ios";
+ case Client::CHROME_MAC:
+ return "mac";
+ case Client::CHROME_CHROMEOS:
+ return "chromeos";
+ case Client::CHROME_LINUX:
+ return "linux";
+ case Client::CHROME_WINDOWS:
+ return "win";
+ case Client::CHROME_FREEBSD:
+ return "freebsd";
+ case Client::CHROME_OPENBSD:
+ return "openbsd";
+ case Client::CHROME_SOLARIS:
+ return "solaris";
+ case Client::CHROME_QNX:
+ return "qnx";
+ default:
+ NOTREACHED();
+ return "";
+ }
+}
+
bool IsMethodIdempotent(const std::string& method) {
return method == "GET" || method == "OPTIONS" || method == "HEAD" ||
method == "PUT" || method == "DELETE" || method == "TRACE";
}
GURL AddApiKeyToUrl(const GURL& url) {
GURL new_url = url;
#if defined(USE_GOOGLE_API_KEYS)
std::string api_key = google_apis::GetAPIKey();
if (google_apis::HasKeysConfigured() && !api_key.empty()) {
« no previous file with comments | « components/data_reduction_proxy/core/common/data_reduction_proxy_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698