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

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: Moved Secure Proxy check to separate class. Addressed comments. Created 5 years, 9 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 932af6f2b6bcfea71ae42686a7ea18c2b3c781f1..ed171fb802291d4db802870934f7f006c9055a81 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
@@ -14,7 +14,11 @@
#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_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_status.h"
@@ -46,7 +50,71 @@ void RecordNetworkChangeEvent(DataReductionProxyNetworkChangeEvent event) {
namespace data_reduction_proxy {
+class SecureProxyChecker : public net::URLFetcherDelegate {
+ public:
+ explicit SecureProxyChecker(
+ scoped_ptr<net::URLRequestContext> url_request_context,
+ net::HttpNetworkSession::Params params_modified,
sclittle 2015/04/02 00:06:59 Change to const reference.
tbansal1 2015/04/02 23:21:19 Done.
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter
sclittle 2015/04/02 00:06:59 Move the end-paren at the start of the next line u
tbansal1 2015/04/02 23:21:19 Done.
+ ) : url_request_context_(url_request_context.release()) {
sclittle 2015/04/02 00:06:59 s/.release()/.Pass()/
tbansal1 2015/04/02 23:21:18 Done.
+ 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(),
+ url_request_context_getter->GetNetworkTaskRunner());
+ }
+
+ void OnURLFetchComplete(const net::URLFetcher* source) override {
sclittle 2015/04/02 00:06:59 Maybe add DCHECKs to ensure that all the methods o
tbansal1 2015/04/02 23:21:19 Done.
+ 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) {
+ net::URLFetcher* fetcher = net::URLFetcher::Create(
sclittle 2015/04/02 00:06:59 Could you just use |fetcher_|, and remove this |fe
tbansal1 2015/04/02 23:21:19 Done.
+ 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_.reset(fetcher);
+ fetcher_callback_ = fetcher_callback;
+
+ fetcher->Start();
+ }
+
+ ~SecureProxyChecker() override {}
+
+ private:
+ 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,
@@ -69,6 +137,8 @@ DataReductionProxyConfig::DataReductionProxyConfig(
DCHECK(configurator);
DCHECK(event_store);
InitOnIOThread();
+ url_request_context_getter_ = request_context_getter;
sclittle 2015/04/02 00:06:59 Move this into the initializer list.
tbansal1 2015/04/02 23:21:18 Done.
+ DCHECK(url_request_context_getter_);
}
DataReductionProxyConfig::~DataReductionProxyConfig() {
@@ -333,16 +403,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());
}
@@ -467,11 +528,15 @@ void DataReductionProxyConfig::StartSecureProxyCheck() {
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)));
+ io_task_runner_->PostTask(
+ FROM_HERE, base::Bind(
+ &DataReductionProxyConfig::SecureProxyCheck,
+ base::Unretained(this),
+ config_values_->secure_proxy_check_url(),
+ base::Bind(
+ &DataReductionProxyConfig::HandleSecureProxyCheckResponse,
+ base::Unretained(this))
+ ));
sclittle 2015/04/02 00:06:59 Move end-parens up.
tbansal1 2015/04/02 23:21:18 Done.
}
}
@@ -509,4 +574,31 @@ bool DataReductionProxyConfig::DisableIfVPN() {
return false;
}
+void DataReductionProxyConfig::SecureProxyCheck(
+ const GURL& secure_proxy_check_url,
+ FetcherResponseCallback fetcher_callback) {
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
+
+ if (!secure_proxy_checker_) {
+ scoped_ptr<net::URLRequestContext> url_request_context_(
+ new net::URLRequestContext());
+ DCHECK(url_request_context_getter_->GetURLRequestContext());
+ url_request_context_->CopyFrom(
+ url_request_context_getter_->GetURLRequestContext());
+
+ net::HttpNetworkSession::Params params_modified =
+ *(url_request_context_->GetNetworkSessionParams());
+ params_modified.enable_quic = false;
+ params_modified.next_protos = net::NextProtosWithSpdyAndQuic(false, false);
+
+ secure_proxy_checker_.reset(new SecureProxyChecker(
+ url_request_context_.Pass(), params_modified,
+ url_request_context_getter_)
+ );
sclittle 2015/04/02 00:06:59 Move end-paren up
tbansal1 2015/04/02 23:21:19 Done.
+ }
+
+ secure_proxy_checker_->CheckIfSecureProxyIsAllowed(secure_proxy_check_url,
+ fetcher_callback);
+}
+
} // namespace data_reduction_proxy

Powered by Google App Engine
This is Rietveld 408576698