| Index: net/proxy/proxy_service.cc
|
| diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
|
| index b385e52c966a293861ff90f0a44658af156af825..d6d410c205ef380d4f2209a2848fa08c6db8eae6 100644
|
| --- a/net/proxy/proxy_service.cc
|
| +++ b/net/proxy/proxy_service.cc
|
| @@ -18,25 +18,25 @@
|
| #include "base/metrics/histogram_macros.h"
|
| #include "base/metrics/sparse_histogram.h"
|
| #include "base/single_thread_task_runner.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/thread_task_runner_handle.h"
|
| #include "base/time/time.h"
|
| #include "base/values.h"
|
| #include "net/base/completion_callback.h"
|
| #include "net/base/load_flags.h"
|
| #include "net/base/net_errors.h"
|
| +#include "net/base/proxy_delegate.h"
|
| #include "net/base/url_util.h"
|
| #include "net/log/net_log.h"
|
| #include "net/proxy/dhcp_proxy_script_fetcher.h"
|
| #include "net/proxy/multi_threaded_proxy_resolver.h"
|
| -#include "net/proxy/network_delegate_error_observer.h"
|
| #include "net/proxy/proxy_config_service_fixed.h"
|
| #include "net/proxy/proxy_resolver.h"
|
| #include "net/proxy/proxy_resolver_factory.h"
|
| #include "net/proxy/proxy_script_decider.h"
|
| #include "net/proxy/proxy_script_fetcher.h"
|
| #include "net/url_request/url_request_context.h"
|
| #include "url/gurl.h"
|
|
|
| #if defined(OS_WIN)
|
| #include "net/proxy/proxy_config_service_win.h"
|
| @@ -761,30 +761,30 @@ const ProxyService::PacPollPolicy*
|
| ProxyService::ProxyScriptDeciderPoller::poll_policy_ = NULL;
|
|
|
| // ProxyService::PacRequest ---------------------------------------------------
|
|
|
| class ProxyService::PacRequest
|
| : public base::RefCounted<ProxyService::PacRequest> {
|
| public:
|
| PacRequest(ProxyService* service,
|
| const GURL& url,
|
| int load_flags,
|
| - NetworkDelegate* network_delegate,
|
| + ProxyDelegate* proxy_delegate,
|
| ProxyInfo* results,
|
| const CompletionCallback& user_callback,
|
| const BoundNetLog& net_log)
|
| : service_(service),
|
| user_callback_(user_callback),
|
| results_(results),
|
| url_(url),
|
| load_flags_(load_flags),
|
| - network_delegate_(network_delegate),
|
| + proxy_delegate_(proxy_delegate),
|
| resolve_job_(NULL),
|
| config_id_(ProxyConfig::kInvalidConfigID),
|
| config_source_(PROXY_CONFIG_SOURCE_UNKNOWN),
|
| net_log_(net_log),
|
| creation_time_(TimeTicks::Now()) {
|
| DCHECK(!user_callback.is_null());
|
| }
|
|
|
| // Starts the resolve proxy request.
|
| int Start() {
|
| @@ -802,21 +802,21 @@ class ProxyService::PacRequest
|
| &resolve_job_, net_log_);
|
| }
|
|
|
| bool is_started() const {
|
| // Note that !! casts to bool. (VS gives a warning otherwise).
|
| return !!resolve_job_;
|
| }
|
|
|
| void StartAndCompleteCheckingForSynchronous() {
|
| int rv = service_->TryToCompleteSynchronously(url_, load_flags_,
|
| - network_delegate_, results_);
|
| + proxy_delegate_, results_);
|
| if (rv == ERR_IO_PENDING)
|
| rv = Start();
|
| if (rv != ERR_IO_PENDING)
|
| QueryComplete(rv);
|
| }
|
|
|
| void CancelResolveJob() {
|
| DCHECK(is_started());
|
| // The request may already be running in the resolver.
|
| resolver()->CancelRequest(resolve_job_);
|
| @@ -850,21 +850,21 @@ class ProxyService::PacRequest
|
|
|
| // This state is cleared when resolve_job_ is set to nullptr below.
|
| bool script_executed = is_started();
|
|
|
| // Clear |resolve_job_| so is_started() returns false while
|
| // DidFinishResolvingProxy() runs.
|
| resolve_job_ = nullptr;
|
|
|
| // Note that DidFinishResolvingProxy might modify |results_|.
|
| int rv = service_->DidFinishResolvingProxy(
|
| - url_, load_flags_, network_delegate_, results_, result_code, net_log_,
|
| + url_, load_flags_, proxy_delegate_, results_, result_code, net_log_,
|
| creation_time_, script_executed);
|
|
|
| // Make a note in the results which configuration was in use at the
|
| // time of the resolve.
|
| results_->config_id_ = config_id_;
|
| results_->config_source_ = config_source_;
|
| results_->did_use_pac_script_ = true;
|
| results_->proxy_resolve_start_time_ = creation_time_;
|
| results_->proxy_resolve_end_time_ = TimeTicks::Now();
|
|
|
| @@ -904,21 +904,21 @@ class ProxyService::PacRequest
|
| ProxyResolver* resolver() const { return service_->resolver_.get(); }
|
|
|
| // Note that we don't hold a reference to the ProxyService. Outstanding
|
| // requests are cancelled during ~ProxyService, so this is guaranteed
|
| // to be valid throughout our lifetime.
|
| ProxyService* service_;
|
| CompletionCallback user_callback_;
|
| ProxyInfo* results_;
|
| GURL url_;
|
| int load_flags_;
|
| - NetworkDelegate* network_delegate_;
|
| + ProxyDelegate* proxy_delegate_;
|
| ProxyResolver::RequestHandle resolve_job_;
|
| ProxyConfig::ID config_id_; // The config id when the resolve was started.
|
| ProxyConfigSource config_source_; // The source of proxy settings.
|
| BoundNetLog net_log_;
|
| // Time when the request was created. Stored here rather than in |results_|
|
| // because the time in |results_| will be cleared.
|
| TimeTicks creation_time_;
|
| };
|
|
|
| // ProxyService ---------------------------------------------------------------
|
| @@ -1006,73 +1006,66 @@ scoped_ptr<ProxyService> ProxyService::CreateFixedFromPacResult(
|
| return make_scoped_ptr(new ProxyService(
|
| std::move(proxy_config_service),
|
| make_scoped_ptr(new ProxyResolverFactoryForPacResult(pac_string)), NULL));
|
| }
|
|
|
| int ProxyService::ResolveProxy(const GURL& raw_url,
|
| int load_flags,
|
| ProxyInfo* result,
|
| const CompletionCallback& callback,
|
| PacRequest** pac_request,
|
| - NetworkDelegate* network_delegate,
|
| + ProxyDelegate* proxy_delegate,
|
| const BoundNetLog& net_log) {
|
| DCHECK(!callback.is_null());
|
| - return ResolveProxyHelper(raw_url,
|
| - load_flags,
|
| - result,
|
| - callback,
|
| - pac_request,
|
| - network_delegate,
|
| - net_log);
|
| + return ResolveProxyHelper(raw_url, load_flags, result, callback, pac_request,
|
| + proxy_delegate, net_log);
|
| }
|
|
|
| int ProxyService::ResolveProxyHelper(const GURL& raw_url,
|
| int load_flags,
|
| ProxyInfo* result,
|
| const CompletionCallback& callback,
|
| PacRequest** pac_request,
|
| - NetworkDelegate* network_delegate,
|
| + ProxyDelegate* proxy_delegate,
|
| const BoundNetLog& net_log) {
|
| DCHECK(CalledOnValidThread());
|
|
|
| net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE);
|
|
|
| // Notify our polling-based dependencies that a resolve is taking place.
|
| // This way they can schedule their polls in response to network activity.
|
| config_service_->OnLazyPoll();
|
| if (script_poller_.get())
|
| script_poller_->OnLazyPoll();
|
|
|
| if (current_state_ == STATE_NONE)
|
| ApplyProxyConfigIfAvailable();
|
|
|
| // Strip away any reference fragments and the username/password, as they
|
| // are not relevant to proxy resolution.
|
| GURL url = SimplifyUrlForRequest(raw_url);
|
|
|
| // Check if the request can be completed right away. (This is the case when
|
| // using a direct connection for example).
|
| - int rv = TryToCompleteSynchronously(url, load_flags,
|
| - network_delegate, result);
|
| + int rv = TryToCompleteSynchronously(url, load_flags, proxy_delegate, result);
|
| if (rv != ERR_IO_PENDING) {
|
| rv = DidFinishResolvingProxy(
|
| - url, load_flags, network_delegate, result, rv, net_log,
|
| + url, load_flags, proxy_delegate, result, rv, net_log,
|
| callback.is_null() ? TimeTicks() : TimeTicks::Now(), false);
|
| return rv;
|
| }
|
|
|
| if (callback.is_null())
|
| return ERR_IO_PENDING;
|
|
|
| - scoped_refptr<PacRequest> req(
|
| - new PacRequest(this, url, load_flags, network_delegate,
|
| - result, callback, net_log));
|
| + scoped_refptr<PacRequest> req(new PacRequest(
|
| + this, url, load_flags, proxy_delegate, result, callback, net_log));
|
|
|
| if (current_state_ == STATE_READY) {
|
| // Start the resolve request.
|
| rv = req->Start();
|
| if (rv != ERR_IO_PENDING)
|
| return req->QueryDidComplete(rv);
|
| } else {
|
| req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC);
|
| }
|
|
|
| @@ -1080,39 +1073,34 @@ int ProxyService::ResolveProxyHelper(const GURL& raw_url,
|
| DCHECK(!ContainsPendingRequest(req.get()));
|
| pending_requests_.insert(req);
|
|
|
| // Completion will be notified through |callback|, unless the caller cancels
|
| // the request using |pac_request|.
|
| if (pac_request)
|
| *pac_request = req.get();
|
| return rv; // ERR_IO_PENDING
|
| }
|
|
|
| -bool ProxyService:: TryResolveProxySynchronously(
|
| - const GURL& raw_url,
|
| - int load_flags,
|
| - ProxyInfo* result,
|
| - NetworkDelegate* network_delegate,
|
| - const BoundNetLog& net_log) {
|
| +bool ProxyService::TryResolveProxySynchronously(const GURL& raw_url,
|
| + int load_flags,
|
| + ProxyInfo* result,
|
| + ProxyDelegate* proxy_delegate,
|
| + const BoundNetLog& net_log) {
|
| CompletionCallback null_callback;
|
| - return ResolveProxyHelper(raw_url,
|
| - load_flags,
|
| - result,
|
| - null_callback,
|
| - NULL /* pac_request*/,
|
| - network_delegate,
|
| + return ResolveProxyHelper(raw_url, load_flags, result, null_callback,
|
| + nullptr /* pac_request*/, proxy_delegate,
|
| net_log) == OK;
|
| }
|
|
|
| int ProxyService::TryToCompleteSynchronously(const GURL& url,
|
| int load_flags,
|
| - NetworkDelegate* network_delegate,
|
| + ProxyDelegate* proxy_delegate,
|
| ProxyInfo* result) {
|
| DCHECK_NE(STATE_NONE, current_state_);
|
|
|
| if (current_state_ != STATE_READY)
|
| return ERR_IO_PENDING; // Still initializing.
|
|
|
| DCHECK_NE(config_.id(), ProxyConfig::kInvalidConfigID);
|
|
|
| // If it was impossible to fetch or parse the PAC script, we cannot complete
|
| // the request here and bail out.
|
| @@ -1256,37 +1244,37 @@ void ProxyService::OnInitProxyResolverComplete(int result) {
|
| // downloaded.
|
| SetReady();
|
| }
|
|
|
| int ProxyService::ReconsiderProxyAfterError(const GURL& url,
|
| int load_flags,
|
| int net_error,
|
| ProxyInfo* result,
|
| const CompletionCallback& callback,
|
| PacRequest** pac_request,
|
| - NetworkDelegate* network_delegate,
|
| + ProxyDelegate* proxy_delegate,
|
| const BoundNetLog& net_log) {
|
| DCHECK(CalledOnValidThread());
|
|
|
| // Check to see if we have a new config since ResolveProxy was called. We
|
| // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a
|
| // direct connection failed and we never tried the current config.
|
|
|
| DCHECK(result);
|
| bool re_resolve = result->config_id_ != config_.id();
|
|
|
| if (re_resolve) {
|
| // If we have a new config or the config was never tried, we delete the
|
| // list of bad proxies and we try again.
|
| proxy_retry_info_.clear();
|
| return ResolveProxy(url, load_flags, result, callback, pac_request,
|
| - network_delegate, net_log);
|
| + proxy_delegate, net_log);
|
| }
|
|
|
| DCHECK(!result->is_empty());
|
| ProxyServer bad_proxy = result->proxy_server();
|
|
|
| // We don't have new proxy settings to try, try to fallback to the next proxy
|
| // in the list.
|
| bool did_fallback = result->Fallback(net_error, net_log);
|
|
|
| // Return synchronous failure if there is nothing left to fall-back to.
|
| @@ -1299,38 +1287,37 @@ bool ProxyService::MarkProxiesAsBadUntil(
|
| base::TimeDelta retry_delay,
|
| const std::vector<ProxyServer>& additional_bad_proxies,
|
| const BoundNetLog& net_log) {
|
| result.proxy_list_.UpdateRetryInfoOnFallback(&proxy_retry_info_, retry_delay,
|
| false, additional_bad_proxies,
|
| OK, net_log);
|
| return result.proxy_list_.size() > (additional_bad_proxies.size() + 1);
|
| }
|
|
|
| void ProxyService::ReportSuccess(const ProxyInfo& result,
|
| - NetworkDelegate* network_delegate) {
|
| + ProxyDelegate* proxy_delegate) {
|
| DCHECK(CalledOnValidThread());
|
|
|
| const ProxyRetryInfoMap& new_retry_info = result.proxy_retry_info();
|
| if (new_retry_info.empty())
|
| return;
|
|
|
| for (ProxyRetryInfoMap::const_iterator iter = new_retry_info.begin();
|
| iter != new_retry_info.end(); ++iter) {
|
| ProxyRetryInfoMap::iterator existing = proxy_retry_info_.find(iter->first);
|
| if (existing == proxy_retry_info_.end()) {
|
| proxy_retry_info_[iter->first] = iter->second;
|
| - if (network_delegate) {
|
| + if (proxy_delegate) {
|
| const ProxyServer& bad_proxy =
|
| ProxyServer::FromURI(iter->first, ProxyServer::SCHEME_HTTP);
|
| const ProxyRetryInfo& proxy_retry_info = iter->second;
|
| - network_delegate->NotifyProxyFallback(bad_proxy,
|
| - proxy_retry_info.net_error);
|
| + proxy_delegate->OnFallback(bad_proxy, proxy_retry_info.net_error);
|
| }
|
| }
|
| else if (existing->second.bad_until < iter->second.bad_until)
|
| existing->second.bad_until = iter->second.bad_until;
|
| }
|
| if (net_log_) {
|
| net_log_->AddGlobalEntry(
|
| NetLog::TYPE_BAD_PROXY_LIST_REPORTED,
|
| base::Bind(&NetLogBadProxyListCallback, &new_retry_info));
|
| }
|
| @@ -1354,21 +1341,21 @@ bool ProxyService::ContainsPendingRequest(PacRequest* req) {
|
| return pending_requests_.count(req) == 1;
|
| }
|
|
|
| void ProxyService::RemovePendingRequest(PacRequest* req) {
|
| DCHECK(ContainsPendingRequest(req));
|
| pending_requests_.erase(req);
|
| }
|
|
|
| int ProxyService::DidFinishResolvingProxy(const GURL& url,
|
| int load_flags,
|
| - NetworkDelegate* network_delegate,
|
| + ProxyDelegate* proxy_delegate,
|
| ProxyInfo* result,
|
| int result_code,
|
| const BoundNetLog& net_log,
|
| base::TimeTicks start_time,
|
| bool script_executed) {
|
| // Don't track any metrics if start_time is 0, which will happen when the user
|
| // calls |TryResolveProxySynchronously|.
|
| if (!start_time.is_null()) {
|
| TimeDelta diff = TimeTicks::Now() - start_time;
|
| if (script_executed) {
|
| @@ -1382,27 +1369,26 @@ int ProxyService::DidFinishResolvingProxy(const GURL& url,
|
| base::TimeDelta::FromSeconds(20), 50);
|
| UMA_HISTOGRAM_SPARSE_SLOWLY("Net.ProxyService.GetProxyUsingScriptResult",
|
| std::abs(result_code));
|
| }
|
| UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ResolvedUsingScript",
|
| script_executed);
|
| UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.ResolveProxyTime", diff,
|
| base::TimeDelta::FromMicroseconds(100),
|
| base::TimeDelta::FromSeconds(20), 50);
|
| }
|
| -
|
| // Log the result of the proxy resolution.
|
| if (result_code == OK) {
|
| - // Allow the network delegate to interpose on the resolution decision,
|
| + // Allow the proxy delegate to interpose on the resolution decision,
|
| // possibly modifying the ProxyInfo.
|
| - if (network_delegate)
|
| - network_delegate->NotifyResolveProxy(url, load_flags, *this, result);
|
| + if (proxy_delegate)
|
| + proxy_delegate->OnResolveProxy(url, load_flags, *this, result);
|
|
|
| net_log.AddEvent(NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST,
|
| base::Bind(&NetLogFinishedResolvingProxyCallback, result));
|
|
|
| // This check is done to only log the NetLog event when necessary, it's
|
| // not a performance optimization.
|
| if (!proxy_retry_info_.empty()) {
|
| result->DeprioritizeBadProxies(proxy_retry_info_);
|
| net_log.AddEvent(
|
| NetLog::TYPE_PROXY_SERVICE_DEPRIORITIZED_BAD_PROXIES,
|
| @@ -1417,24 +1403,24 @@ int ProxyService::DidFinishResolvingProxy(const GURL& url,
|
| // Fall-back to direct when the proxy resolver fails. This corresponds
|
| // with a javascript runtime error in the PAC script.
|
| //
|
| // This implicit fall-back to direct matches Firefox 3.5 and
|
| // Internet Explorer 8. For more information, see:
|
| //
|
| // http://www.chromium.org/developers/design-documents/proxy-settings-fallback
|
| result->UseDirect();
|
| result_code = OK;
|
|
|
| - // Allow the network delegate to interpose on the resolution decision,
|
| + // Allow the proxy delegate to interpose on the resolution decision,
|
| // possibly modifying the ProxyInfo.
|
| - if (network_delegate)
|
| - network_delegate->NotifyResolveProxy(url, load_flags, *this, result);
|
| + if (proxy_delegate)
|
| + proxy_delegate->OnResolveProxy(url, load_flags, *this, result);
|
| } else {
|
| result_code = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED;
|
| }
|
| if (reset_config) {
|
| ResetProxyConfig(false);
|
| // If the ProxyResolver crashed, force it to be re-initialized for the
|
| // next request by resetting the proxy config. If there are other pending
|
| // requests, trigger the recreation immediately so those requests retry.
|
| if (pending_requests_.size() > 1)
|
| ApplyProxyConfigIfAvailable();
|
|
|