| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { | 239 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { |
| 240 return Create(&pc, false, NULL, NULL); | 240 return Create(&pc, false, NULL, NULL); |
| 241 } | 241 } |
| 242 | 242 |
| 243 // static | 243 // static |
| 244 ProxyService* ProxyService::CreateNull() { | 244 ProxyService* ProxyService::CreateNull() { |
| 245 // Use a configuration fetcher and proxy resolver which always fail. | 245 // Use a configuration fetcher and proxy resolver which always fail. |
| 246 return new ProxyService(new ProxyConfigServiceNull, new ProxyResolverNull); | 246 return new ProxyService(new ProxyConfigServiceNull, new ProxyResolverNull); |
| 247 } | 247 } |
| 248 | 248 |
| 249 int ProxyService::ResolveProxy(const GURL& raw_url, ProxyInfo* result, | 249 int ProxyService::ResolveProxy(LoadLog* load_log, |
| 250 const GURL& raw_url, |
| 251 ProxyInfo* result, |
| 250 CompletionCallback* callback, | 252 CompletionCallback* callback, |
| 251 PacRequest** pac_request) { | 253 PacRequest** pac_request) { |
| 252 DCHECK(callback); | 254 DCHECK(callback); |
| 253 | 255 |
| 254 // Strip away any reference fragments and the username/password, as they | 256 // Strip away any reference fragments and the username/password, as they |
| 255 // are not relevant to proxy resolution. | 257 // are not relevant to proxy resolution. |
| 256 GURL url = SimplifyUrlForRequest(raw_url); | 258 GURL url = SimplifyUrlForRequest(raw_url); |
| 257 | 259 |
| 258 // Check if the request can be completed right away. This is the case when | 260 // Check if the request can be completed right away. This is the case when |
| 259 // using a direct connection, or when the config is bad. | 261 // using a direct connection, or when the config is bad. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 if (result != OK) { | 398 if (result != OK) { |
| 397 LOG(INFO) << "Failed configuring with PAC script, falling-back to manual " | 399 LOG(INFO) << "Failed configuring with PAC script, falling-back to manual " |
| 398 "proxy servers."; | 400 "proxy servers."; |
| 399 } | 401 } |
| 400 | 402 |
| 401 // Resume any requests which we had to defer until the PAC script was | 403 // Resume any requests which we had to defer until the PAC script was |
| 402 // downloaded. | 404 // downloaded. |
| 403 ResumeAllPendingRequests(); | 405 ResumeAllPendingRequests(); |
| 404 } | 406 } |
| 405 | 407 |
| 406 int ProxyService::ReconsiderProxyAfterError(const GURL& url, | 408 int ProxyService::ReconsiderProxyAfterError(LoadLog* load_log, |
| 409 const GURL& url, |
| 407 ProxyInfo* result, | 410 ProxyInfo* result, |
| 408 CompletionCallback* callback, | 411 CompletionCallback* callback, |
| 409 PacRequest** pac_request) { | 412 PacRequest** pac_request) { |
| 410 // Check to see if we have a new config since ResolveProxy was called. We | 413 // Check to see if we have a new config since ResolveProxy was called. We |
| 411 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a | 414 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a |
| 412 // direct connection failed and we never tried the current config. | 415 // direct connection failed and we never tried the current config. |
| 413 | 416 |
| 414 bool re_resolve = result->config_id_ != config_.id(); | 417 bool re_resolve = result->config_id_ != config_.id(); |
| 415 if (!re_resolve) { | 418 if (!re_resolve) { |
| 416 UpdateConfig(); | 419 UpdateConfig(); |
| 417 if (result->config_id_ != config_.id()) { | 420 if (result->config_id_ != config_.id()) { |
| 418 // A new configuration! | 421 // A new configuration! |
| 419 re_resolve = true; | 422 re_resolve = true; |
| 420 } else if (!result->config_was_tried_) { | 423 } else if (!result->config_was_tried_) { |
| 421 // We never tried the proxy configuration since we thought it was bad, | 424 // We never tried the proxy configuration since we thought it was bad, |
| 422 // but because we failed to establish a connection, let's try the proxy | 425 // but because we failed to establish a connection, let's try the proxy |
| 423 // configuration again to see if it will work now. | 426 // configuration again to see if it will work now. |
| 424 config_is_bad_ = false; | 427 config_is_bad_ = false; |
| 425 re_resolve = true; | 428 re_resolve = true; |
| 426 } | 429 } |
| 427 } | 430 } |
| 428 if (re_resolve) { | 431 if (re_resolve) { |
| 429 // If we have a new config or the config was never tried, we delete the | 432 // If we have a new config or the config was never tried, we delete the |
| 430 // list of bad proxies and we try again. | 433 // list of bad proxies and we try again. |
| 431 proxy_retry_info_.clear(); | 434 proxy_retry_info_.clear(); |
| 432 return ResolveProxy(url, result, callback, pac_request); | 435 return ResolveProxy(load_log, url, result, callback, pac_request); |
| 433 } | 436 } |
| 434 | 437 |
| 435 // We don't have new proxy settings to try, fallback to the next proxy | 438 // We don't have new proxy settings to try, fallback to the next proxy |
| 436 // in the list. | 439 // in the list. |
| 437 bool was_direct = result->is_direct(); | 440 bool was_direct = result->is_direct(); |
| 438 if (!was_direct && result->Fallback(&proxy_retry_info_)) | 441 if (!was_direct && result->Fallback(&proxy_retry_info_)) |
| 439 return OK; | 442 return OK; |
| 440 | 443 |
| 441 // TODO(eroman): Hmm, this doesn't seem right. For starters just because | 444 // TODO(eroman): Hmm, this doesn't seem right. For starters just because |
| 442 // auto_detect is true doesn't mean we are actually using it. | 445 // auto_detect is true doesn't mean we are actually using it. |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 SyncProxyServiceHelper::SyncProxyServiceHelper(MessageLoop* io_message_loop, | 695 SyncProxyServiceHelper::SyncProxyServiceHelper(MessageLoop* io_message_loop, |
| 693 ProxyService* proxy_service) | 696 ProxyService* proxy_service) |
| 694 : io_message_loop_(io_message_loop), | 697 : io_message_loop_(io_message_loop), |
| 695 proxy_service_(proxy_service), | 698 proxy_service_(proxy_service), |
| 696 event_(false, false), | 699 event_(false, false), |
| 697 ALLOW_THIS_IN_INITIALIZER_LIST(callback_( | 700 ALLOW_THIS_IN_INITIALIZER_LIST(callback_( |
| 698 this, &SyncProxyServiceHelper::OnCompletion)) { | 701 this, &SyncProxyServiceHelper::OnCompletion)) { |
| 699 DCHECK(io_message_loop_ != MessageLoop::current()); | 702 DCHECK(io_message_loop_ != MessageLoop::current()); |
| 700 } | 703 } |
| 701 | 704 |
| 702 int SyncProxyServiceHelper::ResolveProxy(const GURL& url, | 705 int SyncProxyServiceHelper::ResolveProxy(LoadLog* load_log, |
| 706 const GURL& url, |
| 703 ProxyInfo* proxy_info) { | 707 ProxyInfo* proxy_info) { |
| 704 DCHECK(io_message_loop_ != MessageLoop::current()); | 708 DCHECK(io_message_loop_ != MessageLoop::current()); |
| 705 | 709 |
| 706 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 710 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 707 this, &SyncProxyServiceHelper::StartAsyncResolve, url)); | 711 this, &SyncProxyServiceHelper::StartAsyncResolve, load_log, url)); |
| 708 | 712 |
| 709 event_.Wait(); | 713 event_.Wait(); |
| 710 | 714 |
| 711 if (result_ == net::OK) { | 715 if (result_ == net::OK) { |
| 712 *proxy_info = proxy_info_; | 716 *proxy_info = proxy_info_; |
| 713 } | 717 } |
| 714 return result_; | 718 return result_; |
| 715 } | 719 } |
| 716 | 720 |
| 717 int SyncProxyServiceHelper::ReconsiderProxyAfterError(const GURL& url, | 721 int SyncProxyServiceHelper::ReconsiderProxyAfterError( |
| 718 ProxyInfo* proxy_info) { | 722 LoadLog* load_log, const GURL& url, ProxyInfo* proxy_info) { |
| 719 DCHECK(io_message_loop_ != MessageLoop::current()); | 723 DCHECK(io_message_loop_ != MessageLoop::current()); |
| 720 | 724 |
| 721 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 725 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 722 this, &SyncProxyServiceHelper::StartAsyncReconsider, url)); | 726 this, &SyncProxyServiceHelper::StartAsyncReconsider, load_log, url)); |
| 723 | 727 |
| 724 event_.Wait(); | 728 event_.Wait(); |
| 725 | 729 |
| 726 if (result_ == net::OK) { | 730 if (result_ == net::OK) { |
| 727 *proxy_info = proxy_info_; | 731 *proxy_info = proxy_info_; |
| 728 } | 732 } |
| 729 return result_; | 733 return result_; |
| 730 } | 734 } |
| 731 | 735 |
| 732 void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url) { | 736 void SyncProxyServiceHelper::StartAsyncResolve(LoadLog* load_log, |
| 733 result_ = proxy_service_->ResolveProxy(url, &proxy_info_, &callback_, NULL); | 737 const GURL& url) { |
| 738 result_ = proxy_service_->ResolveProxy( |
| 739 load_log, url, &proxy_info_, &callback_, NULL); |
| 734 if (result_ != net::ERR_IO_PENDING) { | 740 if (result_ != net::ERR_IO_PENDING) { |
| 735 OnCompletion(result_); | 741 OnCompletion(result_); |
| 736 } | 742 } |
| 737 } | 743 } |
| 738 | 744 |
| 739 void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url) { | 745 void SyncProxyServiceHelper::StartAsyncReconsider(LoadLog* load_log, |
| 746 const GURL& url) { |
| 740 result_ = proxy_service_->ReconsiderProxyAfterError( | 747 result_ = proxy_service_->ReconsiderProxyAfterError( |
| 741 url, &proxy_info_, &callback_, NULL); | 748 load_log, url, &proxy_info_, &callback_, NULL); |
| 742 if (result_ != net::ERR_IO_PENDING) { | 749 if (result_ != net::ERR_IO_PENDING) { |
| 743 OnCompletion(result_); | 750 OnCompletion(result_); |
| 744 } | 751 } |
| 745 } | 752 } |
| 746 | 753 |
| 747 void SyncProxyServiceHelper::OnCompletion(int rv) { | 754 void SyncProxyServiceHelper::OnCompletion(int rv) { |
| 748 result_ = rv; | 755 result_ = rv; |
| 749 event_.Signal(); | 756 event_.Signal(); |
| 750 } | 757 } |
| 751 | 758 |
| 752 } // namespace net | 759 } // namespace net |
| OLD | NEW |