Chromium Code Reviews| Index: chrome/browser/net/predictor.cc |
| diff --git a/chrome/browser/net/predictor.cc b/chrome/browser/net/predictor.cc |
| index df12e02534c37b11e1f49ad8d7a988b9131cd2d1..07f371de8b2eb0ca247308fe09e28f6f7b9569c6 100644 |
| --- a/chrome/browser/net/predictor.cc |
| +++ b/chrome/browser/net/predictor.cc |
| @@ -38,6 +38,7 @@ |
| #include "net/base/address_list.h" |
| #include "net/base/completion_callback.h" |
| #include "net/base/host_port_pair.h" |
| +#include "net/base/load_flags.h" |
| #include "net/base/net_errors.h" |
| #include "net/base/net_log.h" |
| #include "net/dns/host_resolver.h" |
| @@ -148,6 +149,7 @@ Predictor::Predictor(bool preconnect_enabled, bool predictor_enabled) |
| host_resolver_(NULL), |
| transport_security_state_(NULL), |
| ssl_config_service_(NULL), |
| + proxy_service_(NULL), |
| preconnect_enabled_(preconnect_enabled), |
| consecutive_omnibox_preconnect_count_(0), |
| next_trim_time_(base::TimeTicks::Now() + |
| @@ -699,6 +701,7 @@ void Predictor::FinalizeInitializationOnIOThread( |
| url_request_context_getter_->GetURLRequestContext(); |
| transport_security_state_ = context->transport_security_state(); |
| ssl_config_service_ = context->ssl_config_service(); |
| + proxy_service_ = context->proxy_service(); |
| // base::WeakPtrFactory instances need to be created and destroyed |
| // on the same thread. The predictor lives on the IO thread and will die |
| @@ -1033,6 +1036,31 @@ void Predictor::LookupFinished(LookupRequest* request, const GURL& url, |
| } |
| } |
| +// Dummy function, used to discard asynchronous results from ResolveProxy. |
| +void DiscardInput(int x) {} |
| + |
| +bool Predictor::WouldDefinitelyProxyURL(const GURL& url) { |
|
eroman
2014/09/10 01:26:04
This title is misleading. It is still possible for
bemasc
2014/09/10 15:19:02
OK. Do you think I should change the name ("Would
eroman
2014/09/18 17:51:28
How about:
"WouldLikelyProxyURL()"
That name is
bemasc
2014/09/19 19:41:37
Done.
|
| + if (!proxy_service_) |
| + return false; |
| + |
| + net::ProxyInfo info; |
| + net::CompletionCallback callback = base::Bind(&DiscardInput); |
| + net::ProxyService::PacRequest* pac_request = NULL; |
| + int response_code = proxy_service_->ResolveProxy(url, net::LOAD_NORMAL, &info, |
| + callback, &pac_request, NULL, net::BoundNetLog()); |
| + if (response_code != net::LOAD_NORMAL) { |
|
eroman
2014/09/10 01:26:04
This code is incorrect:
(1) Use net::OK not net:
bemasc
2014/09/19 19:41:37
Done.
|
| + // Avoid performing the asynchronous proxy resolution work for no reason. |
| + DCHECK(pac_request != NULL); |
| + proxy_service_->CancelPacRequest(pac_request); |
|
eroman
2014/09/10 01:26:04
In the case where a PAC script _is_ configured, it
bemasc
2014/09/10 15:19:02
OK. There are 10 calls to ResolveProxy in the cod
eroman
2014/09/18 17:51:28
My thinking was that ResolveProxy() keep the same
bemasc
2014/09/19 19:41:37
Done.
|
| + |
| + // The request did not synchronously return "success", so we do not know |
| + // whether a proxy would be used for requests to this URL. |
| + return false; |
| + } |
| + |
| + return !info.is_direct(); |
| +} |
| + |
| UrlInfo* Predictor::AppendToResolutionQueue( |
| const GURL& url, |
| UrlInfo::ResolutionMotivation motivation) { |
| @@ -1055,7 +1083,8 @@ UrlInfo* Predictor::AppendToResolutionQueue( |
| } |
| AdviseProxy(url, motivation, false /* is_preconnect */); |
| - if (proxy_advisor_ && proxy_advisor_->WouldProxyURL(url)) { |
| + if ((proxy_advisor_ && proxy_advisor_->WouldProxyURL(url)) || |
| + WouldDefinitelyProxyURL(url)) { |
| info->DLogResultsStats("DNS PrefetchForProxiedRequest"); |
| return NULL; |
| } |