diff options
author | megjablon@chromium.org <megjablon@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-07 06:57:07 +0000 |
---|---|---|
committer | megjablon@chromium.org <megjablon@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-07 06:57:07 +0000 |
commit | 0f9e5b14cb75b2ac53ad3576125ba045f5ec53e2 (patch) | |
tree | 9cc85aa4449040a9c84c91f44e6b8acf5f0e5eef | |
parent | 82f3d0b93dfffe25a62ed5afa2015c7d1bbea9ba (diff) | |
download | chromium_src-0f9e5b14cb75b2ac53ad3576125ba045f5ec53e2.zip chromium_src-0f9e5b14cb75b2ac53ad3576125ba045f5ec53e2.tar.gz chromium_src-0f9e5b14cb75b2ac53ad3576125ba045f5ec53e2.tar.bz2 |
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
8 files changed, 91 insertions, 44 deletions
diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc index 15f1c8a..614bd82 100644 --- a/android_webview/browser/aw_browser_context.cc +++ b/android_webview/browser/aw_browser_context.cc @@ -105,6 +105,8 @@ void AwBrowserContext::PreMainMessageLoopRun() { data_reduction_proxy::DataReductionProxyParams::kAllowed))); data_reduction_proxy_auth_request_handler_.reset( new DataReductionProxyAuthRequestHandler( + data_reduction_proxy::kClientAndroidWebview, + data_reduction_proxy::kAndroidWebViewProtocolVersion, data_reduction_proxy_settings_->params())); #endif diff --git a/android_webview/native/aw_contents_statics.cc b/android_webview/native/aw_contents_statics.cc index 3f2ab86..9888aad 100644 --- a/android_webview/native/aw_contents_statics.cc +++ b/android_webview/native/aw_contents_statics.cc @@ -58,9 +58,7 @@ void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) { browser_context->GetDataReductionProxyAuthRequestHandler(); if (drp_auth_request_handler) drp_auth_request_handler->SetKey( - ConvertJavaStringToUTF8(env, key), - data_reduction_proxy::kClientAndroidWebview, - data_reduction_proxy::kProtocolVersion); + ConvertJavaStringToUTF8(env, key)); } // static diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 405018e..82bfdac 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -34,6 +34,7 @@ #include "chrome/browser/net/dns_probe_service.h" #include "chrome/browser/net/pref_proxy_config_tracker.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_switches.h" #include "chrome/common/chrome_version_info.h" @@ -654,7 +655,10 @@ void IOThread::InitAsync() { new DataReductionProxyParams(drp_flags); globals_->data_reduction_proxy_params.reset(proxy_params); 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 = ChromeNetworkDelegate::OnResolveProxyHandler( base::Bind(data_reduction_proxy::OnResolveProxyHandler)); diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc index ff30a18..1faf4aa 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc @@ -4,11 +4,14 @@ #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/metrics/chrome_metrics_service_accessor.h" #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h" #include "chrome/browser/profiles/profile.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_params.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h" @@ -49,3 +52,24 @@ void DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial( "DataReductionProxyEnabled", 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 +} diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h index 43e6774..12882d4 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h @@ -32,6 +32,14 @@ class DataReductionProxyChromeSettings // get the appropriate pref service. 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: // Registers the DataReductionProxyEnabled synthetic field trial with // the group |data_reduction_proxy_enabled|. diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc index 6130eda..36a796f 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc @@ -20,8 +20,11 @@ namespace data_reduction_proxy { -// The version of the authentication protocol. -const char kProtocolVersion[] = "0"; +// The empty version for the authentication protocol. Currently used by +// Android webview. +#if defined(OS_ANDROID) +const char kAndroidWebViewProtocolVersion[] = "0"; +#endif // The clients supported by the data reduction proxy. const char kClientAndroidWebview[] = "webview"; @@ -36,14 +39,12 @@ bool DataReductionProxyAuthRequestHandler::IsKeySetOnCommandLine() { } DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler( + const std::string& client, + const std::string& version, DataReductionProxyParams* params) : data_reduction_proxy_params_(params) { - version_ = kProtocolVersion; -#if defined(OS_ANDROID) - client_ = kClientChromeAndroid; -#elif defined(OS_IOS) - client_ = kClientChromeIOS; -#endif + client_ = client; + version_ = version; Init(); } @@ -126,11 +127,7 @@ void DataReductionProxyAuthRequestHandler::InitAuthentication( << "password: [" << credentials_ << "]"; } -void DataReductionProxyAuthRequestHandler::SetKey(const std::string& key, - const std::string& client, - const std::string& version) { - client_ = client; - version_ = version; +void DataReductionProxyAuthRequestHandler::SetKey(const std::string& key) { if (!key.empty()) InitAuthentication(key); } diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h index ca913c6..17ffb37 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h @@ -20,7 +20,9 @@ class URLRequest; namespace data_reduction_proxy { -extern const char kProtocolVersion[]; +#if defined(OS_ANDROID) +extern const char kAndroidWebViewProtocolVersion[]; +#endif extern const char kClientAndroidWebview[]; extern const char kClientChromeAndroid[]; @@ -32,8 +34,14 @@ class DataReductionProxyAuthRequestHandler { public: static bool IsKeySetOnCommandLine(); - // Constructs an authentication request handler. - explicit DataReductionProxyAuthRequestHandler( + // Constructs an authentication request handler. Client is the canonical name + // 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); virtual ~DataReductionProxyAuthRequestHandler(); @@ -47,14 +55,8 @@ class DataReductionProxyAuthRequestHandler { // Sets a new authentication key. This must be called for platforms that do // not have a default key defined. See the constructor implementation for - // those platforms. Client is the canonical name 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. - void SetKey(const std::string& key, - const std::string& client, - const std::string& version); + // those platforms. + void SetKey(const std::string& key); protected: void Init(); diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc index 8b0e950..b5bc709 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc @@ -22,19 +22,35 @@ namespace { const char kChromeProxyHeader[] = "chrome-proxy"; 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 kTestKey[] = "test-key"; const char kExpectedCredentials[] = "96bd72ec4a050ba60981743d41787768"; const char kExpectedSession[] = "0-1633771873-1633771873-1633771873"; const char kTestKey2[] = "test-key2"; -const char kClient2[] = "foo"; -const char kVersion2[] = "2"; const char kExpectedCredentials2[] = "c911fdb402f578787562cf7f00eda972"; const char kExpectedSession2[] = "0-1633771873-1633771873-1633771873"; +#if defined(OS_ANDROID) const char kExpectedHeader2[] = "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"; } // namespace @@ -46,8 +62,10 @@ class TestDataReductionProxyAuthRequestHandler : public DataReductionProxyAuthRequestHandler { public: TestDataReductionProxyAuthRequestHandler( + const std::string& client, + const std::string& version, DataReductionProxyParams* params) - : DataReductionProxyAuthRequestHandler(params) {} + : DataReductionProxyAuthRequestHandler(client,version, params) {} virtual std::string GetDefaultKey() const OVERRIDE { return kTestKey; @@ -79,24 +97,18 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, Authorization) { DataReductionProxyParams::kPromoAllowed, TestDataReductionProxyParams::HAS_EVERYTHING & ~TestDataReductionProxyParams::HAS_DEV_ORIGIN)); - TestDataReductionProxyAuthRequestHandler auth_handler(params.get()); + TestDataReductionProxyAuthRequestHandler auth_handler(kClient, + kVersion, + params.get()); auth_handler.Init(); -#if defined(OS_ANDROID) - 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(auth_handler.client_, kClient); EXPECT_EQ(kVersion, auth_handler.version_); EXPECT_EQ(auth_handler.key_, kTestKey); EXPECT_EQ(kExpectedCredentials, auth_handler.credentials_); EXPECT_EQ(kExpectedSession, auth_handler.session_); // Now set a key. - auth_handler.SetKey(kTestKey2, kClient2, kVersion2); - EXPECT_EQ(kClient2, auth_handler.client_); - EXPECT_EQ(kVersion2, auth_handler.version_); + auth_handler.SetKey(kTestKey2); EXPECT_EQ(kTestKey2, auth_handler.key_); EXPECT_EQ(kExpectedCredentials2, auth_handler.credentials_); EXPECT_EQ(kExpectedSession2, auth_handler.session_); |