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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 | 157 |
158 // Config getter that always returns direct settings. | 158 // Config getter that always returns direct settings. |
159 class ProxyConfigServiceDirect : public ProxyConfigService { | 159 class ProxyConfigServiceDirect : public ProxyConfigService { |
160 public: | 160 public: |
161 // ProxyConfigService implementation: | 161 // ProxyConfigService implementation: |
162 virtual void AddObserver(Observer* observer) OVERRIDE {} | 162 virtual void AddObserver(Observer* observer) OVERRIDE {} |
163 virtual void RemoveObserver(Observer* observer) OVERRIDE {} | 163 virtual void RemoveObserver(Observer* observer) OVERRIDE {} |
164 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) | 164 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) |
165 OVERRIDE { | 165 OVERRIDE { |
166 *config = ProxyConfig::CreateDirect(); | 166 *config = ProxyConfig::CreateDirect(); |
167 config->set_source(PROXY_CONFIG_SOURCE_NONE); | |
167 return CONFIG_VALID; | 168 return CONFIG_VALID; |
168 } | 169 } |
169 }; | 170 }; |
170 | 171 |
171 // Proxy resolver that fails every time. | 172 // Proxy resolver that fails every time. |
172 class ProxyResolverNull : public ProxyResolver { | 173 class ProxyResolverNull : public ProxyResolver { |
173 public: | 174 public: |
174 ProxyResolverNull() : ProxyResolver(false /*expects_pac_bytes*/) {} | 175 ProxyResolverNull() : ProxyResolver(false /*expects_pac_bytes*/) {} |
175 | 176 |
176 // ProxyResolver implementation. | 177 // ProxyResolver implementation. |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
792 const GURL& url, | 793 const GURL& url, |
793 ProxyInfo* results, | 794 ProxyInfo* results, |
794 const net::CompletionCallback& user_callback, | 795 const net::CompletionCallback& user_callback, |
795 const BoundNetLog& net_log) | 796 const BoundNetLog& net_log) |
796 : service_(service), | 797 : service_(service), |
797 user_callback_(user_callback), | 798 user_callback_(user_callback), |
798 results_(results), | 799 results_(results), |
799 url_(url), | 800 url_(url), |
800 resolve_job_(NULL), | 801 resolve_job_(NULL), |
801 config_id_(ProxyConfig::kInvalidConfigID), | 802 config_id_(ProxyConfig::kInvalidConfigID), |
803 config_source_(PROXY_CONFIG_SOURCE_UNKNOWN), | |
802 net_log_(net_log) { | 804 net_log_(net_log) { |
803 DCHECK(!user_callback.is_null()); | 805 DCHECK(!user_callback.is_null()); |
804 } | 806 } |
805 | 807 |
806 // Starts the resolve proxy request. | 808 // Starts the resolve proxy request. |
807 int Start() { | 809 int Start() { |
808 DCHECK(!was_cancelled()); | 810 DCHECK(!was_cancelled()); |
809 DCHECK(!is_started()); | 811 DCHECK(!is_started()); |
810 | 812 |
811 DCHECK(service_->config_.is_valid()); | 813 DCHECK(service_->config_.is_valid()); |
812 | 814 |
813 config_id_ = service_->config_.id(); | 815 config_id_ = service_->config_.id(); |
816 config_source_ = service_->config_.source(); | |
814 | 817 |
815 return resolver()->GetProxyForURL( | 818 return resolver()->GetProxyForURL( |
816 url_, results_, | 819 url_, results_, |
817 base::Bind(&PacRequest::QueryComplete, base::Unretained(this)), | 820 base::Bind(&PacRequest::QueryComplete, base::Unretained(this)), |
818 &resolve_job_, net_log_); | 821 &resolve_job_, net_log_); |
819 } | 822 } |
820 | 823 |
821 bool is_started() const { | 824 bool is_started() const { |
822 // Note that !! casts to bool. (VS gives a warning otherwise). | 825 // Note that !! casts to bool. (VS gives a warning otherwise). |
823 return !!resolve_job_; | 826 return !!resolve_job_; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
859 } | 862 } |
860 | 863 |
861 // Helper to call after ProxyResolver completion (both synchronous and | 864 // Helper to call after ProxyResolver completion (both synchronous and |
862 // asynchronous). Fixes up the result that is to be returned to user. | 865 // asynchronous). Fixes up the result that is to be returned to user. |
863 int QueryDidComplete(int result_code) { | 866 int QueryDidComplete(int result_code) { |
864 DCHECK(!was_cancelled()); | 867 DCHECK(!was_cancelled()); |
865 | 868 |
866 // Make a note in the results which configuration was in use at the | 869 // Make a note in the results which configuration was in use at the |
867 // time of the resolve. | 870 // time of the resolve. |
868 results_->config_id_ = config_id_; | 871 results_->config_id_ = config_id_; |
872 results_->config_source_ = config_source_; | |
869 | 873 |
870 // Reset the state associated with in-progress-resolve. | 874 // Reset the state associated with in-progress-resolve. |
871 resolve_job_ = NULL; | 875 resolve_job_ = NULL; |
872 config_id_ = ProxyConfig::kInvalidConfigID; | 876 config_id_ = ProxyConfig::kInvalidConfigID; |
877 config_source_ = PROXY_CONFIG_SOURCE_UNKNOWN; | |
873 | 878 |
874 return service_->DidFinishResolvingProxy(results_, result_code, net_log_); | 879 return service_->DidFinishResolvingProxy(results_, result_code, net_log_); |
875 } | 880 } |
876 | 881 |
877 BoundNetLog* net_log() { return &net_log_; } | 882 BoundNetLog* net_log() { return &net_log_; } |
878 | 883 |
879 LoadState GetLoadState() const { | 884 LoadState GetLoadState() const { |
880 if (is_started()) | 885 if (is_started()) |
881 return resolver()->GetLoadState(resolve_job_); | 886 return resolver()->GetLoadState(resolve_job_); |
882 return LOAD_STATE_RESOLVING_PROXY_FOR_URL; | 887 return LOAD_STATE_RESOLVING_PROXY_FOR_URL; |
(...skipping 21 matching lines...) Expand all Loading... | |
904 | 909 |
905 // Note that we don't hold a reference to the ProxyService. Outstanding | 910 // Note that we don't hold a reference to the ProxyService. Outstanding |
906 // requests are cancelled during ~ProxyService, so this is guaranteed | 911 // requests are cancelled during ~ProxyService, so this is guaranteed |
907 // to be valid throughout our lifetime. | 912 // to be valid throughout our lifetime. |
908 ProxyService* service_; | 913 ProxyService* service_; |
909 net::CompletionCallback user_callback_; | 914 net::CompletionCallback user_callback_; |
910 ProxyInfo* results_; | 915 ProxyInfo* results_; |
911 GURL url_; | 916 GURL url_; |
912 ProxyResolver::RequestHandle resolve_job_; | 917 ProxyResolver::RequestHandle resolve_job_; |
913 ProxyConfig::ID config_id_; // The config id when the resolve was started. | 918 ProxyConfig::ID config_id_; // The config id when the resolve was started. |
919 ProxyConfigSource config_source_; // The source of proxy settings. | |
914 BoundNetLog net_log_; | 920 BoundNetLog net_log_; |
915 }; | 921 }; |
916 | 922 |
917 // ProxyService --------------------------------------------------------------- | 923 // ProxyService --------------------------------------------------------------- |
918 | 924 |
919 ProxyService::ProxyService(ProxyConfigService* config_service, | 925 ProxyService::ProxyService(ProxyConfigService* config_service, |
920 ProxyResolver* resolver, | 926 ProxyResolver* resolver, |
921 NetLog* net_log) | 927 NetLog* net_log) |
922 : resolver_(resolver), | 928 : resolver_(resolver), |
923 next_config_id_(1), | 929 next_config_id_(1), |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1105 | 1111 |
1106 // If it was impossible to fetch or parse the PAC script, we cannot complete | 1112 // If it was impossible to fetch or parse the PAC script, we cannot complete |
1107 // the request here and bail out. | 1113 // the request here and bail out. |
1108 if (permanent_error_ != OK) | 1114 if (permanent_error_ != OK) |
1109 return permanent_error_; | 1115 return permanent_error_; |
1110 | 1116 |
1111 if (config_.HasAutomaticSettings()) | 1117 if (config_.HasAutomaticSettings()) |
1112 return ERR_IO_PENDING; // Must submit the request to the proxy resolver. | 1118 return ERR_IO_PENDING; // Must submit the request to the proxy resolver. |
1113 | 1119 |
1114 // Use the manual proxy settings. | 1120 // Use the manual proxy settings. |
1115 config_.proxy_rules().Apply(url, result); | 1121 bool did_use_proxy_rules = config_.proxy_rules().Apply(url, result); |
1122 result->config_source_ = | |
1123 (did_use_proxy_rules ? config_.source() : PROXY_CONFIG_SOURCE_NONE); | |
eroman
2012/05/18 03:58:56
I'm not sure that I follow this.
Apply() can retu
asanka
2012/05/18 16:27:01
I wanted to distinguish between:
- There are no pr
| |
1116 result->config_id_ = config_.id(); | 1124 result->config_id_ = config_.id(); |
1117 return OK; | 1125 return OK; |
1118 } | 1126 } |
1119 | 1127 |
1120 ProxyService::~ProxyService() { | 1128 ProxyService::~ProxyService() { |
1121 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1129 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
1122 config_service_->RemoveObserver(this); | 1130 config_service_->RemoveObserver(this); |
1123 | 1131 |
1124 // Cancel any inprogress requests. | 1132 // Cancel any inprogress requests. |
1125 for (PendingRequests::iterator it = pending_requests_.begin(); | 1133 for (PendingRequests::iterator it = pending_requests_.begin(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1227 config_ = fetched_config_; | 1235 config_ = fetched_config_; |
1228 config_.ClearAutomaticSettings(); | 1236 config_.ClearAutomaticSettings(); |
1229 result = OK; | 1237 result = OK; |
1230 } | 1238 } |
1231 } | 1239 } |
1232 permanent_error_ = result; | 1240 permanent_error_ = result; |
1233 | 1241 |
1234 // TODO(eroman): Make this ID unique in the case where configuration changed | 1242 // TODO(eroman): Make this ID unique in the case where configuration changed |
1235 // due to ProxyScriptDeciderPoller. | 1243 // due to ProxyScriptDeciderPoller. |
1236 config_.set_id(fetched_config_.id()); | 1244 config_.set_id(fetched_config_.id()); |
1245 config_.set_source(fetched_config_.source()); | |
eroman
2012/05/18 03:58:56
Perhaps this should be done internally by ProxyScr
asanka
2012/05/18 16:27:01
Do you mean to fold PacSource into ConfigSource?
| |
1237 | 1246 |
1238 // Resume any requests which we had to defer until the PAC script was | 1247 // Resume any requests which we had to defer until the PAC script was |
1239 // downloaded. | 1248 // downloaded. |
1240 SetReady(); | 1249 SetReady(); |
1241 } | 1250 } |
1242 | 1251 |
1243 int ProxyService::ReconsiderProxyAfterError(const GURL& url, | 1252 int ProxyService::ReconsiderProxyAfterError(const GURL& url, |
1244 ProxyInfo* result, | 1253 ProxyInfo* result, |
1245 const CompletionCallback& callback, | 1254 const CompletionCallback& callback, |
1246 PacRequest** pac_request, | 1255 PacRequest** pac_request, |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1640 OnCompletion(result_); | 1649 OnCompletion(result_); |
1641 } | 1650 } |
1642 } | 1651 } |
1643 | 1652 |
1644 void SyncProxyServiceHelper::OnCompletion(int rv) { | 1653 void SyncProxyServiceHelper::OnCompletion(int rv) { |
1645 result_ = rv; | 1654 result_ = rv; |
1646 event_.Signal(); | 1655 event_.Signal(); |
1647 } | 1656 } |
1648 | 1657 |
1649 } // namespace net | 1658 } // namespace net |
OLD | NEW |