Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1752)

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc

Issue 981633002: Created new URLRequestContext for secure proxy check (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed minor bug Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
index a6f47c13867d6ed7c367aeb9155d1e1dc1e23641..bccbcbd1f32f8338c80395e2363207f12817303e 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
@@ -11,10 +11,14 @@
#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_config_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/load_flags.h"
+#include "net/http/http_network_layer.h"
#include "net/proxy/proxy_server.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_status.h"
@@ -46,14 +50,90 @@ void RecordNetworkChangeEvent(DataReductionProxyNetworkChangeEvent event) {
namespace data_reduction_proxy {
+// Checks if the secure proxy is allowed by the carrier by sending a probe.
+class SecureProxyChecker : public net::URLFetcherDelegate {
+ public:
+ SecureProxyChecker(net::URLRequestContext* url_request_context,
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
+ : io_task_runner_(io_task_runner) {
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
+
+ url_request_context_.reset(new net::URLRequestContext());
+ url_request_context_->CopyFrom(url_request_context);
+
+ net::HttpNetworkSession::Params params_modified =
+ *(url_request_context_->GetNetworkSessionParams());
+ params_modified.enable_quic = false;
+ params_modified.next_protos = net::NextProtosWithSpdyAndQuic(false, false);
+
+ http_network_layer_.reset(new net::HttpNetworkLayer(
+ new net::HttpNetworkSession(params_modified)));
+ url_request_context_->set_http_transaction_factory(
+ http_network_layer_.get());
+
+ url_request_context_getter_ = new net::TrivialURLRequestContextGetter(
+ url_request_context_.get(), io_task_runner_);
+ }
+
+ void OnURLFetchComplete(const net::URLFetcher* source) override {
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
bengr 2015/04/10 17:11:43 Ideally, no classes that are owned by DRPIOData wo
tbansal1 2015/04/14 22:36:22 There is no Post in drp_config but I am still keep
+ DCHECK_EQ(source, fetcher_.get());
+ net::URLRequestStatus status = source->GetStatus();
+
+ std::string response;
+ source->GetResponseAsString(&response);
+
+ fetcher_callback_.Run(response, status);
+ }
+
+ void CheckIfSecureProxyIsAllowed(const GURL& secure_proxy_check_url,
+ FetcherResponseCallback fetcher_callback) {
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
+ fetcher_.reset(net::URLFetcher::Create(secure_proxy_check_url,
+ net::URLFetcher::GET, this));
+ fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY);
+ fetcher_->SetRequestContext(url_request_context_getter_.get());
+ // Configure max retries to be at most kMaxRetries times for 5xx errors.
+ static const int kMaxRetries = 5;
+ fetcher_->SetMaxRetriesOn5xx(kMaxRetries);
+ fetcher_->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries);
+ // The secure proxy check should not be redirected. Since the secure proxy
+ // check will inevitably fail if it gets redirected somewhere else (e.g. by
+ // a captive portal), short circuit that by giving up on the secure proxy
+ // check if it gets redirected.
+ fetcher_->SetStopOnRedirect(true);
+
+ fetcher_callback_ = fetcher_callback;
+
+ fetcher_->Start();
+ }
+
+ ~SecureProxyChecker() override {}
+
+ private:
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
+
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
+ scoped_ptr<net::URLRequestContext> url_request_context_;
+ scoped_ptr<net::HttpNetworkLayer> http_network_layer_;
+
+ // The URLFetcher being used for the secure proxy check.
+ scoped_ptr<net::URLFetcher> fetcher_;
+ FetcherResponseCallback fetcher_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(SecureProxyChecker);
+};
+
DataReductionProxyConfig::DataReductionProxyConfig(
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
net::NetLog* net_log,
scoped_ptr<DataReductionProxyConfigValues> config_values,
DataReductionProxyConfigurator* configurator,
DataReductionProxyEventStore* event_store)
- : restricted_by_carrier_(false),
+ : url_request_context_getter_(request_context_getter),
+ restricted_by_carrier_(false),
disabled_on_vpn_(false),
unreachable_(false),
enabled_by_user_(false),
@@ -64,6 +144,7 @@ DataReductionProxyConfig::DataReductionProxyConfig(
net_log_(net_log),
configurator_(configurator),
event_store_(event_store) {
+ DCHECK(url_request_context_getter_);
DCHECK(io_task_runner);
DCHECK(ui_task_runner);
DCHECK(configurator);
@@ -75,11 +156,6 @@ DataReductionProxyConfig::~DataReductionProxyConfig() {
net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
}
-void DataReductionProxyConfig::SetDataReductionProxyService(
- base::WeakPtr<DataReductionProxyService> data_reduction_proxy_service) {
- data_reduction_proxy_service_ = data_reduction_proxy_service;
-}
-
void DataReductionProxyConfig::SetProxyPrefs(bool enabled,
bool alternative_enabled,
bool at_startup) {
@@ -246,6 +322,7 @@ bool DataReductionProxyConfig::promo_allowed() const {
void DataReductionProxyConfig::SetProxyConfigOnIOThread(
bool enabled, bool alternative_enabled, bool at_startup) {
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
enabled_by_user_ = enabled;
alternative_enabled_by_user_ = alternative_enabled;
UpdateConfigurator(enabled_by_user_, alternative_enabled_by_user_,
@@ -254,10 +331,11 @@ void DataReductionProxyConfig::SetProxyConfigOnIOThread(
// Check if the proxy has been restricted explicitly by the carrier.
if (enabled &&
!(alternative_enabled &&
- !config_values_->alternative_fallback_allowed())) {
- ui_task_runner_->PostTask(
- FROM_HERE, base::Bind(&DataReductionProxyConfig::StartSecureProxyCheck,
- base::Unretained(this)));
+ !config_values_->alternative_fallback_allowed())) {
+ SecureProxyCheck(
+ config_values_->secure_proxy_check_url(),
+ base::Bind(&DataReductionProxyConfig::HandleSecureProxyCheckResponse,
+ base::Unretained(this)));
}
}
@@ -321,16 +399,7 @@ void DataReductionProxyConfig::LogProxyState(bool enabled,
void DataReductionProxyConfig::HandleSecureProxyCheckResponse(
const std::string& response, const net::URLRequestStatus& status) {
- DCHECK(ui_task_runner_->BelongsToCurrentThread());
- io_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(
- &DataReductionProxyConfig::HandleSecureProxyCheckResponseOnIOThread,
- base::Unretained(this), response, status));
-}
-
-void DataReductionProxyConfig::HandleSecureProxyCheckResponseOnIOThread(
- const std::string& response, const net::URLRequestStatus& status) {
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
if (event_store_) {
event_store_->EndSecureProxyCheck(bound_net_log_, status.error());
}
@@ -393,9 +462,10 @@ void DataReductionProxyConfig::OnIPAddressChanged() {
return;
}
- ui_task_runner_->PostTask(
- FROM_HERE, base::Bind(&DataReductionProxyConfig::StartSecureProxyCheck,
- base::Unretained(this)));
+ SecureProxyCheck(
+ config_values_->secure_proxy_check_url(),
+ base::Bind(&DataReductionProxyConfig::HandleSecureProxyCheckResponse,
+ base::Unretained(this)));
}
}
@@ -446,21 +516,26 @@ void DataReductionProxyConfig::RecordSecureProxyCheckFetchResult(
SECURE_PROXY_CHECK_FETCH_RESULT_COUNT);
}
-void DataReductionProxyConfig::StartSecureProxyCheck() {
- DCHECK(ui_task_runner_->BelongsToCurrentThread());
+void DataReductionProxyConfig::SecureProxyCheck(
+ const GURL& secure_proxy_check_url,
+ FetcherResponseCallback fetcher_callback) {
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
bound_net_log_ = net::BoundNetLog::Make(
net_log_, net::NetLog::SOURCE_DATA_REDUCTION_PROXY);
- if (data_reduction_proxy_service_) {
- if (event_store_) {
- event_store_->BeginSecureProxyCheck(
- bound_net_log_, config_values_->secure_proxy_check_url());
- }
- data_reduction_proxy_service_->SecureProxyCheck(
- config_values_->secure_proxy_check_url(),
- base::Bind(&DataReductionProxyConfig::HandleSecureProxyCheckResponse,
- base::Unretained(this)));
+ if (event_store_) {
+ event_store_->BeginSecureProxyCheck(
+ bound_net_log_, config_values_->secure_proxy_check_url());
+ }
+
+ if (!secure_proxy_checker_) {
+ DCHECK(url_request_context_getter_->GetURLRequestContext());
+
+ secure_proxy_checker_.reset(new SecureProxyChecker(
+ url_request_context_getter_->GetURLRequestContext(), io_task_runner_));
}
+ secure_proxy_checker_->CheckIfSecureProxyIsAllowed(secure_proxy_check_url,
+ fetcher_callback);
}
void DataReductionProxyConfig::GetNetworkList(

Powered by Google App Engine
This is Rietveld 408576698