Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 | 160 |
| 161 // Config getter that always returns direct settings. | 161 // Config getter that always returns direct settings. |
| 162 class ProxyConfigServiceDirect : public ProxyConfigService { | 162 class ProxyConfigServiceDirect : public ProxyConfigService { |
| 163 public: | 163 public: |
| 164 // ProxyConfigService implementation: | 164 // ProxyConfigService implementation: |
| 165 virtual void AddObserver(Observer* observer) OVERRIDE {} | 165 virtual void AddObserver(Observer* observer) OVERRIDE {} |
| 166 virtual void RemoveObserver(Observer* observer) OVERRIDE {} | 166 virtual void RemoveObserver(Observer* observer) OVERRIDE {} |
| 167 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) | 167 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) |
| 168 OVERRIDE { | 168 OVERRIDE { |
| 169 *config = ProxyConfig::CreateDirect(); | 169 *config = ProxyConfig::CreateDirect(); |
| 170 config->set_source(PROXY_CONFIG_SOURCE_NONE); | |
|
eroman
2012/06/11 23:18:34
See earlier comment. I think this should be either
asanka
2012/06/12 19:37:18
Done. Went with SOURCE_UNKNOWN.
| |
| 170 return CONFIG_VALID; | 171 return CONFIG_VALID; |
| 171 } | 172 } |
| 172 }; | 173 }; |
| 173 | 174 |
| 174 // Proxy resolver that fails every time. | 175 // Proxy resolver that fails every time. |
| 175 class ProxyResolverNull : public ProxyResolver { | 176 class ProxyResolverNull : public ProxyResolver { |
| 176 public: | 177 public: |
| 177 ProxyResolverNull() : ProxyResolver(false /*expects_pac_bytes*/) {} | 178 ProxyResolverNull() : ProxyResolver(false /*expects_pac_bytes*/) {} |
| 178 | 179 |
| 179 // ProxyResolver implementation. | 180 // ProxyResolver implementation. |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 const GURL& url, | 796 const GURL& url, |
| 796 ProxyInfo* results, | 797 ProxyInfo* results, |
| 797 const net::CompletionCallback& user_callback, | 798 const net::CompletionCallback& user_callback, |
| 798 const BoundNetLog& net_log) | 799 const BoundNetLog& net_log) |
| 799 : service_(service), | 800 : service_(service), |
| 800 user_callback_(user_callback), | 801 user_callback_(user_callback), |
| 801 results_(results), | 802 results_(results), |
| 802 url_(url), | 803 url_(url), |
| 803 resolve_job_(NULL), | 804 resolve_job_(NULL), |
| 804 config_id_(ProxyConfig::kInvalidConfigID), | 805 config_id_(ProxyConfig::kInvalidConfigID), |
| 806 config_source_(PROXY_CONFIG_SOURCE_UNKNOWN), | |
| 805 net_log_(net_log) { | 807 net_log_(net_log) { |
| 806 DCHECK(!user_callback.is_null()); | 808 DCHECK(!user_callback.is_null()); |
| 807 } | 809 } |
| 808 | 810 |
| 809 // Starts the resolve proxy request. | 811 // Starts the resolve proxy request. |
| 810 int Start() { | 812 int Start() { |
| 811 DCHECK(!was_cancelled()); | 813 DCHECK(!was_cancelled()); |
| 812 DCHECK(!is_started()); | 814 DCHECK(!is_started()); |
| 813 | 815 |
| 814 DCHECK(service_->config_.is_valid()); | 816 DCHECK(service_->config_.is_valid()); |
| 815 | 817 |
| 816 config_id_ = service_->config_.id(); | 818 config_id_ = service_->config_.id(); |
| 819 config_source_ = service_->config_.source(); | |
| 817 | 820 |
| 818 return resolver()->GetProxyForURL( | 821 return resolver()->GetProxyForURL( |
| 819 url_, results_, | 822 url_, results_, |
| 820 base::Bind(&PacRequest::QueryComplete, base::Unretained(this)), | 823 base::Bind(&PacRequest::QueryComplete, base::Unretained(this)), |
| 821 &resolve_job_, net_log_); | 824 &resolve_job_, net_log_); |
| 822 } | 825 } |
| 823 | 826 |
| 824 bool is_started() const { | 827 bool is_started() const { |
| 825 // Note that !! casts to bool. (VS gives a warning otherwise). | 828 // Note that !! casts to bool. (VS gives a warning otherwise). |
| 826 return !!resolve_job_; | 829 return !!resolve_job_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 862 } | 865 } |
| 863 | 866 |
| 864 // Helper to call after ProxyResolver completion (both synchronous and | 867 // Helper to call after ProxyResolver completion (both synchronous and |
| 865 // asynchronous). Fixes up the result that is to be returned to user. | 868 // asynchronous). Fixes up the result that is to be returned to user. |
| 866 int QueryDidComplete(int result_code) { | 869 int QueryDidComplete(int result_code) { |
| 867 DCHECK(!was_cancelled()); | 870 DCHECK(!was_cancelled()); |
| 868 | 871 |
| 869 // Make a note in the results which configuration was in use at the | 872 // Make a note in the results which configuration was in use at the |
| 870 // time of the resolve. | 873 // time of the resolve. |
| 871 results_->config_id_ = config_id_; | 874 results_->config_id_ = config_id_; |
| 875 results_->config_source_ = config_source_; | |
| 876 results_->did_use_pac_script_ = true; | |
| 872 | 877 |
| 873 // Reset the state associated with in-progress-resolve. | 878 // Reset the state associated with in-progress-resolve. |
| 874 resolve_job_ = NULL; | 879 resolve_job_ = NULL; |
| 875 config_id_ = ProxyConfig::kInvalidConfigID; | 880 config_id_ = ProxyConfig::kInvalidConfigID; |
| 881 config_source_ = PROXY_CONFIG_SOURCE_UNKNOWN; | |
| 876 | 882 |
| 877 return service_->DidFinishResolvingProxy(results_, result_code, net_log_); | 883 return service_->DidFinishResolvingProxy(results_, result_code, net_log_); |
| 878 } | 884 } |
| 879 | 885 |
| 880 BoundNetLog* net_log() { return &net_log_; } | 886 BoundNetLog* net_log() { return &net_log_; } |
| 881 | 887 |
| 882 LoadState GetLoadState() const { | 888 LoadState GetLoadState() const { |
| 883 if (is_started()) | 889 if (is_started()) |
| 884 return resolver()->GetLoadState(resolve_job_); | 890 return resolver()->GetLoadState(resolve_job_); |
| 885 return LOAD_STATE_RESOLVING_PROXY_FOR_URL; | 891 return LOAD_STATE_RESOLVING_PROXY_FOR_URL; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 907 | 913 |
| 908 // Note that we don't hold a reference to the ProxyService. Outstanding | 914 // Note that we don't hold a reference to the ProxyService. Outstanding |
| 909 // requests are cancelled during ~ProxyService, so this is guaranteed | 915 // requests are cancelled during ~ProxyService, so this is guaranteed |
| 910 // to be valid throughout our lifetime. | 916 // to be valid throughout our lifetime. |
| 911 ProxyService* service_; | 917 ProxyService* service_; |
| 912 net::CompletionCallback user_callback_; | 918 net::CompletionCallback user_callback_; |
| 913 ProxyInfo* results_; | 919 ProxyInfo* results_; |
| 914 GURL url_; | 920 GURL url_; |
| 915 ProxyResolver::RequestHandle resolve_job_; | 921 ProxyResolver::RequestHandle resolve_job_; |
| 916 ProxyConfig::ID config_id_; // The config id when the resolve was started. | 922 ProxyConfig::ID config_id_; // The config id when the resolve was started. |
| 923 ProxyConfigSource config_source_; // The source of proxy settings. | |
| 917 BoundNetLog net_log_; | 924 BoundNetLog net_log_; |
| 918 }; | 925 }; |
| 919 | 926 |
| 920 // ProxyService --------------------------------------------------------------- | 927 // ProxyService --------------------------------------------------------------- |
| 921 | 928 |
| 922 ProxyService::ProxyService(ProxyConfigService* config_service, | 929 ProxyService::ProxyService(ProxyConfigService* config_service, |
| 923 ProxyResolver* resolver, | 930 ProxyResolver* resolver, |
| 924 NetLog* net_log) | 931 NetLog* net_log) |
| 925 : resolver_(resolver), | 932 : resolver_(resolver), |
| 926 next_config_id_(1), | 933 next_config_id_(1), |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1109 // If it was impossible to fetch or parse the PAC script, we cannot complete | 1116 // If it was impossible to fetch or parse the PAC script, we cannot complete |
| 1110 // the request here and bail out. | 1117 // the request here and bail out. |
| 1111 if (permanent_error_ != OK) | 1118 if (permanent_error_ != OK) |
| 1112 return permanent_error_; | 1119 return permanent_error_; |
| 1113 | 1120 |
| 1114 if (config_.HasAutomaticSettings()) | 1121 if (config_.HasAutomaticSettings()) |
| 1115 return ERR_IO_PENDING; // Must submit the request to the proxy resolver. | 1122 return ERR_IO_PENDING; // Must submit the request to the proxy resolver. |
| 1116 | 1123 |
| 1117 // Use the manual proxy settings. | 1124 // Use the manual proxy settings. |
| 1118 config_.proxy_rules().Apply(url, result); | 1125 config_.proxy_rules().Apply(url, result); |
| 1126 result->config_source_ = config_.source(); | |
| 1119 result->config_id_ = config_.id(); | 1127 result->config_id_ = config_.id(); |
| 1120 return OK; | 1128 return OK; |
| 1121 } | 1129 } |
| 1122 | 1130 |
| 1123 ProxyService::~ProxyService() { | 1131 ProxyService::~ProxyService() { |
| 1124 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1132 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1125 config_service_->RemoveObserver(this); | 1133 config_service_->RemoveObserver(this); |
| 1126 | 1134 |
| 1127 // Cancel any inprogress requests. | 1135 // Cancel any inprogress requests. |
| 1128 for (PendingRequests::iterator it = pending_requests_.begin(); | 1136 for (PendingRequests::iterator it = pending_requests_.begin(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1230 config_ = fetched_config_; | 1238 config_ = fetched_config_; |
| 1231 config_.ClearAutomaticSettings(); | 1239 config_.ClearAutomaticSettings(); |
| 1232 result = OK; | 1240 result = OK; |
| 1233 } | 1241 } |
| 1234 } | 1242 } |
| 1235 permanent_error_ = result; | 1243 permanent_error_ = result; |
| 1236 | 1244 |
| 1237 // TODO(eroman): Make this ID unique in the case where configuration changed | 1245 // TODO(eroman): Make this ID unique in the case where configuration changed |
| 1238 // due to ProxyScriptDeciderPoller. | 1246 // due to ProxyScriptDeciderPoller. |
| 1239 config_.set_id(fetched_config_.id()); | 1247 config_.set_id(fetched_config_.id()); |
| 1248 config_.set_source(fetched_config_.source()); | |
| 1240 | 1249 |
| 1241 // Resume any requests which we had to defer until the PAC script was | 1250 // Resume any requests which we had to defer until the PAC script was |
| 1242 // downloaded. | 1251 // downloaded. |
| 1243 SetReady(); | 1252 SetReady(); |
| 1244 } | 1253 } |
| 1245 | 1254 |
| 1246 int ProxyService::ReconsiderProxyAfterError(const GURL& url, | 1255 int ProxyService::ReconsiderProxyAfterError(const GURL& url, |
| 1247 ProxyInfo* result, | 1256 ProxyInfo* result, |
| 1248 const CompletionCallback& callback, | 1257 const CompletionCallback& callback, |
| 1249 PacRequest** pac_request, | 1258 PacRequest** pac_request, |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1648 OnCompletion(result_); | 1657 OnCompletion(result_); |
| 1649 } | 1658 } |
| 1650 } | 1659 } |
| 1651 | 1660 |
| 1652 void SyncProxyServiceHelper::OnCompletion(int rv) { | 1661 void SyncProxyServiceHelper::OnCompletion(int rv) { |
| 1653 result_ = rv; | 1662 result_ = rv; |
| 1654 event_.Signal(); | 1663 event_.Signal(); |
| 1655 } | 1664 } |
| 1656 | 1665 |
| 1657 } // namespace net | 1666 } // namespace net |
| OLD | NEW |