summaryrefslogtreecommitdiffstats
path: root/components/data_reduction_proxy
diff options
context:
space:
mode:
authormegjablon <megjablon@chromium.org>2015-02-06 00:05:43 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-06 08:07:12 +0000
commit8fbff4fad29b9e2408c634e178386d456acf6467 (patch)
tree0b8b6d0a1744921d0651975f44f7b8195bc2ccd2 /components/data_reduction_proxy
parent988f27aa96696be93821c601b09d085398c997b8 (diff)
downloadchromium_src-8fbff4fad29b9e2408c634e178386d456acf6467.zip
chromium_src-8fbff4fad29b9e2408c634e178386d456acf6467.tar.gz
chromium_src-8fbff4fad29b9e2408c634e178386d456acf6467.tar.bz2
Adding q=low to the Chrome-Proxy request header
and renaming DataReductionProxyAuthRequestHandler to DataReductionProxyRequestOptions BUG=449665 Review URL: https://codereview.chromium.org/791493015 Cr-Commit-Position: refs/heads/master@{#315000}
Diffstat (limited to 'components/data_reduction_proxy')
-rw-r--r--components/data_reduction_proxy/core/browser/BUILD.gn6
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler_unittest.cc322
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc9
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h8
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc2
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc7
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h4
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc2
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc12
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h7
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc14
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc (renamed from components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.cc)120
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h (renamed from components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h)64
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc478
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc1
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc6
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_params.h4
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc4
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h1
19 files changed, 654 insertions, 417 deletions
diff --git a/components/data_reduction_proxy/core/browser/BUILD.gn b/components/data_reduction_proxy/core/browser/BUILD.gn
index a8b7424..1d659d3 100644
--- a/components/data_reduction_proxy/core/browser/BUILD.gn
+++ b/components/data_reduction_proxy/core/browser/BUILD.gn
@@ -4,8 +4,6 @@
static_library("browser") {
sources = [
- "data_reduction_proxy_auth_request_handler.cc",
- "data_reduction_proxy_auth_request_handler.h",
"data_reduction_proxy_bypass_protocol.cc",
"data_reduction_proxy_bypass_protocol.h",
"data_reduction_proxy_config.cc",
@@ -24,6 +22,8 @@ static_library("browser") {
"data_reduction_proxy_network_delegate.h",
"data_reduction_proxy_prefs.cc",
"data_reduction_proxy_prefs.h",
+ "data_reduction_proxy_request_options.cc",
+ "data_reduction_proxy_request_options.h",
"data_reduction_proxy_settings.cc",
"data_reduction_proxy_settings.h",
"data_reduction_proxy_statistics_prefs.cc",
@@ -77,7 +77,6 @@ source_set("test_support") {
source_set("unit_tests") {
testonly = true
sources = [
- "data_reduction_proxy_auth_request_handler_unittest.cc",
"data_reduction_proxy_bypass_protocol_unittest.cc",
"data_reduction_proxy_config_unittest.cc",
"data_reduction_proxy_configurator_unittest.cc",
@@ -85,6 +84,7 @@ source_set("unit_tests") {
"data_reduction_proxy_metrics_unittest.cc",
"data_reduction_proxy_network_delegate_unittest.cc",
"data_reduction_proxy_prefs_unittest.cc",
+ "data_reduction_proxy_request_options_unittest.cc",
"data_reduction_proxy_settings_unittest.cc",
"data_reduction_proxy_usage_stats_unittest.cc",
]
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler_unittest.cc
deleted file mode 100644
index 647cac1..0000000
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler_unittest.cc
+++ /dev/null
@@ -1,322 +0,0 @@
-// Copyright 2014 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/browser/data_reduction_proxy_auth_request_handler.h"
-
-#include "base/md5.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/run_loop.h"
-#include "base/strings/string16.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/time/time.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
-#include "net/base/auth.h"
-#include "net/base/host_port_pair.h"
-#include "net/proxy/proxy_server.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace {
-const char kChromeProxyHeader[] = "chrome-proxy";
-const char kOtherProxy[] = "testproxy:17";
-
-const char kVersion[] = "0.1.2.3";
-const char kExpectedBuild[] = "2";
-const char kExpectedPatch[] = "3";
-const char kBogusVersion[] = "0.0";
-const char kTestKey[] = "test-key";
-const char kExpectedCredentials[] = "96bd72ec4a050ba60981743d41787768";
-const char kExpectedSession[] = "0-1633771873-1633771873-1633771873";
-
-const char kTestKey2[] = "test-key2";
-const char kExpectedCredentials2[] = "c911fdb402f578787562cf7f00eda972";
-const char kExpectedSession2[] = "0-1633771873-1633771873-1633771873";
-const char kDataReductionProxyKey[] = "12345";
-} // namespace
-
-
-namespace data_reduction_proxy {
-namespace {
-
-#if defined(OS_ANDROID)
-const Client kClient = Client::CHROME_ANDROID;
-const char kClientStr[] = "android";
-#elif defined(OS_IOS)
-const Client kClient = Client::CHROME_IOS;
-const char kClientStr[] = "ios";
-#elif defined(OS_MACOSX)
-const Client kClient = Client::CHROME_MAC;
-const char kClientStr[] = "mac";
-#elif defined(OS_CHROMEOS)
-const Client kClient = Client::CHROME_CHROMEOS;
-const char kClientStr[] = "chromeos";
-#elif defined(OS_LINUX)
-const Client kClient = Client::CHROME_LINUX;
-const char kClientStr[] = "linux";
-#elif defined(OS_WIN)
-const Client kClient = Client::CHROME_WINDOWS;
-const char kClientStr[] = "win";
-#elif defined(OS_FREEBSD)
-const Client kClient = Client::CHROME_FREEBSD;
-const char kClientStr[] = "freebsd";
-#elif defined(OS_OPENBSD)
-const Client kClient = Client::CHROME_OPENBSD;
-const char kClientStr[] = "openbsd";
-#elif defined(OS_SOLARIS)
-const Client kClient = Client::CHROME_SOLARIS;
-const char kClientStr[] = "solaris";
-#elif defined(OS_QNX)
-const Client kClient = Client::CHROME_QNX;
-const char kClientStr[] = "qnx";
-#else
-const Client kClient = Client::UNKNOWN;
-const char kClientStr[] = "";
-#endif
-
-const std::string kExpectedHeader2 =
- std::string("ps=0-1633771873-1633771873-1633771873, ") +
- std::string("sid=c911fdb402f578787562cf7f00eda972, b=2, p=3, c=") +
- kClientStr;
-const std::string kExpectedHeader3 =
- std::string("ps=86401-1633771873-1633771873-1633771873, ") +
- std::string("sid=d7c1c34ef6b90303b01c48a6c1db6419, b=2, p=3, c=") +
- kClientStr;
-const std::string kExpectedHeader4 =
- std::string("ps=0-1633771873-1633771873-1633771873, ") +
- std::string("sid=c911fdb402f578787562cf7f00eda972, c=") +
- kClientStr;
-
-class TestDataReductionProxyAuthRequestHandler
- : public DataReductionProxyAuthRequestHandler {
- public:
- TestDataReductionProxyAuthRequestHandler(
- Client client,
- const std::string& version,
- DataReductionProxyParams* params,
- base::MessageLoopProxy* loop_proxy)
- : DataReductionProxyAuthRequestHandler(
- client, version, params, loop_proxy) {}
-
- std::string GetDefaultKey() const override { return kTestKey; }
-
- base::Time Now() const override {
- return base::Time::UnixEpoch() + now_offset_;
- }
-
- void RandBytes(void* output, size_t length) override {
- char* c = static_cast<char*>(output);
- for (size_t i = 0; i < length; ++i) {
- c[i] = 'a';
- }
- }
-
- // Time after the unix epoch that Now() reports.
- void set_offset(const base::TimeDelta& now_offset) {
- now_offset_ = now_offset;
- }
-
- private:
- base::TimeDelta now_offset_;
-};
-
-} // namespace
-
-class DataReductionProxyAuthRequestHandlerTest : public testing::Test {
- public:
- DataReductionProxyAuthRequestHandlerTest()
- : loop_proxy_(base::MessageLoopProxy::current().get()) {
- }
- // Required for MessageLoopProxy::current().
- base::MessageLoopForUI loop_;
- base::MessageLoopProxy* loop_proxy_;
-};
-
-TEST_F(DataReductionProxyAuthRequestHandlerTest, AuthorizationOnIOThread) {
- scoped_ptr<TestDataReductionProxyParams> params;
- params.reset(
- new TestDataReductionProxyParams(
- DataReductionProxyParams::kAllowed |
- DataReductionProxyParams::kFallbackAllowed |
- DataReductionProxyParams::kPromoAllowed,
- TestDataReductionProxyParams::HAS_EVERYTHING &
- ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
- ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
- // loop_proxy_ is just the current message loop. This means loop_proxy_
- // is the network thread used by DataReductionProxyAuthRequestHandler.
- TestDataReductionProxyAuthRequestHandler auth_handler(kClient,
- kVersion,
- params.get(),
- loop_proxy_);
- auth_handler.Init();
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(auth_handler.client_, kClientStr);
- EXPECT_EQ(kExpectedBuild, auth_handler.build_number_);
- EXPECT_EQ(kExpectedPatch, auth_handler.patch_number_);
- EXPECT_EQ(auth_handler.key_, kTestKey);
- EXPECT_EQ(kExpectedCredentials, auth_handler.credentials_);
- EXPECT_EQ(kExpectedSession, auth_handler.session_);
-
- // Now set a key.
- auth_handler.InitAuthentication(kTestKey2);
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(kTestKey2, auth_handler.key_);
- EXPECT_EQ(kExpectedCredentials2, auth_handler.credentials_);
- EXPECT_EQ(kExpectedSession2, auth_handler.session_);
-
- // Don't write headers if the proxy is invalid.
- net::HttpRequestHeaders headers;
- auth_handler.MaybeAddRequestHeader(NULL, net::ProxyServer(), &headers);
- EXPECT_FALSE(headers.HasHeader(kChromeProxyHeader));
-
- // Don't write headers with a valid proxy, that's not a data reduction proxy.
- auth_handler.MaybeAddRequestHeader(
- NULL,
- net::ProxyServer::FromURI(kOtherProxy, net::ProxyServer::SCHEME_HTTP),
- &headers);
- EXPECT_FALSE(headers.HasHeader(kChromeProxyHeader));
-
- // Don't write headers with a valid data reduction ssl proxy.
- auth_handler.MaybeAddRequestHeader(
- NULL,
- net::ProxyServer::FromURI(params->DefaultSSLOrigin(),
- net::ProxyServer::SCHEME_HTTP),
- &headers);
- EXPECT_FALSE(headers.HasHeader(kChromeProxyHeader));
-
- // Write headers with a valid data reduction proxy.
- auth_handler.MaybeAddRequestHeader(
- NULL,
- net::ProxyServer::FromURI(params->DefaultOrigin(),
- net::ProxyServer::SCHEME_HTTP),
- &headers);
- EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader));
- std::string header_value;
- headers.GetHeader(kChromeProxyHeader, &header_value);
- EXPECT_EQ(kExpectedHeader2, header_value);
-
- // Write headers with a valid data reduction ssl proxy when one is expected.
- net::HttpRequestHeaders ssl_headers;
- auth_handler.MaybeAddProxyTunnelRequestHandler(
- net::ProxyServer::FromURI(
- params->DefaultSSLOrigin(),
- net::ProxyServer::SCHEME_HTTP).host_port_pair(),
- &ssl_headers);
- EXPECT_TRUE(ssl_headers.HasHeader(kChromeProxyHeader));
- std::string ssl_header_value;
- ssl_headers.GetHeader(kChromeProxyHeader, &ssl_header_value);
- EXPECT_EQ(kExpectedHeader2, ssl_header_value);
-
- // Fast forward 24 hours. The header should be the same.
- auth_handler.set_offset(base::TimeDelta::FromSeconds(24 * 60 * 60));
- net::HttpRequestHeaders headers2;
- // Write headers with a valid data reduction proxy.
- auth_handler.MaybeAddRequestHeader(
- NULL,
- net::ProxyServer::FromURI(params->DefaultOrigin(),
- net::ProxyServer::SCHEME_HTTP),
- &headers2);
- EXPECT_TRUE(headers2.HasHeader(kChromeProxyHeader));
- std::string header_value2;
- headers2.GetHeader(kChromeProxyHeader, &header_value2);
- EXPECT_EQ(kExpectedHeader2, header_value2);
-
- // Fast forward one more second. The header should be new.
- auth_handler.set_offset(base::TimeDelta::FromSeconds(24 * 60 * 60 + 1));
- net::HttpRequestHeaders headers3;
- // Write headers with a valid data reduction proxy.
- auth_handler.MaybeAddRequestHeader(
- NULL,
- net::ProxyServer::FromURI(params->DefaultOrigin(),
- net::ProxyServer::SCHEME_HTTP),
- &headers3);
- EXPECT_TRUE(headers3.HasHeader(kChromeProxyHeader));
- std::string header_value3;
- headers3.GetHeader(kChromeProxyHeader, &header_value3);
- EXPECT_EQ(kExpectedHeader3, header_value3);
-}
-
-TEST_F(DataReductionProxyAuthRequestHandlerTest, AuthorizationIgnoresEmptyKey) {
-scoped_ptr<TestDataReductionProxyParams> params;
- params.reset(
- new TestDataReductionProxyParams(
- DataReductionProxyParams::kAllowed |
- DataReductionProxyParams::kFallbackAllowed |
- DataReductionProxyParams::kPromoAllowed,
- TestDataReductionProxyParams::HAS_EVERYTHING &
- ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
- ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
- // loop_proxy_ is just the current message loop. This means loop_proxy_
- // is the network thread used by DataReductionProxyAuthRequestHandler.
- TestDataReductionProxyAuthRequestHandler auth_handler(kClient,
- kVersion,
- params.get(),
- loop_proxy_);
- auth_handler.Init();
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(auth_handler.client_, kClientStr);
- EXPECT_EQ(kExpectedBuild, auth_handler.build_number_);
- EXPECT_EQ(kExpectedPatch, auth_handler.patch_number_);
- EXPECT_EQ(auth_handler.key_, kTestKey);
- EXPECT_EQ(kExpectedCredentials, auth_handler.credentials_);
- EXPECT_EQ(kExpectedSession, auth_handler.session_);
-
- // Now set an empty key. The auth handler should ignore that, and the key
- // remains |kTestKey|.
- auth_handler.InitAuthentication("");
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(auth_handler.key_, kTestKey);
- EXPECT_EQ(kExpectedCredentials, auth_handler.credentials_);
- EXPECT_EQ(kExpectedSession, auth_handler.session_);
-}
-
-TEST_F(DataReductionProxyAuthRequestHandlerTest, AuthorizationBogusVersion) {
- scoped_ptr<TestDataReductionProxyParams> params;
- params.reset(
- new TestDataReductionProxyParams(
- DataReductionProxyParams::kAllowed |
- DataReductionProxyParams::kFallbackAllowed |
- DataReductionProxyParams::kPromoAllowed,
- TestDataReductionProxyParams::HAS_EVERYTHING &
- ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
- ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
- TestDataReductionProxyAuthRequestHandler auth_handler(kClient,
- kBogusVersion,
- params.get(),
- loop_proxy_);
- EXPECT_TRUE(auth_handler.build_number_.empty());
- EXPECT_TRUE(auth_handler.patch_number_.empty());
-
- // Now set a key.
- auth_handler.InitAuthentication(kTestKey2);
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(kTestKey2, auth_handler.key_);
- EXPECT_EQ(kExpectedCredentials2, auth_handler.credentials_);
- EXPECT_EQ(kExpectedSession2, auth_handler.session_);
-
- net::HttpRequestHeaders headers;
- // Write headers with a valid data reduction proxy;
- auth_handler.MaybeAddRequestHeader(
- NULL,
- net::ProxyServer::FromURI(
- params->DefaultOrigin(),
- net::ProxyServer::SCHEME_HTTP),
- &headers);
- EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader));
- std::string header_value;
- headers.GetHeader(kChromeProxyHeader, &header_value);
- EXPECT_EQ(kExpectedHeader4, header_value);
-}
-
-TEST_F(DataReductionProxyAuthRequestHandlerTest, AuthHashForSalt) {
- std::string salt = "8675309"; // Jenny's number to test the hash generator.
- std::string salted_key = salt + kDataReductionProxyKey + salt;
- base::string16 expected_hash = base::UTF8ToUTF16(base::MD5String(salted_key));
- EXPECT_EQ(expected_hash,
- DataReductionProxyAuthRequestHandler::AuthHashForSalt(
- 8675309, kDataReductionProxyKey));
-}
-
-} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc
index d990f26..9ea835f 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.cc
@@ -14,11 +14,11 @@
namespace data_reduction_proxy {
DataReductionProxyDelegate::DataReductionProxyDelegate(
- DataReductionProxyAuthRequestHandler* auth_handler,
+ DataReductionProxyRequestOptions* request_options,
DataReductionProxyParams* params)
- : auth_handler_(auth_handler),
+ : request_options_(request_options),
params_(params) {
- DCHECK(auth_handler);
+ DCHECK(request_options);
DCHECK(params);
}
@@ -55,7 +55,8 @@ void DataReductionProxyDelegate::OnBeforeSendHeaders(
void DataReductionProxyDelegate::OnBeforeTunnelRequest(
const net::HostPortPair& proxy_server,
net::HttpRequestHeaders* extra_headers) {
- auth_handler_->MaybeAddProxyTunnelRequestHandler(proxy_server, extra_headers);
+ request_options_->MaybeAddProxyTunnelRequestHandler(
+ proxy_server, extra_headers);
}
void DataReductionProxyDelegate::OnTunnelHeadersReceived(
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h
index c803627..53c3308 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h
@@ -5,7 +5,7 @@
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_DELEGATE_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_DELEGATE_H_
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
#include "net/base/proxy_delegate.h"
#include "url/gurl.h"
@@ -21,14 +21,14 @@ class URLRequest;
namespace data_reduction_proxy {
-class DataReductionProxyAuthRequestHandler;
+class DataReductionProxyRequestOptions;
class DataReductionProxyDelegate : public net::ProxyDelegate {
public:
// ProxyDelegate instance is owned by io_thread. |auth_handler| and |params|
// outlives this class instance.
explicit DataReductionProxyDelegate(
- DataReductionProxyAuthRequestHandler* auth_handler,
+ DataReductionProxyRequestOptions* request_options,
DataReductionProxyParams* params);
~DataReductionProxyDelegate() override;
@@ -57,7 +57,7 @@ class DataReductionProxyDelegate : public net::ProxyDelegate {
const net::HttpResponseHeaders& response_headers) override;
private:
- DataReductionProxyAuthRequestHandler* auth_handler_;
+ DataReductionProxyRequestOptions* request_options_;
const DataReductionProxyParams* params_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyDelegate);
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
index 9bbca1b..c8ef3b8 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
@@ -11,8 +11,8 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
index 71d206e..bbd51ea 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
@@ -8,7 +8,6 @@
#include "base/command_line.h"
#include "base/prefs/pref_member.h"
#include "base/single_thread_task_runner.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h"
@@ -42,14 +41,14 @@ DataReductionProxyIOData::DataReductionProxyIOData(
DCHECK(io_task_runner_.get());
DCHECK(ui_task_runner_.get());
params_ = settings->params()->Clone();
- auth_request_handler_.reset(new DataReductionProxyAuthRequestHandler(
+ request_options_.reset(new DataReductionProxyRequestOptions(
client_, params_.get(), io_task_runner_));
event_store_.reset(new DataReductionProxyEventStore(ui_task_runner));
configurator_.reset(new DataReductionProxyConfigurator(
io_task_runner, net_log, event_store_.get()));
proxy_delegate_.reset(
new data_reduction_proxy::DataReductionProxyDelegate(
- auth_request_handler_.get(), params_.get()));
+ request_options_.get(), params_.get()));
}
DataReductionProxyIOData::~DataReductionProxyIOData() {
@@ -104,7 +103,7 @@ DataReductionProxyIOData::CreateNetworkDelegate(
scoped_ptr<DataReductionProxyNetworkDelegate> network_delegate(
new DataReductionProxyNetworkDelegate(
wrapped_network_delegate.Pass(), params_.get(),
- auth_request_handler_.get(), configurator_.get()));
+ request_options_.get(), configurator_.get()));
if (track_proxy_bypass_statistics && !usage_stats_) {
usage_stats_.reset(
new data_reduction_proxy::DataReductionProxyUsageStats(
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h
index b679892..cee8fa5 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h
@@ -7,9 +7,9 @@
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_member.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h"
#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"
namespace net {
class NetLog;
@@ -125,7 +125,7 @@ class DataReductionProxyIOData {
scoped_ptr<DataReductionProxyUsageStats> usage_stats_;
// Constructs credentials suitable for authenticating the client.
- scoped_ptr<DataReductionProxyAuthRequestHandler> auth_request_handler_;
+ scoped_ptr<DataReductionProxyRequestOptions> request_options_;
// A net log.
net::NetLog* net_log_;
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc
index 641f625..c735119 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc
@@ -11,8 +11,8 @@
#include "base/prefs/testing_pref_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
index b925211..739e738 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
@@ -10,8 +10,8 @@
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h"
#include "net/base/load_flags.h"
@@ -74,7 +74,7 @@ namespace data_reduction_proxy {
DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate(
scoped_ptr<net::NetworkDelegate> network_delegate,
DataReductionProxyParams* params,
- DataReductionProxyAuthRequestHandler* handler,
+ DataReductionProxyRequestOptions* request_options,
const DataReductionProxyConfigurator* configurator)
: LayeredNetworkDelegate(network_delegate.Pass()),
ui_task_runner_(NULL),
@@ -83,11 +83,11 @@ DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate(
data_reduction_proxy_enabled_(NULL),
data_reduction_proxy_params_(params),
data_reduction_proxy_usage_stats_(NULL),
- data_reduction_proxy_auth_request_handler_(handler),
+ data_reduction_proxy_request_options_(request_options),
data_reduction_proxy_statistics_prefs_(NULL),
configurator_(configurator) {
DCHECK(data_reduction_proxy_params_);
- DCHECK(data_reduction_proxy_auth_request_handler_);
+ DCHECK(data_reduction_proxy_request_options_);
}
DataReductionProxyNetworkDelegate::~DataReductionProxyNetworkDelegate() {
@@ -162,8 +162,8 @@ void DataReductionProxyNetworkDelegate::OnBeforeSendProxyHeadersInternal(
net::URLRequest* request,
const net::ProxyInfo& proxy_info,
net::HttpRequestHeaders* headers) {
- if (data_reduction_proxy_auth_request_handler_) {
- data_reduction_proxy_auth_request_handler_->MaybeAddRequestHeader(
+ if (data_reduction_proxy_request_options_) {
+ data_reduction_proxy_request_options_->MaybeAddRequestHeader(
request, proxy_info.proxy_server(), headers);
}
}
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h
index 7da1858..3b8fbab 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h
@@ -37,9 +37,9 @@ class URLRequest;
namespace data_reduction_proxy {
-class DataReductionProxyAuthRequestHandler;
class DataReductionProxyConfigurator;
class DataReductionProxyParams;
+class DataReductionProxyRequestOptions;
class DataReductionProxyStatisticsPrefs;
class DataReductionProxyUsageStats;
@@ -60,7 +60,7 @@ class DataReductionProxyNetworkDelegate : public net::LayeredNetworkDelegate {
DataReductionProxyNetworkDelegate(
scoped_ptr<net::NetworkDelegate> network_delegate,
DataReductionProxyParams* params,
- DataReductionProxyAuthRequestHandler* handler,
+ DataReductionProxyRequestOptions* handler,
const DataReductionProxyConfigurator* configurator);
~DataReductionProxyNetworkDelegate() override;
@@ -137,8 +137,7 @@ class DataReductionProxyNetworkDelegate : public net::LayeredNetworkDelegate {
// Must outlive this DataReductionProxyNetworkDelegate.
DataReductionProxyUsageStats* data_reduction_proxy_usage_stats_;
- DataReductionProxyAuthRequestHandler*
- data_reduction_proxy_auth_request_handler_;
+ DataReductionProxyRequestOptions* data_reduction_proxy_request_options_;
DataReductionProxyStatisticsPrefs* data_reduction_proxy_statistics_prefs_;
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc
index 46e235e..1b87c9c 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc
@@ -14,8 +14,8 @@
#include "base/strings/string_number_conversions.h"
#include "base/test/histogram_tester.h"
#include "base/time/time.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.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_store.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
@@ -153,8 +153,8 @@ TEST_F(DataReductionProxyNetworkDelegateTest, AuthenticationTest) {
~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
// loop_proxy_ is just the current message loop. This means loop_proxy_
- // is the network thread used by DataReductionProxyAuthRequestHandler.
- DataReductionProxyAuthRequestHandler auth_handler(
+ // is the network thread used by DataReductionProxyRequestOptions.
+ DataReductionProxyRequestOptions request_options(
kClient, params.get(), message_loop_proxy());
scoped_ptr<DataReductionProxyConfigurator> configurator(
@@ -164,7 +164,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, AuthenticationTest) {
scoped_ptr<DataReductionProxyNetworkDelegate> network_delegate(
new DataReductionProxyNetworkDelegate(
scoped_ptr<net::NetworkDelegate>(new TestNetworkDelegate()),
- params.get(), &auth_handler,
+ params.get(), &request_options,
configurator.get()));
set_network_delegate(network_delegate.get());
@@ -217,8 +217,8 @@ TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) {
~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
// loop_proxy_ is just the current message loop. This means loop_proxy_
- // is the network thread used by DataReductionProxyAuthRequestHandler.
- DataReductionProxyAuthRequestHandler auth_handler(
+ // is the network thread used by DataReductionProxyRequestOptions.
+ DataReductionProxyRequestOptions request_options(
kClient, params.get(), message_loop_proxy());
base::HistogramTester histogram_tester;
@@ -228,7 +228,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) {
scoped_ptr<DataReductionProxyNetworkDelegate> network_delegate(
new DataReductionProxyNetworkDelegate(
scoped_ptr<net::NetworkDelegate>(
- new TestNetworkDelegate()), params.get(), &auth_handler,
+ new TestNetworkDelegate()), params.get(), &request_options,
configurator.get()));
set_network_delegate(network_delegate.get());
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
index 768db66..74fac43 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
@@ -2,12 +2,15 @@
// 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/browser/data_reduction_proxy_auth_request_handler.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
+
+#include <vector>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
@@ -45,37 +48,40 @@ const char* GetString(Client client) {
#undef CLIENT_ENUM
// static
-bool DataReductionProxyAuthRequestHandler::IsKeySetOnCommandLine() {
+bool DataReductionProxyRequestOptions::IsKeySetOnCommandLine() {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
return command_line.HasSwitch(
data_reduction_proxy::switches::kDataReductionProxyKey);
}
-DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler(
+DataReductionProxyRequestOptions::DataReductionProxyRequestOptions(
Client client,
DataReductionProxyParams* params,
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
- : client_(GetString(client)),
- data_reduction_proxy_params_(params),
+ : data_reduction_proxy_params_(params),
network_task_runner_(network_task_runner) {
- GetChromiumBuildAndPatch(ChromiumVersion(), &build_number_, &patch_number_);
Init();
+ UpdateLoFi();
+ UpdateVersion(client, ChromiumVersion());
}
-DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler(
+DataReductionProxyRequestOptions::DataReductionProxyRequestOptions(
Client client,
const std::string& version,
DataReductionProxyParams* params,
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
- : client_(GetString(client)),
- data_reduction_proxy_params_(params),
+ : data_reduction_proxy_params_(params),
network_task_runner_(network_task_runner) {
- GetChromiumBuildAndPatch(version, &build_number_, &patch_number_);
Init();
+ UpdateLoFi();
+ UpdateVersion(client, version);
+}
+
+DataReductionProxyRequestOptions::~DataReductionProxyRequestOptions() {
}
-std::string DataReductionProxyAuthRequestHandler::ChromiumVersion() const {
+std::string DataReductionProxyRequestOptions::ChromiumVersion() const {
#if defined(PRODUCT_VERSION)
return PRODUCT_VERSION;
#else
@@ -83,8 +89,7 @@ std::string DataReductionProxyAuthRequestHandler::ChromiumVersion() const {
#endif
}
-
-void DataReductionProxyAuthRequestHandler::GetChromiumBuildAndPatch(
+void DataReductionProxyRequestOptions::GetChromiumBuildAndPatch(
const std::string& version,
std::string* build,
std::string* patch) const {
@@ -96,16 +101,43 @@ void DataReductionProxyAuthRequestHandler::GetChromiumBuildAndPatch(
*patch = version_parts[3];
}
-void DataReductionProxyAuthRequestHandler::Init() {
- InitAuthentication(GetDefaultKey());
+void DataReductionProxyRequestOptions::UpdateVersion(
+ const Client& client, const std::string& version) {
+ std::string build_number;
+ std::string patch_number;
+ GetChromiumBuildAndPatch(version, &build_number, &patch_number);
+ if (!build_number.empty() && !patch_number.empty()) {
+ header_options_[kBuildNumberHeaderOption] = build_number;
+ header_options_[kPatchNumberHeaderOption] = patch_number;
+ }
+ std::string client_string = GetString(client);
+ if (!client_string.empty())
+ header_options_[kClientHeaderOption] = client_string;
+ RegenerateRequestHeaderValue();
}
+void DataReductionProxyRequestOptions::UpdateLoFi() {
+ // LoFi was not enabled, but now is. Add the header option.
+ if (header_options_.find(kLoFiHeaderOption) == header_options_.end() &&
+ DataReductionProxyParams::IsDataReductionProxyLoFiEnabled()) {
+ header_options_[kLoFiHeaderOption] = "low";
+ RegenerateRequestHeaderValue();
+ return;
+ }
+ // LoFi was enabled, but no longer is. Remove the header option.
+ if (header_options_.find(kLoFiHeaderOption) != header_options_.end() &&
+ !DataReductionProxyParams::IsDataReductionProxyLoFiEnabled()) {
+ header_options_.erase(kLoFiHeaderOption);
+ RegenerateRequestHeaderValue();
+ }
+}
-DataReductionProxyAuthRequestHandler::~DataReductionProxyAuthRequestHandler() {
+void DataReductionProxyRequestOptions::Init() {
+ InitAuthentication(GetDefaultKey());
}
// static
-base::string16 DataReductionProxyAuthRequestHandler::AuthHashForSalt(
+base::string16 DataReductionProxyRequestOptions::AuthHashForSalt(
int64 salt,
const std::string& key) {
std::string salted_key =
@@ -118,16 +150,15 @@ base::string16 DataReductionProxyAuthRequestHandler::AuthHashForSalt(
-base::Time DataReductionProxyAuthRequestHandler::Now() const {
+base::Time DataReductionProxyRequestOptions::Now() const {
return base::Time::Now();
}
-void DataReductionProxyAuthRequestHandler::RandBytes(
- void* output, size_t length) {
+void DataReductionProxyRequestOptions::RandBytes(void* output, size_t length) {
crypto::RandBytes(output, length);
}
-void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeader(
+void DataReductionProxyRequestOptions::MaybeAddRequestHeader(
net::URLRequest* request,
const net::ProxyServer& proxy_server,
net::HttpRequestHeaders* request_headers) {
@@ -141,20 +172,22 @@ void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeader(
request_headers);
}
-void DataReductionProxyAuthRequestHandler::MaybeAddProxyTunnelRequestHandler(
+void DataReductionProxyRequestOptions::MaybeAddProxyTunnelRequestHandler(
const net::HostPortPair& proxy_server,
net::HttpRequestHeaders* request_headers) {
DCHECK(network_task_runner_->BelongsToCurrentThread());
MaybeAddRequestHeaderImpl(proxy_server, true, request_headers);
}
-void DataReductionProxyAuthRequestHandler::AddAuthorizationHeader(
+void DataReductionProxyRequestOptions::SetHeader(
net::HttpRequestHeaders* headers) {
base::Time now = Now();
+ // Authorization credentials must be regenerated at least every 24 hours.
if (now - last_update_time_ > base::TimeDelta::FromHours(24)) {
last_update_time_ = now;
- ComputeCredentials(last_update_time_, &session_, &credentials_);
+ UpdateCredentials();
}
+ UpdateLoFi();
const char kChromeProxyHeader[] = "Chrome-Proxy";
std::string header_value;
if (headers->HasHeader(kChromeProxyHeader)) {
@@ -162,16 +195,11 @@ void DataReductionProxyAuthRequestHandler::AddAuthorizationHeader(
headers->RemoveHeader(kChromeProxyHeader);
header_value += ", ";
}
- header_value +=
- "ps=" + session_ + ", sid=" + credentials_;
- if (!build_number_.empty() && !patch_number_.empty())
- header_value += ", b=" + build_number_ + ", p=" + patch_number_;
- if (!client_.empty())
- header_value += ", c=" + client_;
+ header_value += header_value_;
headers->SetHeader(kChromeProxyHeader, header_value);
}
-void DataReductionProxyAuthRequestHandler::ComputeCredentials(
+void DataReductionProxyRequestOptions::ComputeCredentials(
const base::Time& now,
std::string* session,
std::string* credentials) {
@@ -193,12 +221,21 @@ void DataReductionProxyAuthRequestHandler::ComputeCredentials(
<< "password: [" << *credentials << "]";
}
-void DataReductionProxyAuthRequestHandler::InitAuthentication(
+void DataReductionProxyRequestOptions::UpdateCredentials() {
+ std::string session;
+ std::string credentials;
+ ComputeCredentials(last_update_time_, &session, &credentials);
+ header_options_[kSessionHeaderOption] = session;
+ header_options_[kCredentialsHeaderOption] = credentials;
+ RegenerateRequestHeaderValue();
+}
+
+void DataReductionProxyRequestOptions::InitAuthentication(
const std::string& key) {
if (!network_task_runner_->BelongsToCurrentThread()) {
network_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&DataReductionProxyAuthRequestHandler::InitAuthentication,
+ base::Bind(&DataReductionProxyRequestOptions::InitAuthentication,
base::Unretained(this),
key));
return;
@@ -209,10 +246,10 @@ void DataReductionProxyAuthRequestHandler::InitAuthentication(
key_ = key;
last_update_time_ = Now();
- ComputeCredentials(last_update_time_, &session_, &credentials_);
+ UpdateCredentials();
}
-std::string DataReductionProxyAuthRequestHandler::GetDefaultKey() const {
+std::string DataReductionProxyRequestOptions::GetDefaultKey() const {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
std::string key =
@@ -232,7 +269,7 @@ std::string DataReductionProxyAuthRequestHandler::GetDefaultKey() const {
return key;
}
-void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeaderImpl(
+void DataReductionProxyRequestOptions::MaybeAddRequestHeaderImpl(
const net::HostPortPair& proxy_server,
bool expect_ssl,
net::HttpRequestHeaders* request_headers) {
@@ -243,8 +280,17 @@ void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeaderImpl(
((data_reduction_proxy_params_->ssl_origin().is_valid() &&
data_reduction_proxy_params_->ssl_origin().host_port_pair().Equals(
proxy_server)) == expect_ssl)) {
- AddAuthorizationHeader(request_headers);
+ SetHeader(request_headers);
+ }
+}
+
+void DataReductionProxyRequestOptions::RegenerateRequestHeaderValue() {
+ std::vector <std::string> options;
+ for (std::map<std::string, std::string>::iterator
+ it = header_options_.begin(); it != header_options_.end(); ++it) {
+ options.push_back(it->first + "=" + it->second);
}
+ header_value_ = JoinString(options, ", ");
}
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h
index 4675ec4e..a862cd6 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h
@@ -5,6 +5,9 @@
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUEST_HANDLER_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUEST_HANDLER_H_
+#include <map>
+#include <string>
+
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/strings/string16.h"
@@ -24,6 +27,13 @@ class URLRequest;
namespace data_reduction_proxy {
+const char kSessionHeaderOption[] = "ps";
+const char kCredentialsHeaderOption[] = "sid";
+const char kBuildNumberHeaderOption[] = "b";
+const char kPatchNumberHeaderOption[] = "p";
+const char kClientHeaderOption[] = "c";
+const char kLoFiHeaderOption[] = "q";
+
#if defined(OS_ANDROID)
extern const char kAndroidWebViewProtocolVersion[];
#endif
@@ -50,18 +60,18 @@ typedef enum {
class DataReductionProxyParams;
-class DataReductionProxyAuthRequestHandler {
+class DataReductionProxyRequestOptions {
public:
static bool IsKeySetOnCommandLine();
- // Constructs a DataReductionProxyAuthRequestHandler object with the given
+ // Constructs a DataReductionProxyRequestOptions object with the given
// client type, params, and network task runner.
- DataReductionProxyAuthRequestHandler(
+ DataReductionProxyRequestOptions(
Client client,
DataReductionProxyParams* params,
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner);
- virtual ~DataReductionProxyAuthRequestHandler();
+ virtual ~DataReductionProxyRequestOptions();
// Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction
// proxy authentication credentials. Only adds this header if the provided
@@ -91,7 +101,7 @@ class DataReductionProxyAuthRequestHandler {
protected:
void Init();
- void AddAuthorizationHeader(net::HttpRequestHeaders* headers);
+ void SetHeader(net::HttpRequestHeaders* headers);
// Returns a UTF16 string that's the hash of the configured authentication
// |key| and |salt|. Returns an empty UTF16 string if no key is configured or
@@ -106,21 +116,25 @@ class DataReductionProxyAuthRequestHandler {
virtual std::string GetDefaultKey() const;
// Visible for testing.
- DataReductionProxyAuthRequestHandler(
+ DataReductionProxyRequestOptions(
Client client,
const std::string& version,
DataReductionProxyParams* params,
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner);
private:
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest,
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxyRequestOptionsTest,
AuthorizationOnIOThread);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest,
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxyRequestOptionsTest,
AuthorizationIgnoresEmptyKey);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest,
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxyRequestOptionsTest,
AuthorizationBogusVersion);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest,
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxyRequestOptionsTest,
AuthHashForSalt);
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxyRequestOptionsTest,
+ AuthorizationLoFi);
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxyRequestOptionsTest,
+ AuthorizationLoFiOffThenOn);
// Returns the version of Chromium that is being used.
std::string ChromiumVersion() const;
@@ -131,12 +145,22 @@ class DataReductionProxyAuthRequestHandler {
std::string* build,
std::string* patch) const;
+ // Gets the version and client values and updates them in |header_options_|.
+ void UpdateVersion(const Client& client, const std::string& version);
+
+ // Updates the value of LoFi in |header_options_| and regenerates the header
+ // if necessary.
+ void UpdateLoFi();
+
// Generates a session ID and credentials suitable for authenticating with
// the data reduction proxy.
void ComputeCredentials(const base::Time& now,
std::string* session,
std::string* credentials);
+ // Generates and updates the session ID and credentials in |header_options_|.
+ void UpdateCredentials();
+
// Adds authentication headers only if |expects_ssl| is true and
// |proxy_server| is a data reduction proxy used for ssl tunneling via
// HTTP CONNECT, or |expect_ssl| is false and |proxy_server| is a data
@@ -145,18 +169,16 @@ class DataReductionProxyAuthRequestHandler {
bool expect_ssl,
net::HttpRequestHeaders* request_headers);
- // Authentication state.
- std::string key_;
+ // Regenerates the |header_value_| string which is concatenated to the
+ // Chrome-proxy header.
+ void RegenerateRequestHeaderValue();
- // Lives on the IO thread.
- std::string session_;
- std::string credentials_;
+ // Map and string of the request options to be added to the header.
+ std::map<std::string, std::string> header_options_;
+ std::string header_value_;
- // Name of the client and version of the data reduction proxy protocol to use.
- // Both live on the IO thread.
- std::string client_;
- std::string build_number_;
- std::string patch_number_;
+ // Authentication state.
+ std::string key_;
// The last time the session was updated. Used to ensure that a session is
// never used for more than twenty-four hours.
@@ -166,7 +188,7 @@ class DataReductionProxyAuthRequestHandler {
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
- DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler);
+ DISALLOW_COPY_AND_ASSIGN(DataReductionProxyRequestOptions);
};
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc
new file mode 100644
index 0000000..982f8a0
--- /dev/null
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc
@@ -0,0 +1,478 @@
+// Copyright 2014 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/browser/data_reduction_proxy_request_options.h"
+
+#include "base/command_line.h"
+#include "base/md5.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/run_loop.h"
+#include "base/strings/string16.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/time/time.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
+#include "net/base/auth.h"
+#include "net/base/host_port_pair.h"
+#include "net/proxy/proxy_server.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+const char kChromeProxyHeader[] = "chrome-proxy";
+const char kOtherProxy[] = "testproxy:17";
+
+const char kVersion[] = "0.1.2.3";
+const char kExpectedBuild[] = "2";
+const char kExpectedPatch[] = "3";
+const char kBogusVersion[] = "0.0";
+const char kTestKey[] = "test-key";
+const char kExpectedCredentials[] = "96bd72ec4a050ba60981743d41787768";
+const char kExpectedSession[] = "0-1633771873-1633771873-1633771873";
+
+const char kTestKey2[] = "test-key2";
+const char kExpectedCredentials2[] = "c911fdb402f578787562cf7f00eda972";
+const char kExpectedSession2[] = "0-1633771873-1633771873-1633771873";
+const char kDataReductionProxyKey[] = "12345";
+} // namespace
+
+
+namespace data_reduction_proxy {
+namespace {
+
+#if defined(OS_ANDROID)
+const Client kClient = Client::CHROME_ANDROID;
+const char kClientStr[] = "android";
+#elif defined(OS_IOS)
+const Client kClient = Client::CHROME_IOS;
+const char kClientStr[] = "ios";
+#elif defined(OS_MACOSX)
+const Client kClient = Client::CHROME_MAC;
+const char kClientStr[] = "mac";
+#elif defined(OS_CHROMEOS)
+const Client kClient = Client::CHROME_CHROMEOS;
+const char kClientStr[] = "chromeos";
+#elif defined(OS_LINUX)
+const Client kClient = Client::CHROME_LINUX;
+const char kClientStr[] = "linux";
+#elif defined(OS_WIN)
+const Client kClient = Client::CHROME_WINDOWS;
+const char kClientStr[] = "win";
+#elif defined(OS_FREEBSD)
+const Client kClient = Client::CHROME_FREEBSD;
+const char kClientStr[] = "freebsd";
+#elif defined(OS_OPENBSD)
+const Client kClient = Client::CHROME_OPENBSD;
+const char kClientStr[] = "openbsd";
+#elif defined(OS_SOLARIS)
+const Client kClient = Client::CHROME_SOLARIS;
+const char kClientStr[] = "solaris";
+#elif defined(OS_QNX)
+const Client kClient = Client::CHROME_QNX;
+const char kClientStr[] = "qnx";
+#else
+const Client kClient = Client::UNKNOWN;
+const char kClientStr[] = "";
+#endif
+
+class TestDataReductionProxyRequestOptions
+ : public DataReductionProxyRequestOptions {
+ public:
+ TestDataReductionProxyRequestOptions(
+ Client client,
+ const std::string& version,
+ DataReductionProxyParams* params,
+ base::MessageLoopProxy* loop_proxy)
+ : DataReductionProxyRequestOptions(
+ client, version, params, loop_proxy) {}
+
+ std::string GetDefaultKey() const override { return kTestKey; }
+
+ base::Time Now() const override {
+ return base::Time::UnixEpoch() + now_offset_;
+ }
+
+ void RandBytes(void* output, size_t length) override {
+ char* c = static_cast<char*>(output);
+ for (size_t i = 0; i < length; ++i) {
+ c[i] = 'a';
+ }
+ }
+
+ // Time after the unix epoch that Now() reports.
+ void set_offset(const base::TimeDelta& now_offset) {
+ now_offset_ = now_offset;
+ }
+
+ private:
+ base::TimeDelta now_offset_;
+};
+
+} // namespace
+
+class DataReductionProxyRequestOptionsTest : public testing::Test {
+ public:
+ DataReductionProxyRequestOptionsTest()
+ : loop_proxy_(base::MessageLoopProxy::current().get()) {
+ }
+
+ std::map<std::string, std::string> ParseHeader(std::string header) {
+ std::map<std::string, std::string> header_options;
+ size_t pos = 0;
+ std::string name;
+ std::string value;
+ std::string equals_delimiter = "=";
+ std::string comma_delimiter = ", ";
+ while ((pos = header.find(equals_delimiter)) != std::string::npos) {
+ name = header.substr(0, pos);
+ header.erase(0, pos + equals_delimiter.length());
+ pos = header.find(comma_delimiter);
+ if (pos != std::string::npos) {
+ value = header.substr(0, pos);
+ header.erase(0, pos + comma_delimiter.length());
+ header_options[name] = value;
+ }
+ }
+
+ if (!header.empty())
+ header_options[name] = header;
+
+ return header_options;
+ }
+
+ // Required for MessageLoopProxy::current().
+ base::MessageLoopForUI loop_;
+ base::MessageLoopProxy* loop_proxy_;
+};
+
+TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationOnIOThread) {
+ std::map<std::string, std::string> kExpectedHeader;
+ kExpectedHeader[kSessionHeaderOption] = kExpectedSession2;
+ kExpectedHeader[kCredentialsHeaderOption] = kExpectedCredentials2;
+ kExpectedHeader[kBuildNumberHeaderOption] = "2";
+ kExpectedHeader[kPatchNumberHeaderOption] = "3";
+ kExpectedHeader[kClientHeaderOption] = kClientStr;
+
+ std::map<std::string, std::string> kExpectedHeader2;
+ kExpectedHeader2[kSessionHeaderOption] =
+ "86401-1633771873-1633771873-1633771873";
+ kExpectedHeader2[kCredentialsHeaderOption] =
+ "d7c1c34ef6b90303b01c48a6c1db6419";
+ kExpectedHeader2[kBuildNumberHeaderOption] = "2";
+ kExpectedHeader2[kPatchNumberHeaderOption] = "3";
+ kExpectedHeader2[kClientHeaderOption] = kClientStr;
+
+ scoped_ptr<TestDataReductionProxyParams> params;
+ params.reset(
+ new TestDataReductionProxyParams(
+ DataReductionProxyParams::kAllowed |
+ DataReductionProxyParams::kFallbackAllowed |
+ DataReductionProxyParams::kPromoAllowed,
+ TestDataReductionProxyParams::HAS_EVERYTHING &
+ ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
+ ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
+ // loop_proxy_ is just the current message loop. This means loop_proxy_
+ // is the network thread used by DataReductionProxyRequestOptions.
+ TestDataReductionProxyRequestOptions request_options(kClient,
+ kVersion,
+ params.get(),
+ loop_proxy_);
+ request_options.Init();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(kExpectedBuild,
+ request_options.header_options_[kBuildNumberHeaderOption]);
+ EXPECT_EQ(kExpectedPatch,
+ request_options.header_options_[kPatchNumberHeaderOption]);
+ EXPECT_EQ(request_options.key_, kTestKey);
+ EXPECT_EQ(kExpectedCredentials,
+ request_options.header_options_[kCredentialsHeaderOption]);
+ EXPECT_EQ(kExpectedSession,
+ request_options.header_options_[kSessionHeaderOption]);
+ EXPECT_EQ(kClientStr, request_options.header_options_[kClientHeaderOption]);
+
+ // Now set a key.
+ request_options.InitAuthentication(kTestKey2);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(kTestKey2, request_options.key_);
+ EXPECT_EQ(kExpectedCredentials2,
+ request_options.header_options_[kCredentialsHeaderOption]);
+ EXPECT_EQ(kExpectedSession2,
+ request_options.header_options_[kSessionHeaderOption]);
+
+ // Don't write headers if the proxy is invalid.
+ net::HttpRequestHeaders headers;
+ request_options.MaybeAddRequestHeader(NULL, net::ProxyServer(), &headers);
+ EXPECT_FALSE(headers.HasHeader(kChromeProxyHeader));
+
+ // Don't write headers with a valid proxy, that's not a data reduction proxy.
+ request_options.MaybeAddRequestHeader(
+ NULL,
+ net::ProxyServer::FromURI(kOtherProxy, net::ProxyServer::SCHEME_HTTP),
+ &headers);
+ EXPECT_FALSE(headers.HasHeader(kChromeProxyHeader));
+
+ // Don't write headers with a valid data reduction ssl proxy.
+ request_options.MaybeAddRequestHeader(
+ NULL,
+ net::ProxyServer::FromURI(params->DefaultSSLOrigin(),
+ net::ProxyServer::SCHEME_HTTP),
+ &headers);
+ EXPECT_FALSE(headers.HasHeader(kChromeProxyHeader));
+
+ // Write headers with a valid data reduction proxy.
+ request_options.MaybeAddRequestHeader(
+ NULL,
+ net::ProxyServer::FromURI(params->DefaultOrigin(),
+ net::ProxyServer::SCHEME_HTTP),
+ &headers);
+ EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader));
+ std::string header_value;
+ headers.GetHeader(kChromeProxyHeader, &header_value);
+ EXPECT_EQ(kExpectedHeader, ParseHeader(header_value));
+
+ // Write headers with a valid data reduction ssl proxy when one is expected.
+ net::HttpRequestHeaders ssl_headers;
+ request_options.MaybeAddProxyTunnelRequestHandler(
+ net::ProxyServer::FromURI(
+ params->DefaultSSLOrigin(),
+ net::ProxyServer::SCHEME_HTTP).host_port_pair(),
+ &ssl_headers);
+ EXPECT_TRUE(ssl_headers.HasHeader(kChromeProxyHeader));
+ std::string ssl_header_value;
+ ssl_headers.GetHeader(kChromeProxyHeader, &ssl_header_value);
+ EXPECT_EQ(kExpectedHeader, ParseHeader(ssl_header_value));
+
+ // Fast forward 24 hours. The header should be the same.
+ request_options.set_offset(base::TimeDelta::FromSeconds(24 * 60 * 60));
+ net::HttpRequestHeaders headers2;
+ // Write headers with a valid data reduction proxy.
+ request_options.MaybeAddRequestHeader(
+ NULL,
+ net::ProxyServer::FromURI(params->DefaultOrigin(),
+ net::ProxyServer::SCHEME_HTTP),
+ &headers2);
+ EXPECT_TRUE(headers2.HasHeader(kChromeProxyHeader));
+ std::string header_value2;
+ headers2.GetHeader(kChromeProxyHeader, &header_value2);
+ EXPECT_EQ(kExpectedHeader, ParseHeader(header_value2));
+
+ // Fast forward one more second. The header should be new.
+ request_options.set_offset(base::TimeDelta::FromSeconds(24 * 60 * 60 + 1));
+ net::HttpRequestHeaders headers3;
+ // Write headers with a valid data reduction proxy.
+ request_options.MaybeAddRequestHeader(
+ NULL,
+ net::ProxyServer::FromURI(params->DefaultOrigin(),
+ net::ProxyServer::SCHEME_HTTP),
+ &headers3);
+ EXPECT_TRUE(headers3.HasHeader(kChromeProxyHeader));
+ std::string header_value3;
+ headers3.GetHeader(kChromeProxyHeader, &header_value3);
+ EXPECT_EQ(kExpectedHeader2, ParseHeader(header_value3));
+}
+
+TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationIgnoresEmptyKey) {
+scoped_ptr<TestDataReductionProxyParams> params;
+ params.reset(
+ new TestDataReductionProxyParams(
+ DataReductionProxyParams::kAllowed |
+ DataReductionProxyParams::kFallbackAllowed |
+ DataReductionProxyParams::kPromoAllowed,
+ TestDataReductionProxyParams::HAS_EVERYTHING &
+ ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
+ ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
+ // loop_proxy_ is just the current message loop. This means loop_proxy_
+ // is the network thread used by DataReductionProxyRequestOptions.
+ TestDataReductionProxyRequestOptions request_options(kClient,
+ kVersion,
+ params.get(),
+ loop_proxy_);
+ request_options.Init();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(kExpectedBuild,
+ request_options.header_options_[kBuildNumberHeaderOption]);
+ EXPECT_EQ(kExpectedPatch,
+ request_options.header_options_[kPatchNumberHeaderOption]);
+ EXPECT_EQ(request_options.key_, kTestKey);
+ EXPECT_EQ(kExpectedCredentials,
+ request_options.header_options_[kCredentialsHeaderOption]);
+ EXPECT_EQ(kExpectedSession,
+ request_options.header_options_[kSessionHeaderOption]);
+ EXPECT_EQ(kClientStr, request_options.header_options_[kClientHeaderOption]);
+
+ // Now set an empty key. The auth handler should ignore that, and the key
+ // remains |kTestKey|.
+ request_options.InitAuthentication("");
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(request_options.key_, kTestKey);
+ EXPECT_EQ(kExpectedCredentials,
+ request_options.header_options_[kCredentialsHeaderOption]);
+ EXPECT_EQ(kExpectedSession,
+ request_options.header_options_[kSessionHeaderOption]);
+}
+
+TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationBogusVersion) {
+ std::map<std::string, std::string> kExpectedHeader;
+ kExpectedHeader[kSessionHeaderOption] = kExpectedSession2;
+ kExpectedHeader[kCredentialsHeaderOption] = kExpectedCredentials2;
+ kExpectedHeader[kClientHeaderOption] = kClientStr;
+
+ scoped_ptr<TestDataReductionProxyParams> params;
+ params.reset(
+ new TestDataReductionProxyParams(
+ DataReductionProxyParams::kAllowed |
+ DataReductionProxyParams::kFallbackAllowed |
+ DataReductionProxyParams::kPromoAllowed,
+ TestDataReductionProxyParams::HAS_EVERYTHING &
+ ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
+ ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
+ TestDataReductionProxyRequestOptions request_options(kClient,
+ kBogusVersion,
+ params.get(),
+ loop_proxy_);
+ EXPECT_TRUE(request_options.header_options_.find(kBuildNumberHeaderOption) ==
+ request_options.header_options_.end());
+ EXPECT_TRUE(request_options.header_options_.find(kPatchNumberHeaderOption) ==
+ request_options.header_options_.end());
+
+ // Now set a key.
+ request_options.InitAuthentication(kTestKey2);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(kTestKey2, request_options.key_);
+ EXPECT_EQ(kExpectedCredentials2,
+ request_options.header_options_[kCredentialsHeaderOption]);
+ EXPECT_EQ(kExpectedSession2,
+ request_options.header_options_[kSessionHeaderOption]);
+
+ net::HttpRequestHeaders headers;
+ // Write headers with a valid data reduction proxy;
+ request_options.MaybeAddRequestHeader(
+ NULL,
+ net::ProxyServer::FromURI(
+ params->DefaultOrigin(),
+ net::ProxyServer::SCHEME_HTTP),
+ &headers);
+ EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader));
+ std::string header_value;
+ headers.GetHeader(kChromeProxyHeader, &header_value);
+ EXPECT_EQ(kExpectedHeader, ParseHeader(header_value));
+}
+
+TEST_F(DataReductionProxyRequestOptionsTest, AuthHashForSalt) {
+ std::string salt = "8675309"; // Jenny's number to test the hash generator.
+ std::string salted_key = salt + kDataReductionProxyKey + salt;
+ base::string16 expected_hash = base::UTF8ToUTF16(base::MD5String(salted_key));
+ EXPECT_EQ(expected_hash,
+ DataReductionProxyRequestOptions::AuthHashForSalt(
+ 8675309, kDataReductionProxyKey));
+}
+
+TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationLoFi) {
+ std::map<std::string, std::string> kExpectedHeader;
+ kExpectedHeader[kSessionHeaderOption] = kExpectedSession2;
+ kExpectedHeader[kCredentialsHeaderOption] = kExpectedCredentials2;
+ kExpectedHeader[kClientHeaderOption] = kClientStr;
+ kExpectedHeader[kLoFiHeaderOption] = "low";
+
+ scoped_ptr<TestDataReductionProxyParams> params;
+ params.reset(
+ new TestDataReductionProxyParams(
+ DataReductionProxyParams::kAllowed |
+ DataReductionProxyParams::kFallbackAllowed |
+ DataReductionProxyParams::kPromoAllowed,
+ TestDataReductionProxyParams::HAS_EVERYTHING &
+ ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
+ ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
+
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ data_reduction_proxy::switches::kEnableDataReductionProxyLoFi);
+
+ TestDataReductionProxyRequestOptions request_options(kClient,
+ kBogusVersion,
+ params.get(),
+ loop_proxy_);
+
+ // Now set a key.
+ request_options.InitAuthentication(kTestKey2);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(kTestKey2, request_options.key_);
+ EXPECT_EQ(kExpectedCredentials2,
+ request_options.header_options_[kCredentialsHeaderOption]);
+ EXPECT_EQ(kExpectedSession2,
+ request_options.header_options_[kSessionHeaderOption]);
+
+ net::HttpRequestHeaders headers;
+ // Write headers with a valid data reduction proxy;
+ request_options.MaybeAddRequestHeader(
+ NULL,
+ net::ProxyServer::FromURI(params->DefaultOrigin(),
+ net::ProxyServer::SCHEME_HTTP),
+ &headers);
+ EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader));
+ std::string header_value;
+ headers.GetHeader(kChromeProxyHeader, &header_value);
+ EXPECT_EQ(kExpectedHeader, ParseHeader(header_value));
+}
+
+TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationLoFiOffThenOn) {
+ std::map<std::string, std::string> kExpectedHeader;
+ kExpectedHeader[kSessionHeaderOption] = kExpectedSession2;
+ kExpectedHeader[kCredentialsHeaderOption] = kExpectedCredentials2;
+ kExpectedHeader[kClientHeaderOption] = kClientStr;
+
+ scoped_ptr<TestDataReductionProxyParams> params;
+ params.reset(
+ new TestDataReductionProxyParams(
+ DataReductionProxyParams::kAllowed |
+ DataReductionProxyParams::kFallbackAllowed |
+ DataReductionProxyParams::kPromoAllowed,
+ TestDataReductionProxyParams::HAS_EVERYTHING &
+ ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
+ ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
+
+ TestDataReductionProxyRequestOptions request_options(kClient,
+ kBogusVersion,
+ params.get(),
+ loop_proxy_);
+
+ // Now set a key.
+ request_options.InitAuthentication(kTestKey2);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(kTestKey2, request_options.key_);
+ EXPECT_EQ(kExpectedCredentials2,
+ request_options.header_options_[kCredentialsHeaderOption]);
+ EXPECT_EQ(kExpectedSession2,
+ request_options.header_options_[kSessionHeaderOption]);
+
+ net::HttpRequestHeaders headers;
+ // Write headers with a valid data reduction proxy;
+ request_options.MaybeAddRequestHeader(
+ NULL,
+ net::ProxyServer::FromURI(params->DefaultOrigin(),
+ net::ProxyServer::SCHEME_HTTP),
+ &headers);
+ EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader));
+ std::string header_value;
+ headers.GetHeader(kChromeProxyHeader, &header_value);
+ EXPECT_EQ(kExpectedHeader, ParseHeader(header_value));
+
+ // Add the LoFi command line switch.
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ data_reduction_proxy::switches::kEnableDataReductionProxyLoFi);
+ kExpectedHeader[kLoFiHeaderOption] = "low";
+
+ // Write headers with a valid data reduction proxy;
+ request_options.MaybeAddRequestHeader(
+ NULL,
+ net::ProxyServer::FromURI(params->DefaultOrigin(),
+ net::ProxyServer::SCHEME_HTTP),
+ &headers);
+ EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader));
+ headers.GetHeader(kChromeProxyHeader, &header_value);
+ EXPECT_EQ(kExpectedHeader, ParseHeader(header_value));
+}
+
+} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc
index 26fad47..43324cd 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc
@@ -17,7 +17,6 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc
index 4f0ca9a0..70c5679 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc
@@ -98,6 +98,12 @@ bool DataReductionProxyParams::IsIncludedInAndroidOnePromoFieldTrial(
return (fingerprint.find(kAndroidOneIdentifier) != std::string::npos);
}
+// static
+bool DataReductionProxyParams::IsDataReductionProxyLoFiEnabled() {
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(
+ data_reduction_proxy::switches::kEnableDataReductionProxyLoFi);
+}
+
DataReductionProxyTypeInfo::DataReductionProxyTypeInfo()
: proxy_servers(),
is_fallback(false),
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h
index e8164d7..c293516 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h
@@ -99,6 +99,10 @@ class DataReductionProxyParams {
static bool IsIncludedInAndroidOnePromoFieldTrial(
const char* build_fingerprint);
+ // Returns true if this client has the command line switch to enable Lo-Fi
+ // mode.
+ static bool IsDataReductionProxyLoFiEnabled();
+
// Constructs configuration parameters. If |kAllowed|, then the standard
// data reduction proxy configuration is allowed to be used. If
// |kfallbackAllowed| a fallback proxy can be used if the primary proxy is
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc
index 9d7a5b2..1ca5238 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc
@@ -51,5 +51,9 @@ const char kEnableDataReductionProxy[] = "enable-spdy-proxy-auth";
// Enable the alternative data reduction proxy.
const char kEnableDataReductionProxyAlt[] = "enable-data-reduction-proxy-alt";
+// Enable Data Reduction Proxy Lo-Fi mode.
+const char kEnableDataReductionProxyLoFi[] =
+ "enable-data-reduction-proxy-lo-fi";
+
} // namespace switches
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h b/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h
index f26b6f2..ad850fc 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h
@@ -24,6 +24,7 @@ extern const char kDisableDataReductionProxyDev[];
extern const char kEnableDataReductionProxyDev[];
extern const char kEnableDataReductionProxy[];
extern const char kEnableDataReductionProxyAlt[];
+extern const char kEnableDataReductionProxyLoFi[];
} // namespace switches
} // namespace data_reduction_proxy