The data reduction proxy client should be specific about it's capabilities by...

The data reduction proxy client should be specific about it's capabilities by specifying the version of the proxy client that is being used. 
A version field is now added to the Chrome-Proxy header in requests, but that version is set to zero. 
This corrects the version field in the Chrome-Proxy header to be the chromium build and patch number.

BUG=367268

Review URL: https://codereview.chromium.org/430643002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287970 0039d316-1c4b-4281-b951-d872f2087c98
parent 82f3d0b9
...@@ -105,6 +105,8 @@ void AwBrowserContext::PreMainMessageLoopRun() { ...@@ -105,6 +105,8 @@ void AwBrowserContext::PreMainMessageLoopRun() {
data_reduction_proxy::DataReductionProxyParams::kAllowed))); data_reduction_proxy::DataReductionProxyParams::kAllowed)));
data_reduction_proxy_auth_request_handler_.reset( data_reduction_proxy_auth_request_handler_.reset(
new DataReductionProxyAuthRequestHandler( new DataReductionProxyAuthRequestHandler(
data_reduction_proxy::kClientAndroidWebview,
data_reduction_proxy::kAndroidWebViewProtocolVersion,
data_reduction_proxy_settings_->params())); data_reduction_proxy_settings_->params()));
#endif #endif
......
...@@ -58,9 +58,7 @@ void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) { ...@@ -58,9 +58,7 @@ void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) {
browser_context->GetDataReductionProxyAuthRequestHandler(); browser_context->GetDataReductionProxyAuthRequestHandler();
if (drp_auth_request_handler) if (drp_auth_request_handler)
drp_auth_request_handler->SetKey( drp_auth_request_handler->SetKey(
ConvertJavaStringToUTF8(env, key), ConvertJavaStringToUTF8(env, key));
data_reduction_proxy::kClientAndroidWebview,
data_reduction_proxy::kProtocolVersion);
} }
// static // static
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "chrome/browser/net/dns_probe_service.h" #include "chrome/browser/net/dns_probe_service.h"
#include "chrome/browser/net/pref_proxy_config_tracker.h" #include "chrome/browser/net/pref_proxy_config_tracker.h"
#include "chrome/browser/net/proxy_service_factory.h" #include "chrome/browser/net/proxy_service_factory.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h" #include "chrome/common/chrome_version_info.h"
...@@ -654,7 +655,10 @@ void IOThread::InitAsync() { ...@@ -654,7 +655,10 @@ void IOThread::InitAsync() {
new DataReductionProxyParams(drp_flags); new DataReductionProxyParams(drp_flags);
globals_->data_reduction_proxy_params.reset(proxy_params); globals_->data_reduction_proxy_params.reset(proxy_params);
globals_->data_reduction_proxy_auth_request_handler.reset( globals_->data_reduction_proxy_auth_request_handler.reset(
new DataReductionProxyAuthRequestHandler(proxy_params)); new DataReductionProxyAuthRequestHandler(
DataReductionProxyChromeSettings::GetClient(),
DataReductionProxyChromeSettings::GetBuildAndPatchNumber(),
proxy_params));
globals_->on_resolve_proxy_handler = globals_->on_resolve_proxy_handler =
ChromeNetworkDelegate::OnResolveProxyHandler( ChromeNetworkDelegate::OnResolveProxyHandler(
base::Bind(data_reduction_proxy::OnResolveProxyHandler)); base::Bind(data_reduction_proxy::OnResolveProxyHandler));
......
...@@ -4,11 +4,14 @@ ...@@ -4,11 +4,14 @@
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
#include "base/strings/string_split.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h" #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h" #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_version_info.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
...@@ -49,3 +52,24 @@ void DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial( ...@@ -49,3 +52,24 @@ void DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial(
"DataReductionProxyEnabled", "DataReductionProxyEnabled",
data_reduction_proxy_enabled ? "true" : "false"); data_reduction_proxy_enabled ? "true" : "false");
} }
// static
std::string DataReductionProxyChromeSettings::GetBuildAndPatchNumber() {
chrome::VersionInfo version_info;
std::vector<std::string> version_parts;
base::SplitString(version_info.Version(), '.', &version_parts);
if (version_parts.size() != 4)
return "";
return version_parts[2] + version_parts[3];
}
// static
std::string DataReductionProxyChromeSettings::GetClient() {
#if defined(OS_ANDROID)
return data_reduction_proxy::kClientChromeAndroid;
#elif defined(OS_IOS)
return data_reduction_proxy::kClientChromeIOS;
#else
return "";
#endif
}
...@@ -32,6 +32,14 @@ class DataReductionProxyChromeSettings ...@@ -32,6 +32,14 @@ class DataReductionProxyChromeSettings
// get the appropriate pref service. // get the appropriate pref service.
virtual void InitDataReductionProxySettings(Profile* profile); virtual void InitDataReductionProxySettings(Profile* profile);
// Using the chrome::VersionInfo version, returns the build and patch portion
// of the string delimited by a period. If the chrome::VersionInfo version
// isn't of the form xx.xx.xx.xx returns an empty string.
static std::string GetBuildAndPatchNumber();
// Gets the client type for the data reduction proxy.
static std::string GetClient();
private: private:
// Registers the DataReductionProxyEnabled synthetic field trial with // Registers the DataReductionProxyEnabled synthetic field trial with
// the group |data_reduction_proxy_enabled|. // the group |data_reduction_proxy_enabled|.
......
...@@ -20,8 +20,11 @@ ...@@ -20,8 +20,11 @@
namespace data_reduction_proxy { namespace data_reduction_proxy {
// The version of the authentication protocol. // The empty version for the authentication protocol. Currently used by
const char kProtocolVersion[] = "0"; // Android webview.
#if defined(OS_ANDROID)
const char kAndroidWebViewProtocolVersion[] = "0";
#endif
// The clients supported by the data reduction proxy. // The clients supported by the data reduction proxy.
const char kClientAndroidWebview[] = "webview"; const char kClientAndroidWebview[] = "webview";
...@@ -36,14 +39,12 @@ bool DataReductionProxyAuthRequestHandler::IsKeySetOnCommandLine() { ...@@ -36,14 +39,12 @@ bool DataReductionProxyAuthRequestHandler::IsKeySetOnCommandLine() {
} }
DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler( DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler(
const std::string& client,
const std::string& version,
DataReductionProxyParams* params) DataReductionProxyParams* params)
: data_reduction_proxy_params_(params) { : data_reduction_proxy_params_(params) {
version_ = kProtocolVersion; client_ = client;
#if defined(OS_ANDROID) version_ = version;
client_ = kClientChromeAndroid;
#elif defined(OS_IOS)
client_ = kClientChromeIOS;
#endif
Init(); Init();
} }
...@@ -126,11 +127,7 @@ void DataReductionProxyAuthRequestHandler::InitAuthentication( ...@@ -126,11 +127,7 @@ void DataReductionProxyAuthRequestHandler::InitAuthentication(
<< "password: [" << credentials_ << "]"; << "password: [" << credentials_ << "]";
} }
void DataReductionProxyAuthRequestHandler::SetKey(const std::string& key, void DataReductionProxyAuthRequestHandler::SetKey(const std::string& key) {
const std::string& client,
const std::string& version) {
client_ = client;
version_ = version;
if (!key.empty()) if (!key.empty())
InitAuthentication(key); InitAuthentication(key);
} }
......
...@@ -20,7 +20,9 @@ class URLRequest; ...@@ -20,7 +20,9 @@ class URLRequest;
namespace data_reduction_proxy { namespace data_reduction_proxy {
extern const char kProtocolVersion[]; #if defined(OS_ANDROID)
extern const char kAndroidWebViewProtocolVersion[];
#endif
extern const char kClientAndroidWebview[]; extern const char kClientAndroidWebview[];
extern const char kClientChromeAndroid[]; extern const char kClientChromeAndroid[];
...@@ -32,8 +34,14 @@ class DataReductionProxyAuthRequestHandler { ...@@ -32,8 +34,14 @@ class DataReductionProxyAuthRequestHandler {
public: public:
static bool IsKeySetOnCommandLine(); static bool IsKeySetOnCommandLine();
// Constructs an authentication request handler. // Constructs an authentication request handler. Client is the canonical name
explicit DataReductionProxyAuthRequestHandler( // for the client. Client names should be defined in this file as one of
// |kClient...|. Version is the authentication protocol version that the
// client uses, which should be |kProtocolVersion| unless the client expects
// to be handled differently from the standard behavior.
DataReductionProxyAuthRequestHandler(
const std::string& client,
const std::string& version,
DataReductionProxyParams* params); DataReductionProxyParams* params);
virtual ~DataReductionProxyAuthRequestHandler(); virtual ~DataReductionProxyAuthRequestHandler();
...@@ -47,14 +55,8 @@ class DataReductionProxyAuthRequestHandler { ...@@ -47,14 +55,8 @@ class DataReductionProxyAuthRequestHandler {
// Sets a new authentication key. This must be called for platforms that do // Sets a new authentication key. This must be called for platforms that do
// not have a default key defined. See the constructor implementation for // not have a default key defined. See the constructor implementation for
// those platforms. Client is the canonical name for the client. Client names // those platforms.
// should be defined in this file as one of |kClient...|. Version is the void SetKey(const std::string& key);
// authentication protocol version that the client uses, which should be
// |kProtocolVersion| unless the client expects to be handled differently from
// the standard behavior.
void SetKey(const std::string& key,
const std::string& client,
const std::string& version);
protected: protected:
void Init(); void Init();
......
...@@ -22,19 +22,35 @@ namespace { ...@@ -22,19 +22,35 @@ namespace {
const char kChromeProxyHeader[] = "chrome-proxy"; const char kChromeProxyHeader[] = "chrome-proxy";
const char kOtherProxy[] = "testproxy:17"; const char kOtherProxy[] = "testproxy:17";
const char kTestKey[] = "test-key";
#if defined(OS_ANDROID)
const char kClient[] = "android";
#elif defined(OS_IOS)
const char kClient[] = "ios";
#else
const char kClient[] = "";
#endif
const char kVersion[] = "0"; const char kVersion[] = "0";
const char kTestKey[] = "test-key";
const char kExpectedCredentials[] = "96bd72ec4a050ba60981743d41787768"; const char kExpectedCredentials[] = "96bd72ec4a050ba60981743d41787768";
const char kExpectedSession[] = "0-1633771873-1633771873-1633771873"; const char kExpectedSession[] = "0-1633771873-1633771873-1633771873";
const char kTestKey2[] = "test-key2"; const char kTestKey2[] = "test-key2";
const char kClient2[] = "foo";
const char kVersion2[] = "2";
const char kExpectedCredentials2[] = "c911fdb402f578787562cf7f00eda972"; const char kExpectedCredentials2[] = "c911fdb402f578787562cf7f00eda972";
const char kExpectedSession2[] = "0-1633771873-1633771873-1633771873"; const char kExpectedSession2[] = "0-1633771873-1633771873-1633771873";
#if defined(OS_ANDROID)
const char kExpectedHeader2[] = const char kExpectedHeader2[] =
"ps=0-1633771873-1633771873-1633771873, " "ps=0-1633771873-1633771873-1633771873, "
"sid=c911fdb402f578787562cf7f00eda972, v=2, c=foo"; "sid=c911fdb402f578787562cf7f00eda972, v=0, c=android";
#elif defined(OS_IOS)
const char kExpectedHeader2[] =
"ps=0-1633771873-1633771873-1633771873, "
"sid=c911fdb402f578787562cf7f00eda972, v=0, c=ios";
#else
const char kExpectedHeader2[] =
"ps=0-1633771873-1633771873-1633771873, "
"sid=c911fdb402f578787562cf7f00eda972, v=0";
#endif
const char kDataReductionProxyKey[] = "12345"; const char kDataReductionProxyKey[] = "12345";
} // namespace } // namespace
...@@ -46,8 +62,10 @@ class TestDataReductionProxyAuthRequestHandler ...@@ -46,8 +62,10 @@ class TestDataReductionProxyAuthRequestHandler
: public DataReductionProxyAuthRequestHandler { : public DataReductionProxyAuthRequestHandler {
public: public:
TestDataReductionProxyAuthRequestHandler( TestDataReductionProxyAuthRequestHandler(
const std::string& client,
const std::string& version,
DataReductionProxyParams* params) DataReductionProxyParams* params)
: DataReductionProxyAuthRequestHandler(params) {} : DataReductionProxyAuthRequestHandler(client,version, params) {}
virtual std::string GetDefaultKey() const OVERRIDE { virtual std::string GetDefaultKey() const OVERRIDE {
return kTestKey; return kTestKey;
...@@ -79,24 +97,18 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, Authorization) { ...@@ -79,24 +97,18 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, Authorization) {
DataReductionProxyParams::kPromoAllowed, DataReductionProxyParams::kPromoAllowed,
TestDataReductionProxyParams::HAS_EVERYTHING & TestDataReductionProxyParams::HAS_EVERYTHING &
~TestDataReductionProxyParams::HAS_DEV_ORIGIN)); ~TestDataReductionProxyParams::HAS_DEV_ORIGIN));
TestDataReductionProxyAuthRequestHandler auth_handler(params.get()); TestDataReductionProxyAuthRequestHandler auth_handler(kClient,
kVersion,
params.get());
auth_handler.Init(); auth_handler.Init();
#if defined(OS_ANDROID) EXPECT_EQ(auth_handler.client_, kClient);
EXPECT_EQ(auth_handler.client_, "android");
#elif defined(OS_IOS)
EXPECT_EQ(auth_handler.client_, "ios");
#else
EXPECT_EQ(auth_handler.client_, "");
#endif
EXPECT_EQ(kVersion, auth_handler.version_); EXPECT_EQ(kVersion, auth_handler.version_);
EXPECT_EQ(auth_handler.key_, kTestKey); EXPECT_EQ(auth_handler.key_, kTestKey);
EXPECT_EQ(kExpectedCredentials, auth_handler.credentials_); EXPECT_EQ(kExpectedCredentials, auth_handler.credentials_);
EXPECT_EQ(kExpectedSession, auth_handler.session_); EXPECT_EQ(kExpectedSession, auth_handler.session_);
// Now set a key. // Now set a key.
auth_handler.SetKey(kTestKey2, kClient2, kVersion2); auth_handler.SetKey(kTestKey2);
EXPECT_EQ(kClient2, auth_handler.client_);
EXPECT_EQ(kVersion2, auth_handler.version_);
EXPECT_EQ(kTestKey2, auth_handler.key_); EXPECT_EQ(kTestKey2, auth_handler.key_);
EXPECT_EQ(kExpectedCredentials2, auth_handler.credentials_); EXPECT_EQ(kExpectedCredentials2, auth_handler.credentials_);
EXPECT_EQ(kExpectedSession2, auth_handler.session_); EXPECT_EQ(kExpectedSession2, auth_handler.session_);
......
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