| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 *config = ProxyConfig::CreateDirect(); | 101 *config = ProxyConfig::CreateDirect(); |
| 102 return CONFIG_VALID; | 102 return CONFIG_VALID; |
| 103 } | 103 } |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 // Proxy resolver that fails every time. | 106 // Proxy resolver that fails every time. |
| 107 class ProxyResolverNull : public ProxyResolver { | 107 class ProxyResolverNull : public ProxyResolver { |
| 108 public: | 108 public: |
| 109 ProxyResolverNull() : ProxyResolver(false /*expects_pac_bytes*/) {} | 109 ProxyResolverNull() : ProxyResolver(false /*expects_pac_bytes*/) {} |
| 110 | 110 |
| 111 // ProxyResolver implementation: | 111 // ProxyResolver implementation. |
| 112 virtual int GetProxyForURL(const GURL& url, | 112 virtual int GetProxyForURL(const GURL& url, |
| 113 ProxyInfo* results, | 113 ProxyInfo* results, |
| 114 OldCompletionCallback* callback, | 114 const CompletionCallback& callback, |
| 115 RequestHandle* request, | 115 RequestHandle* request, |
| 116 const BoundNetLog& net_log) OVERRIDE { | 116 const BoundNetLog& net_log) OVERRIDE { |
| 117 return ERR_NOT_IMPLEMENTED; | 117 return ERR_NOT_IMPLEMENTED; |
| 118 } | 118 } |
| 119 | 119 |
| 120 virtual void CancelRequest(RequestHandle request) OVERRIDE { | 120 virtual void CancelRequest(RequestHandle request) OVERRIDE { |
| 121 NOTREACHED(); | 121 NOTREACHED(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { | 124 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { |
| 125 NOTREACHED(); | 125 NOTREACHED(); |
| 126 return LOAD_STATE_IDLE; | 126 return LOAD_STATE_IDLE; |
| 127 } | 127 } |
| 128 | 128 |
| 129 virtual LoadState GetLoadStateThreadSafe( | 129 virtual LoadState GetLoadStateThreadSafe( |
| 130 RequestHandle request) const OVERRIDE { | 130 RequestHandle request) const OVERRIDE { |
| 131 NOTREACHED(); | 131 NOTREACHED(); |
| 132 return LOAD_STATE_IDLE; | 132 return LOAD_STATE_IDLE; |
| 133 } | 133 } |
| 134 | 134 |
| 135 virtual void CancelSetPacScript() OVERRIDE { | 135 virtual void CancelSetPacScript() OVERRIDE { |
| 136 NOTREACHED(); | 136 NOTREACHED(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 virtual int SetPacScript( | 139 virtual int SetPacScript( |
| 140 const scoped_refptr<ProxyResolverScriptData>& /*script_data*/, | 140 const scoped_refptr<ProxyResolverScriptData>& /*script_data*/, |
| 141 OldCompletionCallback* /*callback*/) OVERRIDE { | 141 const CompletionCallback& /*callback*/) OVERRIDE { |
| 142 return ERR_NOT_IMPLEMENTED; | 142 return ERR_NOT_IMPLEMENTED; |
| 143 } | 143 } |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 // ProxyResolver that simulates a PAC script which returns | 146 // ProxyResolver that simulates a PAC script which returns |
| 147 // |pac_string| for every single URL. | 147 // |pac_string| for every single URL. |
| 148 class ProxyResolverFromPacString : public ProxyResolver { | 148 class ProxyResolverFromPacString : public ProxyResolver { |
| 149 public: | 149 public: |
| 150 ProxyResolverFromPacString(const std::string& pac_string) | 150 ProxyResolverFromPacString(const std::string& pac_string) |
| 151 : ProxyResolver(false /*expects_pac_bytes*/), | 151 : ProxyResolver(false /*expects_pac_bytes*/), |
| 152 pac_string_(pac_string) {} | 152 pac_string_(pac_string) {} |
| 153 | 153 |
| 154 virtual int GetProxyForURL(const GURL& url, | 154 virtual int GetProxyForURL(const GURL& url, |
| 155 ProxyInfo* results, | 155 ProxyInfo* results, |
| 156 OldCompletionCallback* callback, | 156 const CompletionCallback& callback, |
| 157 RequestHandle* request, | 157 RequestHandle* request, |
| 158 const BoundNetLog& net_log) OVERRIDE { | 158 const BoundNetLog& net_log) OVERRIDE { |
| 159 results->UsePacString(pac_string_); | 159 results->UsePacString(pac_string_); |
| 160 return OK; | 160 return OK; |
| 161 } | 161 } |
| 162 | 162 |
| 163 virtual void CancelRequest(RequestHandle request) OVERRIDE { | 163 virtual void CancelRequest(RequestHandle request) OVERRIDE { |
| 164 NOTREACHED(); | 164 NOTREACHED(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { | 167 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { |
| 168 NOTREACHED(); | 168 NOTREACHED(); |
| 169 return LOAD_STATE_IDLE; | 169 return LOAD_STATE_IDLE; |
| 170 } | 170 } |
| 171 | 171 |
| 172 virtual LoadState GetLoadStateThreadSafe( | 172 virtual LoadState GetLoadStateThreadSafe( |
| 173 RequestHandle request) const OVERRIDE { | 173 RequestHandle request) const OVERRIDE { |
| 174 NOTREACHED(); | 174 NOTREACHED(); |
| 175 return LOAD_STATE_IDLE; | 175 return LOAD_STATE_IDLE; |
| 176 } | 176 } |
| 177 | 177 |
| 178 virtual void CancelSetPacScript() OVERRIDE { | 178 virtual void CancelSetPacScript() OVERRIDE { |
| 179 NOTREACHED(); | 179 NOTREACHED(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 virtual int SetPacScript( | 182 virtual int SetPacScript( |
| 183 const scoped_refptr<ProxyResolverScriptData>& pac_script, | 183 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 184 OldCompletionCallback* callback) OVERRIDE { | 184 const CompletionCallback& callback) OVERRIDE { |
| 185 return OK; | 185 return OK; |
| 186 } | 186 } |
| 187 | 187 |
| 188 private: | 188 private: |
| 189 const std::string pac_string_; | 189 const std::string pac_string_; |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 // This factory creates V8ProxyResolvers with appropriate javascript bindings. | 192 // This factory creates V8ProxyResolvers with appropriate javascript bindings. |
| 193 class ProxyResolverFactoryForV8 : public ProxyResolverFactory { | 193 class ProxyResolverFactoryForV8 : public ProxyResolverFactory { |
| 194 public: | 194 public: |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 // things similar. It will probably end up changing while solving bug 90581. | 327 // things similar. It will probably end up changing while solving bug 90581. |
| 328 | 328 |
| 329 class ProxyService::InitProxyResolver { | 329 class ProxyService::InitProxyResolver { |
| 330 public: | 330 public: |
| 331 InitProxyResolver(ProxyResolver* proxy_resolver, | 331 InitProxyResolver(ProxyResolver* proxy_resolver, |
| 332 ProxyScriptFetcher* proxy_script_fetcher, | 332 ProxyScriptFetcher* proxy_script_fetcher, |
| 333 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, | 333 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, |
| 334 NetLog* net_log) | 334 NetLog* net_log) |
| 335 : decider_(proxy_script_fetcher, dhcp_proxy_script_fetcher, net_log), | 335 : decider_(proxy_script_fetcher, dhcp_proxy_script_fetcher, net_log), |
| 336 effective_config_(NULL), | 336 effective_config_(NULL), |
| 337 proxy_resolver_(proxy_resolver), | 337 proxy_resolver_(proxy_resolver) { |
| 338 user_callback_(NULL), | |
| 339 ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_( | |
| 340 this, &InitProxyResolver::OnIOCompletion)) { | |
| 341 } | 338 } |
| 342 | 339 |
| 343 ~InitProxyResolver() { | 340 ~InitProxyResolver() { |
| 344 // Note that the destruction of ProxyScriptDecider will automatically cancel | 341 // Note that the destruction of ProxyScriptDecider will automatically cancel |
| 345 // any outstanding work. | 342 // any outstanding work. |
| 346 if (next_state_ == STATE_SET_PAC_SCRIPT_COMPLETE) { | 343 if (next_state_ == STATE_SET_PAC_SCRIPT_COMPLETE) { |
| 347 proxy_resolver_->CancelSetPacScript(); | 344 proxy_resolver_->CancelSetPacScript(); |
| 348 } | 345 } |
| 349 } | 346 } |
| 350 | 347 |
| 351 int Init(const ProxyConfig& config, | 348 int Init(const ProxyConfig& config, |
| 352 base::TimeDelta wait_delay, | 349 base::TimeDelta wait_delay, |
| 353 ProxyConfig* effective_config, | 350 ProxyConfig* effective_config, |
| 354 OldCompletionCallback* callback) { | 351 const CompletionCallback& callback) { |
| 355 config_ = config; | 352 config_ = config; |
| 356 wait_delay_ = wait_delay; | 353 wait_delay_ = wait_delay; |
| 357 effective_config_ = effective_config; | 354 effective_config_ = effective_config; |
| 358 user_callback_ = callback; | 355 callback_ = callback; |
| 359 | 356 |
| 360 next_state_ = STATE_DECIDE_PROXY_SCRIPT; | 357 next_state_ = STATE_DECIDE_PROXY_SCRIPT; |
| 361 return DoLoop(OK); | 358 return DoLoop(OK); |
| 362 } | 359 } |
| 363 | 360 |
| 364 private: | 361 private: |
| 365 enum State { | 362 enum State { |
| 366 STATE_NONE, | 363 STATE_NONE, |
| 367 STATE_DECIDE_PROXY_SCRIPT, | 364 STATE_DECIDE_PROXY_SCRIPT, |
| 368 STATE_DECIDE_PROXY_SCRIPT_COMPLETE, | 365 STATE_DECIDE_PROXY_SCRIPT_COMPLETE, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 398 } | 395 } |
| 399 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 396 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 400 return rv; | 397 return rv; |
| 401 } | 398 } |
| 402 | 399 |
| 403 int DoDecideProxyScript() { | 400 int DoDecideProxyScript() { |
| 404 next_state_ = STATE_DECIDE_PROXY_SCRIPT_COMPLETE; | 401 next_state_ = STATE_DECIDE_PROXY_SCRIPT_COMPLETE; |
| 405 | 402 |
| 406 return decider_.Start( | 403 return decider_.Start( |
| 407 config_, wait_delay_, proxy_resolver_->expects_pac_bytes(), | 404 config_, wait_delay_, proxy_resolver_->expects_pac_bytes(), |
| 408 &io_callback_); | 405 base::Bind(&InitProxyResolver::OnIOCompletion, base::Unretained(this))); |
| 409 } | 406 } |
| 410 | 407 |
| 411 int DoDecideProxyScriptComplete(int result) { | 408 int DoDecideProxyScriptComplete(int result) { |
| 412 if (result != OK) | 409 if (result != OK) |
| 413 return result; | 410 return result; |
| 414 | 411 |
| 415 *effective_config_ = decider_.effective_config(); | 412 *effective_config_ = decider_.effective_config(); |
| 416 next_state_ = STATE_SET_PAC_SCRIPT; | 413 next_state_ = STATE_SET_PAC_SCRIPT; |
| 417 return OK; | 414 return OK; |
| 418 } | 415 } |
| 419 | 416 |
| 420 int DoSetPacScript() { | 417 int DoSetPacScript() { |
| 421 DCHECK(decider_.script_data()); | 418 DCHECK(decider_.script_data()); |
| 422 // TODO(eroman): Should log this latency to the NetLog. | 419 // TODO(eroman): Should log this latency to the NetLog. |
| 423 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; | 420 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; |
| 424 return proxy_resolver_->SetPacScript(decider_.script_data(), &io_callback_); | 421 return proxy_resolver_->SetPacScript( |
| 422 decider_.script_data(), |
| 423 base::Bind(&InitProxyResolver::OnIOCompletion, base::Unretained(this))); |
| 425 } | 424 } |
| 426 | 425 |
| 427 int DoSetPacScriptComplete(int result) { | 426 int DoSetPacScriptComplete(int result) { |
| 428 return result; | 427 return result; |
| 429 } | 428 } |
| 430 | 429 |
| 431 void OnIOCompletion(int result) { | 430 void OnIOCompletion(int result) { |
| 432 DCHECK_NE(STATE_NONE, next_state_); | 431 DCHECK_NE(STATE_NONE, next_state_); |
| 433 int rv = DoLoop(result); | 432 int rv = DoLoop(result); |
| 434 if (rv != ERR_IO_PENDING) | 433 if (rv != ERR_IO_PENDING) |
| 435 DoCallback(rv); | 434 DoCallback(rv); |
| 436 } | 435 } |
| 437 | 436 |
| 438 void DoCallback(int result) { | 437 void DoCallback(int result) { |
| 439 DCHECK_NE(ERR_IO_PENDING, result); | 438 DCHECK_NE(ERR_IO_PENDING, result); |
| 440 user_callback_->Run(result); | 439 callback_.Run(result); |
| 441 } | 440 } |
| 442 | 441 |
| 443 ProxyConfig config_; | 442 ProxyConfig config_; |
| 444 base::TimeDelta wait_delay_; | 443 base::TimeDelta wait_delay_; |
| 445 ProxyScriptDecider decider_; | 444 ProxyScriptDecider decider_; |
| 446 ProxyConfig* effective_config_; | 445 ProxyConfig* effective_config_; |
| 447 ProxyResolver* proxy_resolver_; | 446 ProxyResolver* proxy_resolver_; |
| 448 OldCompletionCallback* user_callback_; | 447 CompletionCallback callback_; |
| 449 OldCompletionCallbackImpl<InitProxyResolver> io_callback_; | |
| 450 State next_state_; | 448 State next_state_; |
| 451 | 449 |
| 452 DISALLOW_COPY_AND_ASSIGN(InitProxyResolver); | 450 DISALLOW_COPY_AND_ASSIGN(InitProxyResolver); |
| 453 }; | 451 }; |
| 454 | 452 |
| 455 // ProxyService::PacRequest --------------------------------------------------- | 453 // ProxyService::PacRequest --------------------------------------------------- |
| 456 | 454 |
| 457 class ProxyService::PacRequest | 455 class ProxyService::PacRequest |
| 458 : public base::RefCounted<ProxyService::PacRequest> { | 456 : public base::RefCounted<ProxyService::PacRequest> { |
| 459 public: | 457 public: |
| 460 PacRequest(ProxyService* service, | 458 PacRequest(ProxyService* service, |
| 461 const GURL& url, | |
| 462 ProxyInfo* results, | |
| 463 OldCompletionCallback* user_callback, | |
| 464 const BoundNetLog& net_log) | |
| 465 : service_(service), | |
| 466 old_user_callback_(user_callback), | |
| 467 ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_( | |
| 468 this, &PacRequest::QueryComplete)), | |
| 469 results_(results), | |
| 470 url_(url), | |
| 471 resolve_job_(NULL), | |
| 472 config_id_(ProxyConfig::kInvalidConfigID), | |
| 473 net_log_(net_log) { | |
| 474 DCHECK(user_callback); | |
| 475 } | |
| 476 | |
| 477 PacRequest(ProxyService* service, | |
| 478 const GURL& url, | 459 const GURL& url, |
| 479 ProxyInfo* results, | 460 ProxyInfo* results, |
| 480 const net::CompletionCallback& user_callback, | 461 const net::CompletionCallback& user_callback, |
| 481 const BoundNetLog& net_log) | 462 const BoundNetLog& net_log) |
| 482 : service_(service), | 463 : service_(service), |
| 483 old_user_callback_(NULL), | |
| 484 user_callback_(user_callback), | 464 user_callback_(user_callback), |
| 485 ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_( | |
| 486 this, &PacRequest::QueryComplete)), | |
| 487 results_(results), | 465 results_(results), |
| 488 url_(url), | 466 url_(url), |
| 489 resolve_job_(NULL), | 467 resolve_job_(NULL), |
| 490 config_id_(ProxyConfig::kInvalidConfigID), | 468 config_id_(ProxyConfig::kInvalidConfigID), |
| 491 net_log_(net_log) { | 469 net_log_(net_log) { |
| 492 DCHECK(!user_callback.is_null()); | 470 DCHECK(!user_callback.is_null()); |
| 493 } | 471 } |
| 494 | 472 |
| 495 // Starts the resolve proxy request. | 473 // Starts the resolve proxy request. |
| 496 int Start() { | 474 int Start() { |
| 497 DCHECK(!was_cancelled()); | 475 DCHECK(!was_cancelled()); |
| 498 DCHECK(!is_started()); | 476 DCHECK(!is_started()); |
| 499 | 477 |
| 500 DCHECK(service_->config_.is_valid()); | 478 DCHECK(service_->config_.is_valid()); |
| 501 | 479 |
| 502 config_id_ = service_->config_.id(); | 480 config_id_ = service_->config_.id(); |
| 503 | 481 |
| 504 return resolver()->GetProxyForURL( | 482 return resolver()->GetProxyForURL( |
| 505 url_, results_, &io_callback_, &resolve_job_, net_log_); | 483 url_, results_, |
| 484 base::Bind(&PacRequest::QueryComplete, base::Unretained(this)), |
| 485 &resolve_job_, net_log_); |
| 506 } | 486 } |
| 507 | 487 |
| 508 bool is_started() const { | 488 bool is_started() const { |
| 509 // Note that !! casts to bool. (VS gives a warning otherwise). | 489 // Note that !! casts to bool. (VS gives a warning otherwise). |
| 510 return !!resolve_job_; | 490 return !!resolve_job_; |
| 511 } | 491 } |
| 512 | 492 |
| 513 void StartAndCompleteCheckingForSynchronous() { | 493 void StartAndCompleteCheckingForSynchronous() { |
| 514 int rv = service_->TryToCompleteSynchronously(url_, results_); | 494 int rv = service_->TryToCompleteSynchronously(url_, results_); |
| 515 if (rv == ERR_IO_PENDING) | 495 if (rv == ERR_IO_PENDING) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 527 } | 507 } |
| 528 | 508 |
| 529 void Cancel() { | 509 void Cancel() { |
| 530 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); | 510 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); |
| 531 | 511 |
| 532 if (is_started()) | 512 if (is_started()) |
| 533 CancelResolveJob(); | 513 CancelResolveJob(); |
| 534 | 514 |
| 535 // Mark as cancelled, to prevent accessing this again later. | 515 // Mark as cancelled, to prevent accessing this again later. |
| 536 service_ = NULL; | 516 service_ = NULL; |
| 537 old_user_callback_ = NULL; | |
| 538 user_callback_.Reset(); | 517 user_callback_.Reset(); |
| 539 results_ = NULL; | 518 results_ = NULL; |
| 540 | 519 |
| 541 net_log_.EndEvent(NetLog::TYPE_PROXY_SERVICE, NULL); | 520 net_log_.EndEvent(NetLog::TYPE_PROXY_SERVICE, NULL); |
| 542 } | 521 } |
| 543 | 522 |
| 544 // Returns true if Cancel() has been called. | 523 // Returns true if Cancel() has been called. |
| 545 bool was_cancelled() const { | 524 bool was_cancelled() const { |
| 546 return old_user_callback_ == NULL && user_callback_.is_null(); | 525 return user_callback_.is_null(); |
| 547 } | 526 } |
| 548 | 527 |
| 549 // Helper to call after ProxyResolver completion (both synchronous and | 528 // Helper to call after ProxyResolver completion (both synchronous and |
| 550 // asynchronous). Fixes up the result that is to be returned to user. | 529 // asynchronous). Fixes up the result that is to be returned to user. |
| 551 int QueryDidComplete(int result_code) { | 530 int QueryDidComplete(int result_code) { |
| 552 DCHECK(!was_cancelled()); | 531 DCHECK(!was_cancelled()); |
| 553 | 532 |
| 554 // Make a note in the results which configuration was in use at the | 533 // Make a note in the results which configuration was in use at the |
| 555 // time of the resolve. | 534 // time of the resolve. |
| 556 results_->config_id_ = config_id_; | 535 results_->config_id_ = config_id_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 574 friend class base::RefCounted<ProxyService::PacRequest>; | 553 friend class base::RefCounted<ProxyService::PacRequest>; |
| 575 | 554 |
| 576 ~PacRequest() {} | 555 ~PacRequest() {} |
| 577 | 556 |
| 578 // Callback for when the ProxyResolver request has completed. | 557 // Callback for when the ProxyResolver request has completed. |
| 579 void QueryComplete(int result_code) { | 558 void QueryComplete(int result_code) { |
| 580 result_code = QueryDidComplete(result_code); | 559 result_code = QueryDidComplete(result_code); |
| 581 | 560 |
| 582 // Remove this completed PacRequest from the service's pending list. | 561 // Remove this completed PacRequest from the service's pending list. |
| 583 /// (which will probably cause deletion of |this|). | 562 /// (which will probably cause deletion of |this|). |
| 584 if (old_user_callback_) { | 563 if (!user_callback_.is_null()){ |
| 585 OldCompletionCallback* callback = old_user_callback_; | |
| 586 service_->RemovePendingRequest(this); | |
| 587 callback->Run(result_code); | |
| 588 } else if (!user_callback_.is_null()){ | |
| 589 net::CompletionCallback callback = user_callback_; | 564 net::CompletionCallback callback = user_callback_; |
| 590 service_->RemovePendingRequest(this); | 565 service_->RemovePendingRequest(this); |
| 591 callback.Run(result_code); | 566 callback.Run(result_code); |
| 592 } | 567 } |
| 593 } | 568 } |
| 594 | 569 |
| 595 ProxyResolver* resolver() const { return service_->resolver_.get(); } | 570 ProxyResolver* resolver() const { return service_->resolver_.get(); } |
| 596 | 571 |
| 597 // Note that we don't hold a reference to the ProxyService. Outstanding | 572 // Note that we don't hold a reference to the ProxyService. Outstanding |
| 598 // requests are cancelled during ~ProxyService, so this is guaranteed | 573 // requests are cancelled during ~ProxyService, so this is guaranteed |
| 599 // to be valid throughout our lifetime. | 574 // to be valid throughout our lifetime. |
| 600 ProxyService* service_; | 575 ProxyService* service_; |
| 601 OldCompletionCallback* old_user_callback_; | |
| 602 net::CompletionCallback user_callback_; | 576 net::CompletionCallback user_callback_; |
| 603 OldCompletionCallbackImpl<PacRequest> io_callback_; | |
| 604 ProxyInfo* results_; | 577 ProxyInfo* results_; |
| 605 GURL url_; | 578 GURL url_; |
| 606 ProxyResolver::RequestHandle resolve_job_; | 579 ProxyResolver::RequestHandle resolve_job_; |
| 607 ProxyConfig::ID config_id_; // The config id when the resolve was started. | 580 ProxyConfig::ID config_id_; // The config id when the resolve was started. |
| 608 BoundNetLog net_log_; | 581 BoundNetLog net_log_; |
| 609 }; | 582 }; |
| 610 | 583 |
| 611 // ProxyService --------------------------------------------------------------- | 584 // ProxyService --------------------------------------------------------------- |
| 612 | 585 |
| 613 ProxyService::ProxyService(ProxyConfigService* config_service, | 586 ProxyService::ProxyService(ProxyConfigService* config_service, |
| 614 ProxyResolver* resolver, | 587 ProxyResolver* resolver, |
| 615 NetLog* net_log) | 588 NetLog* net_log) |
| 616 : resolver_(resolver), | 589 : resolver_(resolver), |
| 617 next_config_id_(1), | 590 next_config_id_(1), |
| 618 ALLOW_THIS_IN_INITIALIZER_LIST(init_proxy_resolver_callback_( | |
| 619 this, &ProxyService::OnInitProxyResolverComplete)), | |
| 620 current_state_(STATE_NONE) , | 591 current_state_(STATE_NONE) , |
| 621 net_log_(net_log), | 592 net_log_(net_log), |
| 622 stall_proxy_auto_config_delay_( | 593 stall_proxy_auto_config_delay_( |
| 623 base::TimeDelta::FromMilliseconds( | 594 base::TimeDelta::FromMilliseconds( |
| 624 kNumMillisToStallAfterNetworkChanges)) { | 595 kNumMillisToStallAfterNetworkChanges)) { |
| 625 NetworkChangeNotifier::AddIPAddressObserver(this); | 596 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 626 ResetConfigService(config_service); | 597 ResetConfigService(config_service); |
| 627 } | 598 } |
| 628 | 599 |
| 629 // static | 600 // static |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 scoped_ptr<ProxyResolver> proxy_resolver( | 704 scoped_ptr<ProxyResolver> proxy_resolver( |
| 734 new ProxyResolverFromPacString(pac_string)); | 705 new ProxyResolverFromPacString(pac_string)); |
| 735 | 706 |
| 736 return new ProxyService(proxy_config_service.release(), | 707 return new ProxyService(proxy_config_service.release(), |
| 737 proxy_resolver.release(), | 708 proxy_resolver.release(), |
| 738 NULL); | 709 NULL); |
| 739 } | 710 } |
| 740 | 711 |
| 741 int ProxyService::ResolveProxy(const GURL& raw_url, | 712 int ProxyService::ResolveProxy(const GURL& raw_url, |
| 742 ProxyInfo* result, | 713 ProxyInfo* result, |
| 743 OldCompletionCallback* callback, | |
| 744 PacRequest** pac_request, | |
| 745 const BoundNetLog& net_log) { | |
| 746 DCHECK(CalledOnValidThread()); | |
| 747 DCHECK(callback); | |
| 748 | |
| 749 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE, NULL); | |
| 750 | |
| 751 config_service_->OnLazyPoll(); | |
| 752 if (current_state_ == STATE_NONE) | |
| 753 ApplyProxyConfigIfAvailable(); | |
| 754 | |
| 755 // Strip away any reference fragments and the username/password, as they | |
| 756 // are not relevant to proxy resolution. | |
| 757 GURL url = SimplifyUrlForRequest(raw_url); | |
| 758 | |
| 759 // Check if the request can be completed right away. (This is the case when | |
| 760 // using a direct connection for example). | |
| 761 int rv = TryToCompleteSynchronously(url, result); | |
| 762 if (rv != ERR_IO_PENDING) | |
| 763 return DidFinishResolvingProxy(result, rv, net_log); | |
| 764 | |
| 765 scoped_refptr<PacRequest> req( | |
| 766 new PacRequest(this, url, result, callback, net_log)); | |
| 767 | |
| 768 if (current_state_ == STATE_READY) { | |
| 769 // Start the resolve request. | |
| 770 rv = req->Start(); | |
| 771 if (rv != ERR_IO_PENDING) | |
| 772 return req->QueryDidComplete(rv); | |
| 773 } else { | |
| 774 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC, | |
| 775 NULL); | |
| 776 } | |
| 777 | |
| 778 DCHECK_EQ(ERR_IO_PENDING, rv); | |
| 779 DCHECK(!ContainsPendingRequest(req)); | |
| 780 pending_requests_.push_back(req); | |
| 781 | |
| 782 // Completion will be notified through |callback|, unless the caller cancels | |
| 783 // the request using |pac_request|. | |
| 784 if (pac_request) | |
| 785 *pac_request = req.get(); | |
| 786 return rv; // ERR_IO_PENDING | |
| 787 } | |
| 788 | |
| 789 int ProxyService::ResolveProxy(const GURL& raw_url, | |
| 790 ProxyInfo* result, | |
| 791 const net::CompletionCallback& callback, | 714 const net::CompletionCallback& callback, |
| 792 PacRequest** pac_request, | 715 PacRequest** pac_request, |
| 793 const BoundNetLog& net_log) { | 716 const BoundNetLog& net_log) { |
| 794 DCHECK(CalledOnValidThread()); | 717 DCHECK(CalledOnValidThread()); |
| 795 DCHECK(!callback.is_null()); | 718 DCHECK(!callback.is_null()); |
| 796 | 719 |
| 797 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE, NULL); | 720 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE, NULL); |
| 798 | 721 |
| 799 config_service_->OnLazyPoll(); | 722 config_service_->OnLazyPoll(); |
| 800 if (current_state_ == STATE_NONE) | 723 if (current_state_ == STATE_NONE) |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 new InitProxyResolver(resolver_.get(), | 1158 new InitProxyResolver(resolver_.get(), |
| 1236 proxy_script_fetcher_.get(), | 1159 proxy_script_fetcher_.get(), |
| 1237 dhcp_proxy_script_fetcher_.get(), | 1160 dhcp_proxy_script_fetcher_.get(), |
| 1238 net_log_)); | 1161 net_log_)); |
| 1239 | 1162 |
| 1240 // If we changed networks recently, we should delay running proxy auto-config. | 1163 // If we changed networks recently, we should delay running proxy auto-config. |
| 1241 base::TimeDelta wait_delay = | 1164 base::TimeDelta wait_delay = |
| 1242 stall_proxy_autoconfig_until_ - base::TimeTicks::Now(); | 1165 stall_proxy_autoconfig_until_ - base::TimeTicks::Now(); |
| 1243 | 1166 |
| 1244 int rv = init_proxy_resolver_->Init( | 1167 int rv = init_proxy_resolver_->Init( |
| 1245 fetched_config_, wait_delay, &config_, &init_proxy_resolver_callback_); | 1168 fetched_config_, wait_delay, &config_, |
| 1169 base::Bind(&ProxyService::OnInitProxyResolverComplete, |
| 1170 base::Unretained(this))); |
| 1246 | 1171 |
| 1247 if (rv != ERR_IO_PENDING) | 1172 if (rv != ERR_IO_PENDING) |
| 1248 OnInitProxyResolverComplete(rv); | 1173 OnInitProxyResolverComplete(rv); |
| 1249 } | 1174 } |
| 1250 | 1175 |
| 1251 void ProxyService::OnIPAddressChanged() { | 1176 void ProxyService::OnIPAddressChanged() { |
| 1252 // See the comment block by |kNumMillisToStallAfterNetworkChanges| for info. | 1177 // See the comment block by |kNumMillisToStallAfterNetworkChanges| for info. |
| 1253 stall_proxy_autoconfig_until_ = | 1178 stall_proxy_autoconfig_until_ = |
| 1254 base::TimeTicks::Now() + stall_proxy_auto_config_delay_; | 1179 base::TimeTicks::Now() + stall_proxy_auto_config_delay_; |
| 1255 | 1180 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1267 base::Bind(&SyncProxyServiceHelper::OnCompletion, | 1192 base::Bind(&SyncProxyServiceHelper::OnCompletion, |
| 1268 base::Unretained(this)))) { | 1193 base::Unretained(this)))) { |
| 1269 DCHECK(io_message_loop_ != MessageLoop::current()); | 1194 DCHECK(io_message_loop_ != MessageLoop::current()); |
| 1270 } | 1195 } |
| 1271 | 1196 |
| 1272 int SyncProxyServiceHelper::ResolveProxy(const GURL& url, | 1197 int SyncProxyServiceHelper::ResolveProxy(const GURL& url, |
| 1273 ProxyInfo* proxy_info, | 1198 ProxyInfo* proxy_info, |
| 1274 const BoundNetLog& net_log) { | 1199 const BoundNetLog& net_log) { |
| 1275 DCHECK(io_message_loop_ != MessageLoop::current()); | 1200 DCHECK(io_message_loop_ != MessageLoop::current()); |
| 1276 | 1201 |
| 1277 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 1202 io_message_loop_->PostTask( |
| 1278 this, &SyncProxyServiceHelper::StartAsyncResolve, url, net_log)); | 1203 FROM_HERE, |
| 1204 base::Bind(&SyncProxyServiceHelper::StartAsyncResolve, this, url, |
| 1205 net_log)); |
| 1279 | 1206 |
| 1280 event_.Wait(); | 1207 event_.Wait(); |
| 1281 | 1208 |
| 1282 if (result_ == net::OK) { | 1209 if (result_ == net::OK) { |
| 1283 *proxy_info = proxy_info_; | 1210 *proxy_info = proxy_info_; |
| 1284 } | 1211 } |
| 1285 return result_; | 1212 return result_; |
| 1286 } | 1213 } |
| 1287 | 1214 |
| 1288 int SyncProxyServiceHelper::ReconsiderProxyAfterError( | 1215 int SyncProxyServiceHelper::ReconsiderProxyAfterError( |
| 1289 const GURL& url, ProxyInfo* proxy_info, const BoundNetLog& net_log) { | 1216 const GURL& url, ProxyInfo* proxy_info, const BoundNetLog& net_log) { |
| 1290 DCHECK(io_message_loop_ != MessageLoop::current()); | 1217 DCHECK(io_message_loop_ != MessageLoop::current()); |
| 1291 | 1218 |
| 1292 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 1219 io_message_loop_->PostTask( |
| 1293 this, &SyncProxyServiceHelper::StartAsyncReconsider, url, net_log)); | 1220 FROM_HERE, |
| 1221 base::Bind(&SyncProxyServiceHelper::StartAsyncReconsider, this, url, |
| 1222 net_log)); |
| 1294 | 1223 |
| 1295 event_.Wait(); | 1224 event_.Wait(); |
| 1296 | 1225 |
| 1297 if (result_ == net::OK) { | 1226 if (result_ == net::OK) { |
| 1298 *proxy_info = proxy_info_; | 1227 *proxy_info = proxy_info_; |
| 1299 } | 1228 } |
| 1300 return result_; | 1229 return result_; |
| 1301 } | 1230 } |
| 1302 | 1231 |
| 1303 SyncProxyServiceHelper::~SyncProxyServiceHelper() {} | 1232 SyncProxyServiceHelper::~SyncProxyServiceHelper() {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1319 OnCompletion(result_); | 1248 OnCompletion(result_); |
| 1320 } | 1249 } |
| 1321 } | 1250 } |
| 1322 | 1251 |
| 1323 void SyncProxyServiceHelper::OnCompletion(int rv) { | 1252 void SyncProxyServiceHelper::OnCompletion(int rv) { |
| 1324 result_ = rv; | 1253 result_ = rv; |
| 1325 event_.Signal(); | 1254 event_.Signal(); |
| 1326 } | 1255 } |
| 1327 | 1256 |
| 1328 } // namespace net | 1257 } // namespace net |
| OLD | NEW |