| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 DCHECK(!was_cancelled()); | 151 DCHECK(!was_cancelled()); |
| 152 | 152 |
| 153 // Make a note in the results which configuration was in use at the | 153 // Make a note in the results which configuration was in use at the |
| 154 // time of the resolve. | 154 // time of the resolve. |
| 155 results_->config_id_ = config_id_; | 155 results_->config_id_ = config_id_; |
| 156 | 156 |
| 157 // Reset the state associated with in-progress-resolve. | 157 // Reset the state associated with in-progress-resolve. |
| 158 resolve_job_ = NULL; | 158 resolve_job_ = NULL; |
| 159 config_id_ = ProxyConfig::INVALID_ID; | 159 config_id_ = ProxyConfig::INVALID_ID; |
| 160 | 160 |
| 161 // Clean up the results list. | 161 return service_->DidFinishResolvingProxy(results_, result_code, load_log_); |
| 162 if (result_code == OK) | |
| 163 results_->RemoveBadProxies(service_->proxy_retry_info_); | |
| 164 | |
| 165 LoadLog::EndEvent(load_log_, LoadLog::TYPE_PROXY_SERVICE); | |
| 166 | |
| 167 return result_code; | |
| 168 } | 162 } |
| 169 | 163 |
| 170 LoadLog* load_log() const { return load_log_; } | 164 LoadLog* load_log() const { return load_log_; } |
| 171 | 165 |
| 172 private: | 166 private: |
| 173 friend class base::RefCounted<ProxyService::PacRequest>; | 167 friend class base::RefCounted<ProxyService::PacRequest>; |
| 174 | 168 |
| 175 ~PacRequest() {} | 169 ~PacRequest() {} |
| 176 | 170 |
| 177 // Callback for when the ProxyResolver request has completed. | 171 // Callback for when the ProxyResolver request has completed. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 LoadLog::BeginEvent(load_log, LoadLog::TYPE_PROXY_SERVICE); | 264 LoadLog::BeginEvent(load_log, LoadLog::TYPE_PROXY_SERVICE); |
| 271 | 265 |
| 272 // Strip away any reference fragments and the username/password, as they | 266 // Strip away any reference fragments and the username/password, as they |
| 273 // are not relevant to proxy resolution. | 267 // are not relevant to proxy resolution. |
| 274 GURL url = SimplifyUrlForRequest(raw_url); | 268 GURL url = SimplifyUrlForRequest(raw_url); |
| 275 | 269 |
| 276 // Check if the request can be completed right away. This is the case when | 270 // Check if the request can be completed right away. This is the case when |
| 277 // using a direct connection, or when the config is bad. | 271 // using a direct connection, or when the config is bad. |
| 278 UpdateConfigIfOld(load_log); | 272 UpdateConfigIfOld(load_log); |
| 279 int rv = TryToCompleteSynchronously(url, result); | 273 int rv = TryToCompleteSynchronously(url, result); |
| 280 if (rv != ERR_IO_PENDING) { | 274 if (rv != ERR_IO_PENDING) |
| 281 LoadLog::EndEvent(load_log, LoadLog::TYPE_PROXY_SERVICE); | 275 return DidFinishResolvingProxy(result, rv, load_log); |
| 282 return rv; | |
| 283 } | |
| 284 | 276 |
| 285 scoped_refptr<PacRequest> req = | 277 scoped_refptr<PacRequest> req = |
| 286 new PacRequest(this, url, result, callback, load_log); | 278 new PacRequest(this, url, result, callback, load_log); |
| 287 | 279 |
| 288 bool resolver_is_ready = !IsInitializingProxyResolver(); | 280 bool resolver_is_ready = !IsInitializingProxyResolver(); |
| 289 | 281 |
| 290 if (resolver_is_ready) { | 282 if (resolver_is_ready) { |
| 291 // Start the resolve request. | 283 // Start the resolve request. |
| 292 rv = req->Start(); | 284 rv = req->Start(); |
| 293 if (rv != ERR_IO_PENDING) | 285 if (rv != ERR_IO_PENDING) |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 return pending_requests_.end() != it; | 462 return pending_requests_.end() != it; |
| 471 } | 463 } |
| 472 | 464 |
| 473 void ProxyService::RemovePendingRequest(PacRequest* req) { | 465 void ProxyService::RemovePendingRequest(PacRequest* req) { |
| 474 DCHECK(ContainsPendingRequest(req)); | 466 DCHECK(ContainsPendingRequest(req)); |
| 475 PendingRequests::iterator it = std::find( | 467 PendingRequests::iterator it = std::find( |
| 476 pending_requests_.begin(), pending_requests_.end(), req); | 468 pending_requests_.begin(), pending_requests_.end(), req); |
| 477 pending_requests_.erase(it); | 469 pending_requests_.erase(it); |
| 478 } | 470 } |
| 479 | 471 |
| 472 int ProxyService::DidFinishResolvingProxy(ProxyInfo* result, |
| 473 int result_code, |
| 474 LoadLog* load_log) { |
| 475 // Log the result of the proxy resolution. |
| 476 if (result_code == OK) { |
| 477 // When full logging is enabled, dump the proxy list. |
| 478 if (LoadLog::IsUnbounded(load_log)) { |
| 479 LoadLog::AddString( |
| 480 load_log, |
| 481 std::string("Resolved proxy list: ") + result->ToPacString()); |
| 482 } |
| 483 } else { |
| 484 LoadLog::AddErrorCode(load_log, result_code); |
| 485 } |
| 486 |
| 487 // Clean up the results list. |
| 488 if (result_code == OK) |
| 489 result->RemoveBadProxies(proxy_retry_info_); |
| 490 |
| 491 LoadLog::EndEvent(load_log, LoadLog::TYPE_PROXY_SERVICE); |
| 492 return result_code; |
| 493 } |
| 494 |
| 480 void ProxyService::SetProxyScriptFetcher( | 495 void ProxyService::SetProxyScriptFetcher( |
| 481 ProxyScriptFetcher* proxy_script_fetcher) { | 496 ProxyScriptFetcher* proxy_script_fetcher) { |
| 482 if (init_proxy_resolver_.get()) { | 497 if (init_proxy_resolver_.get()) { |
| 483 // We need to be careful to first cancel |init_proxy_resolver_|, since it | 498 // We need to be careful to first cancel |init_proxy_resolver_|, since it |
| 484 // holds a pointer to the old proxy script fetcher we are about to delete. | 499 // holds a pointer to the old proxy script fetcher we are about to delete. |
| 485 | 500 |
| 486 DCHECK(IsInitializingProxyResolver()); | 501 DCHECK(IsInitializingProxyResolver()); |
| 487 init_proxy_resolver_.reset(); | 502 init_proxy_resolver_.reset(); |
| 488 proxy_script_fetcher_.reset(proxy_script_fetcher); | 503 proxy_script_fetcher_.reset(proxy_script_fetcher); |
| 489 | 504 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 OnCompletion(result_); | 794 OnCompletion(result_); |
| 780 } | 795 } |
| 781 } | 796 } |
| 782 | 797 |
| 783 void SyncProxyServiceHelper::OnCompletion(int rv) { | 798 void SyncProxyServiceHelper::OnCompletion(int rv) { |
| 784 result_ = rv; | 799 result_ = rv; |
| 785 event_.Signal(); | 800 event_.Signal(); |
| 786 } | 801 } |
| 787 | 802 |
| 788 } // namespace net | 803 } // namespace net |
| OLD | NEW |