Commit 5bba9e15 authored by ryansturm's avatar ryansturm Committed by Commit bot

Refactoring client/version to util

BUG=622374

Review-Url: https://codereview.chromium.org/2104143002
Cr-Commit-Position: refs/heads/master@{#403201}
parent 5ec2d0a0
......@@ -90,7 +90,7 @@ BasicHTTPURLRequestContextGetter::~BasicHTTPURLRequestContextGetter() {
}
DataReductionProxyIOData::DataReductionProxyIOData(
const Client& client,
Client client,
int param_flags,
net::NetLog* net_log,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
......@@ -115,7 +115,7 @@ DataReductionProxyIOData::DataReductionProxyIOData(
configurator_.reset(
new DataReductionProxyConfigurator(net_log, event_creator_.get()));
bool use_config_client =
params::IsConfigClientEnabled() && client_ != CRONET_ANDROID;
params::IsConfigClientEnabled() && client_ != Client::CRONET_ANDROID;
DataReductionProxyMutableConfigValues* raw_mutable_config = nullptr;
if (use_config_client) {
std::unique_ptr<DataReductionProxyMutableConfigValues> mutable_config =
......
......@@ -20,6 +20,7 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_storage_delegate.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_util.h"
#include "components/data_reduction_proxy/core/common/lofi_decider.h"
#include "components/data_reduction_proxy/core/common/lofi_ui_service.h"
......@@ -51,7 +52,7 @@ class DataReductionProxyIOData : public DataReductionProxyEventStorageDelegate {
// configurations. |enabled| sets the initial state of the Data Reduction
// Proxy.
DataReductionProxyIOData(
const Client& client,
Client client,
int param_flags,
net::NetLog* net_log,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
......
......@@ -7,7 +7,6 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/string_tokenizer.h"
......@@ -15,13 +14,11 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/version.h"
#include "build/build_config.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
#include "components/data_reduction_proxy/core/common/version.h"
#include "components/variations/variations_associated_data.h"
#include "crypto/random.h"
#include "net/base/host_port_pair.h"
......@@ -40,46 +37,6 @@ std::string FormatOption(const std::string& name, const std::string& value) {
return name + "=" + value;
}
// Returns the version of Chromium that is being used, e.g. "1.2.3.4".
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;
}
// Returns the build and patch numbers of |version_string|. |version_string|
// must be a properly formed Chromium version number, e.g. "1.2.3.4".
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]);
}
#define CLIENT_ENUM(name, str_value) \
case name: \
return str_value;
const char* GetString(Client client) {
switch (client) { CLIENT_ENUMS_LIST }
NOTREACHED();
return "";
}
#undef CLIENT_ENUM
} // namespace
const char kSessionHeaderOption[] = "ps";
......@@ -107,17 +64,19 @@ bool DataReductionProxyRequestOptions::IsKeySetOnCommandLine() {
DataReductionProxyRequestOptions::DataReductionProxyRequestOptions(
Client client,
DataReductionProxyConfig* config)
: DataReductionProxyRequestOptions(client, ChromiumVersion(), config) {}
: DataReductionProxyRequestOptions(client,
util::ChromiumVersion(),
config) {}
DataReductionProxyRequestOptions::DataReductionProxyRequestOptions(
Client client,
const std::string& version,
DataReductionProxyConfig* config)
: client_(GetString(client)),
: client_(util::GetStringForClient(client)),
use_assigned_credentials_(false),
data_reduction_proxy_config_(config) {
DCHECK(data_reduction_proxy_config_);
GetChromiumBuildAndPatch(version, &build_, &patch_);
util::GetChromiumBuildAndPatch(version, &build_, &patch_);
// Constructed on the UI thread, but should be checked on the IO thread.
thread_checker_.DetachFromThread();
}
......
......@@ -17,6 +17,7 @@
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_util.h"
namespace net {
class HostPortPair;
......@@ -40,27 +41,6 @@ extern const char kExperimentsOption[];
extern const char kAndroidWebViewProtocolVersion[];
#endif
#define CLIENT_ENUMS_LIST \
CLIENT_ENUM(UNKNOWN, "") \
CLIENT_ENUM(CRONET_ANDROID, "cronet") \
CLIENT_ENUM(WEBVIEW_ANDROID, "webview") \
CLIENT_ENUM(CHROME_ANDROID, "android") \
CLIENT_ENUM(CHROME_IOS, "ios") \
CLIENT_ENUM(CHROME_MAC, "mac") \
CLIENT_ENUM(CHROME_CHROMEOS, "chromeos") \
CLIENT_ENUM(CHROME_LINUX, "linux") \
CLIENT_ENUM(CHROME_WINDOWS, "win") \
CLIENT_ENUM(CHROME_FREEBSD, "freebsd") \
CLIENT_ENUM(CHROME_OPENBSD, "openbsd") \
CLIENT_ENUM(CHROME_SOLARIS, "solaris") \
CLIENT_ENUM(CHROME_QNX, "qnx")
#define CLIENT_ENUM(name, str_value) name,
typedef enum {
CLIENT_ENUMS_LIST
} Client;
#undef CLIENT_ENUM
class DataReductionProxyConfig;
class DataReductionProxyRequestOptions {
......
......@@ -4,7 +4,10 @@
#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"
......@@ -25,6 +28,67 @@ const char kApiKeyName[] = "key";
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";
......
......@@ -25,8 +25,36 @@ class ProxyInfo;
namespace data_reduction_proxy {
enum class Client {
UNKNOWN,
CRONET_ANDROID,
WEBVIEW_ANDROID,
CHROME_ANDROID,
CHROME_IOS,
CHROME_MAC,
CHROME_CHROMEOS,
CHROME_LINUX,
CHROME_WINDOWS,
CHROME_FREEBSD,
CHROME_OPENBSD,
CHROME_SOLARIS,
CHROME_QNX,
};
namespace util {
// Returns the version of Chromium that is being used, e.g. "1.2.3.4".
const char* ChromiumVersion();
// Returns the build and patch numbers of |version_string|. |version_string|
// must be a properly formed Chromium version number, e.g. "1.2.3.4".
void GetChromiumBuildAndPatch(const std::string& version_string,
std::string* build,
std::string* patch);
// Get the human-readable version of |client|.
const char* GetStringForClient(Client client);
// Returns true if the request method is idempotent.
bool IsMethodIdempotent(const std::string& method);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment