Commit a9b01b75 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Migrate...

Migrate components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc to using SimpleURLLoader

URLFetcher will stop working with advent of Network Service, and
SimpleURLLoader is the replacement API for most clients.
This CL migrates Android's WarmupURLFetcher and the
respective unittests away from URLFetcher.

When migrating the unittests, it was opted to implement a
queue of mocked responses mechanism, to mimic the current behavior
(using net::MockClientSocketFactory and net::MockRead objects).

The CL also removed the helper method GetURLFetcherForConfig,
merging it into RetrieveRemoteConfig. Basically, although it made
sense with URLFetcher's set up and flow of method calls, it is
not the case with SimpleURLLoader.

BUG=879784

Change-Id: I0c38042fcd37f5848dca49ff8322e514f818cdba
Reviewed-on: https://chromium-review.googlesource.com/c/1274405Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#598936}
parent 75583c7c
...@@ -46,9 +46,9 @@ ...@@ -46,9 +46,9 @@
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
#include "net/log/net_log_source_type.h" #include "net/log/net_log_source_type.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_status.h"
#include "services/network/public/cpp/features.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"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "net/android/network_library.h" #include "net/android/network_library.h"
...@@ -164,7 +164,6 @@ DataReductionProxyConfigServiceClient::DataReductionProxyConfigServiceClient( ...@@ -164,7 +164,6 @@ DataReductionProxyConfigServiceClient::DataReductionProxyConfigServiceClient(
config_service_url_(util::AddApiKeyToUrl(params::GetConfigServiceURL())), config_service_url_(util::AddApiKeyToUrl(params::GetConfigServiceURL())),
enabled_(false), enabled_(false),
remote_config_applied_(false), remote_config_applied_(false),
url_request_context_getter_(nullptr),
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
foreground_fetch_pending_(false), foreground_fetch_pending_(false),
#endif #endif
...@@ -221,12 +220,8 @@ DataReductionProxyConfigServiceClient::CalculateNextConfigRefreshTime( ...@@ -221,12 +220,8 @@ DataReductionProxyConfigServiceClient::CalculateNextConfigRefreshTime(
} }
void DataReductionProxyConfigServiceClient::InitializeOnIOThread( void DataReductionProxyConfigServiceClient::InitializeOnIOThread(
net::URLRequestContextGetter* url_request_context_getter) { scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) {
// TODO(crbug.com/721403): DRP is disabled with network service enabled. When DCHECK(url_loader_factory);
// DRP is switched to mojo, we won't need URLRequestContext.
if (!base::FeatureList::IsEnabled(network::features::kNetworkService)) {
DCHECK(url_request_context_getter);
}
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// It is okay to use Unretained here because |app_status_listener| would be // It is okay to use Unretained here because |app_status_listener| would be
// destroyed before |this|. // destroyed before |this|.
...@@ -235,7 +230,7 @@ void DataReductionProxyConfigServiceClient::InitializeOnIOThread( ...@@ -235,7 +230,7 @@ void DataReductionProxyConfigServiceClient::InitializeOnIOThread(
&DataReductionProxyConfigServiceClient::OnApplicationStateChange, &DataReductionProxyConfigServiceClient::OnApplicationStateChange,
base::Unretained(this))); base::Unretained(this)));
#endif #endif
url_request_context_getter_ = url_request_context_getter; url_loader_factory_ = std::move(url_loader_factory);
network_connection_tracker_->AddNetworkConnectionObserver(this); network_connection_tracker_->AddNetworkConnectionObserver(this);
} }
...@@ -411,15 +406,17 @@ void DataReductionProxyConfigServiceClient::OnConnectionChanged( ...@@ -411,15 +406,17 @@ void DataReductionProxyConfigServiceClient::OnConnectionChanged(
RetrieveConfig(); RetrieveConfig();
} }
void DataReductionProxyConfigServiceClient::OnURLFetchComplete( void DataReductionProxyConfigServiceClient::OnURLLoadComplete(
const net::URLFetcher* source) { std::unique_ptr<std::string> response_body) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(source == fetcher_.get());
fetch_in_progress_ = false; fetch_in_progress_ = false;
net::URLRequestStatus status = source->GetStatus();
std::string response; int response_code = -1;
source->GetResponseAsString(&response); if (url_loader_->ResponseInfo() && url_loader_->ResponseInfo()->headers) {
HandleResponse(response, status, source->GetResponseCode()); response_code = url_loader_->ResponseInfo()->headers->response_code();
}
HandleResponse(response_body ? *response_body : "", url_loader_->NetError(),
response_code);
} }
void DataReductionProxyConfigServiceClient::RetrieveRemoteConfig() { void DataReductionProxyConfigServiceClient::RetrieveRemoteConfig() {
...@@ -452,43 +449,7 @@ void DataReductionProxyConfigServiceClient::RetrieveRemoteConfig() { ...@@ -452,43 +449,7 @@ void DataReductionProxyConfigServiceClient::RetrieveRemoteConfig() {
version_info->set_patch(patch); version_info->set_patch(patch);
version_info->set_channel(io_data_->channel()); version_info->set_channel(io_data_->channel());
request.SerializeToString(&serialized_request); request.SerializeToString(&serialized_request);
std::unique_ptr<net::URLFetcher> fetcher =
GetURLFetcherForConfig(config_service_url_, serialized_request);
if (!fetcher) {
HandleResponse(std::string(),
net::URLRequestStatus::FromError(net::ERR_ABORTED),
net::URLFetcher::RESPONSE_CODE_INVALID);
return;
}
fetcher_ = std::move(fetcher);
fetch_in_progress_ = true;
// Attach variations headers.
net::HttpRequestHeaders headers;
variations::AppendVariationHeaders(config_service_url_,
variations::InIncognito::kNo,
variations::SignedIn::kNo, &headers);
if (!headers.IsEmpty())
fetcher_->SetExtraRequestHeaders(headers.ToString());
fetcher_->Start();
}
void DataReductionProxyConfigServiceClient::InvalidateConfig() {
DCHECK(thread_checker_.CalledOnValidThread());
GetBackoffEntry()->InformOfRequest(false);
config_storer_.Run(std::string());
request_options_->Invalidate();
config_values_->Invalidate();
io_data_->SetPingbackReportingFraction(0.0f);
config_->OnNewClientConfigFetched();
}
std::unique_ptr<net::URLFetcher>
DataReductionProxyConfigServiceClient::GetURLFetcherForConfig(
const GURL& secure_proxy_check_url,
const std::string& request_body) {
DCHECK(thread_checker_.CalledOnValidThread());
net::NetworkTrafficAnnotationTag traffic_annotation = net::NetworkTrafficAnnotationTag traffic_annotation =
net::DefineNetworkTrafficAnnotation("data_reduction_proxy_config", R"( net::DefineNetworkTrafficAnnotation("data_reduction_proxy_config", R"(
semantics { semantics {
...@@ -511,28 +472,47 @@ DataReductionProxyConfigServiceClient::GetURLFetcherForConfig( ...@@ -511,28 +472,47 @@ DataReductionProxyConfigServiceClient::GetURLFetcherForConfig(
"by insalling the Data Saver extension." "by insalling the Data Saver extension."
policy_exception_justification: "Not implemented." policy_exception_justification: "Not implemented."
})"); })");
std::unique_ptr<net::URLFetcher> fetcher(net::URLFetcher::Create( fetch_in_progress_ = true;
secure_proxy_check_url, net::URLFetcher::POST, this, traffic_annotation));
data_use_measurement::DataUseUserData::AttachToFetcher( auto resource_request = std::make_unique<network::ResourceRequest>();
fetcher.get(), resource_request->url = config_service_url_;
data_use_measurement::DataUseUserData::DATA_REDUCTION_PROXY); resource_request->method = "POST";
fetcher->SetLoadFlags(net::LOAD_BYPASS_PROXY | net::LOAD_DO_NOT_SEND_COOKIES | resource_request->load_flags = net::LOAD_BYPASS_PROXY |
net::LOAD_DO_NOT_SAVE_COOKIES); net::LOAD_DO_NOT_SEND_COOKIES |
fetcher->SetUploadData("application/x-protobuf", request_body); net::LOAD_DO_NOT_SAVE_COOKIES;
DCHECK(url_request_context_getter_); // Attach variations headers.
fetcher->SetRequestContext(url_request_context_getter_); url_loader_ = variations::CreateSimpleURLLoaderWithVariationsHeaders(
// |fetcher| should not retry on 5xx errors since the server may already be std::move(resource_request), variations::InIncognito::kNo,
// overloaded. Spurious 5xx errors are still retried on exponential backoff. variations::SignedIn::kNo, traffic_annotation);
// |fetcher| should retry on network changes since the network stack may
// receive the connection change event later than |this|. url_loader_->AttachStringForUpload(serialized_request,
"application/x-protobuf");
// |url_loader_| should not retry on 5xx errors since the server may already
// be overloaded. Spurious 5xx errors are still retried on exponential
// backoff. |url_loader_| should retry on network changes since the network
// stack may receive the connection change event later than |this|.
static const int kMaxRetries = 5; static const int kMaxRetries = 5;
fetcher->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); url_loader_->SetRetryOptions(
return fetcher; kMaxRetries, network::SimpleURLLoader::RETRY_ON_NETWORK_CHANGE);
url_loader_->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
url_loader_factory_.get(),
base::BindOnce(&DataReductionProxyConfigServiceClient::OnURLLoadComplete,
base::Unretained(this)));
}
void DataReductionProxyConfigServiceClient::InvalidateConfig() {
DCHECK(thread_checker_.CalledOnValidThread());
GetBackoffEntry()->InformOfRequest(false);
config_storer_.Run(std::string());
request_options_->Invalidate();
config_values_->Invalidate();
io_data_->SetPingbackReportingFraction(0.0f);
config_->OnNewClientConfigFetched();
} }
void DataReductionProxyConfigServiceClient::HandleResponse( void DataReductionProxyConfigServiceClient::HandleResponse(
const std::string& config_data, const std::string& config_data,
const net::URLRequestStatus& status, int status,
int response_code) { int response_code) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
ClientConfig config; ClientConfig config;
...@@ -545,8 +525,8 @@ void DataReductionProxyConfigServiceClient::HandleResponse( ...@@ -545,8 +525,8 @@ void DataReductionProxyConfigServiceClient::HandleResponse(
base::UmaHistogramSparse(kUMAConfigServiceFetchResponseCode, response_code); base::UmaHistogramSparse(kUMAConfigServiceFetchResponseCode, response_code);
} }
if (status.status() == net::URLRequestStatus::SUCCESS && if (status == net::OK && response_code == net::HTTP_OK &&
response_code == net::HTTP_OK && config.ParseFromString(config_data)) { config.ParseFromString(config_data)) {
succeeded = ParseAndApplyProxyConfig(config); succeeded = ParseAndApplyProxyConfig(config);
} }
...@@ -581,7 +561,7 @@ void DataReductionProxyConfigServiceClient::HandleResponse( ...@@ -581,7 +561,7 @@ void DataReductionProxyConfigServiceClient::HandleResponse(
SetConfigRefreshTimer(next_config_refresh_time); SetConfigRefreshTimer(next_config_refresh_time);
event_creator_->EndConfigRequest( event_creator_->EndConfigRequest(
net_log_with_source_, status.error(), response_code, net_log_with_source_, status, response_code,
GetBackoffEntry()->failure_count(), GetBackoffEntry()->failure_count(),
DataReductionProxyServer::ConvertToNetProxyServers(proxies), DataReductionProxyServer::ConvertToNetProxyServers(proxies),
refresh_duration, next_config_refresh_time); refresh_duration, next_config_refresh_time);
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "net/base/backoff_entry.h" #include "net/base/backoff_entry.h"
#include "net/log/net_log_with_source.h" #include "net/log/net_log_with_source.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "services/network/public/cpp/network_connection_tracker.h" #include "services/network/public/cpp/network_connection_tracker.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -32,11 +31,13 @@ class HttpResponseHeaders; ...@@ -32,11 +31,13 @@ class HttpResponseHeaders;
class NetLog; class NetLog;
struct LoadTimingInfo; struct LoadTimingInfo;
class ProxyServer; class ProxyServer;
class URLFetcher;
class URLRequestContextGetter;
class URLRequestStatus;
} }
namespace network {
class SharedURLLoaderFactory;
class SimpleURLLoader;
} // namespace network
namespace data_reduction_proxy { namespace data_reduction_proxy {
class ClientConfig; class ClientConfig;
...@@ -82,8 +83,7 @@ const net::BackoffEntry::Policy& GetBackoffPolicy(); ...@@ -82,8 +83,7 @@ const net::BackoffEntry::Policy& GetBackoffPolicy();
// fetch policy is different if Chrome is in the background. Every time a config // fetch policy is different if Chrome is in the background. Every time a config
// is fetched, it is written to the disk. // is fetched, it is written to the disk.
class DataReductionProxyConfigServiceClient class DataReductionProxyConfigServiceClient
: public network::NetworkConnectionTracker::NetworkConnectionObserver, : public network::NetworkConnectionTracker::NetworkConnectionObserver {
public net::URLFetcherDelegate {
public: public:
// The caller must ensure that all parameters remain alive for the lifetime of // The caller must ensure that all parameters remain alive for the lifetime of
// the |DataReductionProxyConfigClient|. // the |DataReductionProxyConfigClient|.
...@@ -102,7 +102,7 @@ class DataReductionProxyConfigServiceClient ...@@ -102,7 +102,7 @@ class DataReductionProxyConfigServiceClient
// Performs initialization on the IO thread. // Performs initialization on the IO thread.
void InitializeOnIOThread( void InitializeOnIOThread(
net::URLRequestContextGetter* url_request_context_getter); scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
// Sets whether the configuration should be retrieved or not. // Sets whether the configuration should be retrieved or not.
void SetEnabled(bool enabled); void SetEnabled(bool enabled);
...@@ -163,8 +163,8 @@ class DataReductionProxyConfigServiceClient ...@@ -163,8 +163,8 @@ class DataReductionProxyConfigServiceClient
// Override of network::NetworkConnectionTracker::NetworkConnectionObserver. // Override of network::NetworkConnectionTracker::NetworkConnectionObserver.
void OnConnectionChanged(network::mojom::ConnectionType type) override; void OnConnectionChanged(network::mojom::ConnectionType type) override;
// Override of net::URLFetcherDelegate. // URL loader completion callback.
void OnURLFetchComplete(const net::URLFetcher* source) override; void OnURLLoadComplete(std::unique_ptr<std::string> response_body);
// Retrieves the Data Reduction Proxy configuration from a remote service. // Retrieves the Data Reduction Proxy configuration from a remote service.
void RetrieveRemoteConfig(); void RetrieveRemoteConfig();
...@@ -172,19 +172,12 @@ class DataReductionProxyConfigServiceClient ...@@ -172,19 +172,12 @@ class DataReductionProxyConfigServiceClient
// Invalidates the current Data Reduction Proxy configuration. // Invalidates the current Data Reduction Proxy configuration.
void InvalidateConfig(); void InvalidateConfig();
// Returns a fetcher to retrieve the Data Reduction Proxy configuration.
// |secure_proxy_check_url| is the url from which to retrieve the config.
// |request_body| is the request body sent to the configuration service.
std::unique_ptr<net::URLFetcher> GetURLFetcherForConfig(
const GURL& secure_proxy_check_url,
const std::string& request_body);
// Handles the response from the remote Data Reduction Proxy configuration // Handles the response from the remote Data Reduction Proxy configuration
// service. |response| is the response body, |status| is the // service. |response| is the response body, |status| is the
// |net::URLRequestStatus| of the response, and response_code is the HTTP // |net::Error| of the response, and response_code is the HTTP
// response code (if available). // response code (if available).
void HandleResponse(const std::string& response, void HandleResponse(const std::string& response,
const net::URLRequestStatus& status, int status,
int response_code); int response_code);
// Parses out the proxy configuration portion of |config| and applies it to // Parses out the proxy configuration portion of |config| and applies it to
...@@ -236,15 +229,15 @@ class DataReductionProxyConfigServiceClient ...@@ -236,15 +229,15 @@ class DataReductionProxyConfigServiceClient
// successfully applied. // successfully applied.
bool remote_config_applied_; bool remote_config_applied_;
// Used for setting up |fetcher_|. // Used for setting up the |url_loader_|.
net::URLRequestContextGetter* url_request_context_getter_; scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
// An event that fires when it is time to refresh the Data Reduction Proxy // An event that fires when it is time to refresh the Data Reduction Proxy
// configuration. // configuration.
base::OneShotTimer config_refresh_timer_; base::OneShotTimer config_refresh_timer_;
// A |net::URLFetcher| to retrieve the Data Reduction Proxy configuration. // A |network::URLLoader| to retrieve the Date Reduction Proxy configuration.
std::unique_ptr<net::URLFetcher> fetcher_; std::unique_ptr<network::SimpleURLLoader> url_loader_;
// Used to correlate the start and end of requests. // Used to correlate the start and end of requests.
net::NetLogWithSource net_log_with_source_; net::NetLogWithSource net_log_with_source_;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_entropy_provider.h" #include "base/test/mock_entropy_provider.h"
#include "base/time/default_clock.h" #include "base/time/default_clock.h"
...@@ -41,6 +42,9 @@ ...@@ -41,6 +42,9 @@
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h" #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_request_context_storage.h" #include "net/url_request/url_request_context_storage.h"
#include "net/url_request/url_request_test_util.h" #include "net/url_request/url_request_test_util.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -80,23 +84,51 @@ namespace data_reduction_proxy { ...@@ -80,23 +84,51 @@ namespace data_reduction_proxy {
class DataReductionProxyConfigServiceClientTest : public testing::Test { class DataReductionProxyConfigServiceClientTest : public testing::Test {
protected: protected:
DataReductionProxyConfigServiceClientTest() { DataReductionProxyConfigServiceClientTest()
: test_shared_url_loader_factory_(
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_)) {
// TODO(tonikitoo): Do a clean up pass to remove unneeded class members
// once the URLFetcher->SimpleURLLoader switch stabalizes.
// This includes |context_|, |context_storage_|, |mock_socket_factory_|,
// |success_reads_|, |previous_success_reads_| and |not_found_reads_|.
context_.reset(new net::TestURLRequestContext(true)); context_.reset(new net::TestURLRequestContext(true));
context_storage_.reset(new net::URLRequestContextStorage(context_.get())); context_storage_.reset(new net::URLRequestContextStorage(context_.get()));
mock_socket_factory_.reset(new net::MockClientSocketFactory()); mock_socket_factory_.reset(new net::MockClientSocketFactory());
} }
void SetUp() override {
testing::Test::SetUp();
// Install an interceptor here to process the queue of responses
// (fed by calls to AddMock{Success,PreviousSuccess,Failure}.
test_url_loader_factory_.SetInterceptor(base::BindLambdaForTesting(
[&](const network::ResourceRequest& request) {
// Some tests trigger loading, without having an respective
// mock response set. Ignore such cases.
if (mock_responses_.size() <= curr_mock_response_index_) {
test_url_loader_factory_.pending_requests()->clear();
return;
}
test_url_loader_factory_.ClearResponses();
test_url_loader_factory_.AddResponse(
request.url.spec(),
mock_responses_[curr_mock_response_index_].response,
mock_responses_[curr_mock_response_index_].http_code);
curr_mock_response_index_++;
RunUntilIdle();
}));
}
void Init(bool use_mock_client_socket_factory) { void Init(bool use_mock_client_socket_factory) {
if (!use_mock_client_socket_factory) if (!use_mock_client_socket_factory)
mock_socket_factory_.reset(nullptr); mock_socket_factory_.reset(nullptr);
test_context_ = test_context_ = DataReductionProxyTestContext::Builder()
DataReductionProxyTestContext::Builder() .WithURLLoaderFactory(test_shared_url_loader_factory_)
.WithURLRequestContext(context_.get()) .WithMockRequestOptions()
.WithMockClientSocketFactory(mock_socket_factory_.get()) .WithTestConfigClient()
.WithMockRequestOptions() .SkipSettingsInitialization()
.WithTestConfigClient() .Build();
.SkipSettingsInitialization()
.Build();
context_->set_client_socket_factory(mock_socket_factory_.get()); context_->set_client_socket_factory(mock_socket_factory_.get());
test_context_->AttachToURLRequestContext(context_storage_.get()); test_context_->AttachToURLRequestContext(context_storage_.get());
...@@ -357,27 +389,15 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test { ...@@ -357,27 +389,15 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
} }
void AddMockSuccess() { void AddMockSuccess() {
socket_data_providers_.push_back( mock_responses_.push_back({success_response(), net::HTTP_OK});
std::make_unique<net::StaticSocketDataProvider>(
success_reads_, base::span<net::MockWrite>()));
mock_socket_factory_->AddSocketDataProvider(
socket_data_providers_.back().get());
} }
void AddMockPreviousSuccess() { void AddMockPreviousSuccess() {
socket_data_providers_.push_back( mock_responses_.push_back({previous_success_response(), net::HTTP_OK});
std::make_unique<net::StaticSocketDataProvider>(
previous_success_reads_, base::span<net::MockWrite>()));
mock_socket_factory_->AddSocketDataProvider(
socket_data_providers_.back().get());
} }
void AddMockFailure() { void AddMockFailure() {
socket_data_providers_.push_back( mock_responses_.push_back({std::string(), net::HTTP_NOT_FOUND});
std::make_unique<net::StaticSocketDataProvider>(
not_found_reads_, base::span<net::MockWrite>()));
mock_socket_factory_->AddSocketDataProvider(
socket_data_providers_.back().get());
} }
std::string persisted_config() const { std::string persisted_config() const {
...@@ -427,6 +447,10 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test { ...@@ -427,6 +447,10 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
std::unique_ptr<net::TestURLRequestContext> context_; std::unique_ptr<net::TestURLRequestContext> context_;
std::unique_ptr<net::MockClientSocketFactory> mock_socket_factory_; std::unique_ptr<net::MockClientSocketFactory> mock_socket_factory_;
network::TestURLLoaderFactory test_url_loader_factory_;
scoped_refptr<network::SharedURLLoaderFactory>
test_shared_url_loader_factory_;
protected: protected:
std::unique_ptr<DataReductionProxyTestContext> test_context_; std::unique_ptr<DataReductionProxyTestContext> test_context_;
...@@ -472,6 +496,13 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test { ...@@ -472,6 +496,13 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
net::MockRead previous_success_reads_[3]; net::MockRead previous_success_reads_[3];
net::MockRead not_found_reads_[2]; net::MockRead not_found_reads_[2];
struct MockResponse {
std::string response;
net::HttpStatusCode http_code;
};
std::vector<MockResponse> mock_responses_;
size_t curr_mock_response_index_ = 0;
std::unique_ptr<net::URLRequestContextStorage> context_storage_; std::unique_ptr<net::URLRequestContextStorage> context_storage_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigServiceClientTest); DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigServiceClientTest);
......
...@@ -228,7 +228,7 @@ void DataReductionProxyIOData::InitializeOnIOThread() { ...@@ -228,7 +228,7 @@ void DataReductionProxyIOData::InitializeOnIOThread() {
bypass_stats_->InitializeOnIOThread(); bypass_stats_->InitializeOnIOThread();
proxy_delegate_->InitializeOnIOThread(this); proxy_delegate_->InitializeOnIOThread(this);
if (config_client_) if (config_client_)
config_client_->InitializeOnIOThread(url_request_context_getter_); config_client_->InitializeOnIOThread(url_loader_factory);
if (ui_task_runner_->BelongsToCurrentThread()) { if (ui_task_runner_->BelongsToCurrentThread()) {
service_->SetIOData(weak_factory_.GetWeakPtr()); service_->SetIOData(weak_factory_.GetWeakPtr());
return; return;
......
...@@ -365,6 +365,13 @@ DataReductionProxyTestContext::Builder::WithURLRequestContext( ...@@ -365,6 +365,13 @@ DataReductionProxyTestContext::Builder::WithURLRequestContext(
return *this; return *this;
} }
DataReductionProxyTestContext::Builder&
DataReductionProxyTestContext::Builder::WithURLLoaderFactory(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) {
url_loader_factory_ = url_loader_factory;
return *this;
}
DataReductionProxyTestContext::Builder& DataReductionProxyTestContext::Builder&
DataReductionProxyTestContext::Builder::WithMockClientSocketFactory( DataReductionProxyTestContext::Builder::WithMockClientSocketFactory(
net::MockClientSocketFactory* mock_socket_factory) { net::MockClientSocketFactory* mock_socket_factory) {
...@@ -432,7 +439,7 @@ DataReductionProxyTestContext::Builder::Build() { ...@@ -432,7 +439,7 @@ DataReductionProxyTestContext::Builder::Build() {
scoped_refptr<base::SingleThreadTaskRunner> task_runner = scoped_refptr<base::SingleThreadTaskRunner> task_runner =
base::ThreadTaskRunnerHandle::Get(); base::ThreadTaskRunnerHandle::Get();
scoped_refptr<net::URLRequestContextGetter> request_context_getter; scoped_refptr<net::URLRequestContextGetter> request_context_getter;
scoped_refptr<network::TestSharedURLLoaderFactory> url_loader_factory; scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory;
std::unique_ptr<TestingPrefServiceSimple> pref_service( std::unique_ptr<TestingPrefServiceSimple> pref_service(
new TestingPrefServiceSimple()); new TestingPrefServiceSimple());
std::unique_ptr<net::TestNetLog> net_log(new net::TestNetLog()); std::unique_ptr<net::TestNetLog> net_log(new net::TestNetLog());
...@@ -455,13 +462,12 @@ DataReductionProxyTestContext::Builder::Build() { ...@@ -455,13 +462,12 @@ DataReductionProxyTestContext::Builder::Build() {
task_runner, std::move(test_request_context)); task_runner, std::move(test_request_context));
} }
// In theory, when the other related classes (namely SecureProxyChecker if (url_loader_factory_) {
// and DataReductionProxyConfigServiceClient) get migrated away from url_loader_factory = url_loader_factory_;
// using URLFetcher in favor of SimpleURLLoader, there will be a } else {
// Builder::WithURLLoaderFactory, and specific tests will pass in url_loader_factory =
// a URLLoaderFactory instance. For now, we can just create our own. base::MakeRefCounted<network::TestSharedURLLoaderFactory>();
url_loader_factory = }
base::MakeRefCounted<network::TestSharedURLLoaderFactory>();
std::unique_ptr<TestDataReductionProxyEventStorageDelegate> storage_delegate( std::unique_ptr<TestDataReductionProxyEventStorageDelegate> storage_delegate(
new TestDataReductionProxyEventStorageDelegate()); new TestDataReductionProxyEventStorageDelegate());
......
...@@ -332,6 +332,10 @@ class DataReductionProxyTestContext { ...@@ -332,6 +332,10 @@ class DataReductionProxyTestContext {
// owned by the caller. // owned by the caller.
Builder& WithURLRequestContext(net::URLRequestContext* request_context); Builder& WithURLRequestContext(net::URLRequestContext* request_context);
// Specifies a |network::URLLoaderFactory| to use.
Builder& WithURLLoaderFactory(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
// Specifies a |net::MockClientSocketFactory| to use. The // Specifies a |net::MockClientSocketFactory| to use. The
// |mock_socket_factory| is owned by the caller. If a non-NULL // |mock_socket_factory| is owned by the caller. If a non-NULL
// |request_context_| is also specified, then the caller is responsible for // |request_context_| is also specified, then the caller is responsible for
...@@ -373,6 +377,7 @@ class DataReductionProxyTestContext { ...@@ -373,6 +377,7 @@ class DataReductionProxyTestContext {
private: private:
Client client_; Client client_;
net::URLRequestContext* request_context_; net::URLRequestContext* request_context_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
net::MockClientSocketFactory* mock_socket_factory_; net::MockClientSocketFactory* mock_socket_factory_;
bool use_mock_config_; bool use_mock_config_;
......
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