summaryrefslogtreecommitdiffstats
path: root/components/data_reduction_proxy
diff options
context:
space:
mode:
authorbengr <bengr@chromium.org>2015-01-06 16:20:52 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-07 00:22:29 +0000
commit70101ea5186d12e67ed99e67fdafd33813f8da67 (patch)
treea5da53a8a109b083d21874418b0a4610e4bfd39d /components/data_reduction_proxy
parentdf648d28c1db235526abaeda0ee649fce7fdbae0 (diff)
downloadchromium_src-70101ea5186d12e67ed99e67fdafd33813f8da67.zip
chromium_src-70101ea5186d12e67ed99e67fdafd33813f8da67.tar.gz
chromium_src-70101ea5186d12e67ed99e67fdafd33813f8da67.tar.bz2
Make Data Reduction Proxy a best effort proxy
The data reduction proxy is used only if the effective proxy configuration resolves to DIRECT for the requested URL. This works by allowing the ProxyService to choose an effective proxy configuration and to decide on the prioritized list of proxies to use for a URL given that configuration. Just before the list is used, the DataReductionProxyNetworkDelegate's OnResolveProxy() method provides an opportunity to change that list, which it does, only if that list begins with DIRECT. BUG=429826,444169 Review URL: https://codereview.chromium.org/792803007 Cr-Commit-Position: refs/heads/master@{#310182}
Diffstat (limited to 'components/data_reduction_proxy')
-rw-r--r--components/data_reduction_proxy/core/browser/BUILD.gn5
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service.cc200
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service.h125
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_unittest.cc305
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.cc154
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h89
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc160
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc2
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h9
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.cc13
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h12
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol_unittest.cc82
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc26
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h7
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc6
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.cc38
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h2
17 files changed, 489 insertions, 746 deletions
diff --git a/components/data_reduction_proxy/core/browser/BUILD.gn b/components/data_reduction_proxy/core/browser/BUILD.gn
index c5bb287..bb3675b 100644
--- a/components/data_reduction_proxy/core/browser/BUILD.gn
+++ b/components/data_reduction_proxy/core/browser/BUILD.gn
@@ -6,8 +6,7 @@ static_library("browser") {
sources = [
"data_reduction_proxy_auth_request_handler.cc",
"data_reduction_proxy_auth_request_handler.h",
- "data_reduction_proxy_config_service.cc",
- "data_reduction_proxy_config_service.h",
+ "data_reduction_proxy_configurator.cc",
"data_reduction_proxy_configurator.h",
"data_reduction_proxy_delegate.cc",
"data_reduction_proxy_delegate.h",
@@ -71,7 +70,7 @@ source_set("unit_tests") {
testonly = true
sources = [
"data_reduction_proxy_auth_request_handler_unittest.cc",
- "data_reduction_proxy_config_service_unittest.cc",
+ "data_reduction_proxy_configurator_unittest.cc",
"data_reduction_proxy_interceptor_unittest.cc",
"data_reduction_proxy_metrics_unittest.cc",
"data_reduction_proxy_network_delegate_unittest.cc",
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service.cc
deleted file mode 100644
index ac38c1f..0000000
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service.cc
+++ /dev/null
@@ -1,200 +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_config_service.h"
-
-#include "base/bind.h"
-#include "base/memory/ref_counted.h"
-#include "base/message_loop/message_loop.h"
-#include "base/strings/string_util.h"
-
-namespace data_reduction_proxy {
-
-DataReductionProxyConfigService::DataReductionProxyConfigService(
- scoped_ptr<net::ProxyConfigService> base_service)
- : config_read_pending_(true),
- registered_observer_(false),
- enabled_(false),
- restricted_(false) {
- base_service_ = base_service.Pass();
-}
-
-DataReductionProxyConfigService::~DataReductionProxyConfigService() {
- if (registered_observer_ && base_service_.get())
- base_service_->RemoveObserver(this);
-}
-
-void DataReductionProxyConfigService::AddObserver(
- net::ProxyConfigService::Observer* observer) {
- RegisterObserver();
- observers_.AddObserver(observer);
-}
-
-void DataReductionProxyConfigService::RemoveObserver(
- net::ProxyConfigService::Observer* observer) {
- observers_.RemoveObserver(observer);
-}
-
-net::ProxyConfigService::ConfigAvailability
-DataReductionProxyConfigService::GetLatestProxyConfig(
- net::ProxyConfig* config) {
- RegisterObserver();
-
- if (enabled_) {
- *config = config_;
- return net::ProxyConfigService::CONFIG_VALID;
- }
-
- // Ask the base service if available.
- net::ProxyConfig system_config;
- ConfigAvailability system_availability =
- net::ProxyConfigService::CONFIG_UNSET;
- if (base_service_.get()) {
- system_availability = base_service_->GetLatestProxyConfig(&system_config);
- *config = system_config;
- }
- if (system_availability == net::ProxyConfigService::CONFIG_UNSET) {
- *config = net::ProxyConfig::CreateDirect();
- }
-
- return net::ProxyConfigService::CONFIG_VALID;
-}
-
-void DataReductionProxyConfigService::OnLazyPoll() {
- if (base_service_.get())
- base_service_->OnLazyPoll();
-}
-
-void DataReductionProxyConfigService::UpdateProxyConfig(
- bool enabled,
- const net::ProxyConfig& config) {
-
- config_read_pending_ = false;
- enabled_ = enabled;
- config_ = config;
-
- if (!observers_.might_have_observers())
- return;
-
- // Evaluate the proxy configuration. If GetLatestProxyConfig returns
- // CONFIG_PENDING, we are using the system proxy service, but it doesn't have
- // a valid configuration yet. Once it is ready, OnProxyConfigChanged() will be
- // called and broadcast the proxy configuration.
- // Note: If a switch between a preference proxy configuration and the system
- // proxy configuration occurs an unnecessary notification might get sent if
- // the two configurations agree. This case should be rare however, so we don't
- // handle that case specially.
- net::ProxyConfig new_config;
- ConfigAvailability availability = GetLatestProxyConfig(&new_config);
- if (availability != CONFIG_PENDING) {
- FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_,
- OnProxyConfigChanged(new_config, availability));
- }
-}
-
-void DataReductionProxyConfigService::OnProxyConfigChanged(
- const net::ProxyConfig& config,
- ConfigAvailability availability) {
-
- // Check whether the data reduction proxy is enabled. In this case that proxy
- // configuration takes precedence and the change event from the delegate proxy
- // service can be disregarded.
- if (!enabled_) {
- net::ProxyConfig actual_config;
- availability = GetLatestProxyConfig(&actual_config);
- FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_,
- OnProxyConfigChanged(actual_config, availability));
- }
-}
-
-void DataReductionProxyConfigService::RegisterObserver() {
- if (!registered_observer_ && base_service_.get()) {
- base_service_->AddObserver(this);
- registered_observer_ = true;
- }
-}
-
-DataReductionProxyConfigTracker::DataReductionProxyConfigTracker(
- base::Callback<void(bool, const net::ProxyConfig&)> update_proxy_config,
- const scoped_refptr<base::TaskRunner>& task_runner)
- : update_proxy_config_(update_proxy_config),
- task_runner_(task_runner) {
-}
-
-DataReductionProxyConfigTracker::~DataReductionProxyConfigTracker() {
-}
-
-void DataReductionProxyConfigTracker::Enable(
- bool primary_restricted,
- bool fallback_restricted,
- const std::string& primary_origin,
- const std::string& fallback_origin,
- const std::string& ssl_origin) {
-
- std::vector<std::string> proxies;
- if (!primary_restricted) {
- std::string trimmed_primary;
- base::TrimString(primary_origin, "/", &trimmed_primary);
- if (!trimmed_primary.empty())
- proxies.push_back(trimmed_primary);
- }
- if (!fallback_restricted) {
- std::string trimmed_fallback;
- base::TrimString(fallback_origin, "/", &trimmed_fallback);
- if (!trimmed_fallback.empty())
- proxies.push_back(trimmed_fallback);
- }
- if (proxies.empty()) {
- std::string mode;
- Disable();
- return;
- }
-
- std::string trimmed_ssl;
- base::TrimString(ssl_origin, "/", &trimmed_ssl);
-
- std::string server = "http=" + JoinString(proxies, ",") + ",direct://;"
- + (ssl_origin.empty() ? "" : ("https=" + ssl_origin + ",direct://;"));
-
- net::ProxyConfig config;
- config.proxy_rules().ParseFromString(server);
- config.proxy_rules().bypass_rules.ParseFromString(
- JoinString(bypass_rules_, ", "));
- UpdateProxyConfigOnIOThread(true, config);
-}
-
-
-void DataReductionProxyConfigTracker::Disable() {
- net::ProxyConfig config = net::ProxyConfig::CreateDirect();
- UpdateProxyConfigOnIOThread(false, config);
-}
-
-void DataReductionProxyConfigTracker::AddHostPatternToBypass(
- const std::string& pattern) {
- bypass_rules_.push_back(pattern);
-}
-
-void DataReductionProxyConfigTracker::AddURLPatternToBypass(
- const std::string& pattern) {
- size_t pos = pattern.find("/");
- if (pattern.find("/", pos + 1) == pos + 1)
- pos = pattern.find("/", pos + 2);
-
- std::string host_pattern;
- if (pos != std::string::npos)
- host_pattern = pattern.substr(0, pos);
- else
- host_pattern = pattern;
-
- AddHostPatternToBypass(host_pattern);
-}
-
-void DataReductionProxyConfigTracker::UpdateProxyConfigOnIOThread(
- bool enabled,
- const net::ProxyConfig& config) {
- task_runner_->PostTask(
- FROM_HERE, base::Bind(update_proxy_config_, enabled, config));
-}
-
-} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service.h
deleted file mode 100644
index 49e56c4..0000000
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service.h
+++ /dev/null
@@ -1,125 +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.
-
-#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG_SERVICE_H_
-#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG_SERVICE_H_
-
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/callback.h"
-#include "base/gtest_prod_util.h"
-#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/observer_list.h"
-#include "base/task_runner.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
-#include "net/proxy/proxy_config.h"
-#include "net/proxy/proxy_config_service.h"
-
-class PrefService;
-
-namespace net {
-class ProxyConfig;
-}
-
-namespace data_reduction_proxy {
-
-// A net::ProxyConfigService implementation that applies data reduction proxy
-// settings as overrides to the proxy configuration determined by a
-// baseline delegate ProxyConfigService.
-class DataReductionProxyConfigService
- : public net::ProxyConfigService,
- public net::ProxyConfigService::Observer {
- public:
- // Takes ownership of the passed |base_service|.
- DataReductionProxyConfigService(
- scoped_ptr<net::ProxyConfigService> base_service);
- ~DataReductionProxyConfigService() override;
-
- // ProxyConfigService implementation:
- void AddObserver(net::ProxyConfigService::Observer* observer) override;
- void RemoveObserver(net::ProxyConfigService::Observer* observer) override;
- ConfigAvailability GetLatestProxyConfig(net::ProxyConfig* config) override;
- void OnLazyPoll() override;
-
- // Method on IO thread that receives the data reduction proxy settings pushed
- // from DataReductionProxyConfiguratorImpl.
- void UpdateProxyConfig(bool enabled,
- const net::ProxyConfig& config);
-
- private:
- friend class DataReductionProxyConfigServiceTest;
-
- // ProxyConfigService::Observer implementation:
- void OnProxyConfigChanged(const net::ProxyConfig& config,
- ConfigAvailability availability) override;
-
- // Makes sure that the observer registration with the base service is set up.
- void RegisterObserver();
-
- scoped_ptr<net::ProxyConfigService> base_service_;
- ObserverList<net::ProxyConfigService::Observer, true> observers_;
-
- // Configuration as defined by the data reduction proxy.
- net::ProxyConfig config_;
-
- // Flag that indicates that a PrefProxyConfigTracker needs to inform us
- // about a proxy configuration before we may return any configuration.
- bool config_read_pending_;
-
- // Indicates whether the base service registration is done.
- bool registered_observer_;
-
- // The data reduction proxy is enabled.
- bool enabled_;
-
- // Use of the data reduction proxy is restricted to HTTP proxying only.
- bool restricted_;
-
- DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigService);
-};
-
-// A data_reduction_proxy::DataReductionProxyConfigurator implementation that
-// tracks changes to the data reduction proxy configuration and notifies an
-// associated DataReductionProxyConfigService. Configuration changes include
-// adding URL and host patterns to bypass and enabling and disabling use of the
-// proxy.
-class DataReductionProxyConfigTracker : public DataReductionProxyConfigurator {
- public:
- DataReductionProxyConfigTracker(
- base::Callback<void(bool, const net::ProxyConfig&)> update_proxy_config,
- const scoped_refptr<base::TaskRunner>& task_runner);
- ~DataReductionProxyConfigTracker() override;
-
- void Enable(bool primary_restricted,
- bool fallback_restricted,
- const std::string& primary_origin,
- const std::string& fallback_origin,
- const std::string& ssl_origin) override;
- void Disable() override;
- void AddHostPatternToBypass(const std::string& pattern) override;
- void AddURLPatternToBypass(const std::string& pattern) override;
-
- private:
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigServiceTest,
- TrackerEnable);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigServiceTest,
- TrackerRestricted);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigServiceTest,
- TrackerBypassList);
-
- void UpdateProxyConfigOnIOThread(bool enabled,
- const net::ProxyConfig& config);
-
- base::Callback<void(bool, const net::ProxyConfig&)> update_proxy_config_;
- std::vector<std::string> bypass_rules_;
- scoped_refptr<base::TaskRunner> task_runner_;
-
- DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigTracker);
-};
-
-} // namespace data_reduction_proxy
-
-#endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG_SERVICE_H_
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_unittest.cc
deleted file mode 100644
index 0b0876f..0000000
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_unittest.cc
+++ /dev/null
@@ -1,305 +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_config_service.h"
-
-#include <string>
-
-#include "base/bind.h"
-#include "base/memory/ref_counted.h"
-#include "base/message_loop/message_loop.h"
-#include "base/test/test_simple_task_runner.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using testing::Mock;
-
-namespace {
-
-// Test system proxy rules.
-static const char kSystemProxyRules[] = "http=http://system.com:80,direct://";
-
-// Test data reduction proxy rules.
-static const char kDataReductionProxyRules[] =
- "http=https://foo.com:443,http://bar.com:80,direct://";
-
-// Test data reduction proxy rules when in restricted mode.
-static const char kDataReductionProxyRestrictedRules[] =
- "http=http://bar.com:80,direct://";
-
-} // namespace
-
-namespace data_reduction_proxy {
-
-class TestProxyConfigService : public net::ProxyConfigService {
- public:
- TestProxyConfigService()
- : availability_(net::ProxyConfigService::CONFIG_VALID) {
- config_.proxy_rules().ParseFromString(kSystemProxyRules);
- }
-
- void SetProxyConfig(const net::ProxyConfig config,
- ConfigAvailability availability) {
- config_ = config;
- availability_ = availability;
- FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_,
- OnProxyConfigChanged(config, availability));
- }
-
- void AddObserver(net::ProxyConfigService::Observer* observer) override {
- observers_.AddObserver(observer);
- }
-
- void RemoveObserver(net::ProxyConfigService::Observer* observer) override {
- observers_.RemoveObserver(observer);
- }
-
- ConfigAvailability GetLatestProxyConfig(net::ProxyConfig* config) override {
- *config = config_;
- return availability_;
- }
-
- private:
- net::ProxyConfig config_;
- ConfigAvailability availability_;
- ObserverList<net::ProxyConfigService::Observer, true> observers_;
-};
-
-
-// A mock observer for capturing callbacks.
-class MockObserver : public net::ProxyConfigService::Observer {
- public:
- MOCK_METHOD2(OnProxyConfigChanged,
- void(const net::ProxyConfig&,
- net::ProxyConfigService::ConfigAvailability));
-};
-
-
-class DataReductionProxyConfigServiceTest : public testing::Test {
- public:
- void SetUp() override {
- observer_.reset(new MockObserver());
- base_service_ = new TestProxyConfigService();
- scoped_ptr<net::ProxyConfigService> base_service(base_service_);
- config_service_.reset(
- new DataReductionProxyConfigService(base_service.Pass()));
- }
-
- void EnableDataReductionProxy(bool data_reduction_proxy_enabled) {
- config_service_->enabled_ = data_reduction_proxy_enabled;
- config_service_->config_.proxy_rules().ParseFromString(
- kDataReductionProxyRules);
- }
-
- scoped_ptr<net::ProxyConfigService::Observer> observer_;
-
- // Holds a weak pointer to the base service. Ownership is passed to
- // |config_service_|.
- TestProxyConfigService* base_service_;
-
- scoped_ptr<DataReductionProxyConfigService> config_service_;
-};
-
-// Compares proxy configurations, but allows different identifiers.
-MATCHER_P(ProxyConfigMatches, config, "") {
- net::ProxyConfig reference(config);
- reference.set_id(arg.id());
- return reference.Equals(arg);
-}
-
-TEST_F(DataReductionProxyConfigServiceTest, GetLatestProxyConfigEnabled) {
- // Set up the |config_service_| as though Enable had been previously called
- // and check that |GetLatestProxyConfigEnabled| return rules for the data
- // reduction proxy.
- EnableDataReductionProxy(true);
- net::ProxyConfig::ProxyRules expected_rules;
- expected_rules.ParseFromString(kDataReductionProxyRules);
- net::ProxyConfig latest_config;
- EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
- config_service_->GetLatestProxyConfig(&latest_config));
- ASSERT_TRUE(latest_config.proxy_rules().Equals(expected_rules));
-}
-
-TEST_F(DataReductionProxyConfigServiceTest, GetLatestProxyConfigDisabledValid) {
- // Set up the |config_service_| with the data reduction proxy disabled and
- // check that the underlying system config is returned.
- EnableDataReductionProxy(false);
- net::ProxyConfig::ProxyRules expected_rules;
- expected_rules.ParseFromString(kSystemProxyRules);
- net::ProxyConfig latest_config;
- EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
- config_service_->GetLatestProxyConfig(&latest_config));
- ASSERT_TRUE(latest_config.proxy_rules().Equals(expected_rules));
-}
-
-TEST_F(DataReductionProxyConfigServiceTest, GetLatestProxyConfigDisabledUnset) {
- // Set up the |config_service_| with the data reduction proxy disabled and
- // check that direct is returned if the the underlying system config is unset.
- EnableDataReductionProxy(false);
- base_service_->SetProxyConfig(net::ProxyConfig(),
- net::ProxyConfigService::CONFIG_UNSET);
- net::ProxyConfig latest_config;
- EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
- config_service_->GetLatestProxyConfig(&latest_config));
- ASSERT_TRUE(latest_config.Equals(net::ProxyConfig()));
-}
-
-TEST_F(DataReductionProxyConfigServiceTest, UpdateProxyConfig) {
- MockObserver observer;
- base::MessageLoopForUI loop;
- config_service_->AddObserver(&observer);
- // Firing the observers in the delegate should trigger a notification.
- net::ProxyConfig config2;
- config2.set_auto_detect(true);
- EXPECT_CALL(observer, OnProxyConfigChanged(
- ProxyConfigMatches(config2),
- net::ProxyConfigService::CONFIG_VALID)).Times(1);
- base_service_->SetProxyConfig(config2, net::ProxyConfigService::CONFIG_VALID);
- loop.RunUntilIdle();
- Mock::VerifyAndClearExpectations(&observer);
-
- // Enable the data reduction proxy, which should trigger a notification.
- net::ProxyConfig system_config;
- system_config.proxy_rules().ParseFromString(kSystemProxyRules);
- base_service_->SetProxyConfig(system_config,
- net::ProxyConfigService::CONFIG_VALID);
- net::ProxyConfig data_reduction_proxy_config;
- data_reduction_proxy_config.proxy_rules().ParseFromString(
- kDataReductionProxyRules);
-
- EXPECT_CALL(observer, OnProxyConfigChanged(
- ProxyConfigMatches(data_reduction_proxy_config),
- net::ProxyConfigService::CONFIG_VALID)).Times(1);
- config_service_->UpdateProxyConfig(true, data_reduction_proxy_config);
- loop.RunUntilIdle();
- Mock::VerifyAndClearExpectations(&observer);
-
-
- // Disable the data reduction proxy, which should trigger a notification.
- base_service_->SetProxyConfig(system_config,
- net::ProxyConfigService::CONFIG_VALID);
- EXPECT_CALL(observer, OnProxyConfigChanged(
- ProxyConfigMatches(system_config),
- net::ProxyConfigService::CONFIG_VALID)).Times(1);
- config_service_->UpdateProxyConfig(false, data_reduction_proxy_config);
- loop.RunUntilIdle();
- Mock::VerifyAndClearExpectations(&observer);
-
- config_service_->RemoveObserver(&observer);
-}
-
-TEST_F(DataReductionProxyConfigServiceTest, TrackerEnable) {
- MockObserver observer;
- //base::MessageLoopForUI loop;
- config_service_->AddObserver(&observer);
- scoped_refptr<base::TestSimpleTaskRunner> task_runner_(
- new base::TestSimpleTaskRunner());
- DataReductionProxyConfigTracker tracker(
- base::Bind(&data_reduction_proxy::DataReductionProxyConfigService::
- UpdateProxyConfig,
- base::Unretained(config_service_.get())),
- task_runner_.get());
- net::ProxyConfig expected_config;
- expected_config.proxy_rules().ParseFromString(kDataReductionProxyRules);
- EXPECT_CALL(observer, OnProxyConfigChanged(
- ProxyConfigMatches(expected_config),
- net::ProxyConfigService::CONFIG_VALID)).Times(1);
- tracker.Enable(false,
- false,
- "https://foo.com:443",
- "http://bar.com:80",
- "");
- task_runner_->RunUntilIdle();
- Mock::VerifyAndClearExpectations(&observer);
-
- config_service_->RemoveObserver(&observer);
-}
-
-TEST_F(DataReductionProxyConfigServiceTest, TrackerEnableRestricted) {
- MockObserver observer;
- //base::MessageLoopForUI loop;
- config_service_->AddObserver(&observer);
- scoped_refptr<base::TestSimpleTaskRunner> task_runner_(
- new base::TestSimpleTaskRunner());
- DataReductionProxyConfigTracker tracker(
- base::Bind(&data_reduction_proxy::DataReductionProxyConfigService::
- UpdateProxyConfig,
- base::Unretained(config_service_.get())),
- task_runner_.get());
- net::ProxyConfig expected_config;
- expected_config.proxy_rules().ParseFromString(
- kDataReductionProxyRestrictedRules);
- EXPECT_CALL(observer, OnProxyConfigChanged(
- ProxyConfigMatches(expected_config),
- net::ProxyConfigService::CONFIG_VALID)).Times(1);
- tracker.Enable(true,
- false,
- "https://foo.com:443",
- "http://bar.com:80",
- "");
- task_runner_->RunUntilIdle();
- Mock::VerifyAndClearExpectations(&observer);
-
- config_service_->RemoveObserver(&observer);
-}
-
-TEST_F(DataReductionProxyConfigServiceTest, TrackerDisable) {
- MockObserver observer;
- //base::MessageLoopForUI loop;
- config_service_->AddObserver(&observer);
- scoped_refptr<base::TestSimpleTaskRunner> task_runner_(
- new base::TestSimpleTaskRunner());
- DataReductionProxyConfigTracker tracker(
- base::Bind(&data_reduction_proxy::DataReductionProxyConfigService::
- UpdateProxyConfig,
- base::Unretained(config_service_.get())),
- task_runner_.get());
- net::ProxyConfig expected_config;
- expected_config.proxy_rules().ParseFromString(kSystemProxyRules);
- EXPECT_CALL(observer, OnProxyConfigChanged(
- ProxyConfigMatches(expected_config),
- net::ProxyConfigService::CONFIG_VALID)).Times(1);
- tracker.Disable();
- task_runner_->RunUntilIdle();
- //loop.RunUntilIdle();
- Mock::VerifyAndClearExpectations(&observer);
-
- config_service_->RemoveObserver(&observer);
-}
-
-
-TEST_F(DataReductionProxyConfigServiceTest, TrackerBypassList) {
- base::MessageLoopForUI loop;
- scoped_refptr<base::TestSimpleTaskRunner> task_runner_(
- new base::TestSimpleTaskRunner());
- DataReductionProxyConfigTracker tracker(
- base::Bind(&data_reduction_proxy::DataReductionProxyConfigService::
- UpdateProxyConfig,
- base::Unretained(config_service_.get())),
- task_runner_.get());
- tracker.AddHostPatternToBypass("http://www.google.com");
- tracker.AddHostPatternToBypass("fefe:13::abc/33");
- tracker.AddURLPatternToBypass("foo.org/images/*");
- tracker.AddURLPatternToBypass("http://foo.com/*");
- tracker.AddURLPatternToBypass("http://baz.com:22/bar/*");
- tracker.AddURLPatternToBypass("http://*bat.com/bar/*");
-
- std::string expected[] = {
- "http://www.google.com",
- "fefe:13::abc/33",
- "foo.org",
- "http://foo.com",
- "http://baz.com:22",
- "http://*bat.com"
- };
-
- ASSERT_EQ(tracker.bypass_rules_.size(), 6u);
- int i = 0;
- for (std::vector<std::string>::iterator it = tracker.bypass_rules_.begin();
- it != tracker.bypass_rules_.end(); ++it) {
- EXPECT_EQ(expected[i++], *it);
- }
-}
-
-} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.cc
new file mode 100644
index 0000000..8514313
--- /dev/null
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.cc
@@ -0,0 +1,154 @@
+// 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_configurator.h"
+
+#include "base/sequenced_task_runner.h"
+#include "base/strings/string_util.h"
+#include "base/values.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
+#include "net/proxy/proxy_config.h"
+#include "net/proxy/proxy_info.h"
+#include "net/proxy/proxy_list.h"
+#include "net/proxy/proxy_service.h"
+
+namespace data_reduction_proxy {
+
+DataReductionProxyConfigurator::DataReductionProxyConfigurator(
+ scoped_refptr<base::SequencedTaskRunner> network_task_runner,
+ net::NetLog* net_log,
+ data_reduction_proxy::DataReductionProxyEventStore* event_store)
+ : network_task_runner_(network_task_runner),
+ net_log_(net_log),
+ data_reduction_proxy_event_store_(event_store) {
+ DCHECK(network_task_runner.get());
+ DCHECK(net_log);
+ DCHECK(event_store);
+}
+
+DataReductionProxyConfigurator::~DataReductionProxyConfigurator() {
+}
+
+void DataReductionProxyConfigurator::Enable(
+ bool primary_restricted,
+ bool fallback_restricted,
+ const std::string& primary_origin,
+ const std::string& fallback_origin,
+ const std::string& ssl_origin) {
+ std::vector<std::string> proxies;
+ if (!primary_restricted) {
+ std::string trimmed_primary;
+ base::TrimString(primary_origin, "/", &trimmed_primary);
+ if (!trimmed_primary.empty())
+ proxies.push_back(trimmed_primary);
+ }
+ if (!fallback_restricted) {
+ std::string trimmed_fallback;
+ base::TrimString(fallback_origin, "/", &trimmed_fallback);
+ if (!trimmed_fallback.empty())
+ proxies.push_back(trimmed_fallback);
+ }
+ if (proxies.empty()) {
+ Disable();
+ return;
+ }
+
+ std::string trimmed_ssl;
+ base::TrimString(ssl_origin, "/", &trimmed_ssl);
+
+ std::string server = "http=" + JoinString(proxies, ",") + ",direct://;"
+ + (ssl_origin.empty() ? "" : ("https=" + trimmed_ssl + ",direct://;"));
+
+ net::ProxyConfig config;
+ config.proxy_rules().ParseFromString(server);
+ config.proxy_rules().bypass_rules.ParseFromString(
+ JoinString(bypass_rules_, ", "));
+ // The ID is set to a bogus value. It cannot be left uninitialized, else the
+ // config will return invalid.
+ net::ProxyConfig::ID unused_id = 1;
+ config.set_id(unused_id);
+ data_reduction_proxy_event_store_->AddProxyEnabledEvent(
+ net_log_, primary_restricted, fallback_restricted, primary_origin,
+ fallback_origin, ssl_origin);
+ network_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &DataReductionProxyConfigurator::UpdateProxyConfigOnIOThread,
+ base::Unretained(this),
+ config));
+}
+
+void DataReductionProxyConfigurator::Disable() {
+ net::ProxyConfig config = net::ProxyConfig::CreateDirect();
+ data_reduction_proxy_event_store_->AddProxyDisabledEvent(net_log_);
+ network_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &DataReductionProxyConfigurator::UpdateProxyConfigOnIOThread,
+ base::Unretained(this),
+ config));
+}
+
+void DataReductionProxyConfigurator::AddHostPatternToBypass(
+ const std::string& pattern) {
+ bypass_rules_.push_back(pattern);
+}
+
+void DataReductionProxyConfigurator::AddURLPatternToBypass(
+ const std::string& pattern) {
+ size_t pos = pattern.find('/');
+ if (pattern.find('/', pos + 1) == pos + 1)
+ pos = pattern.find('/', pos + 2);
+
+ std::string host_pattern;
+ if (pos != std::string::npos)
+ host_pattern = pattern.substr(0, pos);
+ else
+ host_pattern = pattern;
+
+ AddHostPatternToBypass(host_pattern);
+}
+
+// static
+bool DataReductionProxyConfigurator::ContainsDataReductionProxy(
+ const net::ProxyConfig::ProxyRules& proxy_rules) {
+ data_reduction_proxy::DataReductionProxyParams params(
+ data_reduction_proxy::DataReductionProxyParams::
+ kAllowAllProxyConfigurations);
+ if (proxy_rules.type != net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME)
+ return false;
+
+ const net::ProxyList* https_proxy_list =
+ proxy_rules.MapUrlSchemeToProxyList("https");
+ if (https_proxy_list && !https_proxy_list->IsEmpty() &&
+ // Sufficient to check only the first proxy.
+ params.IsDataReductionProxy(https_proxy_list->Get().host_port_pair(),
+ NULL)) {
+ return true;
+ }
+
+ const net::ProxyList* http_proxy_list =
+ proxy_rules.MapUrlSchemeToProxyList("http");
+ if (http_proxy_list && !http_proxy_list->IsEmpty() &&
+ // Sufficient to check only the first proxy.
+ params.IsDataReductionProxy(http_proxy_list->Get().host_port_pair(),
+ NULL)) {
+ return true;
+ }
+
+ return false;
+}
+
+void DataReductionProxyConfigurator::UpdateProxyConfigOnIOThread(
+ const net::ProxyConfig& config) {
+ config_ = config;
+}
+
+const net::ProxyConfig&
+DataReductionProxyConfigurator::GetProxyConfigOnIOThread() const {
+ return config_;
+}
+
+} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h
index 370ff801..8c4f5ce 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h
@@ -6,46 +6,101 @@
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIGURATOR_H_
#include <string>
+#include <vector>
-#include "base/macros.h"
+#include "base/gtest_prod_util.h"
+#include "base/task_runner.h"
+#include "net/proxy/proxy_config.h"
+
+namespace base {
+class SequencedTaskRunner;
+}
+
+namespace net {
+class NetLog;
+class ProxyInfo;
+class ProxyService;
+}
+
+class PrefService;
namespace data_reduction_proxy {
-// Interface for enabling and disabling the data reduction proxy configuration,
-// and for adding bypass rules. This is the interface that is used to set the
-// networking configuration that causes traffic to be proxied.
+class DataReductionProxyEventStore;
+
class DataReductionProxyConfigurator {
public:
- DataReductionProxyConfigurator() {}
- virtual ~DataReductionProxyConfigurator() {}
-
- // Enable the data reduction proxy. If |primary_restricted|, the
- // |primary_origin| may not be used. If |fallback_restricted|, the
- // |fallback_origin| may not be used. If both are restricted, then the
- // proxy configuration will be the same as when |Disable()| is called.
- // If |ssl_origin| is non-empty, it will be used used for HTTPS traffic.
+ // Check whether the |proxy_rules| contain any of the data reduction proxies.
+ static bool ContainsDataReductionProxy(
+ const net::ProxyConfig::ProxyRules& proxy_rules);
+
+ // Constructs a configurator. |network_task_runner| should be the task runner
+ // for running network operations, |net_log| and |event_store| are used to
+ // track network and Data Reduction Proxy events respectively, must not be
+ // null, and must outlive this instance.
+ DataReductionProxyConfigurator(
+ scoped_refptr<base::SequencedTaskRunner> network_task_runner,
+ net::NetLog* net_log,
+ data_reduction_proxy::DataReductionProxyEventStore* event_store);
+
+ virtual ~DataReductionProxyConfigurator();
+
+ void set_net_log(net::NetLog* net_log) {
+ DCHECK(!net_log_);
+ net_log_ = net_log;
+ DCHECK(net_log_);
+ }
+
+ // Constructs a proxy configuration suitable for enabling the Data Reduction
+ // proxy.
virtual void Enable(bool primary_restricted,
bool fallback_restricted,
const std::string& primary_origin,
const std::string& fallback_origin,
- const std::string& ssl_origin) = 0;
+ const std::string& ssl_origin);
- // Disable the data reduction proxy.
- virtual void Disable() = 0;
+ // Constructs a proxy configuration suitable for disabling the Data Reduction
+ // proxy.
+ virtual void Disable();
// Adds a host pattern to bypass. This should follow the same syntax used
// in net::ProxyBypassRules; that is, a hostname pattern, a hostname suffix
// pattern, an IP literal, a CIDR block, or the magic string '<local>'.
// Bypass settings persist for the life of this object and are applied
// each time the proxy is enabled, but are not updated while it is enabled.
- virtual void AddHostPatternToBypass(const std::string& pattern) = 0;
+ virtual void AddHostPatternToBypass(const std::string& pattern);
// Adds a URL pattern to bypass the proxy. The base implementation strips
// everything in |pattern| after the first single slash and then treats it
// as a hostname pattern.
- virtual void AddURLPatternToBypass(const std::string& pattern) = 0;
+ virtual void AddURLPatternToBypass(const std::string& pattern);
+
+ // Updates the config for use on the IO thread.
+ void UpdateProxyConfigOnIOThread(const net::ProxyConfig& config);
+
+ // Returns the current data reduction proxy config, even if it is not the
+ // effective configuration used by the proxy service.
+ const net::ProxyConfig& GetProxyConfigOnIOThread() const;
private:
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, TestBypassList);
+
+ // Used for updating the proxy config on the IO thread.
+ scoped_refptr<base::SequencedTaskRunner> network_task_runner_;
+
+ // Rules for bypassing the Data Reduction Proxy.
+ std::vector<std::string> bypass_rules_;
+
+ // The Data Reduction Proxy's configuration. This contains the list of
+ // acceptable data reduction proxies and bypass rules. It should be accessed
+ // only on the IO thread.
+ net::ProxyConfig config_;
+
+ // Used for logging of network- and Data Reduction Proxy-related events.
+ net::NetLog* net_log_;
+ data_reduction_proxy::DataReductionProxyEventStore*
+ data_reduction_proxy_event_store_;
+
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigurator);
};
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc
new file mode 100644
index 0000000..9b431a9
--- /dev/null
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc
@@ -0,0 +1,160 @@
+// 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_configurator.h"
+
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/test/test_simple_task_runner.h"
+#include "base/values.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
+#include "net/base/capturing_net_log.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace data_reduction_proxy {
+
+class DataReductionProxyConfigTest : public testing::Test {
+ public:
+ void SetUp() override {
+ task_runner_ = new base::TestSimpleTaskRunner();
+ net_log_.reset(new net::CapturingNetLog());
+ data_reduction_proxy_event_store_.reset(
+ new data_reduction_proxy::DataReductionProxyEventStore(task_runner_));
+ config_.reset(
+ new DataReductionProxyConfigurator(
+ task_runner_, net_log_.get(),
+ data_reduction_proxy_event_store_.get()));
+ }
+
+ void CheckProxyConfig(
+ const net::ProxyConfig::ProxyRules::Type& expected_rules_type,
+ const std::string& expected_http_proxies,
+ const std::string& expected_https_proxies,
+ const std::string& expected_bypass_list) {
+ task_runner_->RunUntilIdle();
+ const net::ProxyConfig::ProxyRules& rules =
+ config_->GetProxyConfigOnIOThread().proxy_rules();
+ ASSERT_EQ(expected_rules_type, rules.type);
+ if (net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME ==
+ expected_rules_type) {
+ ASSERT_EQ(expected_http_proxies, rules.proxies_for_http.ToPacString());
+ ASSERT_EQ(expected_https_proxies, rules.proxies_for_https.ToPacString());
+ ASSERT_EQ(expected_bypass_list, rules.bypass_rules.ToString());
+ }
+ }
+
+ scoped_ptr<DataReductionProxyConfigurator> config_;
+ scoped_ptr<net::NetLog> net_log_;
+ scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
+ scoped_ptr<data_reduction_proxy::DataReductionProxyEventStore>
+ data_reduction_proxy_event_store_;
+};
+
+TEST_F(DataReductionProxyConfigTest, TestUnrestricted) {
+ config_->Enable(false,
+ false,
+ "https://www.foo.com:443/",
+ "http://www.bar.com:80/",
+ "");
+ CheckProxyConfig(
+ net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
+ "HTTPS www.foo.com:443;PROXY www.bar.com:80;DIRECT",
+ "", "");
+}
+
+TEST_F(DataReductionProxyConfigTest, TestUnrestrictedSSL) {
+ config_->Enable(false,
+ false,
+ "https://www.foo.com:443/",
+ "http://www.bar.com:80/",
+ "http://www.ssl.com:80/");
+ CheckProxyConfig(
+ net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
+ "HTTPS www.foo.com:443;PROXY www.bar.com:80;DIRECT",
+ "PROXY www.ssl.com:80;DIRECT",
+ "");
+}
+
+TEST_F(DataReductionProxyConfigTest, TestUnrestrictedWithBypassRule) {
+ config_->AddHostPatternToBypass("<local>");
+ config_->AddHostPatternToBypass("*.goo.com");
+ config_->Enable(false,
+ false,
+ "https://www.foo.com:443/",
+ "http://www.bar.com:80/",
+ "");
+ CheckProxyConfig(
+ net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
+ "HTTPS www.foo.com:443;PROXY www.bar.com:80;DIRECT", "",
+ "<local>;*.goo.com;");
+}
+
+TEST_F(DataReductionProxyConfigTest, TestUnrestrictedWithoutFallback) {
+ config_->Enable(false, false, "https://www.foo.com:443/", "", "");
+ CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
+ "HTTPS www.foo.com:443;DIRECT", "", "");
+}
+
+TEST_F(DataReductionProxyConfigTest, TestRestricted) {
+ config_->Enable(true,
+ false,
+ "https://www.foo.com:443/",
+ "http://www.bar.com:80/",
+ "");
+ CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
+ "PROXY www.bar.com:80;DIRECT", "", "");
+}
+
+TEST_F(DataReductionProxyConfigTest, TestFallbackRestricted) {
+ config_->Enable(false,
+ true,
+ "https://www.foo.com:443/",
+ "http://www.bar.com:80/",
+ "");
+ CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
+ "HTTPS www.foo.com:443;DIRECT", "", "");
+}
+
+TEST_F(DataReductionProxyConfigTest, TestDisable) {
+ data_reduction_proxy::DataReductionProxyParams params(
+ data_reduction_proxy::DataReductionProxyParams::
+ kAllowAllProxyConfigurations);
+ config_->Enable(false,
+ false,
+ params.origin().spec(),
+ params.fallback_origin().spec(),
+ "");
+ config_->Disable();
+ CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_NO_RULES, "", "", "");
+}
+
+TEST_F(DataReductionProxyConfigTest, TestBypassList) {
+ config_->AddHostPatternToBypass("http://www.google.com");
+ config_->AddHostPatternToBypass("fefe:13::abc/33");
+ config_->AddURLPatternToBypass("foo.org/images/*");
+ config_->AddURLPatternToBypass("http://foo.com/*");
+ config_->AddURLPatternToBypass("http://baz.com:22/bar/*");
+ config_->AddURLPatternToBypass("http://*bat.com/bar/*");
+
+ std::string expected[] = {
+ "http://www.google.com",
+ "fefe:13::abc/33",
+ "foo.org",
+ "http://foo.com",
+ "http://baz.com:22",
+ "http://*bat.com"
+ };
+
+ ASSERT_EQ(config_->bypass_rules_.size(), 6u);
+ int i = 0;
+ for (std::vector<std::string>::iterator it = config_->bypass_rules_.begin();
+ it != config_->bypass_rules_.end(); ++it) {
+ EXPECT_EQ(expected[i++], *it);
+ }
+}
+
+} // namespace data_reduction_proxy
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 2abefaf..c435c95 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
@@ -148,7 +148,7 @@ void DataReductionProxyNetworkDelegate::OnResolveProxyInternal(
if (!on_resolve_proxy_handler_.is_null() &&
!proxy_config_getter_.is_null()) {
on_resolve_proxy_handler_.Run(
- url, load_flags, proxy_config_getter_.Run(), proxy_service.config(),
+ url, load_flags, proxy_config_getter_.Run(),
proxy_service.proxy_retry_info(), data_reduction_proxy_params_, result);
}
}
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 17dc32f..90398b2 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
@@ -47,15 +47,14 @@ class DataReductionProxyUsageStats;
class DataReductionProxyNetworkDelegate : public net::LayeredNetworkDelegate {
public:
// Provides an opportunity to interpose on proxy resolution. Called before
- // ProxyService.ResolveProxy() returns. Two proxy configurations are provided
- // that specify the data reduction proxy's configuration and the effective
- // configuration according to the proxy service, respectively. Retry info is
- // presumed to be from the proxy service.
+ // ProxyService.ResolveProxy() returns. The Data Reduction Proxy's
+ // configuration is provided along with the resolution for this URL, in
+ // |result|, whch may be modified. Retry info is presumed to be from the proxy
+ // service.
typedef base::Callback<void(
const GURL& url,
int load_flags,
const net::ProxyConfig& data_reduction_proxy_config,
- const net::ProxyConfig& proxy_service_proxy_config,
const net::ProxyRetryInfoMap& proxy_retry_info_map,
const DataReductionProxyParams* params,
net::ProxyInfo* result)> OnResolveProxyHandler;
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.cc
index bfef9e7..9ed991e 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.cc
@@ -144,13 +144,16 @@ bool MaybeBypassProxyAndPrepareToRetry(
void OnResolveProxyHandler(const GURL& url,
int load_flags,
const net::ProxyConfig& data_reduction_proxy_config,
- const net::ProxyConfig& proxy_service_proxy_config,
const net::ProxyRetryInfoMap& proxy_retry_info,
const DataReductionProxyParams* params,
net::ProxyInfo* result) {
+ DCHECK(params);
+ DCHECK(result->is_empty() || result->is_direct() ||
+ !params->IsDataReductionProxy(result->proxy_server().host_port_pair(),
+ NULL));
if (data_reduction_proxy_config.is_valid() &&
result->proxy_server().is_direct() &&
- !data_reduction_proxy_config.Equals(proxy_service_proxy_config)) {
+ !url.SchemeIsWSOrWSS()) {
net::ProxyInfo data_reduction_proxy_info;
data_reduction_proxy_config.proxy_rules().Apply(
url, &data_reduction_proxy_info);
@@ -159,12 +162,10 @@ void OnResolveProxyHandler(const GURL& url,
result->UseProxyList(data_reduction_proxy_info.proxy_list());
}
- if (url.SchemeIsWSOrWSS() ||
- ((load_flags & net::LOAD_BYPASS_DATA_REDUCTION_PROXY) &&
- DataReductionProxyParams::IsIncludedInCriticalPathBypassFieldTrial())) {
+ if ((load_flags & net::LOAD_BYPASS_DATA_REDUCTION_PROXY) &&
+ DataReductionProxyParams::IsIncludedInCriticalPathBypassFieldTrial()) {
if (!result->is_empty() &&
!result->is_direct() &&
- params &&
params->IsDataReductionProxy(result->proxy_server().host_port_pair(),
NULL)) {
result->UseDirect();
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h
index 84ab2bc..5658dce 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h
@@ -39,16 +39,14 @@ bool MaybeBypassProxyAndPrepareToRetry(
DataReductionProxyEventStore* event_store);
// Adds data reduction proxies to |result|, where applicable, if result
-// otherwise uses a direct connection for |url|, the proxy service's effective
-// proxy configuration is not the data reduction proxy configuration, and the
-// data reduction proxy is not bypassed. Also, configures |result| to proceed
-// directly to the origin if |result|'s current proxy is the data
-// reduction proxy, the |net::LOAD_BYPASS_DATA_REDUCTION_PROXY| |load_flag| is
-// set, and the DataCompressionProxyCriticalBypass Finch trial is set.
+// otherwise uses a direct connection for |url|, and the data reduction proxy is
+// not bypassed. Also, configures |result| to proceed directly to the origin if
+// |result|'s current proxy is the data reduction proxy, the
+// |net::LOAD_BYPASS_DATA_REDUCTION_PROXY| |load_flag| is set, and the
+// DataCompressionProxyCriticalBypass Finch trial is set.
void OnResolveProxyHandler(const GURL& url,
int load_flags,
const net::ProxyConfig& data_reduction_proxy_config,
- const net::ProxyConfig& proxy_service_proxy_config,
const net::ProxyRetryInfoMap& proxy_retry_info,
const DataReductionProxyParams* params,
net::ProxyInfo* result);
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol_unittest.cc
index b277d46..6889eff 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol_unittest.cc
@@ -818,7 +818,6 @@ class BadEntropyProvider : public base::FieldTrial::EntropyProvider {
TEST_F(DataReductionProxyProtocolTest, OnResolveProxyHandler) {
int load_flags = net::LOAD_NORMAL;
GURL url("http://www.google.com/");
- net::ProxyConfig proxy_config_direct = net::ProxyConfig::CreateDirect();
TestDataReductionProxyParams test_params(
DataReductionProxyParams::kAllowed |
@@ -864,19 +863,10 @@ TEST_F(DataReductionProxyProtocolTest, OnResolveProxyHandler) {
data_reduction_proxy_info.proxy_server().ToURI()] = retry_info;
net::ProxyInfo result;
-
- // The data reduction proxy is used. It should be used afterwards.
- result.Use(data_reduction_proxy_info);
- OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &result);
- EXPECT_EQ(data_reduction_proxy_info.proxy_server(), result.proxy_server());
-
// Another proxy is used. It should be used afterwards.
result.Use(other_proxy_info);
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &result);
+ empty_proxy_retry_info, &test_params, &result);
EXPECT_EQ(other_proxy_info.proxy_server(), result.proxy_server());
// A direct connection is used. The data reduction proxy should be used
@@ -885,8 +875,7 @@ TEST_F(DataReductionProxyProtocolTest, OnResolveProxyHandler) {
result.Use(direct_proxy_info);
net::ProxyConfig::ID prev_id = result.config_id();
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &result);
+ empty_proxy_retry_info, &test_params, &result);
EXPECT_EQ(data_reduction_proxy_info.proxy_server(), result.proxy_server());
// Only the proxy list should be updated, not he proxy info.
EXPECT_EQ(result.config_id(), prev_id);
@@ -896,57 +885,44 @@ TEST_F(DataReductionProxyProtocolTest, OnResolveProxyHandler) {
result.Use(direct_proxy_info);
prev_id = result.config_id();
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config,
- proxy_config_direct, data_reduction_proxy_retry_info,
- &test_params, &result);
+ data_reduction_proxy_retry_info, &test_params, &result);
EXPECT_TRUE(result.proxy_server().is_direct());
EXPECT_EQ(result.config_id(), prev_id);
// Test that ws:// and wss:// URLs bypass the data reduction proxy.
+ result.UseDirect();
OnResolveProxyHandler(GURL("ws://echo.websocket.org/"),
load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &other_proxy_info);
- EXPECT_FALSE(other_proxy_info.is_direct());
-
- OnResolveProxyHandler(GURL("ws://echo.websocket.org/"),
- load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &data_reduction_proxy_info);
- EXPECT_TRUE(data_reduction_proxy_info.is_direct());
+ empty_proxy_retry_info, &test_params, &result);
+ EXPECT_TRUE(result.is_direct());
OnResolveProxyHandler(GURL("wss://echo.websocket.org/"),
load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &other_proxy_info);
- EXPECT_FALSE(other_proxy_info.is_direct());
-
- OnResolveProxyHandler(GURL("wss://echo.websocket.org/"),
- load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &data_reduction_proxy_info);
- EXPECT_TRUE(data_reduction_proxy_info.is_direct());
+ empty_proxy_retry_info, &test_params, &result);
+ EXPECT_TRUE(result.is_direct());
// Without DataCompressionProxyCriticalBypass Finch trial set, the
// BYPASS_DATA_REDUCTION_PROXY load flag should be ignored.
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &data_reduction_proxy_info);
- EXPECT_FALSE(data_reduction_proxy_info.is_direct());
+ empty_proxy_retry_info, &test_params,
+ &result);
+ EXPECT_FALSE(result.is_direct());
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
+ empty_proxy_retry_info,
&test_params, &other_proxy_info);
EXPECT_FALSE(other_proxy_info.is_direct());
load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY;
+ result.UseDirect();
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &data_reduction_proxy_info);
- EXPECT_FALSE(data_reduction_proxy_info.is_direct());
+ empty_proxy_retry_info, &test_params,
+ &result);
+ EXPECT_FALSE(result.is_direct());
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
+ empty_proxy_retry_info,
&test_params, &other_proxy_info);
EXPECT_FALSE(other_proxy_info.is_direct());
@@ -960,27 +936,29 @@ TEST_F(DataReductionProxyProtocolTest, OnResolveProxyHandler) {
load_flags = net::LOAD_NORMAL;
+ result.UseDirect();
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &data_reduction_proxy_info);
- EXPECT_FALSE(data_reduction_proxy_info.is_direct());
+ empty_proxy_retry_info, &test_params,
+ &result);
+ EXPECT_FALSE(result.is_direct());
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &other_proxy_info);
+ empty_proxy_retry_info, &test_params,
+ &other_proxy_info);
EXPECT_FALSE(other_proxy_info.is_direct());
load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY;
+ result.UseDirect();
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &other_proxy_info);
- EXPECT_FALSE(other_proxy_info.is_direct());
+ empty_proxy_retry_info, &test_params,
+ &result);
+ EXPECT_TRUE(result.is_direct());
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config,
- proxy_config_direct, empty_proxy_retry_info,
- &test_params, &data_reduction_proxy_info);
- EXPECT_TRUE(data_reduction_proxy_info.is_direct());
+ empty_proxy_retry_info, &test_params,
+ &other_proxy_info);
+ EXPECT_FALSE(other_proxy_info.is_direct());
}
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
index 8928867..18f8740 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
@@ -44,10 +44,18 @@ ProbeURLFetchResult FetchResult(bool enabled, bool success) {
return FAILED_PROXY_ALREADY_DISABLED;
}
-TestDataReductionProxyConfig::TestDataReductionProxyConfig()
- : enabled_(false),
+TestDataReductionProxyConfig::TestDataReductionProxyConfig(
+ scoped_refptr<base::SequencedTaskRunner> network_task_runner,
+ net::NetLog* net_log,
+ data_reduction_proxy::DataReductionProxyEventStore* event_store)
+ : DataReductionProxyConfigurator(network_task_runner, net_log, event_store),
+ enabled_(false),
restricted_(false),
- fallback_restricted_(false) {}
+ fallback_restricted_(false) {
+}
+
+TestDataReductionProxyConfig::~TestDataReductionProxyConfig() {
+}
void TestDataReductionProxyConfig::Enable(
bool restricted,
@@ -73,7 +81,8 @@ void TestDataReductionProxyConfig::Disable() {
}
DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase()
- : testing::Test() {}
+ : testing::Test() {
+}
DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {}
@@ -152,7 +161,9 @@ void DataReductionProxySettingsTestBase::ResetSettings(bool allowed,
EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
settings_.reset(settings);
- configurator_.reset(new TestDataReductionProxyConfig());
+ configurator_.reset(new TestDataReductionProxyConfig(
+ scoped_refptr<base::TestSimpleTaskRunner>(
+ new base::TestSimpleTaskRunner()), &net_log_, event_store_.get()));
settings_->configurator_ = configurator_.get();
settings_->SetDataReductionProxyStatisticsPrefs(statistics_prefs_.get());
}
@@ -280,7 +291,10 @@ void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy(
bool enabled_at_startup) {
base::MessageLoopForUI loop;
scoped_ptr<DataReductionProxyConfigurator> configurator(
- new TestDataReductionProxyConfig());
+ new TestDataReductionProxyConfig(
+ scoped_refptr<base::TestSimpleTaskRunner>(
+ new base::TestSimpleTaskRunner()), &net_log_,
+ event_store_.get()));
settings_->SetProxyConfigurator(configurator.get());
scoped_refptr<net::TestURLRequestContextGetter> request_context =
new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h
index 6127c84..ccd8170 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h
@@ -27,8 +27,11 @@ class DataReductionProxyStatisticsPrefs;
class TestDataReductionProxyConfig : public DataReductionProxyConfigurator {
public:
- TestDataReductionProxyConfig();
- ~TestDataReductionProxyConfig() override {}
+ TestDataReductionProxyConfig(
+ scoped_refptr<base::SequencedTaskRunner> network_task_runner,
+ net::NetLog* net_log,
+ data_reduction_proxy::DataReductionProxyEventStore* event_store);
+ ~TestDataReductionProxyConfig() override;
void Enable(bool restricted,
bool fallback_restricted,
const std::string& primary_origin,
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
index 19b61e5..307fb50 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
@@ -8,6 +8,7 @@
#include "base/md5.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/test/test_simple_task_runner.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.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
@@ -409,7 +410,10 @@ TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) {
EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE));
scoped_ptr<DataReductionProxyConfigurator> configurator(
- new TestDataReductionProxyConfig());
+ new TestDataReductionProxyConfig(
+ scoped_refptr<base::TestSimpleTaskRunner>(
+ new base::TestSimpleTaskRunner()), &net_log_,
+ event_store_.get()));
settings_->SetProxyConfigurator(configurator.get());
scoped_refptr<net::TestURLRequestContextGetter> request_context =
new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.cc
index cd5e37e..684c4ee 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.cc
@@ -215,14 +215,14 @@ void DataReductionProxyUsageStats::RecordBypassedBytesHistograms(
const net::ProxyConfig& data_reduction_proxy_config) {
int64 content_length = request.received_response_content_length();
- if (data_reduction_proxy_enabled.GetValue() &&
- !data_reduction_proxy_config.Equals(
- request.context()->proxy_service()->config())) {
- RecordBypassedBytes(last_bypass_type_,
- DataReductionProxyUsageStats::MANAGED_PROXY_CONFIG,
- content_length);
+ // Only record histograms when the data reduction proxy is enabled.
+ if (!data_reduction_proxy_enabled.GetValue())
+ return;
+
+ // TODO(bengr): Add histogram(s) for byte counts of unsupported schemes, e.g.,
+ // ws and wss.
+ if (!request.url().SchemeIsHTTPOrHTTPS())
return;
- }
DataReductionProxyTypeInfo data_reduction_proxy_type_info;
if (data_reduction_proxy_params_->WasDataReductionProxyUsed(
@@ -241,16 +241,25 @@ void DataReductionProxyUsageStats::RecordBypassedBytesHistograms(
return;
}
- if (data_reduction_proxy_enabled.GetValue() &&
- request.url().SchemeIs(url::kHttpsScheme)) {
+ if (request.url().SchemeIs(url::kHttpsScheme)) {
RecordBypassedBytes(last_bypass_type_,
DataReductionProxyUsageStats::SSL,
content_length);
return;
}
- if (data_reduction_proxy_enabled.GetValue() &&
- data_reduction_proxy_params_->IsBypassedByDataReductionProxyLocalRules(
+ // Now that the data reduction proxy is a best effort proxy, if the effective
+ // proxy configuration resolves to anything other than direct:// for a URL,
+ // the data reduction proxy will not be used.
+ DCHECK(data_reduction_proxy_type_info.proxy_servers.first.is_empty());
+ if (!request.proxy_server().IsEmpty()) {
+ RecordBypassedBytes(last_bypass_type_,
+ DataReductionProxyUsageStats::PROXY_OVERRIDDEN,
+ content_length);
+ return;
+ }
+
+ if (data_reduction_proxy_params_->IsBypassedByDataReductionProxyLocalRules(
request, data_reduction_proxy_config)) {
RecordBypassedBytes(last_bypass_type_,
DataReductionProxyUsageStats::LOCAL_BYPASS_RULES,
@@ -292,8 +301,7 @@ void DataReductionProxyUsageStats::RecordBypassedBytesHistograms(
return;
}
- if (data_reduction_proxy_enabled.GetValue() &&
- data_reduction_proxy_params_->AreDataReductionProxiesBypassed(request,
+ if (data_reduction_proxy_params_->AreDataReductionProxiesBypassed(request,
NULL)) {
RecordBypassedBytes(last_bypass_type_,
DataReductionProxyUsageStats::NETWORK_ERROR,
@@ -369,9 +377,9 @@ void DataReductionProxyUsageStats::RecordBypassedBytes(
"DataReductionProxy.BypassedBytes.LocalBypassRules",
content_length);
break;
- case DataReductionProxyUsageStats::MANAGED_PROXY_CONFIG:
+ case DataReductionProxyUsageStats::PROXY_OVERRIDDEN:
UMA_HISTOGRAM_COUNTS(
- "DataReductionProxy.BypassedBytes.ManagedProxyConfig",
+ "DataReductionProxy.BypassedBytes.ProxyOverridden",
content_length);
break;
case DataReductionProxyUsageStats::AUDIO_VIDEO:
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h
index a7c03414..33502e9 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h
@@ -94,7 +94,7 @@ class DataReductionProxyUsageStats
NOT_BYPASSED = 0, /* Not bypassed. */
SSL, /* Bypass due to SSL. */
LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */
- MANAGED_PROXY_CONFIG, /* Bypass due to managed config. */
+ PROXY_OVERRIDDEN, /* Bypass due to a proxy taking precedence. */
AUDIO_VIDEO, /* Audio/Video bypass. */
TRIGGERING_REQUEST, /* Triggering request bypass. */
NETWORK_ERROR, /* Network error. */