Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: net/proxy/proxy_service.cc

Issue 2351513002: net: rename BoundNetLog to NetLogWithSource (Closed)
Patch Set: one more fix, content bound_net_log_ Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // Proxy resolver that fails every time. 180 // Proxy resolver that fails every time.
181 class ProxyResolverNull : public ProxyResolver { 181 class ProxyResolverNull : public ProxyResolver {
182 public: 182 public:
183 ProxyResolverNull() {} 183 ProxyResolverNull() {}
184 184
185 // ProxyResolver implementation. 185 // ProxyResolver implementation.
186 int GetProxyForURL(const GURL& url, 186 int GetProxyForURL(const GURL& url,
187 ProxyInfo* results, 187 ProxyInfo* results,
188 const CompletionCallback& callback, 188 const CompletionCallback& callback,
189 RequestHandle* request, 189 RequestHandle* request,
190 const BoundNetLog& net_log) override { 190 const NetLogWithSource& net_log) override {
191 return ERR_NOT_IMPLEMENTED; 191 return ERR_NOT_IMPLEMENTED;
192 } 192 }
193 193
194 void CancelRequest(RequestHandle request) override { NOTREACHED(); } 194 void CancelRequest(RequestHandle request) override { NOTREACHED(); }
195 195
196 LoadState GetLoadState(RequestHandle request) const override { 196 LoadState GetLoadState(RequestHandle request) const override {
197 NOTREACHED(); 197 NOTREACHED();
198 return LOAD_STATE_IDLE; 198 return LOAD_STATE_IDLE;
199 } 199 }
200 200
201 }; 201 };
202 202
203 // ProxyResolver that simulates a PAC script which returns 203 // ProxyResolver that simulates a PAC script which returns
204 // |pac_string| for every single URL. 204 // |pac_string| for every single URL.
205 class ProxyResolverFromPacString : public ProxyResolver { 205 class ProxyResolverFromPacString : public ProxyResolver {
206 public: 206 public:
207 explicit ProxyResolverFromPacString(const std::string& pac_string) 207 explicit ProxyResolverFromPacString(const std::string& pac_string)
208 : pac_string_(pac_string) {} 208 : pac_string_(pac_string) {}
209 209
210 int GetProxyForURL(const GURL& url, 210 int GetProxyForURL(const GURL& url,
211 ProxyInfo* results, 211 ProxyInfo* results,
212 const CompletionCallback& callback, 212 const CompletionCallback& callback,
213 RequestHandle* request, 213 RequestHandle* request,
214 const BoundNetLog& net_log) override { 214 const NetLogWithSource& net_log) override {
215 results->UsePacString(pac_string_); 215 results->UsePacString(pac_string_);
216 return OK; 216 return OK;
217 } 217 }
218 218
219 void CancelRequest(RequestHandle request) override { NOTREACHED(); } 219 void CancelRequest(RequestHandle request) override { NOTREACHED(); }
220 220
221 LoadState GetLoadState(RequestHandle request) const override { 221 LoadState GetLoadState(RequestHandle request) const override {
222 NOTREACHED(); 222 NOTREACHED();
223 return LOAD_STATE_IDLE; 223 return LOAD_STATE_IDLE;
224 } 224 }
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 785
786 class ProxyService::PacRequest 786 class ProxyService::PacRequest
787 : public base::RefCounted<ProxyService::PacRequest> { 787 : public base::RefCounted<ProxyService::PacRequest> {
788 public: 788 public:
789 PacRequest(ProxyService* service, 789 PacRequest(ProxyService* service,
790 const GURL& url, 790 const GURL& url,
791 const std::string& method, 791 const std::string& method,
792 ProxyDelegate* proxy_delegate, 792 ProxyDelegate* proxy_delegate,
793 ProxyInfo* results, 793 ProxyInfo* results,
794 const CompletionCallback& user_callback, 794 const CompletionCallback& user_callback,
795 const BoundNetLog& net_log) 795 const NetLogWithSource& net_log)
796 : service_(service), 796 : service_(service),
797 user_callback_(user_callback), 797 user_callback_(user_callback),
798 results_(results), 798 results_(results),
799 url_(url), 799 url_(url),
800 method_(method), 800 method_(method),
801 proxy_delegate_(proxy_delegate), 801 proxy_delegate_(proxy_delegate),
802 resolve_job_(NULL), 802 resolve_job_(NULL),
803 config_id_(ProxyConfig::kInvalidConfigID), 803 config_id_(ProxyConfig::kInvalidConfigID),
804 config_source_(PROXY_CONFIG_SOURCE_UNKNOWN), 804 config_source_(PROXY_CONFIG_SOURCE_UNKNOWN),
805 net_log_(net_log), 805 net_log_(net_log),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 results_->proxy_resolve_start_time_ = creation_time_; 889 results_->proxy_resolve_start_time_ = creation_time_;
890 results_->proxy_resolve_end_time_ = TimeTicks::Now(); 890 results_->proxy_resolve_end_time_ = TimeTicks::Now();
891 891
892 // Reset the state associated with in-progress-resolve. 892 // Reset the state associated with in-progress-resolve.
893 config_id_ = ProxyConfig::kInvalidConfigID; 893 config_id_ = ProxyConfig::kInvalidConfigID;
894 config_source_ = PROXY_CONFIG_SOURCE_UNKNOWN; 894 config_source_ = PROXY_CONFIG_SOURCE_UNKNOWN;
895 895
896 return rv; 896 return rv;
897 } 897 }
898 898
899 BoundNetLog* net_log() { return &net_log_; } 899 NetLogWithSource* net_log() { return &net_log_; }
900 900
901 LoadState GetLoadState() const { 901 LoadState GetLoadState() const {
902 if (is_started()) 902 if (is_started())
903 return resolver()->GetLoadState(resolve_job_); 903 return resolver()->GetLoadState(resolve_job_);
904 return LOAD_STATE_RESOLVING_PROXY_FOR_URL; 904 return LOAD_STATE_RESOLVING_PROXY_FOR_URL;
905 } 905 }
906 906
907 private: 907 private:
908 friend class base::RefCounted<ProxyService::PacRequest>; 908 friend class base::RefCounted<ProxyService::PacRequest>;
909 909
(...skipping 19 matching lines...) Expand all
929 // to be valid throughout our lifetime. 929 // to be valid throughout our lifetime.
930 ProxyService* service_; 930 ProxyService* service_;
931 CompletionCallback user_callback_; 931 CompletionCallback user_callback_;
932 ProxyInfo* results_; 932 ProxyInfo* results_;
933 GURL url_; 933 GURL url_;
934 std::string method_; 934 std::string method_;
935 ProxyDelegate* proxy_delegate_; 935 ProxyDelegate* proxy_delegate_;
936 ProxyResolver::RequestHandle resolve_job_; 936 ProxyResolver::RequestHandle resolve_job_;
937 ProxyConfig::ID config_id_; // The config id when the resolve was started. 937 ProxyConfig::ID config_id_; // The config id when the resolve was started.
938 ProxyConfigSource config_source_; // The source of proxy settings. 938 ProxyConfigSource config_source_; // The source of proxy settings.
939 BoundNetLog net_log_; 939 NetLogWithSource net_log_;
940 // Time when the request was created. Stored here rather than in |results_| 940 // Time when the request was created. Stored here rather than in |results_|
941 // because the time in |results_| will be cleared. 941 // because the time in |results_| will be cleared.
942 TimeTicks creation_time_; 942 TimeTicks creation_time_;
943 }; 943 };
944 944
945 // ProxyService --------------------------------------------------------------- 945 // ProxyService ---------------------------------------------------------------
946 946
947 ProxyService::ProxyService( 947 ProxyService::ProxyService(
948 std::unique_ptr<ProxyConfigService> config_service, 948 std::unique_ptr<ProxyConfigService> config_service,
949 std::unique_ptr<ProxyResolverFactory> resolver_factory, 949 std::unique_ptr<ProxyResolverFactory> resolver_factory,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 std::move(proxy_config_service), 1032 std::move(proxy_config_service),
1033 base::MakeUnique<ProxyResolverFactoryForPacResult>(pac_string), NULL)); 1033 base::MakeUnique<ProxyResolverFactoryForPacResult>(pac_string), NULL));
1034 } 1034 }
1035 1035
1036 int ProxyService::ResolveProxy(const GURL& raw_url, 1036 int ProxyService::ResolveProxy(const GURL& raw_url,
1037 const std::string& method, 1037 const std::string& method,
1038 ProxyInfo* result, 1038 ProxyInfo* result,
1039 const CompletionCallback& callback, 1039 const CompletionCallback& callback,
1040 PacRequest** pac_request, 1040 PacRequest** pac_request,
1041 ProxyDelegate* proxy_delegate, 1041 ProxyDelegate* proxy_delegate,
1042 const BoundNetLog& net_log) { 1042 const NetLogWithSource& net_log) {
1043 DCHECK(!callback.is_null()); 1043 DCHECK(!callback.is_null());
1044 return ResolveProxyHelper(raw_url, method, result, callback, pac_request, 1044 return ResolveProxyHelper(raw_url, method, result, callback, pac_request,
1045 proxy_delegate, net_log); 1045 proxy_delegate, net_log);
1046 } 1046 }
1047 1047
1048 int ProxyService::ResolveProxyHelper(const GURL& raw_url, 1048 int ProxyService::ResolveProxyHelper(const GURL& raw_url,
1049 const std::string& method, 1049 const std::string& method,
1050 ProxyInfo* result, 1050 ProxyInfo* result,
1051 const CompletionCallback& callback, 1051 const CompletionCallback& callback,
1052 PacRequest** pac_request, 1052 PacRequest** pac_request,
1053 ProxyDelegate* proxy_delegate, 1053 ProxyDelegate* proxy_delegate,
1054 const BoundNetLog& net_log) { 1054 const NetLogWithSource& net_log) {
1055 DCHECK(CalledOnValidThread()); 1055 DCHECK(CalledOnValidThread());
1056 1056
1057 net_log.BeginEvent(NetLogEventType::PROXY_SERVICE); 1057 net_log.BeginEvent(NetLogEventType::PROXY_SERVICE);
1058 1058
1059 // Notify our polling-based dependencies that a resolve is taking place. 1059 // Notify our polling-based dependencies that a resolve is taking place.
1060 // This way they can schedule their polls in response to network activity. 1060 // This way they can schedule their polls in response to network activity.
1061 config_service_->OnLazyPoll(); 1061 config_service_->OnLazyPoll();
1062 if (script_poller_.get()) 1062 if (script_poller_.get())
1063 script_poller_->OnLazyPoll(); 1063 script_poller_->OnLazyPoll();
1064 1064
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 DCHECK(!ContainsPendingRequest(req.get())); 1101 DCHECK(!ContainsPendingRequest(req.get()));
1102 pending_requests_.insert(req); 1102 pending_requests_.insert(req);
1103 1103
1104 // Completion will be notified through |callback|, unless the caller cancels 1104 // Completion will be notified through |callback|, unless the caller cancels
1105 // the request using |pac_request|. 1105 // the request using |pac_request|.
1106 if (pac_request) 1106 if (pac_request)
1107 *pac_request = req.get(); 1107 *pac_request = req.get();
1108 return rv; // ERR_IO_PENDING 1108 return rv; // ERR_IO_PENDING
1109 } 1109 }
1110 1110
1111 bool ProxyService::TryResolveProxySynchronously(const GURL& raw_url, 1111 bool ProxyService::TryResolveProxySynchronously(
1112 const std::string& method, 1112 const GURL& raw_url,
1113 ProxyInfo* result, 1113 const std::string& method,
1114 ProxyDelegate* proxy_delegate, 1114 ProxyInfo* result,
1115 const BoundNetLog& net_log) { 1115 ProxyDelegate* proxy_delegate,
1116 const NetLogWithSource& net_log) {
1116 CompletionCallback null_callback; 1117 CompletionCallback null_callback;
1117 return ResolveProxyHelper(raw_url, method, result, null_callback, 1118 return ResolveProxyHelper(raw_url, method, result, null_callback,
1118 nullptr /* pac_request*/, proxy_delegate, 1119 nullptr /* pac_request*/, proxy_delegate,
1119 net_log) == OK; 1120 net_log) == OK;
1120 } 1121 }
1121 1122
1122 int ProxyService::TryToCompleteSynchronously(const GURL& url, 1123 int ProxyService::TryToCompleteSynchronously(const GURL& url,
1123 ProxyDelegate* proxy_delegate, 1124 ProxyDelegate* proxy_delegate,
1124 ProxyInfo* result) { 1125 ProxyInfo* result) {
1125 DCHECK_NE(STATE_NONE, current_state_); 1126 DCHECK_NE(STATE_NONE, current_state_);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 SetReady(); 1274 SetReady();
1274 } 1275 }
1275 1276
1276 int ProxyService::ReconsiderProxyAfterError(const GURL& url, 1277 int ProxyService::ReconsiderProxyAfterError(const GURL& url,
1277 const std::string& method, 1278 const std::string& method,
1278 int net_error, 1279 int net_error,
1279 ProxyInfo* result, 1280 ProxyInfo* result,
1280 const CompletionCallback& callback, 1281 const CompletionCallback& callback,
1281 PacRequest** pac_request, 1282 PacRequest** pac_request,
1282 ProxyDelegate* proxy_delegate, 1283 ProxyDelegate* proxy_delegate,
1283 const BoundNetLog& net_log) { 1284 const NetLogWithSource& net_log) {
1284 DCHECK(CalledOnValidThread()); 1285 DCHECK(CalledOnValidThread());
1285 1286
1286 // Check to see if we have a new config since ResolveProxy was called. We 1287 // Check to see if we have a new config since ResolveProxy was called. We
1287 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a 1288 // want to re-run ResolveProxy in two cases: 1) we have a new config, or 2) a
1288 // direct connection failed and we never tried the current config. 1289 // direct connection failed and we never tried the current config.
1289 1290
1290 DCHECK(result); 1291 DCHECK(result);
1291 bool re_resolve = result->config_id_ != config_.id(); 1292 bool re_resolve = result->config_id_ != config_.id();
1292 1293
1293 if (re_resolve) { 1294 if (re_resolve) {
(...skipping 13 matching lines...) Expand all
1307 1308
1308 // Return synchronous failure if there is nothing left to fall-back to. 1309 // Return synchronous failure if there is nothing left to fall-back to.
1309 // TODO(eroman): This is a yucky API, clean it up. 1310 // TODO(eroman): This is a yucky API, clean it up.
1310 return did_fallback ? OK : ERR_FAILED; 1311 return did_fallback ? OK : ERR_FAILED;
1311 } 1312 }
1312 1313
1313 bool ProxyService::MarkProxiesAsBadUntil( 1314 bool ProxyService::MarkProxiesAsBadUntil(
1314 const ProxyInfo& result, 1315 const ProxyInfo& result,
1315 base::TimeDelta retry_delay, 1316 base::TimeDelta retry_delay,
1316 const std::vector<ProxyServer>& additional_bad_proxies, 1317 const std::vector<ProxyServer>& additional_bad_proxies,
1317 const BoundNetLog& net_log) { 1318 const NetLogWithSource& net_log) {
1318 result.proxy_list_.UpdateRetryInfoOnFallback(&proxy_retry_info_, retry_delay, 1319 result.proxy_list_.UpdateRetryInfoOnFallback(&proxy_retry_info_, retry_delay,
1319 false, additional_bad_proxies, 1320 false, additional_bad_proxies,
1320 OK, net_log); 1321 OK, net_log);
1321 return result.proxy_list_.size() > (additional_bad_proxies.size() + 1); 1322 return result.proxy_list_.size() > (additional_bad_proxies.size() + 1);
1322 } 1323 }
1323 1324
1324 void ProxyService::ReportSuccess(const ProxyInfo& result, 1325 void ProxyService::ReportSuccess(const ProxyInfo& result,
1325 ProxyDelegate* proxy_delegate) { 1326 ProxyDelegate* proxy_delegate) {
1326 DCHECK(CalledOnValidThread()); 1327 DCHECK(CalledOnValidThread());
1327 1328
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 void ProxyService::RemovePendingRequest(PacRequest* req) { 1373 void ProxyService::RemovePendingRequest(PacRequest* req) {
1373 DCHECK(ContainsPendingRequest(req)); 1374 DCHECK(ContainsPendingRequest(req));
1374 pending_requests_.erase(req); 1375 pending_requests_.erase(req);
1375 } 1376 }
1376 1377
1377 int ProxyService::DidFinishResolvingProxy(const GURL& url, 1378 int ProxyService::DidFinishResolvingProxy(const GURL& url,
1378 const std::string& method, 1379 const std::string& method,
1379 ProxyDelegate* proxy_delegate, 1380 ProxyDelegate* proxy_delegate,
1380 ProxyInfo* result, 1381 ProxyInfo* result,
1381 int result_code, 1382 int result_code,
1382 const BoundNetLog& net_log, 1383 const NetLogWithSource& net_log,
1383 base::TimeTicks start_time, 1384 base::TimeTicks start_time,
1384 bool script_executed) { 1385 bool script_executed) {
1385 // Don't track any metrics if start_time is 0, which will happen when the user 1386 // Don't track any metrics if start_time is 0, which will happen when the user
1386 // calls |TryResolveProxySynchronously|. 1387 // calls |TryResolveProxySynchronously|.
1387 if (!start_time.is_null()) { 1388 if (!start_time.is_null()) {
1388 TimeDelta diff = TimeTicks::Now() - start_time; 1389 TimeDelta diff = TimeTicks::Now() - start_time;
1389 if (script_executed) { 1390 if (script_executed) {
1390 // This function "fixes" the result code, so make sure script terminated 1391 // This function "fixes" the result code, so make sure script terminated
1391 // errors are tracked. Only track result codes that were a result of 1392 // errors are tracked. Only track result codes that were a result of
1392 // script execution. 1393 // script execution.
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 State previous_state = ResetProxyConfig(false); 1670 State previous_state = ResetProxyConfig(false);
1670 if (previous_state != STATE_NONE) 1671 if (previous_state != STATE_NONE)
1671 ApplyProxyConfigIfAvailable(); 1672 ApplyProxyConfigIfAvailable();
1672 } 1673 }
1673 1674
1674 void ProxyService::OnDNSChanged() { 1675 void ProxyService::OnDNSChanged() {
1675 OnIPAddressChanged(); 1676 OnIPAddressChanged();
1676 } 1677 }
1677 1678
1678 } // namespace net 1679 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698