Commit 2961e58a authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Fix DRP warmup URLs with network service

DRP currently handles this by modifying the proxy list to only have a
specific proxy in the ProxyDelegate if the request is for a warmup
URL. This change implements equivalent functionality when using the
network service by creating a new NetworkContext with only the relevant
proxy set in the custom proxy config, and using that context when
making the warmup request.

Bug: 721403
Cq-Include-Trybots: luci.chromium.try:linux_mojo
Change-Id: I10e2ae5a7493526c24ac35c6db9a4d33dbbc6c8c
Reviewed-on: https://chromium-review.googlesource.com/c/1289165
Commit-Queue: rajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarrajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601867}
parent 0d81ad59
......@@ -76,6 +76,7 @@ if (is_android) {
"//components/previews/core",
"//components/variations",
"//components/variations/net",
"//content/public/browser",
"//crypto",
"//google_apis",
"//net:net",
......@@ -111,6 +112,7 @@ static_library("browser") {
"//components/previews/core",
"//components/variations",
"//components/variations/net",
"//content/public/browser",
"//crypto",
"//google_apis",
"//net",
......@@ -218,6 +220,7 @@ source_set("unit_tests") {
"//components/previews/core",
"//components/previews/core:test_support",
"//components/variations",
"//content/public/browser",
"//net:test_support",
"//services/network:network_service",
"//services/network:test_support",
......
......@@ -3,4 +3,5 @@ include_rules = [
"+services/network/public",
"+services/network/test",
"+third_party/leveldatabase",
"+content/public/browser",
]
......@@ -182,6 +182,7 @@ namespace data_reduction_proxy {
DataReductionProxyConfig::DataReductionProxyConfig(
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
network::NetworkConnectionTracker* network_connection_tracker,
std::unique_ptr<DataReductionProxyConfigValues> config_values,
DataReductionProxyConfigurator* configurator)
......@@ -189,6 +190,7 @@ DataReductionProxyConfig::DataReductionProxyConfig(
enabled_by_user_(false),
config_values_(std::move(config_values)),
io_task_runner_(io_task_runner),
ui_task_runner_(ui_task_runner),
network_connection_tracker_(network_connection_tracker),
configurator_(configurator),
connection_type_(network::mojom::ConnectionType::CONNECTION_UNKNOWN),
......@@ -208,6 +210,8 @@ DataReductionProxyConfig::~DataReductionProxyConfig() {
void DataReductionProxyConfig::InitializeOnIOThread(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
WarmupURLFetcher::CreateCustomProxyConfigCallback
create_custom_proxy_config_callback,
NetworkPropertiesManager* manager) {
DCHECK(thread_checker_.CalledOnValidThread());
network_properties_manager_ = manager;
......@@ -215,12 +219,13 @@ void DataReductionProxyConfig::InitializeOnIOThread(
secure_proxy_checker_.reset(new SecureProxyChecker(url_loader_factory));
warmup_url_fetcher_.reset(new WarmupURLFetcher(
url_loader_factory,
url_loader_factory, create_custom_proxy_config_callback,
base::BindRepeating(
&DataReductionProxyConfig::HandleWarmupFetcherResponse,
base::Unretained(this)),
base::BindRepeating(&DataReductionProxyConfig::GetHttpRttEstimate,
base::Unretained(this))));
base::Unretained(this)),
ui_task_runner_));
if (ShouldAddDefaultProxyBypassRules())
AddDefaultProxyBypassRules();
......@@ -443,7 +448,7 @@ void DataReductionProxyConfig::SetNetworkPropertiesManagerForTesting(
network_properties_manager_ = manager;
}
base::Optional<std::pair<bool /* is_secure_proxy */, bool /*is_core_proxy */>>
base::Optional<DataReductionProxyServer>
DataReductionProxyConfig::GetProxyConnectionToProbe() const {
DCHECK(thread_checker_.CalledOnValidThread());
......@@ -461,7 +466,7 @@ DataReductionProxyConfig::GetProxyConnectionToProbe() const {
is_core_proxy) &&
network_properties_manager_->ShouldFetchWarmupProbeURL(is_secure_proxy,
is_core_proxy)) {
return std::make_pair(is_secure_proxy, is_core_proxy);
return proxy_server;
}
}
......@@ -473,7 +478,7 @@ DataReductionProxyConfig::GetProxyConnectionToProbe() const {
bool is_core_proxy = proxy_server.IsCoreProxy();
if (network_properties_manager_->ShouldFetchWarmupProbeURL(is_secure_proxy,
is_core_proxy)) {
return std::make_pair(is_secure_proxy, is_core_proxy);
return proxy_server;
}
}
......@@ -711,15 +716,15 @@ void DataReductionProxyConfig::FetchWarmupProbeURL() {
return;
}
base::Optional<std::pair<bool /* is_secure_proxy */, bool /*is_core_proxy */>>
warmup_config = GetProxyConnectionToProbe();
base::Optional<DataReductionProxyServer> warmup_proxy =
GetProxyConnectionToProbe();
if (!warmup_config)
if (!warmup_proxy)
return;
// Refetch the warmup URL when it has failed.
warmup_url_fetch_in_flight_secure_proxy_ = warmup_config->first;
warmup_url_fetch_in_flight_core_proxy_ = warmup_config->second;
warmup_url_fetch_in_flight_secure_proxy_ = warmup_proxy->IsSecureProxy();
warmup_url_fetch_in_flight_core_proxy_ = warmup_proxy->IsCoreProxy();
size_t previous_attempt_counts = GetWarmupURLFetchAttemptCounts();
......@@ -729,7 +734,8 @@ void DataReductionProxyConfig::FetchWarmupProbeURL() {
RecordWarmupURLFetchAttemptEvent(WarmupURLFetchAttemptEvent::kFetchInitiated);
warmup_url_fetcher_->FetchWarmupURL(previous_attempt_counts);
warmup_url_fetcher_->FetchWarmupURL(previous_attempt_counts,
warmup_proxy.value());
}
size_t DataReductionProxyConfig::GetWarmupURLFetchAttemptCounts() const {
......
......@@ -88,6 +88,7 @@ class DataReductionProxyConfig
// configuration update.
DataReductionProxyConfig(
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
network::NetworkConnectionTracker* network_connection_tracker,
std::unique_ptr<DataReductionProxyConfigValues> config_values,
DataReductionProxyConfigurator* configurator);
......@@ -98,6 +99,8 @@ class DataReductionProxyConfig
// making URL requests. The requests disable the use of proxies.
void InitializeOnIOThread(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
WarmupURLFetcher::CreateCustomProxyConfigCallback
create_custom_proxy_config_callback,
NetworkPropertiesManager* manager);
// Sets the proxy configs, enabling or disabling the proxy according to
......@@ -207,8 +210,7 @@ class DataReductionProxyConfig
// Returns the details of the proxy to which the next warmup URL probe should
// be sent to.
base::Optional<std::pair<bool /* is_secure_proxy */, bool /*is_core_proxy */>>
GetProxyConnectionToProbe() const;
base::Optional<DataReductionProxyServer> GetProxyConnectionToProbe() const;
// Returns true if a warmup URL probe is in-flight. Virtualized for testing.
virtual bool IsFetchInFlight() const;
......@@ -305,6 +307,7 @@ class DataReductionProxyConfig
std::unique_ptr<DataReductionProxyConfigValues> config_values_;
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
#if defined(OS_CHROMEOS)
// Whether the network id should be obtained on a worker thread.
......
......@@ -24,18 +24,22 @@ namespace data_reduction_proxy {
TestDataReductionProxyConfig::TestDataReductionProxyConfig(
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
DataReductionProxyConfigurator* configurator)
: TestDataReductionProxyConfig(
std::make_unique<TestDataReductionProxyParams>(),
io_task_runner,
ui_task_runner,
configurator) {}
TestDataReductionProxyConfig::TestDataReductionProxyConfig(
std::unique_ptr<DataReductionProxyConfigValues> config_values,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
DataReductionProxyConfigurator* configurator)
: DataReductionProxyConfig(
io_task_runner,
ui_task_runner,
network::TestNetworkConnectionTracker::GetInstance(),
std::move(config_values),
configurator),
......@@ -136,9 +140,11 @@ void TestDataReductionProxyConfig::SetWarmupURLFetchAttemptCounts(
MockDataReductionProxyConfig::MockDataReductionProxyConfig(
std::unique_ptr<DataReductionProxyConfigValues> config_values,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
DataReductionProxyConfigurator* configurator)
: TestDataReductionProxyConfig(std::move(config_values),
io_task_runner,
ui_task_runner,
configurator) {}
MockDataReductionProxyConfig::~MockDataReductionProxyConfig() {
......
......@@ -34,6 +34,7 @@ class TestDataReductionProxyConfig : public DataReductionProxyConfig {
public:
TestDataReductionProxyConfig(
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
DataReductionProxyConfigurator* configurator);
// Creates a |TestDataReductionProxyConfig| with the provided |config_values|.
......@@ -42,6 +43,7 @@ class TestDataReductionProxyConfig : public DataReductionProxyConfig {
TestDataReductionProxyConfig(
std::unique_ptr<DataReductionProxyConfigValues> config_values,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
DataReductionProxyConfigurator* configurator);
~TestDataReductionProxyConfig() override;
......@@ -134,6 +136,7 @@ class MockDataReductionProxyConfig : public TestDataReductionProxyConfig {
MockDataReductionProxyConfig(
std::unique_ptr<DataReductionProxyConfigValues> config_values,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
DataReductionProxyConfigurator* configurator);
~MockDataReductionProxyConfig() override;
......
......@@ -180,8 +180,9 @@ class DataReductionProxyConfigTest : public testing::Test {
std::unique_ptr<DataReductionProxyConfig> BuildConfig(
std::unique_ptr<DataReductionProxyParams> params) {
return std::make_unique<DataReductionProxyConfig>(
task_runner(), network::TestNetworkConnectionTracker::GetInstance(),
std::move(params), test_context_->configurator());
task_runner(), task_runner(),
network::TestNetworkConnectionTracker::GetInstance(), std::move(params),
test_context_->configurator());
}
MockDataReductionProxyConfig* mock_config() {
......@@ -420,13 +421,18 @@ TEST_F(DataReductionProxyConfigTest, WarmupURL) {
"Enabled");
base::CommandLine::ForCurrentProcess()->InitFromArgv(0, nullptr);
TestDataReductionProxyConfig config(task_runner(), configurator());
TestDataReductionProxyConfig config(task_runner(), task_runner(),
configurator());
NetworkPropertiesManager network_properties_manager(
base::DefaultClock::GetInstance(), test_context_->pref_service(),
test_context_->task_runner());
config.InitializeOnIOThread(test_context_->url_loader_factory(),
&network_properties_manager);
config.InitializeOnIOThread(
test_context_->url_loader_factory(),
base::BindRepeating([](const std::vector<DataReductionProxyServer>&) {
return network::mojom::CustomProxyConfig::New();
}),
&network_properties_manager);
RunUntilIdle();
{
......@@ -759,8 +765,9 @@ TEST_F(DataReductionProxyConfigTest,
ASSERT_LT(0U, expected_proxies.size());
DataReductionProxyConfig config(
task_runner(), network::TestNetworkConnectionTracker::GetInstance(),
std::move(params), configurator());
task_runner(), task_runner(),
network::TestNetworkConnectionTracker::GetInstance(), std::move(params),
configurator());
for (size_t expected_proxy_index = 0U;
expected_proxy_index < expected_proxies.size(); ++expected_proxy_index) {
......@@ -833,7 +840,8 @@ TEST_F(DataReductionProxyConfigTest,
config_values->UpdateValues(proxies_for_http);
std::unique_ptr<DataReductionProxyConfig> config(new DataReductionProxyConfig(
task_runner(), network::TestNetworkConnectionTracker::GetInstance(),
task_runner(), task_runner(),
network::TestNetworkConnectionTracker::GetInstance(),
std::move(config_values), configurator()));
for (const auto& test : tests) {
base::Optional<DataReductionProxyTypeInfo> proxy_type_info =
......
......@@ -36,6 +36,7 @@
#include "net/url_request/url_request_context_builder.h"
#include "net/url_request/url_request_context_getter.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/network_context.mojom.h"
namespace data_reduction_proxy {
......@@ -68,8 +69,8 @@ DataReductionProxyIOData::DataReductionProxyIOData(
std::make_unique<DataReductionProxyMutableConfigValues>();
raw_mutable_config = mutable_config.get();
config_.reset(new DataReductionProxyConfig(
io_task_runner, network_connection_tracker_, std::move(mutable_config),
configurator_.get()));
io_task_runner, ui_task_runner, network_connection_tracker_,
std::move(mutable_config), configurator_.get()));
// It is safe to use base::Unretained here, since it gets executed
// synchronously on the IO thread, and |this| outlives the caller (since the
......@@ -158,8 +159,11 @@ void DataReductionProxyIOData::InitializeOnIOThread() {
auto url_loader_factory = network::SharedURLLoaderFactory::Create(
std::move(url_loader_factory_info_));
config_->InitializeOnIOThread(url_loader_factory,
network_properties_manager_.get());
config_->InitializeOnIOThread(
url_loader_factory,
base::BindRepeating(&DataReductionProxyIOData::CreateCustomProxyConfig,
base::Unretained(this)),
network_properties_manager_.get());
bypass_stats_->InitializeOnIOThread();
proxy_delegate_->InitializeOnIOThread(this);
if (config_client_)
......@@ -360,12 +364,9 @@ void DataReductionProxyIOData::UpdateProxyRequestHeaders(
OnProxyConfigUpdated();
}
void DataReductionProxyIOData::OnProxyConfigUpdated() {
if (!proxy_config_client_)
return;
const auto proxies_for_http = config_->GetProxiesForHttp();
network::mojom::CustomProxyConfigPtr
DataReductionProxyIOData::CreateCustomProxyConfig(
const std::vector<DataReductionProxyServer>& proxies_for_http) const {
auto config = network::mojom::CustomProxyConfig::New();
config->rules =
configurator_
......@@ -393,7 +394,15 @@ void DataReductionProxyIOData::OnProxyConfigUpdated() {
request_options_->AddRequestHeader(&config->post_cache_headers,
base::nullopt);
proxy_config_client_->OnCustomProxyConfigUpdated(std::move(config));
return config;
}
void DataReductionProxyIOData::OnProxyConfigUpdated() {
if (!proxy_config_client_)
return;
proxy_config_client_->OnCustomProxyConfigUpdated(
CreateCustomProxyConfig(config_->GetProxiesForHttp()));
}
void DataReductionProxyIOData::OnEffectiveConnectionTypeChanged(
......
......@@ -43,6 +43,7 @@ class DataReductionProxyBypassStats;
class DataReductionProxyConfig;
class DataReductionProxyConfigServiceClient;
class DataReductionProxyConfigurator;
class DataReductionProxyServer;
class DataReductionProxyService;
class NetworkPropertiesManager;
......@@ -240,6 +241,11 @@ class DataReductionProxyIOData {
// storage.
void StoreSerializedConfig(const std::string& serialized_config);
// Creates a config using |proxies_for_http| that can be sent to the
// NetworkContext.
network::mojom::CustomProxyConfigPtr CreateCustomProxyConfig(
const std::vector<DataReductionProxyServer>& proxies_for_http) const;
// The type of Data Reduction Proxy client.
const Client client_;
......
......@@ -472,19 +472,20 @@ DataReductionProxyTestContext::Builder::Build() {
mutable_config->UpdateValues(proxy_servers_);
}
raw_mutable_config = mutable_config.get();
config.reset(new TestDataReductionProxyConfig(
std::move(mutable_config), task_runner, configurator.get()));
config.reset(new TestDataReductionProxyConfig(std::move(mutable_config),
task_runner, task_runner,
configurator.get()));
} else if (use_mock_config_) {
test_context_flags |= USE_MOCK_CONFIG;
config.reset(new MockDataReductionProxyConfig(
std::move(params), task_runner, configurator.get()));
std::move(params), task_runner, task_runner, configurator.get()));
} else {
test_context_flags ^= USE_MOCK_CONFIG;
if (!proxy_servers_.empty()) {
params->SetProxiesForHttp(proxy_servers_);
}
config.reset(new TestDataReductionProxyConfig(
std::move(params), task_runner, configurator.get()));
std::move(params), task_runner, task_runner, configurator.get()));
}
std::unique_ptr<TestDataReductionProxyRequestOptions> request_options;
......
......@@ -13,36 +13,56 @@
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_server.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "content/public/browser/network_service_instance.h"
#include "net/base/load_flags.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/network_service.mojom.h"
namespace data_reduction_proxy {
namespace {
const int kInvalidResponseCode = -1;
void BindNetworkContextOnUI(network::mojom::CustomProxyConfigPtr config,
network::mojom::NetworkContextRequest request) {
auto params = network::mojom::NetworkContextParams::New();
params->initial_custom_proxy_config = std::move(config);
content::GetNetworkService()->CreateNetworkContext(std::move(request),
std::move(params));
}
}
WarmupURLFetcher::WarmupURLFetcher(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
scoped_refptr<network::SharedURLLoaderFactory>
non_network_service_url_loader_factory,
CreateCustomProxyConfigCallback create_custom_proxy_config_callback,
WarmupURLFetcherCallback callback,
GetHttpRttCallback get_http_rtt_callback)
GetHttpRttCallback get_http_rtt_callback,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
: is_fetch_in_flight_(false),
previous_attempt_counts_(0),
url_loader_factory_(std::move(url_loader_factory)),
non_network_service_url_loader_factory_(
std::move(non_network_service_url_loader_factory)),
create_custom_proxy_config_callback_(create_custom_proxy_config_callback),
callback_(callback),
get_http_rtt_callback_(get_http_rtt_callback) {
DCHECK(url_loader_factory_);
get_http_rtt_callback_(get_http_rtt_callback),
ui_task_runner_(ui_task_runner) {
DCHECK(non_network_service_url_loader_factory_);
DCHECK(create_custom_proxy_config_callback);
}
WarmupURLFetcher::~WarmupURLFetcher() {}
void WarmupURLFetcher::FetchWarmupURL(size_t previous_attempt_counts) {
void WarmupURLFetcher::FetchWarmupURL(
size_t previous_attempt_counts,
const DataReductionProxyServer& proxy_server) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
previous_attempt_counts_ = previous_attempt_counts;
......@@ -54,11 +74,13 @@ void WarmupURLFetcher::FetchWarmupURL(size_t previous_attempt_counts) {
fetch_delay_timer_.Stop();
if (previous_attempt_counts_ == 0) {
FetchWarmupURLNow();
FetchWarmupURLNow(proxy_server);
return;
}
fetch_delay_timer_.Start(FROM_HERE, GetFetchWaitTime(), this,
&WarmupURLFetcher::FetchWarmupURLNow);
fetch_delay_timer_.Start(
FROM_HERE, GetFetchWaitTime(),
base::BindOnce(&WarmupURLFetcher::FetchWarmupURLNow,
base::Unretained(this), proxy_server));
}
base::TimeDelta WarmupURLFetcher::GetFetchWaitTime() const {
......@@ -77,7 +99,8 @@ base::TimeDelta WarmupURLFetcher::GetFetchWaitTime() const {
"warmup_url_fetch_wait_timer_second_retry_seconds", 30));
}
void WarmupURLFetcher::FetchWarmupURLNow() {
void WarmupURLFetcher::FetchWarmupURLNow(
const DataReductionProxyServer& proxy_server) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
UMA_HISTOGRAM_EXACT_LINEAR("DataReductionProxy.WarmupURL.FetchInitiated", 1,
......@@ -134,10 +157,33 @@ void WarmupURLFetcher::FetchWarmupURLNow() {
&WarmupURLFetcher::OnURLLoadResponseStarted, base::Unretained(this)));
url_loader_->SetOnRedirectCallback(base::BindRepeating(
&WarmupURLFetcher::OnURLLoaderRedirect, base::Unretained(this)));
network::mojom::URLLoaderFactory* factory = nullptr;
if (params::IsEnabledWithNetworkService())
factory = GetNetworkServiceURLLoaderFactory(proxy_server);
else
factory = non_network_service_url_loader_factory_.get();
url_loader_->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
url_loader_factory_.get(),
base::BindOnce(&WarmupURLFetcher::OnURLLoadComplete,
base::Unretained(this)));
factory, base::BindOnce(&WarmupURLFetcher::OnURLLoadComplete,
base::Unretained(this)));
}
network::mojom::URLLoaderFactory*
WarmupURLFetcher::GetNetworkServiceURLLoaderFactory(
const DataReductionProxyServer& proxy_server) {
network::mojom::NetworkContextPtr context;
ui_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&BindNetworkContextOnUI,
create_custom_proxy_config_callback_.Run({proxy_server}),
mojo::MakeRequest(&context_)));
auto factory_params = network::mojom::URLLoaderFactoryParams::New();
factory_params->process_id = network::mojom::kBrowserProcessId;
factory_params->is_corb_enabled = false;
context_->CreateURLLoaderFactory(mojo::MakeRequest(&url_loader_factory_),
std::move(factory_params));
return url_loader_factory_.get();
}
void WarmupURLFetcher::GetWarmupURLWithQueryParam(
......
......@@ -14,6 +14,7 @@
#include "base/sequence_checker.h"
#include "base/timer/timer.h"
#include "net/base/proxy_server.h"
#include "services/network/public/mojom/network_context.mojom.h"
class GURL;
......@@ -28,6 +29,7 @@ class SimpleURLLoader;
} // namespace network
namespace data_reduction_proxy {
class DataReductionProxyServer;
class WarmupURLFetcher {
public:
......@@ -35,17 +37,24 @@ class WarmupURLFetcher {
// The proxy server that was used to fetch the request, and whether the fetch
// was successful.
typedef base::RepeatingCallback<void(const net::ProxyServer&, FetchResult)>
WarmupURLFetcherCallback;
using WarmupURLFetcherCallback =
base::RepeatingCallback<void(const net::ProxyServer&, FetchResult)>;
// Callback to obtain the current HTTP RTT estimate.
typedef base::RepeatingCallback<base::Optional<base::TimeDelta>()>
GetHttpRttCallback;
using GetHttpRttCallback =
base::RepeatingCallback<base::Optional<base::TimeDelta>()>;
// Callback to get a config for the given proxy servers.
using CreateCustomProxyConfigCallback =
base::RepeatingCallback<network::mojom::CustomProxyConfigPtr(
const std::vector<DataReductionProxyServer>&)>;
WarmupURLFetcher(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
CreateCustomProxyConfigCallback create_custom_proxy_config_callback,
WarmupURLFetcherCallback callback,
GetHttpRttCallback get_http_rtt_callback);
GetHttpRttCallback get_http_rtt_callback,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
virtual ~WarmupURLFetcher();
......@@ -53,7 +62,8 @@ class WarmupURLFetcher {
// |previous_attempt_counts| is the count of fetch attempts that have been
// made to the proxy which is being probed. The fetching may happen after some
// delay depending on |previous_attempt_counts|.
void FetchWarmupURL(size_t previous_attempt_counts);
void FetchWarmupURL(size_t previous_attempt_counts,
const DataReductionProxyServer& proxy_server);
// Returns true if a warmup URL fetch is currently in-flight.
bool IsFetchInFlight() const;
......@@ -105,17 +115,26 @@ class WarmupURLFetcher {
private:
// Creates and immediately starts a URLLoader that fetches the warmup URL.
void FetchWarmupURLNow();
void FetchWarmupURLNow(const DataReductionProxyServer& proxy_server);
// Resets the variable after the fetching of the warmup URL has completed or
// timed out. Must be called after |callback_| has been run.
void CleanupAfterFetch();
// Gets a URLLoaderFactory which will only attempt to use |proxy_server| as a
// proxy.
network::mojom::URLLoaderFactory* GetNetworkServiceURLLoaderFactory(
const DataReductionProxyServer& proxy_server);
// Count of fetch attempts that have been made to the proxy which is being
// probed.
size_t previous_attempt_counts_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
scoped_refptr<network::SharedURLLoaderFactory>
non_network_service_url_loader_factory_;
CreateCustomProxyConfigCallback create_custom_proxy_config_callback_;
network::mojom::URLLoaderFactoryPtr url_loader_factory_;
network::mojom::NetworkContextPtr context_;
// Callback that should be executed when the fetching of the warmup URL is
// completed.
......@@ -124,6 +143,8 @@ class WarmupURLFetcher {
// Callback to obtain the current HTTP RTT estimate.
GetHttpRttCallback get_http_rtt_callback_;
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(WarmupURLFetcher);
......
......@@ -1488,8 +1488,10 @@ URLRequestContextOwner NetworkContext::MakeURLRequestContext() {
std::make_unique<NetworkServiceNetworkDelegate>(this);
builder.set_network_delegate(std::move(network_delegate));
if (params_->custom_proxy_config_client_request) {
if (params_->initial_custom_proxy_config ||
params_->custom_proxy_config_client_request) {
proxy_delegate_ = std::make_unique<NetworkServiceProxyDelegate>(
std::move(params_->initial_custom_proxy_config),
std::move(params_->custom_proxy_config_client_request));
builder.set_shared_proxy_delegate(proxy_delegate_.get());
}
......
......@@ -74,8 +74,10 @@ bool IsURLValidForProxy(const GURL& url) {
} // namespace
NetworkServiceProxyDelegate::NetworkServiceProxyDelegate(
mojom::CustomProxyConfigPtr initial_config,
mojom::CustomProxyConfigClientRequest config_client_request)
: binding_(this, std::move(config_client_request)),
: proxy_config_(std::move(initial_config)),
binding_(this, std::move(config_client_request)),
should_use_alternate_proxy_list_cache_(kMaxCacheSize) {}
void NetworkServiceProxyDelegate::OnBeforeStartTransaction(
......
......@@ -29,6 +29,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkServiceProxyDelegate
public mojom::CustomProxyConfigClient {
public:
explicit NetworkServiceProxyDelegate(
mojom::CustomProxyConfigPtr initial_config,
mojom::CustomProxyConfigClientRequest config_client_request);
~NetworkServiceProxyDelegate() override;
......
......@@ -30,7 +30,7 @@ class NetworkServiceProxyDelegateTest : public testing::Test {
std::unique_ptr<NetworkServiceProxyDelegate> CreateDelegate(
mojom::CustomProxyConfigPtr config) {
auto delegate = std::make_unique<NetworkServiceProxyDelegate>(
mojo::MakeRequest(&client_));
network::mojom::CustomProxyConfig::New(), mojo::MakeRequest(&client_));
SetConfig(std::move(config));
return delegate;
}
......@@ -264,7 +264,7 @@ TEST_F(NetworkServiceProxyDelegateTest, OnResolveProxySuccessHttpProxy) {
expected_proxy_list.AddProxyServer(
net::ProxyServer::FromPacString("PROXY foo"));
EXPECT_TRUE(result.proxy_list().Equals(expected_proxy_list));
// HTTP proxies are nto used as alternative QUIC proxies.
// HTTP proxies are not used as alternative QUIC proxies.
EXPECT_FALSE(result.alternative_proxy().is_valid());
}
......@@ -376,4 +376,22 @@ TEST_F(NetworkServiceProxyDelegateTest, OnResolveProxyDeprioritizesBadProxies) {
EXPECT_TRUE(result.proxy_list().Equals(expected_proxy_list));
}
TEST_F(NetworkServiceProxyDelegateTest, InitialConfigUsedForProxy) {
auto config = mojom::CustomProxyConfig::New();
config->rules.ParseFromString("http=foo");
mojom::CustomProxyConfigClientPtr client;
auto delegate = std::make_unique<NetworkServiceProxyDelegate>(
std::move(config), mojo::MakeRequest(&client));
net::ProxyInfo result;
result.UseDirect();
delegate->OnResolveProxy(GURL(kHttpUrl), "GET", net::ProxyRetryInfoMap(),
&result);
net::ProxyList expected_proxy_list;
expected_proxy_list.AddProxyServer(
net::ProxyServer::FromPacString("PROXY foo"));
EXPECT_TRUE(result.proxy_list().Equals(expected_proxy_list));
}
} // namespace network
......@@ -182,6 +182,8 @@ struct NetworkContextParams {
// If |custom_proxy_config_client_request| is set, this context will listen
// for updates to the custom proxy config, and use it if applicable for
// requests which would otherwise be made direct.
// |initial_custom_proxy_config| is the initial config settings.
CustomProxyConfig? initial_custom_proxy_config;
CustomProxyConfigClient&? custom_proxy_config_client_request;
// If |proxy_config_client_request| is non-null, this is called during
......
......@@ -109,9 +109,6 @@
-DataReductionProxyFallbackBrowsertest.FallbackProxyUsedWhenBlockZeroHeaderSent
-DataReductionProxyFallbackBrowsertest.FallbackProxyUsedWhenBypassHeaderSent
-DataReductionProxyFallbackBrowsertest.NoProxyUsedWhenBlockOnceHeaderSent
-DataReductionProxyWarmupURLBrowsertest.WarmupURLsFetchedForEachProxy/0
-DataReductionProxyWarmupURLBrowsertest.WarmupURLsFetchedForEachProxy/1
-DataReductionProxyWarmupURLBrowsertest.WarmupURLsFetchedForEachProxy/3
# NOTE: if adding an exclusion for an existing failure (e.g. additional test for
# feature X that is already not working), please add it beside the existing
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment