Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc |
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc |
index 1b90a14d04568dacabe3396f4bc6885852c63de5..3c17aa24d85fe4824aaec0992992db4db354ba34 100644 |
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc |
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc |
@@ -11,6 +11,9 @@ |
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h" |
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service_observer.h" |
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h" |
+#include "net/base/load_flags.h" |
+#include "net/url_request/url_fetcher.h" |
+#include "net/url_request/url_request_status.h" |
namespace data_reduction_proxy { |
@@ -106,4 +109,47 @@ DataReductionProxyService::GetWeakPtr() { |
return weak_factory_.GetWeakPtr(); |
} |
+void DataReductionProxyService::OnURLFetchComplete( |
+ const net::URLFetcher* source) { |
+ DCHECK(source == fetcher_.get()); |
+ net::URLRequestStatus status = source->GetStatus(); |
+ |
+ std::string response; |
+ source->GetResponseAsString(&response); |
+ |
+ fetcher_callback_.Run(response, status); |
+} |
+ |
+net::URLFetcher* DataReductionProxyService::GetURLFetcherForSecureProxyCheck( |
+ const GURL& secure_proxy_check_url) { |
+ net::URLFetcher* fetcher = net::URLFetcher::Create( |
+ secure_proxy_check_url, net::URLFetcher::GET, this); |
+ fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY); |
+ DCHECK(url_request_context_getter_); |
+ fetcher->SetRequestContext(url_request_context_getter_); |
+ // 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); |
+ return fetcher; |
+} |
+ |
+void DataReductionProxyService::SecureProxyCheck( |
+ const GURL& secure_proxy_check_url, |
+ FetcherResponseCallback fetcher_callback) { |
+ DCHECK(CalledOnValidThread()); |
+ net::URLFetcher* fetcher = |
+ GetURLFetcherForSecureProxyCheck(secure_proxy_check_url); |
+ if (!fetcher) |
+ return; |
+ fetcher_.reset(fetcher); |
+ fetcher_callback_ = fetcher_callback; |
+ fetcher_->Start(); |
+} |
+ |
} // namespace data_reduction_proxy |